From 94620e85f0bdbb054af07ce3670fadc1f76cfdf0 Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Thu, 18 Jun 2020 08:22:13 +0200 Subject: Refactored binapi generator with message encoding Change-Id: I5a6abb68b9d058866f94818169300e5c2fc43895 Signed-off-by: Ondrej Fabry --- codec/msg_codec_test.go | 81 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 4 deletions(-) (limited to 'codec/msg_codec_test.go') diff --git a/codec/msg_codec_test.go b/codec/msg_codec_test.go index cd1240e..bf0695d 100644 --- a/codec/msg_codec_test.go +++ b/codec/msg_codec_test.go @@ -1,10 +1,16 @@ -package codec +package codec_test import ( "bytes" "testing" + "github.com/lunixbochs/struc" + "git.fd.io/govpp.git/api" + "git.fd.io/govpp.git/codec" + "git.fd.io/govpp.git/examples/binapi/ip" + "git.fd.io/govpp.git/examples/binapi/sr" + "git.fd.io/govpp.git/examples/binapi/vpe" ) type MyMsg struct { @@ -30,15 +36,69 @@ func TestEncode(t *testing.T) { msgID uint16 expData []byte }{ - {name: "basic", + /*{name: "basic", msg: &MyMsg{Index: 1, Label: []byte("Abcdef"), Port: 1000}, msgID: 100, expData: []byte{0x00, 0x64, 0x00, 0x01, 0x41, 0x62, 0x63, 0x64, 0x65, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE8}, + },*/ + {name: "show version", + msg: &vpe.ShowVersion{}, + msgID: 743, + expData: []byte{0x02, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, + }, + {name: "ip route", + msg: &ip.IPRouteAddDel{ + IsAdd: true, + IsMultipath: true, + Route: ip.IPRoute{ + TableID: 0, + StatsIndex: 0, + Prefix: ip.Prefix{}, + NPaths: 0, + Paths: []ip.FibPath{ + { + SwIfIndex: 0, + TableID: 0, + RpfID: 0, + Weight: 0, + Preference: 0, + Type: 0, + Flags: 0, + Proto: 0, + Nh: ip.FibPathNh{}, + NLabels: 5, + LabelStack: [16]ip.FibMplsLabel{ + { + IsUniform: 1, + Label: 2, + TTL: 3, + Exp: 4, + }, + }, + }, + }, + }, + }, + msgID: 743, + expData: []byte{0x02, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, }, + /*{name: "sr", + msg: &sr.SrPolicyAdd{ + BsidAddr: sr.IP6Address{}, + Weight: 0, + IsEncap: false, + IsSpray: false, + FibTable: 0, + Sids: sr.Srv6SidList{}, + }, + msgID: 99, + expData: []byte{0x00, 0x64, 0x00, 0x01, 0x41, 0x62, 0x63, 0x64, 0x65, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xE8}, + },*/ } for _, test := range tests { t.Run(test.name, func(t *testing.T) { - c := &MsgCodec{} + c := &codec.MsgCodec{} + //c := &codec.NewCodec{} data, err := c.EncodeMsg(test.msg, test.msgID) if err != nil { @@ -52,7 +112,7 @@ func TestEncode(t *testing.T) { } func TestEncodePanic(t *testing.T) { - c := &MsgCodec{} + c := &codec.MsgCodec{} msg := &MyMsg{Index: 1, Label: []byte("thisIsLongerThan16Bytes"), Port: 1000} @@ -61,3 +121,16 @@ func TestEncodePanic(t *testing.T) { t.Fatalf("expected non-nil error, got: %v", err) } } + +func TestEncodeSr(t *testing.T) { + msg := sr.Srv6SidList{ + NumSids: 0, + Weight: 0, + //Sids: nil, + } + buf := new(bytes.Buffer) + + if err := struc.Pack(buf, msg); err != nil { + t.Fatal(err) + } +} -- cgit 1.2.3-korg