-
Notifications
You must be signed in to change notification settings - Fork 1
/
update_test.go
66 lines (60 loc) · 1.95 KB
/
update_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import (
"bytes"
"encoding/binary"
"github.com/golang/glog"
"net"
"testing"
)
func TestUpdateLocalLspGen(t *testing.T) {
initConfig()
cfg.sid = "1111.1111.1112"
adj := Adjacency{state: "UP", neighborSystemID: []byte{0x11, 0x11, 0x11, 0x11, 0x11, 0x11}}
initInterfaces()
cfg.interfaces[0].adj = &adj
updateDBInit()
generateLocalLsp()
// Check whether it is in the LspDB
testLspID := [8]byte{0x11, 0x11, 0x11, 0x11, 0x11, 0x12, 0x00, 0x00}
tmp := AvlSearch(UpdateDB.Root, binary.BigEndian.Uint64(testLspID[:]))
lsp := tmp.(*IsisLsp)
glog.V(2).Infof("%v", cfg.interfaces[0].lspFloodStates[0])
glog.V(2).Infof("%v", lsp)
// SRM Flag should be set on eth0
if !cfg.interfaces[0].lspFloodStates[binary.BigEndian.Uint64(testLspID[:])].SRM {
t.Fail()
}
}
func TestReachTLV(t *testing.T) {
numRoutesPerInterface := 2
numInterfaces := 2
interfaces := make([]*Intf, numInterfaces)
// Only need the routes attached to the interfaces
for i := 0; i < numInterfaces; i++ {
interfaces[i] = &Intf{}
interfaces[i].routes = make([]*net.IPNet, numRoutesPerInterface)
for j := 0; j < numRoutesPerInterface; j++ {
interfaces[i].routes[j] = &net.IPNet{IP: net.IP{172, byte(j), 0, 0}, Mask: net.IPMask{0xff, 0xff, 0x00, 0x00}}
}
}
tlv := getIPReachTLV(interfaces)
glog.V(2).Infof("%v", tlv)
// 12 bytes per entry in the TLV
if int(tlv.typeTLV) != 128 || int(tlv.lengthTLV) != numRoutesPerInterface*numInterfaces*12 {
t.Fail()
}
}
func TestNeighborTLV(t *testing.T) {
numInterfaces := 2
interfaces := make([]*Intf, numInterfaces)
systemID := []byte{0x01, 0x01, 0x01, 0x01, 0x01, 0x01}
// Need a couple adjacencies with neighbor system IDs
for i := 0; i < numInterfaces; i++ {
interfaces[i] = &Intf{adj: &Adjacency{state: "UP", neighborSystemID: systemID}}
}
tlv := getNeighborTLV(interfaces)
t.Logf("Neighbors TLV %v", tlv)
if !(bytes.Equal(tlv.valueTLV[5:5+6], systemID) && bytes.Equal(tlv.valueTLV[12+4:12+4+6], systemID)) {
t.Fail()
}
}