Ejemplo n.º 1
0
def cloud_init(net, vnfd, host_name):
    "Configures the networks."
    host = net.getNodeByName(host_name)
    cloudinit = vnfd['topology_template']['node_templates']['VDU1'][
        'properties']['user_data']
    output('*** Initializing VDU ' + host_name + ' ...\n')
    host.cmdPrint(cloudinit)
Ejemplo n.º 2
0
def vnfd_list(self, line):
    "Lists all VNFD uploaded."
    if line:
        output('Use: vnfd_list\n')
        return None
    for i in VNFD:
        output('%s: %s\n' % (i, VNFD[i]['description']))
    #output('%s' % VNFD.keys() + '\n')
    return None
Ejemplo n.º 3
0
def vnfd_delete(self, line):
    "Deletes a given vnfd."
    if len(line.split()) != 1:
        output('Use: vnfd_delete <VNFD-NAME>\n')
        return None
    vnfd_name = line.split()[0]
    if VNFD.has_key(vnfd_name):
        del VNFD[vnfd_name]
    else:
        output('<VNFD-NAME> does not exist\n')
    return None
Ejemplo n.º 4
0
def vnffg_delete(self, line):
    "Deletes a given vnffg."
    net = self.mn
    if len(line.split()) != 1:
        output('Use: vnffg_delete <VNFFG-NAME>\n')
        return None
    vnffg_name = line.split()[0]
    if vnffg_name in VNFFGS:
        del VNFFGS[VNFFGS.index(vnffg_name)]
        # net.delNode(vnf_name)
        # AttributeError: 'Mininet' object has no attribute 'delNode'
    else:
        output('<VNFFG-NAME> does not exist\n')
    return None
Ejemplo n.º 5
0
def vnfd_create(self, line, jinja=False):
    "Creates vnfd from template."
    if len(line.split()) != 3 or line.split()[0] != '--vnfd-file':
        output('Use: vnfd_create --vnfd-file <yaml file path> <VNFD-NAME>\n')
        return None
    file_path = line.split()[1]
    vnfd = parse_tosca(file_path)
    if vnfd:
        vnfd_name = line.split()[2]
        if not VNFD.has_key(vnfd_name):
            VNFD[vnfd_name] = vnfd
        else:
            output('<VNFD-NAME> already in use\n')
    return None
Ejemplo n.º 6
0
def list_ports(self, line):
    "List all ports."
    if len(line.split()) != 0:
        output('Use: list_ports\n')
        return None
    for i in PORTS:
        if i[0] == 's':
            output('%s ' % i)
            for j in PORTS[i]:
                output('%s ' % j.IP())
        else:
            output(i, PORTS[i])
        output('\n')
    return None
Ejemplo n.º 7
0
def vnfd_template_show(self, line):
    "Shows the template of a given vnfd."
    if len(line.split()) != 1:
        output('Wrong number or arguments\n')
        output('Use: vnfd_template_show <VNFD-NAME>\n')
        return None
    vnfd_name = line.split()[0]
    output(('%s' % VNFD[vnfd_name]) + '\n')
    return None
Ejemplo n.º 8
0
def add_host(self, line):
    "Adds a host to the mininet topology."
    net = self.mn
    if len(line.split()) < 1:
        output('Use: add_host <HOST-NAME> [<IP1/masc> <IP2/masc> ...]\n')
        return None
    host_name = line.split()[0]
    if host_name in HOSTS:
        output('<HOST-NAME> already in use\n')
        return None
    ips = line.split()[1:]
    if MULTSWITCHES:
        i = 1
        switchs = []
        for i in ips:
            try:
                ip_address = netaddr.IPNetwork(i)
            except netaddr.core.AddrFormatError:
                output('IP format not valid: ' + i + '\n')
                output(
                    'Use: add_host <HOST-NAME> [<IP1/masc> <IP2/masc> ...]\n')
                return None
            switch_name = 's%s' % ip_address.network
            if not SWITCH.has_key(switch_name):
                SWITCH[switch_name] = net.addSwitch(switch_name[:10])
            switchs.append(switch_name)
        host = net.addHost(host_name)
        HOSTS.append(host_name)
        for i in switchs:
            net.addLink(i[:10], host)
            PORTS[i[:10]].append(host)
    else:
        host = net.addHost(host_name)
        HOSTS.append(host_name)
        net.addLink('s1', host)
        PORTS['s1'].append(host)

    configure_host2(net, ips, host_name)
    return None
Ejemplo n.º 9
0
def vnf_create(self, line, jinja=False):
    "Creates vnf from vnfd previously created or directly from template."
    net = self.mn
    if len(line.split()) != 3 or line.split()[0] not in [
            '--vnfd-name', '--vnfd-file', '--vnfd-template'
    ]:
        output('Use: vnf_create --vnfd-name <VNFD-NAME> <VNF-NAME>\n')
        output('     vnf_create --vnfd-file <yaml file path> <VNFD-NAME>\n')
        output(
            '     vnf_create --vnfd-template <yaml file path> <VNFD-NAME>\n')
        return None
    if line.split()[0] in ['--vnfd-file', '--vnfd-template']:
        file_path = line.split()[1]
        vnfd = parse_tosca(file_path)
        if jinja:
            template = Template(str(vnfd))
            print 'template jinja',
            print "{}".format(template.render(net.values))
    else:  # --vnfd-name
        vnfd_name = line.split()[1]
        vnfd = VNFD[vnfd_name]
    if vnfd:
        vnf_name = line.split()[2]
        if vnf_name in VNFS:
            output('<VNF-NAME> already in use\n')
            return None
        VNFS.append(vnf_name)
        net.addHost(vnf_name)
        configure_network(net, vnfd, vnf_name)

        configure_host(net, vnfd, vnf_name)
        if vnfd['topology_template']['node_templates']['VDU1'][
                'properties'].has_key('user_data'):
            cloud_init(net, vnfd, vnf_name)
        return None
    return None
Ejemplo n.º 10
0
def vnffg_create(self, line, jinja=False):
    "Creates vnffg from previously defined vnffgd or directly from template."
    net = self.mn
    #if len(line.split()) != 7:
    #    print 'problema e tamanho'
    #    print line.split()[0]
    if len(line.split()) != 7 or line.split()[0] not in [
            '--vnffgd-name', '--vnffgd-template'
    ] or line.split()[2] != '--vnf-mapping' or line.split(
    )[4] != '--symmetrical':
        output(
            '''Use: vnffg-create --vnffgd-name <vnffgd-name> --vnf-mapping <vnf-mapping>
                  --symmetrical <boolean> <vnffg-name>\n''')
        output(
            '''     vnffg-create --vnffgd-template <vnffgd-template> --vnf-mapping <vnf-mapping>
                  --symmetrical <boolean> <vnffg-name>\n''')
        return None
    if line.split()[0] == '--vnffgd-template':
        file_path = line.split()[1]
        vnffg = parse_tosca(file_path)
        #print 'antes: ', vnffg
        if jinja:
            template = Template(str(vnffg))
            #print 'template jinja',
            #print "{}".format(template.render(net.values))
            vnffg = yaml.load("{}".format(template.render(net.values)))
            #print 'despues: ', vnffg
    else:  # --vnffg-name
        vnffg_name = line.split()[1]
        vnffg = VNFFGD[vnffg_name]
    binds = read_binding(line.split()[3])
    if vnffg:
        vnffg_name = line.split()[6]
        if vnffg_name in VNFFGS:
            output('<VNFFG-NAME> already in use\n')
            return None
        #VNFFGS.append(vnffg_name)
        configure_vnffg(net, vnffg, vnffg_name, binds)
        return None
    return None
Ejemplo n.º 11
0
def do_print(self, line):
    "Prints a given line."
    output(line + '\n')
    return None
Ejemplo n.º 12
0
def vnffg_list(self, line):
    "Lists all vnffgs created."
    output('%s' % VNFFGS + '\n')
Ejemplo n.º 13
0
def configure_vnffg(net, vnffg, vnffg_name, binds):
    "NFV Orchestration function."
    criteria = vnffg['topology_template']['node_templates'][
        'Forwarding_path1']['properties']['policy']['criteria']
    path = vnffg['topology_template']['node_templates']['Forwarding_path1'][
        'properties']['path'][0]
    vnfs = vnffg['topology_template']['groups']['VNFFG1']['properties'][
        'constituent_vnfs']
    if vnfs[0] != binds[0]:
        output('vnf-mapping <' + binds[0] + '> not defined in template\n')
        return
    if len(criteria) != 1:
        for i in range(len(criteria)):
            if criteria[i].has_key('network_src_port_id'):
                port_id = criteria[i]['network_src_port_id']
            elif criteria[i].has_key('ip_src_prefix'):
                ip_src = criteria[i]['ip_src_prefix']
                if not find_port(ip_src):
                    output('ip_src_prefix ,' + ip_src +
                           '> not exists in current environment\n')
                    return
                ip_src = netaddr.IPNetwork(ip_src)
                #ip_address_final = '%s/%s' % (ip_address.ip, ip_address.prefixlen)
            elif criteria[i].has_key('ip_dst_prefix'):
                ip_dst = criteria[i]['ip_dst_prefix']
                if not find_port(ip_dst):
                    output('ip_dst_prefix ,' + ip_dst +
                           '> not exists in current environment\n')
                    return
                ip_dst = netaddr.IPNetwork(ip_dst)
            elif criteria[i].has_key('ip_proto'):
                ip_proto = criteria[i]['ip_proto']
            elif criteria[i].has_key('destination_port_range'):
                port_range = criteria[i]['destination_port_range']
    else:
        if criteria[0].has_key('network_src_port_id'):
            port_id = criteria[0]['network_src_port_id']
        if criteria[0].has_key('ip_src_prefix'):
            ip_src = criteria[0]['ip_src_prefix']
            if not find_port(ip_src):
                output('ip_src_prefix ,' + ip_src +
                       '> not exists in current environment\n')
                return
        if criteria[0].has_key('ip_dst_prefix'):
            ip_dst = criteria[0]['ip_dst_prefix']
            if not find_port(ip_dst):
                output('ip_dst_prefix ,' + ip_dst +
                       '> not exists in current environment\n')
                return
        if criteria[0].has_key('ip_proto'):
            ip_proto = criteria[0]['ip_proto']
        if criteria[i].has_key('destination_port_range'):
            port_range = criteria[0]['destination_port_range']

    print 'vnfs0', binds[1], 'ip_src', ip_src, 'ip_dst', ip_dst
    vnf = binds[1]
    vnf = net.getNodeByName(vnf)

    forwarder = path['forwarder']
    port_dst = find_port2(ip_dst.ip)
    port_vnf = find_port2(find_port3(forwarder, ip_src, ip_dst))
    VNFFGS.append(vnffg_name)
    print ip_src.ip, find_port2(
        ip_src.ip), ip_dst.ip, port_dst, forwarder, port_vnf
    if MULTSWITCHES:
        #command = 'sudo ovs-ofctl mod-flows s192.168.1 ip,nw_src=192.168.120.1,actions=output:2,3'
        command2 = "ovs-ofctl add-flow s192.168.1 priority=1,arp,actions=flood"
        command = 'sudo ovs-ofctl mod-flows s192.168.1 ip,nw_src=%s,actions=output:%s,%s' % (
            ip_src.ip, port_dst, port_vnf)
        #command = 'sudo ovs-ofctl mod-flows s192.168.1 ip,nw_src=%s,actions=output:%s' % (ip_src.ip, port_vnf)
        #command2 = 'sudo ovs-ofctl mod-flows s192.168.1 in_port=%s,actions=output:%s' % (port_vnf, port_dst)
        #command3 = 'sudo ovs-ofctl mod-flows s192.168.1 arp,in_port="s192.168.1-eth4",vlan_tci=0x0000/0x1fff,dl_src=12:b9:d1:5d:26:5e,dl_dst=1e:29:c2:41:d5:02,arp_spa=192.168.120.2,arp_tpa=192.168.120.1,arp_op=2,actions=output:"s192.168.1-eth3"'
        s2 = subprocess.check_output(command2, shell=True)
        s = subprocess.check_output(command, shell=True)
        #s3 = subprocess.check_output(command2, shell=True)
        print s, s2
    else:
        vnf.cmdPrint(
            'ip addr add %s/24 brd + dev %s-eth0' %
            (netaddr.IPAddress(netaddr.IPNetwork(ip_src).first + 1), binds[1]))
        vnf.cmdPrint(
            'ip addr add %s/24 brd + dev %s-eth0' %
            (netaddr.IPAddress(netaddr.IPNetwork(ip_dst).first + 1), binds[1]))
        vnf.cmdPrint("echo 1 > /proc/sys/net/ipv4/ip_forward")
Ejemplo n.º 14
0
def vnf_list(self, line):
    "Lists all vnfs created."
    output('%s' % VNFS + '\n')