@@ -1123,17 +1123,16 @@ func TestLinkAddDelVeth(t *testing.T) {
11231123
11241124 peerMAC , _ := net .ParseMAC ("00:12:34:56:78:02" )
11251125
1126- veth := & Veth {
1127- LinkAttrs : LinkAttrs {
1128- Name : "foo" ,
1129- TxQLen : testTxQLen ,
1130- MTU : 1400 ,
1131- NumTxQueues : testTxQueues ,
1132- NumRxQueues : testRxQueues ,
1133- },
1134- PeerName : "bar" ,
1135- PeerHardwareAddr : peerMAC ,
1136- }
1126+ veth := NewVeth (LinkAttrs {
1127+ Name : "foo" ,
1128+ TxQLen : testTxQLen ,
1129+ MTU : 1400 ,
1130+ NumTxQueues : testTxQueues ,
1131+ NumRxQueues : testRxQueues ,
1132+ })
1133+
1134+ veth .PeerName = "bar"
1135+ veth .PeerHardwareAddr = peerMAC
11371136 testLinkAddDel (t , veth )
11381137}
11391138
@@ -1168,7 +1167,8 @@ func TestLinkAddVethWithDefaultTxQLen(t *testing.T) {
11681167 la := NewLinkAttrs ()
11691168 la .Name = "foo"
11701169
1171- veth := & Veth {LinkAttrs : la , PeerName : "bar" }
1170+ veth := NewVeth (la )
1171+ veth .PeerName = "bar"
11721172 if err := LinkAdd (veth ); err != nil {
11731173 t .Fatal (err )
11741174 }
@@ -1203,7 +1203,8 @@ func TestLinkAddVethWithZeroTxQLen(t *testing.T) {
12031203 la .Name = "foo"
12041204 la .TxQLen = 0
12051205
1206- veth := & Veth {LinkAttrs : la , PeerName : "bar" }
1206+ veth := NewVeth (la )
1207+ veth .PeerName = "bar"
12071208 if err := LinkAdd (veth ); err != nil {
12081209 t .Fatal (err )
12091210 }
@@ -1231,6 +1232,124 @@ func TestLinkAddVethWithZeroTxQLen(t *testing.T) {
12311232 }
12321233}
12331234
1235+ func TestLinkAddVethWithPeerAttrs (t * testing.T ) {
1236+ tearDown := setUpNetlinkTest (t )
1237+ defer tearDown ()
1238+ la := NewLinkAttrs ()
1239+ la .Name = "foo"
1240+ la .MTU = 1500
1241+ la .TxQLen = 500
1242+ la .NumRxQueues = 2
1243+ la .NumTxQueues = 3
1244+
1245+ veth := NewVeth (la )
1246+ veth .PeerName = "bar"
1247+ veth .PeerMTU = 1400
1248+ veth .PeerTxQLen = 1000
1249+ veth .PeerNumRxQueues = 4
1250+ veth .PeerNumTxQueues = 5
1251+ if err := LinkAdd (veth ); err != nil {
1252+ t .Fatal (err )
1253+ }
1254+ link , err := LinkByName ("foo" )
1255+ if err != nil {
1256+ t .Fatal (err )
1257+ }
1258+ if veth , ok := link .(* Veth ); ! ok {
1259+ t .Fatalf ("unexpected link type: %T" , link )
1260+ } else {
1261+ if veth .MTU != 1500 {
1262+ t .Fatalf ("MTU is %d, should be %d" , veth .MTU , 1500 )
1263+ }
1264+ if veth .TxQLen != 500 {
1265+ t .Fatalf ("TxQLen is %d, should be %d" , veth .TxQLen , 500 )
1266+ }
1267+ if veth .NumRxQueues != 2 {
1268+ t .Fatalf ("NumRxQueues is %d, should be %d" , veth .NumRxQueues , 2 )
1269+ }
1270+ if veth .NumTxQueues != 3 {
1271+ t .Fatalf ("NumTxQueues is %d, should be %d" , veth .NumTxQueues , 3 )
1272+ }
1273+ }
1274+ peer , err := LinkByName ("bar" )
1275+ if err != nil {
1276+ t .Fatal (err )
1277+ }
1278+ if veth , ok := peer .(* Veth ); ! ok {
1279+ t .Fatalf ("unexpected link type: %T" , link )
1280+ } else {
1281+ if veth .MTU != 1400 {
1282+ t .Fatalf ("Peer MTU is %d, should be %d" , veth .MTU , 1400 )
1283+ }
1284+ if veth .TxQLen != 1000 {
1285+ t .Fatalf ("Peer TxQLen is %d, should be %d" , veth .TxQLen , 1000 )
1286+ }
1287+ if veth .NumRxQueues != 4 {
1288+ t .Fatalf ("Peer NumRxQueues is %d, should be %d" , veth .NumRxQueues , 4 )
1289+ }
1290+ if veth .NumTxQueues != 5 {
1291+ t .Fatalf ("Peer NumTxQueues is %d, should be %d" , veth .NumTxQueues , 5 )
1292+ }
1293+ }
1294+ }
1295+
1296+ func TestLinkAddVethWithoutPeerAttrs (t * testing.T ) {
1297+ tearDown := setUpNetlinkTest (t )
1298+ defer tearDown ()
1299+ la := NewLinkAttrs ()
1300+ la .Name = "foo"
1301+ la .MTU = 1500
1302+ la .TxQLen = 500
1303+ la .NumRxQueues = 2
1304+ la .NumTxQueues = 3
1305+
1306+ veth := NewVeth (la )
1307+ veth .PeerName = "bar"
1308+ if err := LinkAdd (veth ); err != nil {
1309+ t .Fatal (err )
1310+ }
1311+ link , err := LinkByName ("foo" )
1312+ if err != nil {
1313+ t .Fatal (err )
1314+ }
1315+ if veth , ok := link .(* Veth ); ! ok {
1316+ t .Fatalf ("unexpected link type: %T" , link )
1317+ } else {
1318+ if veth .MTU != 1500 {
1319+ t .Fatalf ("MTU is %d, should be %d" , veth .MTU , 1500 )
1320+ }
1321+ if veth .TxQLen != 500 {
1322+ t .Fatalf ("TxQLen is %d, should be %d" , veth .TxQLen , 500 )
1323+ }
1324+ if veth .NumRxQueues != 2 {
1325+ t .Fatalf ("NumRxQueues is %d, should be %d" , veth .NumRxQueues , 2 )
1326+ }
1327+ if veth .NumTxQueues != 3 {
1328+ t .Fatalf ("NumTxQueues is %d, should be %d" , veth .NumTxQueues , 3 )
1329+ }
1330+ }
1331+ peer , err := LinkByName ("bar" )
1332+ if err != nil {
1333+ t .Fatal (err )
1334+ }
1335+ if veth , ok := peer .(* Veth ); ! ok {
1336+ t .Fatalf ("unexpected link type: %T" , link )
1337+ } else {
1338+ if veth .MTU != 1500 {
1339+ t .Fatalf ("Peer MTU is %d, should be %d" , veth .MTU , 1500 )
1340+ }
1341+ if veth .TxQLen != 500 {
1342+ t .Fatalf ("Peer TxQLen is %d, should be %d" , veth .TxQLen , 500 )
1343+ }
1344+ if veth .NumRxQueues != 2 {
1345+ t .Fatalf ("Peer NumRxQueues is %d, should be %d" , veth .NumRxQueues , 2 )
1346+ }
1347+ if veth .NumTxQueues != 3 {
1348+ t .Fatalf ("Peer NumTxQueues is %d, should be %d" , veth .NumTxQueues , 3 )
1349+ }
1350+ }
1351+ }
1352+
12341353func TestLinkAddDelDummyWithGSO (t * testing.T ) {
12351354 const (
12361355 gsoMaxSegs = 16
@@ -1449,7 +1568,7 @@ func TestLinkSetNs(t *testing.T) {
14491568 }
14501569 defer newns .Close ()
14511570
1452- link := & Veth {LinkAttrs {Name : "foo" }, "bar" , nil , nil }
1571+ link := & Veth {LinkAttrs : LinkAttrs {Name : "foo" }, PeerName : "bar" }
14531572 if err := LinkAdd (link ); err != nil {
14541573 t .Fatal (err )
14551574 }
@@ -1520,7 +1639,7 @@ func TestVethPeerNs(t *testing.T) {
15201639 }
15211640 defer newns .Close ()
15221641
1523- link := & Veth {LinkAttrs {Name : "foo" }, "bar" , nil , NsFd (basens )}
1642+ link := & Veth {LinkAttrs : LinkAttrs {Name : "foo" }, PeerName : "bar" , PeerNamespace : NsFd (basens )}
15241643 if err := LinkAdd (link ); err != nil {
15251644 t .Fatal (err )
15261645 }
@@ -1573,7 +1692,7 @@ func TestVethPeerNs2(t *testing.T) {
15731692 }
15741693 defer twons .Close ()
15751694
1576- link := & Veth {LinkAttrs {Name : "foo" , Namespace : NsFd (onens )}, "bar" , nil , NsFd (basens )}
1695+ link := & Veth {LinkAttrs : LinkAttrs {Name : "foo" , Namespace : NsFd (onens )}, PeerName : "bar" , PeerNamespace : NsFd (basens )}
15771696 if err := LinkAdd (link ); err != nil {
15781697 t .Fatal (err )
15791698 }
@@ -2132,7 +2251,7 @@ func TestLinkSubscribe(t *testing.T) {
21322251 t .Fatal (err )
21332252 }
21342253
2135- link := & Veth {LinkAttrs {Name : "foo" , TxQLen : testTxQLen , MTU : 1400 }, "bar" , nil , nil }
2254+ link := & Veth {LinkAttrs : LinkAttrs {Name : "foo" , TxQLen : testTxQLen , MTU : 1400 }, PeerName : "bar" }
21362255 if err := LinkAdd (link ); err != nil {
21372256 t .Fatal (err )
21382257 }
@@ -2179,7 +2298,7 @@ func TestLinkSubscribeWithOptions(t *testing.T) {
21792298 t .Fatal (err )
21802299 }
21812300
2182- link := & Veth {LinkAttrs {Name : "foo" , TxQLen : testTxQLen , MTU : 1400 }, "bar" , nil , nil }
2301+ link := & Veth {LinkAttrs : LinkAttrs {Name : "foo" , TxQLen : testTxQLen , MTU : 1400 }, PeerName : "bar" }
21832302 if err := LinkAdd (link ); err != nil {
21842303 t .Fatal (err )
21852304 }
@@ -2213,7 +2332,7 @@ func TestLinkSubscribeAt(t *testing.T) {
22132332 t .Fatal (err )
22142333 }
22152334
2216- link := & Veth {LinkAttrs {Name : "test" , TxQLen : testTxQLen , MTU : 1400 }, "bar" , nil , nil }
2335+ link := & Veth {LinkAttrs : LinkAttrs {Name : "test" , TxQLen : testTxQLen , MTU : 1400 }, PeerName : "bar" }
22172336 if err := nh .LinkAdd (link ); err != nil {
22182337 t .Fatal (err )
22192338 }
@@ -2255,7 +2374,7 @@ func TestLinkSubscribeListExisting(t *testing.T) {
22552374 }
22562375 defer nh .Close ()
22572376
2258- link := & Veth {LinkAttrs {Name : "test" , TxQLen : testTxQLen , MTU : 1400 }, "bar" , nil , nil }
2377+ link := & Veth {LinkAttrs : LinkAttrs {Name : "test" , TxQLen : testTxQLen , MTU : 1400 }, PeerName : "bar" }
22592378 if err := nh .LinkAdd (link ); err != nil {
22602379 t .Fatal (err )
22612380 }
0 commit comments