Skip to content
Snippets Groups Projects
Commit 9686de13 authored by Oliver Herms's avatar Oliver Herms
Browse files

Fixing AGGREGATOR and ATOMIC_AGGREGATE

parent dc8e17be
No related branches found
No related tags found
No related merge requests found
...@@ -140,8 +140,3 @@ type PathAttribute struct { ...@@ -140,8 +140,3 @@ type PathAttribute struct {
Value interface{} Value interface{}
Next *PathAttribute Next *PathAttribute
} }
type Aggretator struct {
Addr uint32
ASN uint16
}
...@@ -1195,9 +1195,9 @@ func TestDecodeUpdateMsg(t *testing.T) { ...@@ -1195,9 +1195,9 @@ func TestDecodeUpdateMsg(t *testing.T) {
ExtendedLength: false, ExtendedLength: false,
Length: 6, Length: 6,
TypeCode: 7, TypeCode: 7,
Value: Aggretator{ Value: types.Aggregator{
ASN: uint16(258), ASN: uint16(258),
Addr: strAddr("10.11.12.13"), Address: strAddr("10.11.12.13"),
}, },
}, },
}, },
......
...@@ -224,7 +224,7 @@ func (pa *PathAttribute) decodeLocalPref(buf *bytes.Buffer) error { ...@@ -224,7 +224,7 @@ func (pa *PathAttribute) decodeLocalPref(buf *bytes.Buffer) error {
} }
func (pa *PathAttribute) decodeAggregator(buf *bytes.Buffer) error { func (pa *PathAttribute) decodeAggregator(buf *bytes.Buffer) error {
aggr := Aggretator{} aggr := types.Aggregator{}
p := uint16(0) p := uint16(0)
err := decode(buf, []interface{}{&aggr.ASN}) err := decode(buf, []interface{}{&aggr.ASN})
...@@ -241,7 +241,7 @@ func (pa *PathAttribute) decodeAggregator(buf *bytes.Buffer) error { ...@@ -241,7 +241,7 @@ func (pa *PathAttribute) decodeAggregator(buf *bytes.Buffer) error {
if n != 4 { if n != 4 {
return fmt.Errorf("Unable to read next hop: buf.Read read %d bytes", n) return fmt.Errorf("Unable to read next hop: buf.Read read %d bytes", n)
} }
aggr.Addr = fourBytesToUint32(addr) aggr.Address = fourBytesToUint32(addr)
pa.Value = aggr pa.Value = aggr
p += 4 p += 4
...@@ -622,33 +622,39 @@ func (pa *PathAttribute) AddOptionalPathAttributes(p *route.Path) *PathAttribute ...@@ -622,33 +622,39 @@ func (pa *PathAttribute) AddOptionalPathAttributes(p *route.Path) *PathAttribute
} }
// PathAttributes converts a path object into a linked list of path attributes // PathAttributes converts a path object into a linked list of path attributes
func PathAttributes(p *route.Path) (*PathAttribute, error) { func PathAttributes(p *route.Path, iBGP bool) (*PathAttribute, error) {
asPath := &PathAttribute{ asPath := &PathAttribute{
TypeCode: ASPathAttr, TypeCode: ASPathAttr,
Value: p.BGPPath.ASPath, Value: p.BGPPath.ASPath,
} }
last := asPath
origin := &PathAttribute{ origin := &PathAttribute{
TypeCode: OriginAttr, TypeCode: OriginAttr,
Value: p.BGPPath.Origin, Value: p.BGPPath.Origin,
} }
asPath.Next = origin last.Next = origin
last = origin
nextHop := &PathAttribute{ nextHop := &PathAttribute{
TypeCode: NextHopAttr, TypeCode: NextHopAttr,
Value: p.BGPPath.NextHop, Value: p.BGPPath.NextHop,
} }
origin.Next = nextHop last.Next = nextHop
last = nextHop
localPref := &PathAttribute{ if iBGP {
TypeCode: LocalPrefAttr, localPref := &PathAttribute{
Value: p.BGPPath.LocalPref, TypeCode: LocalPrefAttr,
Value: p.BGPPath.LocalPref,
}
last.Next = localPref
last = localPref
} }
nextHop.Next = localPref
optionals := localPref.AddOptionalPathAttributes(p) optionals := last.AddOptionalPathAttributes(p)
last := optionals last = optionals
for _, unknownAttr := range p.BGPPath.UnknownAttributes { for _, unknownAttr := range p.BGPPath.UnknownAttributes {
last.Next = &PathAttribute{ last.Next = &PathAttribute{
TypeCode: unknownAttr.TypeCode, TypeCode: unknownAttr.TypeCode,
......
...@@ -563,9 +563,9 @@ func TestDecodeAggregator(t *testing.T) { ...@@ -563,9 +563,9 @@ func TestDecodeAggregator(t *testing.T) {
wantFail: false, wantFail: false,
expected: &PathAttribute{ expected: &PathAttribute{
Length: 6, Length: 6,
Value: Aggretator{ Value: types.Aggregator{
ASN: 222, ASN: 222,
Addr: strAddr("10.20.30.40"), Address: strAddr("10.20.30.40"),
}, },
}, },
}, },
......
...@@ -244,6 +244,10 @@ func (s *establishedState) processAttributes(attrs *packet.PathAttribute, path * ...@@ -244,6 +244,10 @@ func (s *establishedState) processAttributes(attrs *packet.PathAttribute, path *
case packet.ASPathAttr: case packet.ASPathAttr:
path.BGPPath.ASPath = pa.Value.(types.ASPath) path.BGPPath.ASPath = pa.Value.(types.ASPath)
path.BGPPath.ASPathLen = path.BGPPath.ASPath.Length() path.BGPPath.ASPathLen = path.BGPPath.ASPath.Length()
case packet.AggregatorAttr:
path.BGPPath.Aggregator = pa.Value.(types.Aggregator)
case packet.AtomicAggrAttr:
path.BGPPath.AtomicAggregate = true
case packet.CommunitiesAttr: case packet.CommunitiesAttr:
path.BGPPath.Communities = pa.Value.([]uint32) path.BGPPath.Communities = pa.Value.([]uint32)
case packet.LargeCommunitiesAttr: case packet.LargeCommunitiesAttr:
......
...@@ -86,7 +86,7 @@ func (u *UpdateSender) sender(aggrTime time.Duration) { ...@@ -86,7 +86,7 @@ func (u *UpdateSender) sender(aggrTime time.Duration) {
for key, pathNLRIs := range u.toSend { for key, pathNLRIs := range u.toSend {
budget = packet.MaxLen - packet.HeaderLen - packet.MinUpdateLen - int(pathNLRIs.path.BGPPath.Length()) budget = packet.MaxLen - packet.HeaderLen - packet.MinUpdateLen - int(pathNLRIs.path.BGPPath.Length())
pathAttrs, err = packet.PathAttributes(pathNLRIs.path) pathAttrs, err = packet.PathAttributes(pathNLRIs.path, u.iBGP)
if err != nil { if err != nil {
log.Errorf("Unable to get path attributes: %v", err) log.Errorf("Unable to get path attributes: %v", err)
continue continue
......
...@@ -19,6 +19,8 @@ type BGPPath struct { ...@@ -19,6 +19,8 @@ type BGPPath struct {
Origin uint8 Origin uint8
MED uint32 MED uint32
EBGP bool EBGP bool
AtomicAggregate bool
Aggregator types.Aggregator
BGPIdentifier uint32 BGPIdentifier uint32
Source uint32 Source uint32
Communities []uint32 Communities []uint32
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment