diff options
author | Yuji Oshima <yuji.oshima0x3fd@gmail.com> | 2015-03-11 19:52:53 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-03-11 19:52:53 +0900 |
commit | 2ada9126011a7f4d3ccbb02d2a9339e5c97d6292 (patch) | |
tree | 519e77e07d1bdd9833331cd4a7929e38a8729de6 /table/destination.go | |
parent | 27a1609aca0a448edf43afc149c5d863abf3b04a (diff) |
table: IPv4_VPN route family
Diffstat (limited to 'table/destination.go')
-rw-r--r-- | table/destination.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/table/destination.go b/table/destination.go index 6734229a..edcda695 100644 --- a/table/destination.go +++ b/table/destination.go @@ -936,3 +936,59 @@ func (ipv6d *IPv6Destination) MarshalJSON() ([]byte, error) { BestPathIdx: idx, }) } + +type IPv4VPNDestination struct { + *DestinationDefault + //need structure +} + +func NewIPv4VPNDestination(nlri bgp.AddrPrefixInterface) *IPv4VPNDestination { + ipv4VPNDestination := &IPv4VPNDestination{} + ipv4VPNDestination.DestinationDefault = NewDestinationDefault(nlri) + ipv4VPNDestination.DestinationDefault.ROUTE_FAMILY = bgp.RF_IPv4_VPN + //need Processing + return ipv4VPNDestination +} + +func (ipv4vpnd *IPv4VPNDestination) String() string { + + str := fmt.Sprintf("Destination NLRI: %s", ipv4vpnd.getPrefix().String()) + return str +} + +func (ipv4vpnd *IPv4VPNDestination) getPrefix() net.IP { + var ip net.IP + log.Debugf("type %s", reflect.TypeOf(ipv4vpnd.nlri)) + switch p := ipv4vpnd.nlri.(type) { + case *bgp.IPv6AddrPrefix: + ip = p.IPAddrPrefix.IPAddrPrefixDefault.Prefix + case *bgp.WithdrawnRoute: + ip = p.IPAddrPrefix.IPAddrPrefixDefault.Prefix + } + return ip +} + +func (ipv4vpnd *IPv4VPNDestination) MarshalJSON() ([]byte, error) { + prefix := ipv4vpnd.getNlri().(*bgp.LabelledVPNIPAddrPrefix).Prefix + idx := func() int { + for i, p := range ipv4vpnd.DestinationDefault.knownPathList { + if p == ipv4vpnd.DestinationDefault.getBestPath() { + return i + } + } + log.WithFields(log.Fields{ + "Topic": "Table", + "Key": prefix.String(), + }).Panic("no best path") + return 0 + }() + return json.Marshal(struct { + Prefix string + Paths []Path + BestPathIdx int + }{ + Prefix: prefix.String(), + Paths: ipv4vpnd.knownPathList, + BestPathIdx: idx, + }) +} |