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/internal/testbinapi/binapi2001/interface"
29 // CliInband represents VPP binary API message 'cli_inband'.
30 type CliInband struct {
31 XXX_CmdLen uint32 `struc:"sizeof=Cmd"`
35 func (m *CliInband) Reset() { *m = CliInband{} }
36 func (*CliInband) GetMessageName() string { return "cli_inband" }
37 func (*CliInband) GetCrcString() string { return "f8377302" }
38 func (*CliInband) GetMessageType() api.MessageType { return api.RequestMessage }
40 // CliInbandReply represents VPP binary API message 'cli_inband_reply'.
41 type CliInbandReply struct {
43 XXX_ReplyLen uint32 `struc:"sizeof=Reply"`
47 func (m *CliInbandReply) Reset() { *m = CliInbandReply{} }
48 func (*CliInbandReply) GetMessageName() string { return "cli_inband_reply" }
49 func (*CliInbandReply) GetCrcString() string { return "05879051" }
50 func (*CliInbandReply) GetMessageType() api.MessageType { return api.ReplyMessage }
52 func TestWrapperEncode(t *testing.T) {
57 expectedData := []byte{
59 0x00, 0x00, 0x00, 0x00,
60 0x00, 0x00, 0x00, 0x00,
61 0x00, 0x00, 0x00, 0x05,
62 0x61, 0x62, 0x63, 0x64, 0x65,
65 c := codec.DefaultCodec
67 data, err := c.EncodeMsg(msg, 100)
69 t.Fatalf("EncodeMsg failed: %v", err)
71 if !bytes.Equal(data, expectedData) {
72 t.Fatalf("unexpected encoded data,\nexpected: % 02x\n got: % 02x\n", expectedData, data)
76 func TestWrapperDecode(t *testing.T) {
79 0x00, 0x00, 0x00, 0x00,
80 0x00, 0x00, 0x00, 0x00,
81 0x00, 0x00, 0x00, 0x05,
82 0x61, 0x62, 0x63, 0x64, 0x65,
84 expectedMsg := &CliInbandReply{
90 c := codec.DefaultCodec
92 msg := new(CliInbandReply)
93 err := c.DecodeMsg(data, msg)
95 t.Fatalf("DecodeMsg failed: %v", err)
97 if !reflect.DeepEqual(msg, expectedMsg) {
98 t.Fatalf("unexpected decoded msg,\nexpected: %+v\n got: %+v\n", expectedMsg, msg)
102 func TestNewCodecEncodeDecode4(t *testing.T) {
103 m := &interfaces.SwInterfaceSetRxMode{
104 Mode: interfaces.RX_MODE_API_POLLING,
110 b := make([]byte, 2+m.Size())
112 data, err := m.Marshal(b[2:])
114 t.Fatalf("expected nil error, got: %v", err)
117 t.Logf("ENCODED DATA(%d): % 03x", len(data), data)
119 var m2 interfaces.SwInterfaceSetRxMode
120 if err := m2.Unmarshal(b[2:]); err != nil {
121 t.Fatalf("expected nil error, got: %v", err)
124 t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
126 if !reflect.DeepEqual(m, &m2) {
127 t.Fatalf("newData differs from oldData")
131 func TestNewCodecEncodeDecode2(t *testing.T) {
132 m := &sr.SrPoliciesDetails{
133 Bsid: ip_types.IP6Address{00, 11, 22, 33, 44, 55, 66, 77, 88, 99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
138 SidLists: []sr.Srv6SidList{
142 Sids: [16]ip_types.IP6Address{
144 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16},
150 b := make([]byte, m.Size())
151 data, err := m.Marshal(b)
153 t.Fatalf("expected nil error, got: %v", err)
156 t.Logf("ENCODED DATA(%d): % 03x", len(data), data)
158 var m2 sr.SrPoliciesDetails
159 if err := m2.Unmarshal(data); err != nil {
160 t.Fatalf("expected nil error, got: %v", err)
163 t.Logf("Data:\nOLD: %+v\nNEW: %+v", m, &m2)
165 if !reflect.DeepEqual(m, &m2) {
166 t.Fatalf("newData differs from oldData")