示例#1
0
 def build_topo(self, topology):
     real_topo = topology.real
     intf_conv = file_io.read_yaml(INTF_CONV_FILE)
     for ((a_name, a_intf), (b_name, b_intf)) in real_topo:
         a_device = Switch(a_name,
                           L2_IMAGE) if 'sw' in a_name.lower() else Router(
                               a_name, L3_IMAGE)
         b_device = Switch(b_name,
                           L2_IMAGE) if 'sw' in b_name.lower() else Router(
                               b_name, L3_IMAGE)
         if a_name not in self.nodes:
             self.nodes[a_name] = self.lab.create_node(a_device)
             # print("*** NODE {} CREATED".format(a_name))
         if b_name not in self.nodes:
             self.nodes[b_name] = self.lab.create_node(b_device)
             # print("*** NODE {} CREATED".format(b_name))
         node_a = self.nodes[a_name]
         node_b = self.nodes[b_name]
         if intf_conv.get(a_name, {}).get(a_intf, None):
             a_intf_lab = intf_conv[a_name][a_intf]
         else:
             a_intf_lab = node_a.get_next_intf()
         if intf_conv.get(b_name, {}).get(b_intf, None):
             b_intf_lab = intf_conv[b_name][b_intf]
         else:
             b_intf_lab = node_b.get_next_intf()
         intf_conv.setdefault(a_name, {})[a_intf] = a_intf_lab
         intf_conv.setdefault(b_name, {})[b_intf] = b_intf_lab
         node_a.connect_node(a_intf_lab, node_b, b_intf_lab)
         # print("*** NODES {} and {} ARE CONNECTED".format(a_name, b_name))
     file_io.write_yaml(INTF_CONV_FILE, intf_conv)
     return None
示例#2
0
 def build_topo(self, topology):
     real_topo = topology.real
     intf_conv = file_io.read_yaml(INTF_CONV_FILE)
     for ((a_name, a_intf), (b_name, b_intf)) in real_topo:
         a_device = Switch(a_name, L2_IMAGE) if "sw" in a_name.lower() else Router(a_name, L3_IMAGE)
         b_device = Switch(b_name, L2_IMAGE) if "sw" in b_name.lower() else Router(b_name, L3_IMAGE)
         if a_name not in self.nodes:
             self.nodes[a_name] = self.lab.create_node(a_device)
             # print("*** NODE {} CREATED".format(a_name))
         if b_name not in self.nodes:
             self.nodes[b_name] = self.lab.create_node(b_device)
             # print("*** NODE {} CREATED".format(b_name))
         node_a = self.nodes[a_name]
         node_b = self.nodes[b_name]
         if intf_conv.get(a_name, {}).get(a_intf, None):
             a_intf_lab = intf_conv[a_name][a_intf]
         else:
             a_intf_lab = node_a.get_next_intf()
         if intf_conv.get(b_name, {}).get(b_intf, None):
             b_intf_lab = intf_conv[b_name][b_intf]
         else:
             b_intf_lab = node_b.get_next_intf()
         intf_conv.setdefault(a_name, {})[a_intf] = a_intf_lab
         intf_conv.setdefault(b_name, {})[b_intf] = b_intf_lab
         node_a.connect_node(a_intf_lab, node_b, b_intf_lab)
         # print("*** NODES {} and {} ARE CONNECTED".format(a_name, b_name))
     file_io.write_yaml(INTF_CONV_FILE, intf_conv)
     return None
示例#3
0
 def ext_connect(self, topo):
     ext_topo = topo.ext_net
     intf_conv = file_io.read_yaml(INTF_CONV_FILE)
     for (node_name, node_intf), pnet in ext_topo.iteritems():
         ext_net = self.lab.create_net('cloud', net_type=pnet)
         the_node = self.nodes[node_name]
         node_intf_lab = the_node.get_next_intf()
         the_node.connect_interface(node_intf_lab, ext_net)
         intf_conv.setdefault(node_name, {})[node_intf] = node_intf_lab
     file_io.write_yaml(INTF_CONV_FILE, intf_conv)
     return None
示例#4
0
 def ext_connect(self, topo):
     ext_topo = topo.ext_net
     intf_conv = file_io.read_yaml(INTF_CONV_FILE)
     for (node_name, node_intf), pnet in ext_topo.iteritems():
         ext_net = self.lab.create_net("cloud", net_type=pnet)
         the_node = self.nodes[node_name]
         node_intf_lab = the_node.get_next_intf()
         the_node.connect_interface(node_intf_lab, ext_net)
         intf_conv.setdefault(node_name, {})[node_intf] = node_intf_lab
     file_io.write_yaml(INTF_CONV_FILE, intf_conv)
     return None
示例#5
0
from restunl.device import IOL
from globals import *
from dns import DNS
import file_io
import re


DEFAULT_INTF = 'Loopback0'
DNS_RESOLVER = DNS(file_io.read_yaml('{}/ip.yml'.format(TMP_DIR)))


class IncorrectEndpointFormat(Exception):
    pass


class Endpoint(object):

    def __init__(self, text):
        self.dev, self.intf, self.ip = '', '', ''
        self.node = None
        if DNS_RESOLVER.is_ip(text):
            self.dev, self.intf = DNS_RESOLVER.get(text)
            self.ip = text
        else:
            self.dev, self.intf = self._parse(text)
            self.ip = DNS_RESOLVER.get(self.dev, self.intf)

    @staticmethod
    def _parse(text):
        separators = ',|\s'
        seq = [word.strip() for word in re.split(separators, text)]
示例#6
0
from restunl.device import IOL
from globals import *
from dns import DNS
import file_io
import re

DEFAULT_INTF = 'Loopback0'
DNS_RESOLVER = DNS(file_io.read_yaml('{}/ip.yml'.format(TMP_DIR)))


class IncorrectEndpointFormat(Exception):
    pass


class Endpoint(object):
    def __init__(self, text):
        self.dev, self.intf, self.ip = '', '', ''
        self.node = None
        if DNS_RESOLVER.is_ip(text):
            self.dev, self.intf = DNS_RESOLVER.get(text)
            self.ip = text
        else:
            self.dev, self.intf = self._parse(text)
            self.ip = DNS_RESOLVER.get(self.dev, self.intf)

    @staticmethod
    def _parse(text):
        separators = ',|\s'
        seq = [word.strip() for word in re.split(separators, text)]
        if len(seq) > 1:
            return seq[0], Endpoint.expand(seq[1])