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.
22 "git.fd.io/govpp.git/api"
23 "git.fd.io/govpp.git/binapi/ip_types"
24 "git.fd.io/govpp.git/binapi/sr"
25 "git.fd.io/govpp.git/codec"
26 "git.fd.io/govpp.git/internal/testbinapi/binapi2001/interfaces"
27 "git.fd.io/govpp.git/internal/testbinapi/binapi2001/ip"
30 // CliInband represents VPP binary API message 'cli_inband'.
31 type CliInband struct {
32 XXX_CmdLen uint32 `struc:"sizeof=Cmd"`
36 func (m *CliInband) Reset() { *m = CliInband{} }
37 func (*CliInband) GetMessageName() string { return "cli_inband" }
38 func (*CliInband) GetCrcString() string { return "f8377302" }
39 func (*CliInband) GetMessageType() api.MessageType { return api.RequestMessage }
41 // CliInbandReply represents VPP binary API message 'cli_inband_reply'.
42 type CliInbandReply struct {
44 XXX_ReplyLen uint32 `struc:"sizeof=Reply"`
48 func (m *CliInbandReply) Reset() { *m = CliInbandReply{} }
49 func (*CliInbandReply) GetMessageName() string { return "cli_inband_reply" }
50 func (*CliInbandReply) GetCrcString() string { return "05879051" }
51 func (*CliInbandReply) GetMessageType() api.MessageType { return api.ReplyMessage }
53 func TestWrapperEncode(t *testing.T) {
58 expectedData := []byte{
60 0x00, 0x00, 0x00, 0x00,
61 0x00, 0x00, 0x00, 0x00,
62 0x00, 0x00, 0x00, 0x05,
63 0x61, 0x62, 0x63, 0x64, 0x65,
66 c := codec.DefaultCodec
68 data, err := c.EncodeMsg(msg, 100)
70 t.Fatalf("EncodeMsg failed: %v", err)
72 if !bytes.Equal(data, expectedData) {
73 t.Fatalf("unexpected encoded data,\nexpected: % 02x\n got: % 02x\n", expectedData, data)
77 func TestWrapperDecode(t *testing.T) {
80 0x00, 0x00, 0x00, 0x00,
81 0x00, 0x00, 0x00, 0x00,
82 0x00, 0x00, 0x00, 0x05,
83 0x61, 0x62, 0x63, 0x64, 0x65,
85 expectedMsg := &CliInbandReply{
91 c := codec.DefaultCodec
93 msg := new(CliInbandReply)
94 err := c.DecodeMsg(data, msg)
96 t.Fatalf("DecodeMsg failed: %v", err)
98 if !reflect.DeepEqual(msg, expectedMsg) {
99 t.Fatalf("unexpected decoded msg,\nexpected: %+v\n got: %+v\n", expectedMsg, msg)
103 func TestNewCodecEncodeDecode4(t *testing.T) {
104 m := &interfaces.SwInterfaceSetRxMode{
105 Mode: interfaces.RX_MODE_API_POLLING,
111 b := make([]byte, 2+m.Size())
113 data, err := m.Marshal(b[2:])
115 t.Fatalf("expected nil error, got: %v", err)
118 t.Logf("ENCODED DATA(%d): % 03x", len(data), data)
120 var m2 interfaces.SwInterfaceSetRxMode
121 if err := m2.Unmarshal(b[2:]); err != nil {
122 t.Fatalf("expected nil error, got: %v", err)
125 t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
127 if !reflect.DeepEqual(m, &m2) {
128 t.Fatalf("newData differs from oldData")
132 func TestNewCodecEncodeDecode2(t *testing.T) {
133 m := &sr.SrPoliciesDetails{
134 Bsid: ip_types.IP6Address{00, 11, 22, 33, 44, 55, 66, 77, 88, 99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
139 SidLists: []sr.Srv6SidList{
143 Sids: [16]ip_types.IP6Address{
145 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
151 b := make([]byte, m.Size())
152 data, err := m.Marshal(b)
154 t.Fatalf("expected nil error, got: %v", err)
157 t.Logf("ENCODED DATA(%d): % 03x", len(data), data)
159 var m2 sr.SrPoliciesDetails
160 if err := m2.Unmarshal(data); err != nil {
161 t.Fatalf("expected nil error, got: %v", err)
164 t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
166 if !reflect.DeepEqual(m, &m2) {
167 t.Fatalf("newData differs from oldData")
171 func TestNewCodecEncode(t *testing.T) {
172 m := NewIPRouteLookupReply()
173 /*m := &sr.SrPoliciesDetails{
174 Bsid: sr.IP6Address{00, 11, 22, 33, 44, 55, 66, 77, 88, 99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
179 SidLists: []sr.Srv6SidList{
183 Sids: [16]sr.IP6Address{
185 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
192 var oldData, newData []byte
194 w := codec.Wrapper{m}
196 t.Logf("wrapper size: %d", size)
197 oldData, err = w.Marshal(nil)
199 t.Fatalf("expected nil error, got: %v", err)
204 t.Logf("size: %d", size)
205 newData, err = m.Marshal(nil)
207 t.Fatalf("expected nil error, got: %v", err)
210 t.Logf("Data:\nOLD[%d]: % 03x\nNEW[%d]: % 03x", len(oldData), oldData, len(newData), newData)
212 if !bytes.Equal(oldData, newData) {
213 t.Fatalf("newData differs from oldData")
217 func TestNewCodecDecode(t *testing.T) {
219 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03,
220 0x00, 0x00, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00,
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x01, 0x00,
223 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00,
224 0x00, 0x00, 0x08, 0x09, 0x0a, 0x00, 0x00, 0x00,
225 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
226 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
228 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
229 0x01, 0x00, 0x00, 0x00, 0x02, 0x01, 0x09, 0x00,
230 0x00, 0x00, 0x08, 0x07, 0x06, 0x00, 0x00, 0x00,
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
238 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
239 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
240 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247 var oldData, newData ip.IPRouteAddDel
249 w := codec.Wrapper{&oldData}
250 err = w.Unmarshal(data)
252 t.Errorf("expected nil error, got: %v", err)
256 err = newData.Unmarshal(data)
258 t.Errorf("expected nil error, got: %v", err)
261 t.Logf("Data:\nOLD: %+v\nNEW: %+v", oldData, newData)
263 if !reflect.DeepEqual(oldData, newData) {
264 t.Fatalf("newData differs from oldData")
268 func NewIPRouteLookupReply() *ip.IPRouteAddDel {
269 return &ip.IPRouteAddDel{
276 Un: ip.AddressUnion{},
292 Address: ip.AddressUnion{},
295 ClassifyTableIndex: 2,
298 LabelStack: [16]ip.FibMplsLabel{
317 Address: ip.AddressUnion{},
320 ClassifyTableIndex: 2,
323 LabelStack: [16]ip.FibMplsLabel{