summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSerguei Bezverkhi <sbezverk@cisco.com>2020-11-29 10:07:59 -0500
committerFUJITA Tomonori <fujita.tomonori@gmail.com>2020-11-30 07:21:40 +0900
commitcb0c7ce51f8900210ac5ea94022c520d4e599857 (patch)
tree63967ec84c82fb3b48936caa2c94f6bbb13cd051
parent0422c608b302cd02b5bc3cd7063714d04c7fd595 (diff)
Unit tests and dependencies
Signed-off-by: Serguei Bezverkhi <sbezverk@cisco.com>
-rw-r--r--go.mod23
-rw-r--r--go.sum49
-rw-r--r--pkg/packet/bgp/sr_policy_test.go219
3 files changed, 265 insertions, 26 deletions
diff --git a/go.mod b/go.mod
index 0ff2519e..aee1c29d 100644
--- a/go.mod
+++ b/go.mod
@@ -3,23 +3,25 @@ module github.com/osrg/gobgp
require (
github.com/BurntSushi/toml v0.3.1
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e
- github.com/davecgh/go-spew v1.1.0 // indirect
+ github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-farm v0.0.0-20171119141306-ac7624ea8da3
github.com/eapache/channels v1.1.0
- github.com/eapache/queue v1.0.2 // indirect
+ github.com/eapache/queue v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.4.2 // indirect
+ github.com/go-test/deep v1.0.6
github.com/golang/protobuf v1.0.0
github.com/google/uuid v1.1.1
github.com/hashicorp/hcl v0.0.0-20170509225359-392dba7d905e // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jessevdk/go-flags v1.3.0
github.com/k-sone/critbitgo v1.3.1-0.20191024122315-48c9e1530131
- github.com/kr/pretty v0.1.0
+ github.com/kr/pretty v0.2.0
+ github.com/kr/text v0.2.0 // indirect
github.com/magiconair/properties v1.7.3 // indirect
github.com/mitchellh/mapstructure v0.0.0-20170523030023-d0303fe80992 // indirect
+ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pelletier/go-buffruneio v0.2.0 // indirect
github.com/pelletier/go-toml v1.0.0 // indirect
- github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v0.0.0-20170713114250-a3f95b5c4235
github.com/spf13/afero v0.0.0-20170217164146-9be650865eab // indirect
github.com/spf13/cast v1.1.0 // indirect
@@ -27,16 +29,17 @@ require (
github.com/spf13/jwalterweatherman v0.0.0-20170523133247-0efa5202c046 // indirect
github.com/spf13/pflag v1.0.0 // indirect
github.com/spf13/viper v1.0.0
- github.com/stretchr/testify v1.1.4
+ github.com/stretchr/testify v1.6.0
github.com/vishvananda/netlink v0.0.0-20170802012344-a95659537721
github.com/vishvananda/netns v0.0.0-20170707011535-86bef332bfc3 // indirect
- golang.org/x/net v0.0.0-20190620200207-3b0461eec859
- golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
- golang.org/x/sys v0.0.0-20190412213103-97732733099d // indirect
+ golang.org/x/net v0.0.0-20200528225125-3c3fba18258b
+ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 // indirect
+ golang.org/x/text v0.3.2 // indirect
google.golang.org/genproto v0.0.0-20170731182057-09f6ed296fc6 // indirect
google.golang.org/grpc v1.5.1
- gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
- gopkg.in/yaml.v2 v2.0.0-20170721122051-25c4ec802a7d // indirect
+ gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
+ gopkg.in/yaml.v2 v2.2.8 // indirect
+ gopkg.in/yaml.v3 v3.0.0-20200601152816-913338de1bd2 // indirect
)
go 1.13
diff --git a/go.sum b/go.sum
index 94da041a..56201914 100644
--- a/go.sum
+++ b/go.sum
@@ -2,16 +2,21 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e h1:Wf6HqHfScWJN9/ZjdUKyjop4mf3Qdd+1TvvltAvM3m8=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
+github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-farm v0.0.0-20171119141306-ac7624ea8da3 h1:fU8XNPEWym5sd75euzRuQBGltQxHVY4gv6mqa2A2Cuo=
github.com/dgryski/go-farm v0.0.0-20171119141306-ac7624ea8da3/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/eapache/channels v1.1.0 h1:F1taHcn7/F0i8DYqKXJnyhJcVpp2kgFcNePxXtnyu4k=
github.com/eapache/channels v1.1.0/go.mod h1:jMm2qB5Ubtg9zLd+inMZd2/NUvXgzmWXsDaLyQIGfH0=
-github.com/eapache/queue v1.0.2 h1:jRJXCx6uciOfN69MfZCC9EZlGRqqHhwlyb6GBeNow+c=
-github.com/eapache/queue v1.0.2/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
+github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
+github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/fsnotify/fsnotify v1.4.2 h1:v5tKwtf2hNhBV24eNYfQ5UmvFOGlOCmRqk7/P1olxtk=
github.com/fsnotify/fsnotify v1.4.2/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
+github.com/go-test/deep v1.0.6 h1:UHSEyLZUwX9Qoi99vVwvewiMC8mM2bf7XEM2nqvzEn8=
+github.com/go-test/deep v1.0.6/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
github.com/golang/protobuf v1.0.0 h1:lsek0oXi8iFE9L+EXARyHIjU5rlWIhhTkjDz3vHhWWQ=
github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
@@ -24,15 +29,19 @@ github.com/jessevdk/go-flags v1.3.0 h1:QmKsgik/Z5fJ11ZtlcA8F+XW9dNybBNFQ1rngF3Mm
github.com/jessevdk/go-flags v1.3.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/k-sone/critbitgo v1.3.1-0.20191024122315-48c9e1530131 h1:2bjzgZk4GiWAFkj15/SkmxIO30u69RyPiSS+F0d+Kzs=
github.com/k-sone/critbitgo v1.3.1-0.20191024122315-48c9e1530131/go.mod h1:7E6pyoyADnFxlUBEKcnfS49b7SUAQGMK+OAp/UQvo0s=
-github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
-github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
+github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
+github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
+github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
+github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.7.3 h1:6AOjgCKyZFMG/1yfReDPDz3CJZPxnYk7DGmj2HtyF24=
github.com/magiconair/properties v1.7.3/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/mapstructure v0.0.0-20170523030023-d0303fe80992 h1:W7VHAEVflA5/eTyRvQ53Lz5j8bhRd1myHZlI/IZFvbU=
github.com/mitchellh/mapstructure v0.0.0-20170523030023-d0303fe80992/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
+github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
+github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pelletier/go-buffruneio v0.2.0 h1:U4t4R6YkofJ5xHm3dJzuRpPZ0mr5MMCoAWooScCR7aA=
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
github.com/pelletier/go-toml v1.0.0 h1:QFDlmAXZrfPXEF6c9+15fMqhQIS3O0pxszhnk936vg4=
@@ -53,27 +62,35 @@ github.com/spf13/pflag v1.0.0 h1:oaPbdDe/x0UncahuwiPxW1GYJyilRAdsPnq3e1yaPcI=
github.com/spf13/pflag v1.0.0/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.0.0 h1:RUA/ghS2i64rlnn4ydTfblY8Og8QzcPtCcHvgMn+w/I=
github.com/spf13/viper v1.0.0/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM=
-github.com/stretchr/testify v1.1.4 h1:ToftOQTytwshuOSj6bDSolVUa3GINfJP/fg3OkkOzQQ=
-github.com/stretchr/testify v1.1.4/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.6.0 h1:jlIyCplCJFULU/01vCkhKuTyc3OorI3bJFuw6obfgho=
+github.com/stretchr/testify v1.6.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/vishvananda/netlink v0.0.0-20170802012344-a95659537721 h1:GObIVSLotoj+Z0hI7oihMG7UG06/bxPw0HRR7hAuadY=
github.com/vishvananda/netlink v0.0.0-20170802012344-a95659537721/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk=
github.com/vishvananda/netns v0.0.0-20170707011535-86bef332bfc3 h1:NcYCJC+LbOrfvuf/uHeM/kxh6vOmiuInC4GAWRdc+P0=
github.com/vishvananda/netns v0.0.0-20170707011535-86bef332bfc3/go.mod h1:ZjcWmFBXmLKZu9Nxj3WKYEafiSqer2rnvPr0en9UNpI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
-golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
-golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
-golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/net v0.0.0-20200528225125-3c3fba18258b h1:IYiJPiJfzktmDAO1HQiwjMjwjlYKHAL7KzeD544RJPs=
+golang.org/x/net v0.0.0-20200528225125-3c3fba18258b/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
+golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208 h1:qwRHBd0NqMbJxfbotnDhm2ByMI1Shq4Y6oRJo21SGJA=
+golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
-golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
+golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
+golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/genproto v0.0.0-20170731182057-09f6ed296fc6 h1:72GtwBPfq6av9X0Ru2HtAopsPW+d+vh1K1zaxanTdE8=
google.golang.org/genproto v0.0.0-20170731182057-09f6ed296fc6/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/grpc v1.5.1 h1:pDBahoEyjFOjJByiWlcl8lTzj3bqilmVSuaSv4ug0nk=
google.golang.org/grpc v1.5.1/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
-gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
-gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v2 v2.0.0-20170721122051-25c4ec802a7d h1:2DX7x6HUDGZUyuEDAhUsQQNqkb1zvDyKTjVoTdzaEzo=
-gopkg.in/yaml.v2 v2.0.0-20170721122051-25c4ec802a7d/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
+gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
+gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.0-20200601152816-913338de1bd2 h1:VEmvx0P+GVTgkNu2EdTN988YCZPcD3lo9AoczZpucwc=
+gopkg.in/yaml.v3 v3.0.0-20200601152816-913338de1bd2/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/pkg/packet/bgp/sr_policy_test.go b/pkg/packet/bgp/sr_policy_test.go
new file mode 100644
index 00000000..41849d90
--- /dev/null
+++ b/pkg/packet/bgp/sr_policy_test.go
@@ -0,0 +1,219 @@
+package bgp
+
+import (
+ "encoding/binary"
+ "net"
+ "reflect"
+ "testing"
+
+ "github.com/go-test/deep"
+)
+
+func TestBindingSIDRoundTrip(t *testing.T) {
+ b := make([]byte, 4)
+ binary.BigEndian.PutUint32(b, 24321)
+ bsid, _ := NewBSID(b)
+ tests := []struct {
+ name string
+ input *TunnelEncapSubTLVSRBSID
+ fail bool
+ }{
+ {
+ name: "no bsid",
+ input: &TunnelEncapSubTLVSRBSID{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: 1,
+ Length: 2,
+ },
+ Flags: 0x0,
+ BSID: nil,
+ },
+ fail: false,
+ },
+ {
+ name: "v4 bsid",
+ input: &TunnelEncapSubTLVSRBSID{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: 1,
+ Length: 6,
+ },
+ Flags: 0x0,
+ BSID: bsid,
+ },
+ fail: false,
+ },
+ {
+ name: "srv6 bsid",
+ input: &TunnelEncapSubTLVSRBSID{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: 1,
+ Length: 18,
+ },
+ Flags: 0x0,
+ BSID: &BSID{
+ Value: net.ParseIP("2001:1::1").To16(),
+ },
+ },
+ fail: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ b, err := tt.input.Serialize()
+ if err != nil && !tt.fail {
+ t.Fatalf("expected to succeed but failed with error: %+v", err)
+ }
+ if err == nil && tt.fail {
+ t.Fatal("Expected to fail but succeeded")
+ }
+ if err != nil {
+ return
+ }
+ result := &TunnelEncapSubTLVSRBSID{}
+ err = result.DecodeFromBytes(b)
+ if err != nil && !tt.fail {
+ t.Fatalf("expected to succeed but failed with error: %+v", err)
+ }
+ if err == nil && tt.fail {
+ t.Fatal("Expected to fail but succeeded")
+ }
+ if err != nil {
+ return
+ }
+ if !reflect.DeepEqual(tt.input, result) {
+ t.Logf("Diffs: %+v", deep.Equal(tt.input, result))
+ t.Fatalf("expected: %+v does not match result: %+v", tt.input, result)
+ }
+ })
+ }
+}
+
+func TestSegmentListRoundTrip(t *testing.T) {
+ tests := []struct {
+ name string
+ input *TunnelEncapSubTLVSRSegmentList
+ fail bool
+ }{
+ {
+ name: "empty Segment List Sub TLV",
+ input: &TunnelEncapSubTLVSRSegmentList{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: ENCAP_SUBTLV_TYPE_SRSEGMENT_LIST,
+ Length: 6, // Weight (6 bytes) + Length of each segment + 2
+ },
+ },
+ fail: false,
+ },
+ {
+ name: "only empty weight",
+ input: &TunnelEncapSubTLVSRSegmentList{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: ENCAP_SUBTLV_TYPE_SRSEGMENT_LIST,
+ Length: 6, // Weight (6 bytes) + Length of each segment + 2
+ },
+ Weight: &SegmentListWeight{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: 9,
+ Length: 6,
+ },
+ Flags: 0,
+ Weight: 100,
+ },
+ },
+ fail: false,
+ },
+ {
+ name: "weight and 1 type A segment",
+ input: &TunnelEncapSubTLVSRSegmentList{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: ENCAP_SUBTLV_TYPE_SRSEGMENT_LIST,
+ Length: 6, // Weight (6 bytes) + Length of each segment + 2
+ },
+ Weight: &SegmentListWeight{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: SegmentListSubTLVWeight,
+ Length: 6,
+ },
+ Flags: 0,
+ Weight: 100,
+ },
+ Segments: []TunnelEncapSubTLVInterface{
+ &SegmentTypeA{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: EncapSubTLVType(TypeA),
+ Length: 6,
+ },
+ Flags: 0,
+ Label: (21431 << 12),
+ },
+ },
+ },
+ fail: false,
+ },
+ {
+ name: "weight and 2 type A segment",
+ input: &TunnelEncapSubTLVSRSegmentList{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: ENCAP_SUBTLV_TYPE_SRSEGMENT_LIST,
+ Length: 6, // Weight (6 bytes) + Length of each segment + 2
+ },
+ Weight: &SegmentListWeight{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: SegmentListSubTLVWeight,
+ Length: 6,
+ },
+ Flags: 0,
+ Weight: 100,
+ },
+ Segments: []TunnelEncapSubTLVInterface{
+ &SegmentTypeA{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: EncapSubTLVType(TypeA),
+ Length: 6,
+ },
+ Flags: 0,
+ Label: (21431 << 12),
+ },
+ &SegmentTypeA{
+ TunnelEncapSubTLV: TunnelEncapSubTLV{
+ Type: EncapSubTLVType(TypeA),
+ Length: 6,
+ },
+ Flags: 0,
+ Label: (100001 << 12),
+ },
+ },
+ },
+ fail: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ b, err := tt.input.Serialize()
+ if err != nil && !tt.fail {
+ t.Fatalf("expected to succeed but failed with error: %+v", err)
+ }
+ if err == nil && tt.fail {
+ t.Fatal("Expected to fail but succeeded")
+ }
+ if err != nil {
+ return
+ }
+ result := &TunnelEncapSubTLVSRSegmentList{}
+ err = result.DecodeFromBytes(b)
+ if err != nil && !tt.fail {
+ t.Fatalf("expected to succeed but failed with error: %+v", err)
+ }
+ if err == nil && tt.fail {
+ t.Fatal("Expected to fail but succeeded")
+ }
+ if err != nil {
+ return
+ }
+ if !reflect.DeepEqual(tt.input, result) {
+ t.Logf("Diffs: %+v", deep.Equal(tt.input, result))
+ t.Fatalf("expected: %+v does not match result: %+v", tt.input, result)
+ }
+ })
+ }
+}