Skip to content
Snippets Groups Projects
Commit d585abb2 authored by Daniel Czerwonk's avatar Daniel Czerwonk
Browse files

Merge remote-tracking branch 'origin/master' into feature/ipv6_support_mp_reach

parents 5f18c477 3107db5e
No related branches found
No related tags found
No related merge requests found
...@@ -142,8 +142,3 @@ type PathAttribute struct { ...@@ -142,8 +142,3 @@ type PathAttribute struct {
Value interface{} Value interface{}
Next *PathAttribute Next *PathAttribute
} }
type Aggretator struct {
Addr uint32
ASN uint16
}
...@@ -1197,9 +1197,9 @@ func TestDecodeUpdateMsg(t *testing.T) { ...@@ -1197,9 +1197,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"),
}, },
}, },
}, },
......
...@@ -232,28 +232,15 @@ func (pa *PathAttribute) decodeLocalPref(buf *bytes.Buffer) error { ...@@ -232,28 +232,15 @@ 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, &aggr.Address})
if err != nil { if err != nil {
return err return err
} }
p += 2 p += 6
addr := [4]byte{}
n, err := buf.Read(addr[:])
if err != nil {
return err
}
if n != 4 {
return fmt.Errorf("Unable to read next hop: buf.Read read %d bytes", n)
}
aggr.Addr = fourBytesToUint32(addr)
pa.Value = aggr pa.Value = aggr
p += 4
return dumpNBytes(buf, pa.Length-p) return dumpNBytes(buf, pa.Length-p)
} }
...@@ -505,10 +492,14 @@ func (pa *PathAttribute) serializeAggregator(buf *bytes.Buffer) uint8 { ...@@ -505,10 +492,14 @@ func (pa *PathAttribute) serializeAggregator(buf *bytes.Buffer) uint8 {
attrFlags = setTransitive(attrFlags) attrFlags = setTransitive(attrFlags)
buf.WriteByte(attrFlags) buf.WriteByte(attrFlags)
buf.WriteByte(AggregatorAttr) buf.WriteByte(AggregatorAttr)
length := uint8(2) length := uint8(6)
buf.WriteByte(length) buf.WriteByte(length)
buf.Write(convert.Uint16Byte(pa.Value.(uint16)))
return 5 aggregator := pa.Value.(types.Aggregator)
buf.Write(convert.Uint16Byte(aggregator.ASN))
buf.Write(convert.Uint32Byte(aggregator.Address))
return 9
} }
func (pa *PathAttribute) serializeCommunities(buf *bytes.Buffer) uint8 { func (pa *PathAttribute) serializeCommunities(buf *bytes.Buffer) uint8 {
...@@ -630,33 +621,56 @@ func (pa *PathAttribute) AddOptionalPathAttributes(p *route.Path) *PathAttribute ...@@ -630,33 +621,56 @@ 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
if p.BGPPath.AtomicAggregate {
atomicAggr := &PathAttribute{
TypeCode: AtomicAggrAttr,
}
last.Next = atomicAggr
last = atomicAggr
}
localPref := &PathAttribute{ if p.BGPPath.Aggregator != nil {
TypeCode: LocalPrefAttr, aggregator := &PathAttribute{
Value: p.BGPPath.LocalPref, TypeCode: AggregatorAttr,
Value: p.BGPPath.Aggregator,
}
last.Next = aggregator
last = aggregator
}
if iBGP {
localPref := &PathAttribute{
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,
......
...@@ -564,9 +564,9 @@ func TestDecodeAggregator(t *testing.T) { ...@@ -564,9 +564,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"),
}, },
}, },
}, },
...@@ -1138,15 +1138,19 @@ func TestSerializeAggregator(t *testing.T) { ...@@ -1138,15 +1138,19 @@ func TestSerializeAggregator(t *testing.T) {
name: "Test #1", name: "Test #1",
input: &PathAttribute{ input: &PathAttribute{
TypeCode: AggregatorAttr, TypeCode: AggregatorAttr,
Value: uint16(174), Value: types.Aggregator{
ASN: 174,
Address: strAddr("10.20.30.40"),
},
}, },
expected: []byte{ expected: []byte{
192, // Attribute flags 192, // Attribute flags
7, // Type 7, // Type
2, // Length 6, // Length
0, 174, // Value = 174 0, 174, // Value = 174
10, 20, 30, 40,
}, },
expectedLen: 5, expectedLen: 9,
}, },
} }
...@@ -1511,7 +1515,10 @@ func TestSerialize(t *testing.T) { ...@@ -1511,7 +1515,10 @@ func TestSerialize(t *testing.T) {
TypeCode: AtomicAggrAttr, TypeCode: AtomicAggrAttr,
Next: &PathAttribute{ Next: &PathAttribute{
TypeCode: AggregatorAttr, TypeCode: AggregatorAttr,
Value: uint16(200), Value: types.Aggregator{
ASN: 200,
Address: strAddr("10.20.30.40"),
},
}, },
}, },
}, },
...@@ -1530,7 +1537,7 @@ func TestSerialize(t *testing.T) { ...@@ -1530,7 +1537,7 @@ func TestSerialize(t *testing.T) {
}, },
expected: []byte{ expected: []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0, 86, // Length 0, 90, // Length
2, // Msg Type 2, // Msg Type
// Withdraws // Withdraws
...@@ -1538,7 +1545,7 @@ func TestSerialize(t *testing.T) { ...@@ -1538,7 +1545,7 @@ func TestSerialize(t *testing.T) {
8, 10, // Withdraw 10/8 8, 10, // Withdraw 10/8
16, 192, 168, // Withdraw 192.168/16 16, 192, 168, // Withdraw 192.168/16
0, 50, // Total Path Attribute Length 0, 54, // Total Path Attribute Length
// ORIGIN // ORIGIN
64, // Attr. Flags 64, // Attr. Flags
...@@ -1577,8 +1584,9 @@ func TestSerialize(t *testing.T) { ...@@ -1577,8 +1584,9 @@ func TestSerialize(t *testing.T) {
// Aggregator // Aggregator
192, // Attr. Flags 192, // Attr. Flags
7, // Attr. Type Code 7, // Attr. Type Code
2, // Length 6, // Length
0, 200, // Aggregator ASN = 200 0, 200, // Aggregator ASN = 200
10, 20, 30, 40, // Aggregator Address
// NLRI // NLRI
24, 8, 8, 8, // 8.8.8.0/24 24, 8, 8, 8, // 8.8.8.0/24
...@@ -1716,7 +1724,10 @@ func TestSerializeAddPath(t *testing.T) { ...@@ -1716,7 +1724,10 @@ func TestSerializeAddPath(t *testing.T) {
TypeCode: AtomicAggrAttr, TypeCode: AtomicAggrAttr,
Next: &PathAttribute{ Next: &PathAttribute{
TypeCode: AggregatorAttr, TypeCode: AggregatorAttr,
Value: uint16(200), Value: types.Aggregator{
ASN: 200,
Address: strAddr("10.20.30.40"),
},
}, },
}, },
}, },
...@@ -1735,7 +1746,7 @@ func TestSerializeAddPath(t *testing.T) { ...@@ -1735,7 +1746,7 @@ func TestSerializeAddPath(t *testing.T) {
}, },
expected: []byte{ expected: []byte{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0, 102, // Length 0, 106, // Length
2, // Msg Type 2, // Msg Type
// Withdraws // Withdraws
...@@ -1745,7 +1756,7 @@ func TestSerializeAddPath(t *testing.T) { ...@@ -1745,7 +1756,7 @@ func TestSerializeAddPath(t *testing.T) {
0, 0, 0, 0, // Path Identifier 0, 0, 0, 0, // Path Identifier
16, 192, 168, // Withdraw 192.168/16 16, 192, 168, // Withdraw 192.168/16
0, 50, // Total Path Attribute Length 0, 54, // Total Path Attribute Length
// ORIGIN // ORIGIN
64, // Attr. Flags 64, // Attr. Flags
...@@ -1784,8 +1795,9 @@ func TestSerializeAddPath(t *testing.T) { ...@@ -1784,8 +1795,9 @@ func TestSerializeAddPath(t *testing.T) {
// Aggregator // Aggregator
192, // Attr. Flags 192, // Attr. Flags
7, // Attr. Type Code 7, // Attr. Type Code
2, // Length 6, // Length
0, 200, // Aggregator ASN = 200 0, 200, // Aggregator ASN = 200
10, 20, 30, 40, // Aggregator Address
// NLRI // NLRI
0, 0, 0, 0, // Path Identifier 0, 0, 0, 0, // Path Identifier
......
...@@ -244,6 +244,11 @@ func (s *establishedState) processAttributes(attrs *packet.PathAttribute, path * ...@@ -244,6 +244,11 @@ 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:
aggr := pa.Value.(types.Aggregator)
path.BGPPath.Aggregator = &aggr
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
......
...@@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") ...@@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library( go_library(
name = "go_default_library", name = "go_default_library",
srcs = [ srcs = [
"aggregator.go",
"as_path.go", "as_path.go",
"community.go", "community.go",
"large_community.go", "large_community.go",
......
package types
// Aggregator represents an AGGREGATOR attribute (type code 7) as in RFC4271
type Aggregator struct {
ASN uint16
Address uint32
}
...@@ -20,6 +20,8 @@ type BGPPath struct { ...@@ -20,6 +20,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 bnet.IP Source bnet.IP
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