summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-08-04 10:45:44 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-05 17:24:36 +0900
commit0d14f7dca2f77f661e4baaaa9d85ff3d0967fe34 (patch)
treea43ba712ad9aad7dc149a35c7ba7c1236c9327b5
parentc059eb0f88969bac02aad13771a1bc2c82c2a803 (diff)
table: clean up
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
-rw-r--r--table/table.go52
1 files changed, 21 insertions, 31 deletions
diff --git a/table/table.go b/table/table.go
index e514395e..a5f867d4 100644
--- a/table/table.go
+++ b/table/table.go
@@ -18,7 +18,6 @@ package table
import (
log "github.com/Sirupsen/logrus"
"github.com/osrg/gobgp/packet"
- "reflect"
)
type Table struct {
@@ -41,7 +40,6 @@ func (t *Table) insert(path *Path) *Destination {
var dest *Destination
t.validatePath(path)
- t.validateNlri(path.GetNlri())
dest = t.getOrCreateDest(path.GetNlri())
if path.IsWithdraw {
@@ -72,7 +70,6 @@ func (t *Table) DeleteDestByPeer(peerInfo *PeerInfo) []*Destination {
}
func (t *Table) deleteDestByNlri(nlri bgp.AddrPrefixInterface) *Destination {
- t.validateNlri(nlri)
destinations := t.GetDestinations()
dest := destinations[t.tableKey(nlri)]
if dest != nil {
@@ -87,23 +84,21 @@ func (t *Table) deleteDest(dest *Destination) {
}
func (t *Table) validatePath(path *Path) {
- if path == nil || path.GetRouteFamily() != t.routeFamily {
- if path == nil {
- log.WithFields(log.Fields{
- "Topic": "Table",
- "Key": t.routeFamily,
- }).Error("path is nil")
- } else if path.GetRouteFamily() != t.routeFamily {
- log.WithFields(log.Fields{
- "Topic": "Table",
- "Key": t.routeFamily,
- "Prefix": path.GetNlri().String(),
- "ReceivedRf": path.GetRouteFamily().String(),
- }).Error("Invalid path. RouteFamily mismatch")
- }
+ if path == nil {
+ log.WithFields(log.Fields{
+ "Topic": "Table",
+ "Key": t.routeFamily,
+ }).Error("path is nil")
}
- _, attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH)
- if attr != nil {
+ if path.GetRouteFamily() != t.routeFamily {
+ log.WithFields(log.Fields{
+ "Topic": "Table",
+ "Key": t.routeFamily,
+ "Prefix": path.GetNlri().String(),
+ "ReceivedRf": path.GetRouteFamily().String(),
+ }).Error("Invalid path. RouteFamily mismatch")
+ }
+ if _, attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH); attr != nil {
pathParam := attr.(*bgp.PathAttributeAsPath).Value
for _, as := range pathParam {
_, y := as.(*bgp.As4PathParam)
@@ -116,34 +111,29 @@ func (t *Table) validatePath(path *Path) {
}
}
}
-
- _, attr = path.getPathAttr(bgp.BGP_ATTR_TYPE_AS4_PATH)
- if attr != nil {
+ if _, attr := path.getPathAttr(bgp.BGP_ATTR_TYPE_AS4_PATH); attr != nil {
log.WithFields(log.Fields{
"Topic": "Table",
"Key": t.routeFamily,
}).Fatal("AS4_PATH must be converted to AS_PATH")
}
-}
-
-func (t *Table) validateNlri(nlri bgp.AddrPrefixInterface) {
- if nlri == nil {
+ if path.GetNlri() == nil {
log.WithFields(log.Fields{
"Topic": "Table",
"Key": t.routeFamily,
- "Nlri": nlri,
- }).Error("Invalid Vpnv4 prefix given.")
-
+ }).Fatal("path's nlri is nil")
}
}
func (t *Table) getOrCreateDest(nlri bgp.AddrPrefixInterface) *Destination {
- log.Debugf("getOrCreateDest Table type : %s", reflect.TypeOf(t))
tableKey := t.tableKey(nlri)
dest := t.GetDestination(tableKey)
// If destination for given prefix does not exist we create it.
if dest == nil {
- log.Debugf("getOrCreateDest dest with key %s is not found", tableKey)
+ log.WithFields(log.Fields{
+ "Topic": "Table",
+ "Key": t.routeFamily,
+ }).Debugf("create Destination with key %s", tableKey)
dest = NewDestination(nlri)
t.setDestination(tableKey, dest)
}