summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/peer.go52
-rw-r--r--table/path.go8
-rw-r--r--table/path_test.go4
-rw-r--r--table/table.go2
-rw-r--r--table/table_manager.go19
5 files changed, 57 insertions, 28 deletions
diff --git a/server/peer.go b/server/peer.go
index 4dbc6c73..faea1a02 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -78,36 +78,43 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) {
peer.sendToHub("", PEER_MSG_PATH, pathList)
}
-func (peer *Peer) handlePeermessage(m *message) {
- switch m.event {
- case PEER_MSG_PATH:
- pList, wList, _ := peer.rib.ProcessPaths(m.data.([]table.Path))
- // TODO: merge multiple messages
- // TODO: 4bytes and 2bytes conversion.
- adjPathLists := append([]table.Path(nil), pList...)
+func (peer *Peer) sendMessages(msgs []*bgp.BGPMessage) {
+ for _, m := range msgs {
+ peer.outgoing <- m
+ }
+}
- msgs := make([]*bgp.BGPMessage, 0)
- for _, p := range pList {
+func (peer *Peer) path2update(pathList []table.Path) []*bgp.BGPMessage {
+ // TODO: merge multiple messages
+ // TODO: 4bytes and 2bytes conversion.
+ msgs := make([]*bgp.BGPMessage, 0)
+ for _, p := range pathList {
+ if p.IsWithdraw() {
+ draw := p.GetNlri().(*bgp.WithdrawnRoute)
+ msgs = append(msgs, bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{*draw}, []bgp.PathAttributeInterface{}, []bgp.NLRInfo{}))
+ } else {
pathAttrs := p.GetPathAttrs()
nlri := p.GetNlri().(*bgp.NLRInfo)
- m := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttrs, []bgp.NLRInfo{*nlri})
- msgs = append(msgs, m)
+ msgs = append(msgs, bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttrs, []bgp.NLRInfo{*nlri}))
}
+ }
+ return msgs
+}
+
+func (peer *Peer) handlePeermessage(m *message) {
+ switch m.event {
+ case PEER_MSG_PATH:
+ pList, wList, _ := peer.rib.ProcessPaths(m.data.([]table.Path))
+ pathList := append([]table.Path(nil), pList...)
for _, dest := range wList {
p := dest.GetOldBestPath()
- draw := p.GetNlri().(*bgp.WithdrawnRoute)
- m := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{*draw}, []bgp.PathAttributeInterface{}, []bgp.NLRInfo{})
- msgs = append(msgs, m)
-
- adjPathLists = append(adjPathLists, p.Clone(true))
+ pathList = append(pathList, p.Clone(true))
}
- peer.adjRib.UpdateOut(adjPathLists)
+ peer.adjRib.UpdateOut(pathList)
- for _, m := range msgs {
- peer.outgoing <- m
- }
+ peer.sendMessages(peer.path2update(pathList))
}
}
@@ -123,6 +130,11 @@ func (peer *Peer) loop() error {
h.Wait()
peer.fsm.StateChange(nextState)
sameState = false
+ // TODO: check peer's rf
+ if nextState == bgp.BGP_FSM_ESTABLISHED {
+ pathList := peer.adjRib.GetOutPathList(table.RF_IPv4_UC)
+ peer.sendMessages(peer.path2update(pathList))
+ }
case <-peer.t.Dying():
close(peer.acceptedConnCh)
h.Stop()
diff --git a/table/path.go b/table/path.go
index 4ef9c070..269f6129 100644
--- a/table/path.go
+++ b/table/path.go
@@ -34,7 +34,7 @@ type Path interface {
setSourceVerNum(sourceVerNum int)
getSourceVerNum() int
setWithdraw(withdraw bool)
- isWithdraw() bool
+ IsWithdraw() bool
GetNlri() bgp.AddrPrefixInterface
getPrefix() net.IP
setMedSetByTargetNeighbor(medSetByTargetNeighbor bool)
@@ -119,7 +119,7 @@ func (pd *PathDefault) setWithdraw(withdraw bool) {
pd.withdraw = withdraw
}
-func (pd *PathDefault) isWithdraw() bool {
+func (pd *PathDefault) IsWithdraw() bool {
return pd.withdraw
}
@@ -171,7 +171,7 @@ func (pi *PathDefault) String() string {
str := fmt.Sprintf("IPv4Path Source: %d, ", pi.getSourceVerNum())
str = str + fmt.Sprintf(" NLRI: %s, ", pi.getPrefix().String())
str = str + fmt.Sprintf(" nexthop: %s, ", pi.getNexthop().String())
- str = str + fmt.Sprintf(" withdraw: %s, ", pi.isWithdraw())
+ str = str + fmt.Sprintf(" withdraw: %s, ", pi.IsWithdraw())
//str = str + fmt.Sprintf(" path attributes: %s, ", pi.getPathAttributeMap())
return str
}
@@ -266,7 +266,7 @@ func (ipv6p *IPv6Path) String() string {
str := fmt.Sprintf("IPv6Path Source: %d, ", ipv6p.getSourceVerNum())
str = str + fmt.Sprintf(" NLRI: %s, ", ipv6p.getPrefix().String())
str = str + fmt.Sprintf(" nexthop: %s, ", ipv6p.getNexthop().String())
- str = str + fmt.Sprintf(" withdraw: %s, ", ipv6p.isWithdraw())
+ str = str + fmt.Sprintf(" withdraw: %s, ", ipv6p.IsWithdraw())
//str = str + fmt.Sprintf(" path attributes: %s, ", ipv6p.getPathAttributeMap())
return str
}
diff --git a/table/path_test.go b/table/path_test.go
index 3cd32d89..b779c84b 100644
--- a/table/path_test.go
+++ b/table/path_test.go
@@ -114,7 +114,7 @@ func TestPathSetWithdraw(t *testing.T) {
pd := &PathDefault{}
wd := true
pd.setWithdraw(wd)
- r_wd := pd.isWithdraw()
+ r_wd := pd.IsWithdraw()
assert.Equal(t, r_wd, wd)
}
@@ -122,7 +122,7 @@ func TestPathGetWithdaw(t *testing.T) {
pd := &PathDefault{}
wd := false
pd.setWithdraw(wd)
- r_wd := pd.isWithdraw()
+ r_wd := pd.IsWithdraw()
assert.Equal(t, r_wd, wd)
}
diff --git a/table/table.go b/table/table.go
index 85110f7b..f60c2dfb 100644
--- a/table/table.go
+++ b/table/table.go
@@ -65,7 +65,7 @@ func insert(table Table, path Path) Destination {
table.validateNlri(path.GetNlri())
dest = getOrCreateDest(table, path.GetNlri())
- if path.isWithdraw() {
+ if path.IsWithdraw() {
// withdraw insert
dest.addWithdraw(path)
} else {
diff --git a/table/table_manager.go b/table/table_manager.go
index 0967f5d1..9dfae5bf 100644
--- a/table/table_manager.go
+++ b/table/table_manager.go
@@ -340,7 +340,7 @@ func (adj *AdjRib) update(rib map[RouteFamily]map[string]*ReceivedRoute, pathLis
for _, path := range pathList {
rf := path.getRouteFamily()
key := path.getPrefix().String()
- if path.isWithdraw() {
+ if path.IsWithdraw() {
_, found := rib[rf][key]
if found {
delete(rib[rf], key)
@@ -359,6 +359,23 @@ func (adj *AdjRib) UpdateOut(pathList []Path) {
adj.update(adj.adjRibOut, pathList)
}
+func (adj *AdjRib) getPathList(rib map[string]*ReceivedRoute) []Path {
+ pathList := []Path{}
+
+ for _, rr := range rib {
+ pathList = append(pathList, rr.path)
+ }
+ return pathList
+}
+
+func (adj *AdjRib) GetInPathList(rf RouteFamily) []Path {
+ return adj.getPathList(adj.adjRibIn[rf])
+}
+
+func (adj *AdjRib) GetOutPathList(rf RouteFamily) []Path {
+ return adj.getPathList(adj.adjRibOut[rf])
+}
+
type ReceivedRoute struct {
path Path
filtered bool