diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-04-27 11:02:42 +0000 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-04-27 15:20:51 +0000 |
commit | 87a951546c43cb70ad3a03ec42de7cead8d25d72 (patch) | |
tree | 62e79e2dea8ae5a6a8f13c7f88f9cd3d0eaf3a29 /table/table_manager.go | |
parent | 91cb8ea23f454592be9fb4565f0f477afdbcb0ec (diff) |
table: make table.ProcessMessage a function
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'table/table_manager.go')
-rw-r--r-- | table/table_manager.go | 53 |
1 files changed, 18 insertions, 35 deletions
diff --git a/table/table_manager.go b/table/table_manager.go index d56c2e65..a027e4a4 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -22,48 +22,36 @@ import ( "time" ) -type ProcessMessage struct { - innerMessage *bgp.BGPMessage - fromPeer *PeerInfo -} - -func NewProcessMessage(m *bgp.BGPMessage, peerInfo *PeerInfo) *ProcessMessage { - return &ProcessMessage{ - innerMessage: m, - fromPeer: peerInfo, - } -} - -func (p *ProcessMessage) nlri2Path(now time.Time) []Path { - updateMsg := p.innerMessage.Body.(*bgp.BGPUpdate) +func nlri2Path(m *bgp.BGPMessage, p *PeerInfo, now time.Time) []Path { + updateMsg := m.Body.(*bgp.BGPUpdate) pathAttributes := updateMsg.PathAttributes pathList := make([]Path, 0) for _, nlri_info := range updateMsg.NLRI { // define local variable to pass nlri's address to CreatePath var nlri bgp.NLRInfo = nlri_info // create Path object - path, _ := CreatePath(p.fromPeer, &nlri, pathAttributes, false, now) + path, _ := CreatePath(p, &nlri, pathAttributes, false, now) pathList = append(pathList, path) } return pathList } -func (p *ProcessMessage) withdraw2Path(now time.Time) []Path { - updateMsg := p.innerMessage.Body.(*bgp.BGPUpdate) +func withdraw2Path(m *bgp.BGPMessage, p *PeerInfo, now time.Time) []Path { + updateMsg := m.Body.(*bgp.BGPUpdate) pathAttributes := updateMsg.PathAttributes pathList := make([]Path, 0) for _, nlriWithdraw := range updateMsg.WithdrawnRoutes { // define local variable to pass nlri's address to CreatePath var w bgp.WithdrawnRoute = nlriWithdraw // create withdrawn Path object - path, _ := CreatePath(p.fromPeer, &w, pathAttributes, true, now) + path, _ := CreatePath(p, &w, pathAttributes, true, now) pathList = append(pathList, path) } return pathList } -func (p *ProcessMessage) mpreachNlri2Path(now time.Time) []Path { - updateMsg := p.innerMessage.Body.(*bgp.BGPUpdate) +func mpreachNlri2Path(m *bgp.BGPMessage, p *PeerInfo, now time.Time) []Path { + updateMsg := m.Body.(*bgp.BGPUpdate) pathAttributes := updateMsg.PathAttributes attrList := []*bgp.PathAttributeMpReachNLRI{} @@ -79,15 +67,15 @@ func (p *ProcessMessage) mpreachNlri2Path(now time.Time) []Path { for _, mp := range attrList { nlri_info := mp.Value for _, nlri := range nlri_info { - path, _ := CreatePath(p.fromPeer, nlri, pathAttributes, false, now) + path, _ := CreatePath(p, nlri, pathAttributes, false, now) pathList = append(pathList, path) } } return pathList } -func (p *ProcessMessage) mpunreachNlri2Path(now time.Time) []Path { - updateMsg := p.innerMessage.Body.(*bgp.BGPUpdate) +func mpunreachNlri2Path(m *bgp.BGPMessage, p *PeerInfo, now time.Time) []Path { + updateMsg := m.Body.(*bgp.BGPUpdate) pathAttributes := updateMsg.PathAttributes attrList := []*bgp.PathAttributeMpUnreachNLRI{} @@ -104,20 +92,20 @@ func (p *ProcessMessage) mpunreachNlri2Path(now time.Time) []Path { nlri_info := mp.Value for _, nlri := range nlri_info { - path, _ := CreatePath(p.fromPeer, nlri, pathAttributes, true, now) + path, _ := CreatePath(p, nlri, pathAttributes, true, now) pathList = append(pathList, path) } } return pathList } -func (p *ProcessMessage) ToPathList() []Path { +func ProcessMessage(m *bgp.BGPMessage, peerInfo *PeerInfo) []Path { pathList := make([]Path, 0) now := time.Now() - pathList = append(pathList, p.nlri2Path(now)...) - pathList = append(pathList, p.withdraw2Path(now)...) - pathList = append(pathList, p.mpreachNlri2Path(now)...) - pathList = append(pathList, p.mpunreachNlri2Path(now)...) + pathList = append(pathList, nlri2Path(m, peerInfo, now)...) + pathList = append(pathList, withdraw2Path(m, peerInfo, now)...) + pathList = append(pathList, mpreachNlri2Path(m, peerInfo, now)...) + pathList = append(pathList, mpunreachNlri2Path(m, peerInfo, now)...) return pathList } @@ -289,12 +277,7 @@ func (manager *TableManager) ProcessUpdate(fromPeer *PeerInfo, message *bgp.BGPM return []Path{}, nil } - msg := &ProcessMessage{ - innerMessage: message, - fromPeer: fromPeer, - } - - return manager.ProcessPaths(msg.ToPathList()) + return manager.ProcessPaths(ProcessMessage(message, fromPeer)) } type AdjRib struct { |