summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-21 18:44:06 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-21 18:44:06 -0800
commit73d7ec4471158abd320c056dc28ed76708f6ba65 (patch)
tree4b6c916b26e97fa72e200f592a375b98b6b58c82
parent704135410381e69e2f39fea84cd029b65148da01 (diff)
server: conver PEER_MSG_PATH to bgp update
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--server/fsm.go22
-rw-r--r--server/peer.go22
-rw-r--r--table/destination.go4
-rw-r--r--table/table_manager_test.go4
4 files changed, 42 insertions, 10 deletions
diff --git a/server/fsm.go b/server/fsm.go
index 9b81d1f4..e0e26ce9 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -308,12 +308,24 @@ func (h *FSMHandler) sendMessageloop() error {
case <-h.t.Dying():
return nil
case m := <-fsm.outgoing:
- b, _ := m.Serialize()
- _, err := conn.Write(b)
- if err != nil {
- return nil
+ isSend := func(state int, Type uint8) bool {
+ switch Type {
+ case bgp.BGP_MSG_UPDATE:
+ if state == bgp.BGP_FSM_ESTABLISHED {
+ return true
+ }
+ }
+ return false
+ }(fsm.state, m.Header.Type)
+
+ if isSend {
+ b, _ := m.Serialize()
+ _, err := conn.Write(b)
+ if err != nil {
+ return nil
+ }
+ fsm.bgpMessageStateUpdate(m.Header.Type, false)
}
- fsm.bgpMessageStateUpdate(m.Header.Type, false)
case <-fsm.keepaliveTicker.C:
m := bgp.NewBGPKeepAliveMessage()
b, _ := m.Serialize()
diff --git a/server/peer.go b/server/peer.go
index 8439e7f5..ab80e9bf 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -82,7 +82,27 @@ func (peer *Peer) handlePeermessage(m *message) {
switch m.event {
case PEER_MSG_PATH:
pList, wList, _ := peer.rib.ProcessPaths(m.data.([]table.Path))
- fmt.Println(pList, wList)
+ // TODO: merge multiple messages
+ // TODO: 4bytes and 2bytes conversion.
+
+ msgs := make([]*bgp.BGPMessage, 0)
+ for _, p := range pList {
+ pathAttrs := p.GetPathAttrs()
+ nlri := p.GetNlri().(*bgp.NLRInfo)
+ m := bgp.NewBGPUpdateMessage([]bgp.WithdrawnRoute{}, pathAttrs, []bgp.NLRInfo{*nlri})
+ msgs = append(msgs, m)
+ }
+
+ 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)
+ }
+
+ for _, m := range msgs {
+ peer.outgoing <- m
+ }
}
}
diff --git a/table/destination.go b/table/destination.go
index aeabfbd0..9461713b 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -55,7 +55,7 @@ type Destination interface {
setBestPathReason(string)
getBestPath() Path
setBestPath(path Path)
- getOldBestPath() Path
+ GetOldBestPath() Path
setOldBestPath(path Path)
getKnownPathList() []Path
String() string
@@ -121,7 +121,7 @@ func (dd *DestinationDefault) setBestPath(path Path) {
dd.bestPath = path
}
-func (dd *DestinationDefault) getOldBestPath() Path {
+func (dd *DestinationDefault) GetOldBestPath() Path {
return dd.oldBestPath
}
diff --git a/table/table_manager_test.go b/table/table_manager_test.go
index c9d6e22a..8c9a8ab4 100644
--- a/table/table_manager_test.go
+++ b/table/table_manager_test.go
@@ -1639,7 +1639,7 @@ func TestProcessBGPUpdate_bestpath_lost_ipv4(t *testing.T) {
assert.NoError(t, err)
// check old best path
- path := wList[0].getOldBestPath()
+ path := wList[0].GetOldBestPath()
expectedType := "*table.IPv4Path"
assert.Equal(t, reflect.TypeOf(path).String(), expectedType)
@@ -1719,7 +1719,7 @@ func TestProcessBGPUpdate_bestpath_lost_ipv6(t *testing.T) {
assert.NoError(t, err)
// check old best path
- path := wList[0].getOldBestPath()
+ path := wList[0].GetOldBestPath()
expectedType := "*table.IPv6Path"
assert.Equal(t, reflect.TypeOf(path).String(), expectedType)