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 "github.com/sirupsen/logrus"
22 "git.fd.io/govpp.git/binapigen/vppapi"
26 serviceEventPrefix = "want_"
27 serviceDumpSuffix = "_dump"
28 serviceDetailsSuffix = "_details"
29 serviceReplySuffix = "_reply"
32 func validateService(svc vppapi.Service) {
33 for _, rpc := range svc.RPCs {
38 func validateRPC(rpc vppapi.RPC) {
39 if len(rpc.Events) > 0 {
41 if !strings.HasPrefix(rpc.RequestMsg, serviceEventPrefix) {
42 logrus.Warnf("unusual EVENTS service: %+v\n"+
43 "- events service %q does not have %q prefix in request.",
44 rpc, rpc.Name, serviceEventPrefix)
46 } else if rpc.Stream {
48 if !strings.HasSuffix(rpc.RequestMsg, serviceDumpSuffix) {
49 logrus.Warnf("unusual STREAM service: %+v\n"+
50 "- stream service %q does not have %q suffix in request.",
51 rpc, rpc.Name, serviceDumpSuffix)
53 if !strings.HasSuffix(rpc.ReplyMsg, serviceDetailsSuffix) && !strings.HasSuffix(rpc.StreamMsg, serviceDetailsSuffix) {
54 logrus.Warnf("unusual STREAM service: %+v\n"+
55 "- stream service %q does not have %q suffix in reply or stream msg.",
56 rpc, rpc.Name, serviceDetailsSuffix)
58 } else if rpc.ReplyMsg != "" {
60 // some messages might have `null` reply (for example: memclnt)
61 if !strings.HasSuffix(rpc.ReplyMsg, serviceReplySuffix) {
62 logrus.Warnf("unusual REQUEST service: %+v\n"+
63 "- service %q does not have %q suffix in reply.",
64 rpc, rpc.Name, serviceReplySuffix)