aboutsummaryrefslogtreecommitdiffstats
path: root/netmodel/model/type.py
diff options
context:
space:
mode:
authorMarcel Enguehard <mengueha+fdio@cisco.com>2017-09-01 11:22:33 +0200
committerMarcel Enguehard <mengueha+fdio@cisco.com>2017-09-01 11:22:33 +0200
commit26ee5a8eadbbbf613616963268a9ff20ac1f9beb (patch)
tree01ae122fd1332b7cd5d68f09ed62896250087d85 /netmodel/model/type.py
parentb8cf65ae7d52754b33c8301e304bc01964b0b36f (diff)
Skip internet address for multicast channels
Change-Id: Id91e3646a9b9fe60923d6f738fe627427968b8ad Signed-off-by: Marcel Enguehard <mengueha+fdio@cisco.com>
Diffstat (limited to 'netmodel/model/type.py')
-rw-r--r--netmodel/model/type.py22
1 files changed, 6 insertions, 16 deletions
diff --git a/netmodel/model/type.py b/netmodel/model/type.py
index 9a7b8740..19be3105 100644
--- a/netmodel/model/type.py
+++ b/netmodel/model/type.py
@@ -149,12 +149,16 @@ class Prefix(BaseType, metaclass=ABCMeta):
return self.get_iterator()
#Iterates by steps of prefix_len, e.g., on all available /31 in a /24
- def get_iterator(self, prefix_len=None):
+ def get_iterator(self, prefix_len=None, skip_internet_address=False):
if prefix_len is None:
prefix_len=self.MAX_PREFIX_SIZE
assert (prefix_len >= self.prefix_len and prefix_len<=self.MAX_PREFIX_SIZE)
step = 2**(self.MAX_PREFIX_SIZE - prefix_len)
- for ip in range(self.first_prefix_address(), self.last_prefix_address()+1, step):
+
+ start = self.first_prefix_address()
+ if skip_internet_address:
+ start = start+1
+ for ip in range(start, self.last_prefix_address()+1, step):
yield type(self)(ip, prefix_len)
class Inet4Prefix(Prefix):
@@ -190,20 +194,6 @@ class Inet6Prefix(Prefix):
def ntoa (cls, address):
return inet_ntop(AF_INET6, pack(">QQ", address >> 64, address & ((1 << 64) -1)))
- #skip_internet_address: skip a:b::0, as v6 often use default /64 prefixes
- def get_iterator(self, prefix_len=None, skip_internet_address=None):
- if skip_internet_address is None:
- #We skip the internet address if we iterate over Addresses
- if prefix_len is None:
- skip_internet_address = True
- #But not if we iterate over prefixes
- else:
- skip_internet_address = False
- it = super().get_iterator(prefix_len)
- if skip_internet_address:
- next(it)
- return it
-
class InetAddress(Prefix):
def get_tuple(self):