table: clean up

Signed-off-by: ISHIDA Wataru <[email protected]>
This commit is contained in:
ISHIDA Wataru
2015-08-05 17:24:36 +09:00
committed by FUJITA Tomonori
parent c059eb0f88
commit 0d14f7dca2
+21 -31
View File
@@ -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)
}