diff options
author | Antoine Eiche <antoine.eiche@cloudwatt.com> | 2016-06-14 08:09:14 +0000 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-06-14 16:46:39 +0900 |
commit | 2f7d308c063289de51dfda52bde37fd276e3ce08 (patch) | |
tree | ad652bd15624c47224301c90fccb60cdde01949d /packet | |
parent | 70f709558781ba6a0ea4d8513d80ef5c80e34c41 (diff) |
bgp: add FlatUpdate to merge Flat representations
Update a Flat representation by adding elements of the second one. If
two elements use same keys, values are separated with ';'. In this
case, it returns an error but the update has been realized.
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bgp/bgp.go | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index 75dda14f..5352e825 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -7146,9 +7146,7 @@ func (e *TrafficActionExtended) Flat() map[string]string { func (p *PathAttributeExtendedCommunities) Flat() map[string]string { flat := map[string]string{} for _, ec := range p.Value { - for k, v := range ec.Flat() { - flat[k] = v - } + FlatUpdate(flat, ec.Flat()) } return flat } @@ -7201,3 +7199,24 @@ func (l *FlowSpecL2VPN) Flat() map[string]string { func (l *OpaqueNLRI) Flat() map[string]string { return map[string]string{} } + +// Update a Flat representation by adding elements of the second +// one. If two elements use same keys, values are separated with +// ';'. In this case, it returns an error but the update has been +// realized. +func FlatUpdate(f1, f2 map[string]string) error { + conflict := false + for k2, v2 := range f2 { + if v1, ok := f1[k2]; ok { + f1[k2] = v1 + ";" + v2 + conflict = true + } else { + f1[k2] = v2 + } + } + if conflict { + return fmt.Errorf("Keys conflict") + } else { + return nil + } +} |