1 // Copyright (c) 2020 Cisco and/or its affiliates.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at:
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
20 "git.fd.io/govpp.git/binapigen/vppapi"
21 "github.com/sirupsen/logrus"
25 serviceEventPrefix = "want_"
26 serviceDumpSuffix = "_dump"
27 serviceDetailsSuffix = "_details"
28 serviceReplySuffix = "_reply"
31 func validateService(svc vppapi.Service) {
32 for _, rpc := range svc.RPCs {
37 func validateRPC(rpc vppapi.RPC) {
38 if len(rpc.Events) > 0 {
40 if !strings.HasPrefix(rpc.RequestMsg, serviceEventPrefix) {
41 logrus.Warnf("unusual EVENTS service: %+v\n"+
42 "- events service %q does not have %q prefix in request.",
43 rpc, rpc.Name, serviceEventPrefix)
45 } else if rpc.Stream {
47 if !strings.HasSuffix(rpc.RequestMsg, serviceDumpSuffix) {
48 logrus.Warnf("unusual STREAM service: %+v\n"+
49 "- stream service %q does not have %q suffix in request.",
50 rpc, rpc.Name, serviceDumpSuffix)
52 if !strings.HasSuffix(rpc.ReplyMsg, serviceDetailsSuffix) && !strings.HasSuffix(rpc.StreamMsg, serviceDetailsSuffix) {
53 logrus.Warnf("unusual STREAM service: %+v\n"+
54 "- stream service %q does not have %q suffix in reply or stream msg.",
55 rpc, rpc.Name, serviceDetailsSuffix)
57 } else if rpc.ReplyMsg != "" {
59 // some messages might have `null` reply (for example: memclnt)
60 if !strings.HasSuffix(rpc.ReplyMsg, serviceReplySuffix) {
61 logrus.Warnf("unusual REQUEST service: %+v\n"+
62 "- service %q does not have %q suffix in reply.",
63 rpc, rpc.Name, serviceReplySuffix)