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 interfaces "git.fd.io/govpp.git/binapi/interface"
27 "git.fd.io/govpp.git/binapi/interface_types"
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: interface_types.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")