summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-18 19:40:59 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-12-18 19:40:59 -0800
commitd5a7a4569a5e6b55eda9c26ce70b846b643ebf50 (patch)
treedfd1ccb457220eb7dc6fd6251d836e5df6cff70e
parentb1c8ed363bdab0d3618077e93a79df227559539c (diff)
server: update adjRibIn
When we get a update message, update adjRibIn, and sends the path infomation to other peers. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--server/peer.go31
-rw-r--r--server/server.go6
-rw-r--r--table/table_manager.go27
3 files changed, 57 insertions, 7 deletions
diff --git a/server/peer.go b/server/peer.go
index 52a8205f..f4e2d1f8 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -20,6 +20,7 @@ import (
"fmt"
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet"
+ "github.com/osrg/gobgp/table"
"gopkg.in/tomb.v2"
"net"
)
@@ -34,6 +35,7 @@ type Peer struct {
inEventCh chan *message
outEventCh chan *message
fsm *FSM
+ adjRib *table.AdjRib
}
func NewPeer(g config.GlobalType, peer config.NeighborType, outEventCh chan *message) *Peer {
@@ -47,10 +49,33 @@ func NewPeer(g config.GlobalType, peer config.NeighborType, outEventCh chan *mes
outEventCh: outEventCh,
}
p.fsm = NewFSM(&g, &peer, p.acceptedConnCh, p.incoming, p.outgoing)
+ p.adjRib = table.NewAdjRib()
p.t.Go(p.loop)
return p
}
+func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) {
+ j, _ := json.Marshal(m)
+ fmt.Println(string(j))
+ // TODO: update state here
+
+ if m.Header.Type != bgp.BGP_MSG_UPDATE {
+ return
+ }
+
+ msg := table.NewProcessMessage(m, peer.fsm.peerInfo)
+ pathList := msg.ToPathList()
+ if len(pathList) == 0 {
+ return
+ }
+
+ peer.adjRib.UpdateIn(pathList)
+
+ for path := range pathList {
+ peer.sendToHub("", PEER_MSG_PATH, path)
+ }
+}
+
// this goroutine handles routing table operations
func (peer *Peer) loop() error {
for {
@@ -70,10 +95,10 @@ func (peer *Peer) loop() error {
close(peer.outgoing)
return nil
case m := <-peer.incoming:
- if m != nil {
- j, _ := json.Marshal(m)
- fmt.Println(string(j))
+ if m == nil {
+ continue
}
+ peer.handleBGPmessage(m)
case m := <-peer.inEventCh:
fmt.Println(m)
}
diff --git a/server/server.go b/server/server.go
index 3f7885a6..a1c0ccad 100644
--- a/server/server.go
+++ b/server/server.go
@@ -24,6 +24,12 @@ import (
"strings"
)
+const (
+ _ = iota
+ PEER_MSG_NEW
+ PEER_MSG_PATH
+)
+
type message struct {
src string
dst string
diff --git a/table/table_manager.go b/table/table_manager.go
index b59912f6..9fe4032a 100644
--- a/table/table_manager.go
+++ b/table/table_manager.go
@@ -18,7 +18,6 @@ package table
import (
log "github.com/Sirupsen/logrus"
"github.com/osrg/gobgp/packet"
- "net"
"os"
"time"
)
@@ -138,6 +137,13 @@ type ProcessMessage struct {
fromPeer *PeerInfo
}
+func NewProcessMessage(m *bgp.BGPMessage, peerInfo *PeerInfo) *ProcessMessage {
+ return &ProcessMessage{
+ innerMessage: m,
+ fromPeer: peerInfo,
+ }
+}
+
func (p *ProcessMessage) nlri2Path() []Path {
updateMsg := p.innerMessage.Body.(*bgp.BGPUpdate)
pathAttributes := updateMsg.PathAttributes
@@ -353,9 +359,23 @@ func NewAdjRib() *AdjRib {
return r
}
+func (adj *AdjRib) UpdateIn(pathList []Path) {
+ for _, path := range pathList {
+ rf := path.getRouteFamily()
+ key := path.getPrefix().String()
+ if path.isWithdraw() {
+ _, found := adj.adjRibIn[rf][key]
+ if found {
+ delete(adj.adjRibIn[rf], key)
+ }
+ } else {
+ adj.adjRibIn[rf][key] = NewReceivedRoute(path, false)
+ }
+ }
+}
+
type ReceivedRoute struct {
path Path
- fromPeer *net.IP
filtered bool
timestamp time.Time
}
@@ -364,11 +384,10 @@ func (rr *ReceivedRoute) String() string {
return rr.path.(*PathDefault).getPrefix().String()
}
-func NewReceivedRoute(path Path, peer *net.IP, filtered bool) *ReceivedRoute {
+func NewReceivedRoute(path Path, filtered bool) *ReceivedRoute {
rroute := &ReceivedRoute{
path: path,
- fromPeer: peer,
filtered: filtered,
timestamp: time.Now(),
}