socket adapter: don't bother sending sockclnt_delete messages
[govpp.git] / binapigen / validate.go
1 //  Copyright (c) 2020 Cisco and/or its affiliates.
2 //
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:
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14
15 package binapigen
16
17 import (
18         "strings"
19
20         "github.com/sirupsen/logrus"
21
22         "git.fd.io/govpp.git/binapigen/vppapi"
23 )
24
25 const (
26         serviceEventPrefix   = "want_"
27         serviceDumpSuffix    = "_dump"
28         serviceDetailsSuffix = "_details"
29         serviceReplySuffix   = "_reply"
30 )
31
32 func validateService(svc vppapi.Service) {
33         for _, rpc := range svc.RPCs {
34                 validateRPC(rpc)
35         }
36 }
37
38 func validateRPC(rpc vppapi.RPC) {
39         if len(rpc.Events) > 0 {
40                 // EVENT service
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)
45                 }
46         } else if rpc.Stream {
47                 // STREAM service
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)
52                 }
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)
57                 }
58         } else if rpc.ReplyMsg != "" {
59                 // REQUEST service
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)
65                 }
66         }
67 }