from exabgp.bgp.message.update.nlri.flow import Flow as ExaBGPFlow
from exabgp.bgp.message.update.nlri.nlri import NLRI

from exabgp.reactor.protocol import AFI
from exabgp.reactor.protocol import SAFI

import logging
log = logging.getLogger(__name__)


@NLRI.register(AFI.ipv4, SAFI.flow_vpn, force=True)
@NLRI.register(AFI.ipv6, SAFI.flow_vpn, force=True)
class Flow(ExaBGPFlow):
    '''This wraps an ExaBGP Flow so that __eq__ and __hash__
    meet the criteria for RouteTableManager (in particular,
    not look at actions and nexthop)
    '''

    def __eq__(self, other):
        return self.rd == other.rd and self.rules == other.rules

    def __hash__(self):
        #FIXME: are dicts hashable ?
        log.debug("flow rules: %s", repr(self.rules))
        return hash((self.rd, repr(self.rules)))


def FlowRouteFactory(afi, rd):
    flowRoute = Flow(afi, safi=SAFI.flow_vpn)
    flowRoute.rd = rd
    return flowRoute

from exabgp.bgp.message.update.nlri.flow import Flow as ExaBGPFlow
from exabgp.bgp.message.update.nlri.nlri import NLRI

from exabgp.reactor.protocol import AFI
from exabgp.reactor.protocol import SAFI

import logging
log = logging.getLogger(__name__)


@NLRI.register(AFI.ipv4, SAFI.flow_vpn, force=True)
@NLRI.register(AFI.ipv6, SAFI.flow_vpn, force=True)
class Flow(ExaBGPFlow):
    '''This wraps an ExaBGP Flow so that __eq__ and __hash__
    meet the criteria for RouteTableManager (in particular,
    not look at actions and nexthop)
    '''

    def __eq__(self, other):
        return self.pack() == other.pack()

    def __hash__(self):
        return hash(self.pack())

    def __repr__(self):
        return str(self)


def FlowRouteFactory(afi, rd):
    flowRoute = Flow(afi, safi=SAFI.flow_vpn)
    flowRoute.rd = rd
    return flowRoute

Fix eq/hash for FlowSpec NLRI
Fix eq/hash for FlowSpec NLRI

Bogus eq/hash was preventing withdraws from behaving
properly.

  from exabgp.bgp.message.update.nlri.flow import Flow as ExaBGPFlow
  from exabgp.bgp.message.update.nlri.nlri import NLRI
  
  from exabgp.reactor.protocol import AFI
  from exabgp.reactor.protocol import SAFI
  
  import logging
  log = logging.getLogger(__name__)
  
  
  @NLRI.register(AFI.ipv4, SAFI.flow_vpn, force=True)
  @NLRI.register(AFI.ipv6, SAFI.flow_vpn, force=True)
  class Flow(ExaBGPFlow):
      '''This wraps an ExaBGP Flow so that __eq__ and __hash__
      meet the criteria for RouteTableManager (in particular,
      not look at actions and nexthop)
      '''
  
      def __eq__(self, other):
-         return self.rd == other.rd and self.rules == other.rules
+         return self.pack() == other.pack()
  
      def __hash__(self):
-         #FIXME: are dicts hashable ?
-         log.debug("flow rules: %s", repr(self.rules))
-         return hash((self.rd, repr(self.rules)))
+         return hash(self.pack())
+ 
+     def __repr__(self):
+         return str(self)
  
  
  def FlowRouteFactory(afi, rd):
      flowRoute = Flow(afi, safi=SAFI.flow_vpn)
      flowRoute.rd = rd
      return flowRoute
  
Fix eq/hash for FlowSpec NLRI
## Code Before:
from exabgp.bgp.message.update.nlri.flow import Flow as ExaBGPFlow
from exabgp.bgp.message.update.nlri.nlri import NLRI

from exabgp.reactor.protocol import AFI
from exabgp.reactor.protocol import SAFI

import logging
log = logging.getLogger(__name__)


@NLRI.register(AFI.ipv4, SAFI.flow_vpn, force=True)
@NLRI.register(AFI.ipv6, SAFI.flow_vpn, force=True)
class Flow(ExaBGPFlow):
    '''This wraps an ExaBGP Flow so that __eq__ and __hash__
    meet the criteria for RouteTableManager (in particular,
    not look at actions and nexthop)
    '''

    def __eq__(self, other):
        return self.rd == other.rd and self.rules == other.rules

    def __hash__(self):
        #FIXME: are dicts hashable ?
        log.debug("flow rules: %s", repr(self.rules))
        return hash((self.rd, repr(self.rules)))


def FlowRouteFactory(afi, rd):
    flowRoute = Flow(afi, safi=SAFI.flow_vpn)
    flowRoute.rd = rd
    return flowRoute

## Instruction:
Fix eq/hash for FlowSpec NLRI
## Code After:
from exabgp.bgp.message.update.nlri.flow import Flow as ExaBGPFlow
from exabgp.bgp.message.update.nlri.nlri import NLRI

from exabgp.reactor.protocol import AFI
from exabgp.reactor.protocol import SAFI

import logging
log = logging.getLogger(__name__)


@NLRI.register(AFI.ipv4, SAFI.flow_vpn, force=True)
@NLRI.register(AFI.ipv6, SAFI.flow_vpn, force=True)
class Flow(ExaBGPFlow):
    '''This wraps an ExaBGP Flow so that __eq__ and __hash__
    meet the criteria for RouteTableManager (in particular,
    not look at actions and nexthop)
    '''

    def __eq__(self, other):
        return self.pack() == other.pack()

    def __hash__(self):
        return hash(self.pack())

    def __repr__(self):
        return str(self)


def FlowRouteFactory(afi, rd):
    flowRoute = Flow(afi, safi=SAFI.flow_vpn)
    flowRoute.rd = rd
    return flowRoute
