From 2f7d308c063289de51dfda52bde37fd276e3ce08 Mon Sep 17 00:00:00 2001 From: Antoine Eiche Date: Tue, 14 Jun 2016 08:09:14 +0000 Subject: 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. --- packet/bgp/bgp.go | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'packet') 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 + } +} -- cgit v1.2.3