diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-05-18 07:07:56 +0000 |
---|---|---|
committer | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2016-05-18 07:08:52 +0000 |
commit | 70e24d96ece4e9405284434de9458e1fb3c77974 (patch) | |
tree | 88e50e115312c48c6c33e704cde1031926456ec6 /packet | |
parent | 1601fd47cf7b4a78a8a008f8aaffd1041dbf6958 (diff) |
packet/bgp: refactor flowspec AFI(), SAFI() methods
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet')
-rw-r--r-- | packet/bgp/bgp.go | 60 |
1 files changed, 15 insertions, 45 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index 4cfcf35f..bca284d2 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -2956,6 +2956,16 @@ type FlowSpecNLRI struct { rf RouteFamily } +func (n *FlowSpecNLRI) AFI() uint16 { + afi, _ := RouteFamilyToAfiSafi(n.rf) + return afi +} + +func (n *FlowSpecNLRI) SAFI() uint8 { + _, safi := RouteFamilyToAfiSafi(n.rf) + return safi +} + func (n *FlowSpecNLRI) decodeFromBytes(rf RouteFamily, data []byte) error { var length int if (data[0]>>4) == 0xf && len(data) > 2 { @@ -3100,14 +3110,6 @@ func (n *FlowSpecIPv4Unicast) DecodeFromBytes(data []byte) error { return n.decodeFromBytes(AfiSafiToRouteFamily(n.AFI(), n.SAFI()), data) } -func (n *FlowSpecIPv4Unicast) AFI() uint16 { - return AFI_IP -} - -func (n *FlowSpecIPv4Unicast) SAFI() uint8 { - return SAFI_FLOW_SPEC_UNICAST -} - func NewFlowSpecIPv4Unicast(value []FlowSpecComponentInterface) *FlowSpecIPv4Unicast { return &FlowSpecIPv4Unicast{FlowSpecNLRI{value, RF_FS_IPv4_UC}} } @@ -3120,14 +3122,6 @@ func (n *FlowSpecIPv4VPN) DecodeFromBytes(data []byte) error { return n.decodeFromBytes(AfiSafiToRouteFamily(n.AFI(), n.SAFI()), data) } -func (n *FlowSpecIPv4VPN) AFI() uint16 { - return AFI_IP -} - -func (n *FlowSpecIPv4VPN) SAFI() uint8 { - return SAFI_FLOW_SPEC_VPN -} - func NewFlowSpecIPv4VPN(value []FlowSpecComponentInterface) *FlowSpecIPv4VPN { return &FlowSpecIPv4VPN{FlowSpecNLRI{value, RF_FS_IPv4_VPN}} } @@ -3140,14 +3134,6 @@ func (n *FlowSpecIPv6Unicast) DecodeFromBytes(data []byte) error { return n.decodeFromBytes(AfiSafiToRouteFamily(n.AFI(), n.SAFI()), data) } -func (n *FlowSpecIPv6Unicast) AFI() uint16 { - return AFI_IP6 -} - -func (n *FlowSpecIPv6Unicast) SAFI() uint8 { - return SAFI_FLOW_SPEC_UNICAST -} - func NewFlowSpecIPv6Unicast(value []FlowSpecComponentInterface) *FlowSpecIPv6Unicast { return &FlowSpecIPv6Unicast{FlowSpecNLRI{ Value: value, @@ -3163,14 +3149,6 @@ func (n *FlowSpecIPv6VPN) DecodeFromBytes(data []byte) error { return n.decodeFromBytes(AfiSafiToRouteFamily(n.AFI(), n.SAFI()), data) } -func (n *FlowSpecIPv6VPN) AFI() uint16 { - return AFI_IP6 -} - -func (n *FlowSpecIPv6VPN) SAFI() uint8 { - return SAFI_FLOW_SPEC_VPN -} - func NewFlowSpecIPv6VPN(value []FlowSpecComponentInterface) *FlowSpecIPv6VPN { return &FlowSpecIPv6VPN{FlowSpecNLRI{ Value: value, @@ -3186,14 +3164,6 @@ func (n *FlowSpecL2VPN) DecodeFromBytes(data []byte) error { return n.decodeFromBytes(AfiSafiToRouteFamily(n.AFI(), n.SAFI()), data) } -func (n *FlowSpecL2VPN) AFI() uint16 { - return AFI_L2VPN -} - -func (n *FlowSpecL2VPN) SAFI() uint8 { - return SAFI_FLOW_SPEC_VPN -} - func NewFlowSpecL2VPN(value []FlowSpecComponentInterface) *FlowSpecL2VPN { return &FlowSpecL2VPN{FlowSpecNLRI{ Value: value, @@ -3371,15 +3341,15 @@ func NewPrefixFromRouteFamily(afi uint16, safi uint8) (prefix AddrPrefixInterfac case RF_IPv6_ENCAP: prefix = NewEncapv6NLRI("") case RF_FS_IPv4_UC: - prefix = &FlowSpecIPv4Unicast{} + prefix = &FlowSpecIPv4Unicast{FlowSpecNLRI{rf: RF_FS_IPv4_UC}} case RF_FS_IPv4_VPN: - prefix = &FlowSpecIPv4VPN{} + prefix = &FlowSpecIPv4VPN{FlowSpecNLRI{rf: RF_FS_IPv4_VPN}} case RF_FS_IPv6_UC: - prefix = &FlowSpecIPv6Unicast{} + prefix = &FlowSpecIPv6Unicast{FlowSpecNLRI{rf: RF_FS_IPv6_UC}} case RF_FS_IPv6_VPN: - prefix = &FlowSpecIPv6VPN{} + prefix = &FlowSpecIPv6VPN{FlowSpecNLRI{rf: RF_FS_IPv6_VPN}} case RF_FS_L2_VPN: - prefix = &FlowSpecL2VPN{} + prefix = &FlowSpecL2VPN{FlowSpecNLRI{rf: RF_FS_L2_VPN}} case RF_OPAQUE: prefix = &OpaqueNLRI{} default: |