Merge branch 'coretk' into coretk-progress

This commit is contained in:
Huy Pham 2019-11-22 14:56:05 -08:00
commit 4788d7aacc
7 changed files with 49 additions and 33 deletions

View file

@ -1,7 +1,7 @@
"""
bird.py: defines routing services provided by the BIRD Internet Routing Daemon.
"""
from core.nodes import ipaddress
from core.services.coreservices import CoreService
@ -38,8 +38,9 @@ class Bird(CoreService):
if hasattr(ifc, "control") and ifc.control is True:
continue
for a in ifc.addrlist:
if a.find(".") >= 0:
return a.split("/")[0]
a = a.split("/")[0]
if ipaddress.is_ipv4_address(a):
return a
# raise ValueError, "no IPv4 address found for router ID"
return "0.0.0.0"

View file

@ -112,9 +112,10 @@ class FRRZebra(CoreService):
"""
helper for mapping IP addresses to zebra config statements
"""
if x.find(".") >= 0:
addr = x.split("/")[0]
if ipaddress.is_ipv4_address(addr):
return "ip address %s" % x
elif x.find(":") >= 0:
elif ipaddress.is_ipv6_address(addr):
return "ipv6 address %s" % x
else:
raise ValueError("invalid address: %s", x)
@ -328,8 +329,9 @@ class FrrService(CoreService):
if hasattr(ifc, "control") and ifc.control is True:
continue
for a in ifc.addrlist:
if a.find(".") >= 0:
return a.split("/")[0]
a = a.split("/")[0]
if ipaddress.is_ipv4_address(a):
return a
# raise ValueError, "no IPv4 address found for router ID"
return "0.0.0.0"
@ -411,7 +413,8 @@ class FRROspfv2(FrrService):
if hasattr(ifc, "control") and ifc.control is True:
continue
for a in ifc.addrlist:
if a.find(".") < 0:
addr = a.split("/")[0]
if not ipaddress.is_ipv4_address(addr):
continue
net = ipaddress.Ipv4Prefix(a)
cfg += " network %s area 0\n" % net

View file

@ -4,6 +4,7 @@ nrl.py: defines services provided by NRL protolib tools hosted here:
"""
from core import utils
from core.nodes import ipaddress
from core.nodes.ipaddress import Ipv4Prefix
from core.services.coreservices import CoreService
@ -36,9 +37,9 @@ class NrlService(CoreService):
if hasattr(ifc, "control") and ifc.control is True:
continue
for a in ifc.addrlist:
if a.find(".") >= 0:
addr = a.split("/")[0]
pre = Ipv4Prefix("%s/%s" % (addr, prefixlen))
a = a.split("/")[0]
if ipaddress.is_ipv4_address(a):
pre = Ipv4Prefix("%s/%s" % (a, prefixlen))
return str(pre)
# raise ValueError, "no IPv4 address found"
return "0.0.0.0/%s" % prefixlen

View file

@ -109,9 +109,10 @@ class Zebra(CoreService):
"""
helper for mapping IP addresses to zebra config statements
"""
if x.find(".") >= 0:
addr = x.split("/")[0]
if ipaddress.is_ipv4_address(addr):
return "ip address %s" % x
elif x.find(":") >= 0:
elif ipaddress.is_ipv6_address(addr):
return "ipv6 address %s" % x
else:
raise ValueError("invalid address: %s", x)
@ -255,8 +256,9 @@ class QuaggaService(CoreService):
if hasattr(ifc, "control") and ifc.control is True:
continue
for a in ifc.addrlist:
if a.find(".") >= 0:
return a.split("/")[0]
a = a.split("/")[0]
if ipaddress.is_ipv4_address(a):
return a
# raise ValueError, "no IPv4 address found for router ID"
return "0.0.0.0"
@ -338,10 +340,10 @@ class Ospfv2(QuaggaService):
if hasattr(ifc, "control") and ifc.control is True:
continue
for a in ifc.addrlist:
if a.find(".") < 0:
continue
net = ipaddress.Ipv4Prefix(a)
cfg += " network %s area 0\n" % net
addr = a.split("/")[0]
if ipaddress.is_ipv4_address(addr):
net = ipaddress.Ipv4Prefix(a)
cfg += " network %s area 0\n" % net
cfg += "!\n"
return cfg

View file

@ -4,6 +4,7 @@ sdn.py defines services to start Open vSwitch and the Ryu SDN Controller.
import re
from core.nodes import ipaddress
from core.services.coreservices import CoreService
@ -56,11 +57,12 @@ class OvsService(SdnService):
# remove ip address of eths because quagga/zebra will assign same IPs to rtr interfaces
# or assign them manually to rtr interfaces if zebra is not running
for ifcaddr in ifc.addrlist:
if ifcaddr.find(".") >= 0:
addr = ifcaddr.split("/")[0]
if ipaddress.is_ipv4_address(addr):
cfg += "ip addr del %s dev %s\n" % (ifcaddr, ifc.name)
if has_zebra == 0:
cfg += "ip addr add %s dev rtr%s\n" % (ifcaddr, ifnum)
elif ifcaddr.find(":") >= 0:
elif ipaddress.is_ipv6_address(addr):
cfg += "ip -6 addr del %s dev %s\n" % (ifcaddr, ifc.name)
if has_zebra == 0:
cfg += "ip -6 addr add %s dev rtr%s\n" % (ifcaddr, ifnum)

View file

@ -6,6 +6,7 @@ import os
from core import constants, utils
from core.errors import CoreCommandError
from core.nodes import ipaddress
from core.nodes.ipaddress import Ipv4Prefix, Ipv6Prefix
from core.services.coreservices import CoreService
@ -87,7 +88,8 @@ class DefaultRouteService(UtilService):
@staticmethod
def addrstr(x):
if x.find(":") >= 0:
addr = x.split("/")[0]
if ipaddress.is_ipv6_address(addr):
net = Ipv6Prefix(x)
else:
net = Ipv4Prefix(x)
@ -147,7 +149,8 @@ class StaticRouteService(UtilService):
@staticmethod
def routestr(x):
if x.find(":") >= 0:
addr = x.split("/")[0]
if ipaddress.is_ipv6_address(addr):
net = Ipv6Prefix(x)
dst = "3ffe:4::/64"
else:
@ -280,7 +283,8 @@ ddns-update-style none;
Generate a subnet declaration block given an IPv4 prefix string
for inclusion in the dhcpd3 config file.
"""
if x.find(":") >= 0:
addr = x.split("/")[0]
if ipaddress.is_ipv6_address(addr):
return ""
else:
addr = x.split("/")[0]
@ -702,7 +706,8 @@ interface %s
Generate a subnet declaration block given an IPv6 prefix string
for inclusion in the RADVD config file.
"""
if x.find(":") >= 0:
addr = x.split("/")[0]
if ipaddress.is_ipv6_address(addr):
net = Ipv6Prefix(x)
return str(net)
else:

View file

@ -4,6 +4,7 @@ xorp.py: defines routing services provided by the XORP routing suite.
import logging
from core.nodes import ipaddress
from core.services.coreservices import CoreService
@ -150,8 +151,9 @@ class XorpService(CoreService):
if hasattr(ifc, "control") and ifc.control is True:
continue
for a in ifc.addrlist:
if a.find(".") >= 0:
return a.split("/")[0]
a = a.split("/")[0]
if ipaddress.is_ipv4_address(a):
return a
# raise ValueError, "no IPv4 address found for router ID"
return "0.0.0.0"
@ -187,9 +189,9 @@ class XorpOspfv2(XorpService):
cfg += "\t interface %s {\n" % ifc.name
cfg += "\t\tvif %s {\n" % ifc.name
for a in ifc.addrlist:
if a.find(".") < 0:
continue
addr = a.split("/")[0]
if not ipaddress.is_ipv4_address(addr):
continue
cfg += "\t\t address %s {\n" % addr
cfg += "\t\t }\n"
cfg += "\t\t}\n"
@ -280,9 +282,9 @@ class XorpRip(XorpService):
cfg += "\tinterface %s {\n" % ifc.name
cfg += "\t vif %s {\n" % ifc.name
for a in ifc.addrlist:
if a.find(".") < 0:
continue
addr = a.split("/")[0]
if not ipaddress.is_ipv4_address(addr):
continue
cfg += "\t\taddress %s {\n" % addr
cfg += "\t\t disable: false\n"
cfg += "\t\t}\n"
@ -462,9 +464,9 @@ class XorpOlsr(XorpService):
cfg += "\tinterface %s {\n" % ifc.name
cfg += "\t vif %s {\n" % ifc.name
for a in ifc.addrlist:
if a.find(".") < 0:
continue
addr = a.split("/")[0]
if not ipaddress.is_ipv4_address(addr):
continue
cfg += "\t\taddress %s {\n" % addr
cfg += "\t\t}\n"
cfg += "\t }\n"