diff options
-rw-r--r-- | table/table.go | 52 |
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) } |