@@ -1123,17 +1123,16 @@ func TestLinkAddDelVeth(t *testing.T) {
1123
1123
1124
1124
peerMAC , _ := net .ParseMAC ("00:12:34:56:78:02" )
1125
1125
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
1137
1136
testLinkAddDel (t , veth )
1138
1137
}
1139
1138
@@ -1168,7 +1167,8 @@ func TestLinkAddVethWithDefaultTxQLen(t *testing.T) {
1168
1167
la := NewLinkAttrs ()
1169
1168
la .Name = "foo"
1170
1169
1171
- veth := & Veth {LinkAttrs : la , PeerName : "bar" }
1170
+ veth := NewVeth (la )
1171
+ veth .PeerName = "bar"
1172
1172
if err := LinkAdd (veth ); err != nil {
1173
1173
t .Fatal (err )
1174
1174
}
@@ -1203,7 +1203,8 @@ func TestLinkAddVethWithZeroTxQLen(t *testing.T) {
1203
1203
la .Name = "foo"
1204
1204
la .TxQLen = 0
1205
1205
1206
- veth := & Veth {LinkAttrs : la , PeerName : "bar" }
1206
+ veth := NewVeth (la )
1207
+ veth .PeerName = "bar"
1207
1208
if err := LinkAdd (veth ); err != nil {
1208
1209
t .Fatal (err )
1209
1210
}
@@ -1231,6 +1232,124 @@ func TestLinkAddVethWithZeroTxQLen(t *testing.T) {
1231
1232
}
1232
1233
}
1233
1234
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
+
1234
1353
func TestLinkAddDelDummyWithGSO (t * testing.T ) {
1235
1354
const (
1236
1355
gsoMaxSegs = 16
@@ -1449,7 +1568,7 @@ func TestLinkSetNs(t *testing.T) {
1449
1568
}
1450
1569
defer newns .Close ()
1451
1570
1452
- link := & Veth {LinkAttrs {Name : "foo" }, "bar" , nil , nil }
1571
+ link := & Veth {LinkAttrs : LinkAttrs {Name : "foo" }, PeerName : "bar" }
1453
1572
if err := LinkAdd (link ); err != nil {
1454
1573
t .Fatal (err )
1455
1574
}
@@ -1520,7 +1639,7 @@ func TestVethPeerNs(t *testing.T) {
1520
1639
}
1521
1640
defer newns .Close ()
1522
1641
1523
- link := & Veth {LinkAttrs {Name : "foo" }, "bar" , nil , NsFd (basens )}
1642
+ link := & Veth {LinkAttrs : LinkAttrs {Name : "foo" }, PeerName : "bar" , PeerNamespace : NsFd (basens )}
1524
1643
if err := LinkAdd (link ); err != nil {
1525
1644
t .Fatal (err )
1526
1645
}
@@ -1573,7 +1692,7 @@ func TestVethPeerNs2(t *testing.T) {
1573
1692
}
1574
1693
defer twons .Close ()
1575
1694
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 )}
1577
1696
if err := LinkAdd (link ); err != nil {
1578
1697
t .Fatal (err )
1579
1698
}
@@ -2132,7 +2251,7 @@ func TestLinkSubscribe(t *testing.T) {
2132
2251
t .Fatal (err )
2133
2252
}
2134
2253
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" }
2136
2255
if err := LinkAdd (link ); err != nil {
2137
2256
t .Fatal (err )
2138
2257
}
@@ -2179,7 +2298,7 @@ func TestLinkSubscribeWithOptions(t *testing.T) {
2179
2298
t .Fatal (err )
2180
2299
}
2181
2300
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" }
2183
2302
if err := LinkAdd (link ); err != nil {
2184
2303
t .Fatal (err )
2185
2304
}
@@ -2213,7 +2332,7 @@ func TestLinkSubscribeAt(t *testing.T) {
2213
2332
t .Fatal (err )
2214
2333
}
2215
2334
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" }
2217
2336
if err := nh .LinkAdd (link ); err != nil {
2218
2337
t .Fatal (err )
2219
2338
}
@@ -2255,7 +2374,7 @@ func TestLinkSubscribeListExisting(t *testing.T) {
2255
2374
}
2256
2375
defer nh .Close ()
2257
2376
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" }
2259
2378
if err := nh .LinkAdd (link ); err != nil {
2260
2379
t .Fatal (err )
2261
2380
}
0 commit comments