Skip to content
Snippets Groups Projects
Unverified Commit 5378049b authored by Daniel Czerwonk's avatar Daniel Czerwonk Committed by GitHub
Browse files

Merge branch 'master' into feature/unknown_attr_pass

parents cd68c8be a5b7e046
No related branches found
No related tags found
No related merge requests found
...@@ -217,6 +217,7 @@ func (s *establishedState) updates(u *packet.BGPUpdate) { ...@@ -217,6 +217,7 @@ func (s *establishedState) updates(u *packet.BGPUpdate) {
Type: route.BGPPathType, Type: route.BGPPathType,
BGPPath: &route.BGPPath{ BGPPath: &route.BGPPath{
Source: bnet.IPv4ToUint32(s.fsm.peer.addr), Source: bnet.IPv4ToUint32(s.fsm.peer.addr),
EBGP: s.fsm.peer.localASN != s.fsm.peer.peerASN,
}, },
} }
......
...@@ -41,6 +41,9 @@ func (b *BGPPath) Compare(c *BGPPath) int8 { ...@@ -41,6 +41,9 @@ func (b *BGPPath) Compare(c *BGPPath) int8 {
return -1 return -1
} }
// 9.1.2.2. Breaking Ties (Phase 2)
// a)
if c.ASPathLen > b.ASPathLen { if c.ASPathLen > b.ASPathLen {
return 1 return 1
} }
...@@ -49,6 +52,7 @@ func (b *BGPPath) Compare(c *BGPPath) int8 { ...@@ -49,6 +52,7 @@ func (b *BGPPath) Compare(c *BGPPath) int8 {
return -1 return -1
} }
// b)
if c.Origin > b.Origin { if c.Origin > b.Origin {
return 1 return 1
} }
...@@ -57,6 +61,7 @@ func (b *BGPPath) Compare(c *BGPPath) int8 { ...@@ -57,6 +61,7 @@ func (b *BGPPath) Compare(c *BGPPath) int8 {
return -1 return -1
} }
// c)
if c.MED > b.MED { if c.MED > b.MED {
return 1 return 1
} }
...@@ -65,6 +70,18 @@ func (b *BGPPath) Compare(c *BGPPath) int8 { ...@@ -65,6 +70,18 @@ func (b *BGPPath) Compare(c *BGPPath) int8 {
return -1 return -1
} }
// d)
if c.EBGP && !b.EBGP {
return -1
}
if !c.EBGP && b.EBGP {
return 1
}
// e) TODO: interiour cost (hello IS-IS and OSPF)
// f)
if c.BGPIdentifier < b.BGPIdentifier { if c.BGPIdentifier < b.BGPIdentifier {
return 1 return 1
} }
...@@ -73,6 +90,7 @@ func (b *BGPPath) Compare(c *BGPPath) int8 { ...@@ -73,6 +90,7 @@ func (b *BGPPath) Compare(c *BGPPath) int8 {
return -1 return -1
} }
// g)
if c.Source < b.Source { if c.Source < b.Source {
return 1 return 1
} }
...@@ -144,6 +162,7 @@ func (b *BGPPath) better(c *BGPPath) bool { ...@@ -144,6 +162,7 @@ func (b *BGPPath) better(c *BGPPath) bool {
return false return false
} }
// Print all known information about a route in human readable form
func (b *BGPPath) Print() string { func (b *BGPPath) Print() string {
origin := "" origin := ""
switch b.Origin { switch b.Origin {
...@@ -154,20 +173,29 @@ func (b *BGPPath) Print() string { ...@@ -154,20 +173,29 @@ func (b *BGPPath) Print() string {
case 2: case 2:
origin = "IGP" origin = "IGP"
} }
bgpType := "internal"
if b.EBGP {
bgpType = "external"
}
ret := fmt.Sprintf("\t\tLocal Pref: %d\n", b.LocalPref) ret := fmt.Sprintf("\t\tLocal Pref: %d\n", b.LocalPref)
ret += fmt.Sprintf("\t\tOrigin: %s\n", origin) ret += fmt.Sprintf("\t\tOrigin: %s\n", origin)
ret += fmt.Sprintf("\t\tAS Path: %v\n", b.ASPath) ret += fmt.Sprintf("\t\tAS Path: %v\n", b.ASPath)
ret += fmt.Sprintf("\t\tBGP type: %s\n", bgpType)
nh := uint32To4Byte(b.NextHop) nh := uint32To4Byte(b.NextHop)
ret += fmt.Sprintf("\t\tNEXT HOP: %d.%d.%d.%d\n", nh[0], nh[1], nh[2], nh[3]) ret += fmt.Sprintf("\t\tNEXT HOP: %d.%d.%d.%d\n", nh[0], nh[1], nh[2], nh[3])
ret += fmt.Sprintf("\t\tMED: %d\n", b.MED) ret += fmt.Sprintf("\t\tMED: %d\n", b.MED)
ret += fmt.Sprintf("\t\tPath ID: %d\n", b.PathIdentifier) ret += fmt.Sprintf("\t\tPath ID: %d\n", b.PathIdentifier)
ret += fmt.Sprintf("\t\tSource: %d\n", b.Source) src := uint32To4Byte(b.Source)
ret += fmt.Sprintf("\t\tSource: %d.%d.%d.%d\n", src[0], src[1], src[2], src[3])
ret += fmt.Sprintf("\t\tCommunities: %v\n", b.Communities) ret += fmt.Sprintf("\t\tCommunities: %v\n", b.Communities)
ret += fmt.Sprintf("\t\tLargeCommunities: %v\n", b.LargeCommunities) ret += fmt.Sprintf("\t\tLargeCommunities: %v\n", b.LargeCommunities)
return ret return ret
} }
// Prepend the given BGPPath with the given ASN given times
func (b *BGPPath) Prepend(asn uint32, times uint16) { func (b *BGPPath) Prepend(asn uint32, times uint16) {
if times == 0 { if times == 0 {
return return
......
...@@ -58,9 +58,6 @@ func (a *AdjRIBOut) AddPath(pfx bnet.Prefix, p *route.Path) error { ...@@ -58,9 +58,6 @@ func (a *AdjRIBOut) AddPath(pfx bnet.Prefix, p *route.Path) error {
p = p.Copy() p = p.Copy()
if !a.neighbor.IBGP && !a.neighbor.RouteServerClient { if !a.neighbor.IBGP && !a.neighbor.RouteServerClient {
p.BGPPath.Prepend(a.neighbor.LocalASN, 1) p.BGPPath.Prepend(a.neighbor.LocalASN, 1)
}
if !a.neighbor.IBGP && !a.neighbor.RouteServerClient {
p.BGPPath.NextHop = a.neighbor.LocalAddress p.BGPPath.NextHop = a.neighbor.LocalAddress
} }
...@@ -114,14 +111,19 @@ func (a *AdjRIBOut) RemovePath(pfx bnet.Prefix, p *route.Path) bool { ...@@ -114,14 +111,19 @@ func (a *AdjRIBOut) RemovePath(pfx bnet.Prefix, p *route.Path) bool {
} }
a.rt.RemovePath(pfx, p) a.rt.RemovePath(pfx, p)
pathID, err := a.pathIDManager.releasePath(p)
if err != nil { // If the neighbar has AddPath capabilities, try to find the PathID
log.Warningf("Unable to release path: %v", err) if a.neighbor.CapAddPathRX {
return true pathID, err := a.pathIDManager.releasePath(p)
if err != nil {
log.Warningf("Unable to release path for prefix %s: %v", pfx.String(), err)
return true
}
p = p.Copy()
p.BGPPath.PathIdentifier = pathID
} }
p = p.Copy()
p.BGPPath.PathIdentifier = pathID
a.removePathFromClients(pfx, p) a.removePathFromClients(pfx, p)
return true return true
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment