def do_info( self, line ): "Print short info about a VNF or all of them if none is specified." vnf_catalog = Catalog().get_db() for metadata in vnf_catalog.itervalues(): try: if metadata['name'] == line.strip(): for k, v in metadata.iteritems(): output('%s: %s\n' % (k, v)) break except KeyError: pass else: for metadata in vnf_catalog.itervalues(): try: info = metadata.get('description', '').split('\n')[0] output('%s: %s\n' % (metadata['name'], info)) except KeyError: pass
class VNFClickBuilder(): def __init__(self): self.catalog = Catalog() def create_vnf(self, opts, host): options = copy.deepcopy(opts) host_name = getattr(host, 'name', None) if host_name is None: raise RuntimeError("Unsupported host type: %s" % type(host)) vnf = Store() del options['name'] vnf.startCmd = self.catalog.make_cmd(options['function'], name=host_name, **options) return vnf
def start(self, nf_g, phy_g=None): """ Create the service chain - Do the resource mapping process - Starts the virtual network element - Install the OF routes Return list of the newly initiated VNFs """ # TODO: instead of phy_g, rely on NetworkManager, or simple_topology # Using NetworkManager to get physical topology if phy_g is not given explicitly if not phy_g: phy_g = self.network_manager.get_initial_topology() # dump(phy_g, 'NetMen converted topo') if nf_g.number_of_nodes() < 1 or phy_g.number_of_nodes( ) < 1 or not self.network_manager.network_alive(): return [] # Run the resource mapping algorithm vnf_to_host_list = Mapping.map(nf_g, phy_g, DefaultSorter) vnf_options = nf_g.node # Config vnf_manager vnf_manager = self.network_manager.vnf_manager vnf_manager.set_vnf_catalog(Catalog().get_db()) # Start mapped VNFs on physical network element vnf_manager.start_vnfs(vnf_to_host_list, vnf_options) # Install routes # update states of VNFs run by netconf agents before route install # (to make phy_g consistent (containing remote VNFs as well)) self.network_manager.scan_network(forced=True) # Error: If phy_g contains initial_topo from NetworkManager, # VNFs are always excluded and no routes will be installed!! self.rm.install_routes(nf_g, phy_g) return vnf_to_host_list
def __init__(self): self.catalog = Catalog()
def __init__ (self): self.vnf_type = None self._parse_args() self.catalog = Catalog() self.click_proc = None atexit.register(self.kill_click_proc)
class ClickHelper( object ): ''' Helper class for starting Click-based VNFs VNF info is read from VNF catalog ''' def __init__ (self): self.vnf_type = None self._parse_args() self.catalog = Catalog() self.click_proc = None atexit.register(self.kill_click_proc) def _parse_args(self): ''' Loading command line args coming from netconfd to a dictionary Format: arg1=argval1 ar2=argval2 ... ''' self.opts = dict(map(lambda x: x.split('='),sys.argv[1:])) self.updateDevs() def updateDevs(self): 'Update devs list based on opts (ex: dev_x=uny_y)' devs = [(k, v) for k,v in self.opts.iteritems() if k.startswith('dev')] devs = dict(devs) devlist = [] for k in sorted(devs.keys()): devlist.append(devs[k]) self.opts.update({'devs': devlist}) def setVNFType(self): 'Set vnf_type based on opts' try: self.vnf_type = self.opts['type'] except KeyError: self.vnf_type = None return self.vnf_type def getVNFType(self): return self.vnf_type def logVNFType(self): if self.vnf_type: #print self.vnf_type with open('/tmp/vnftype.log', 'w') as f: f.write(str(self.vnf_type)) f.close() def initVNF(self): 'Initialize VNF, make command' self.setVNFType() opts = copy.deepcopy(self.opts) startCmd = self.catalog.make_cmd(opts['type'], name = opts['vnf_id'], **self.opts) startCmd = startCmd.replace('&', ' ') self.startCmd = startCmd def getVNFCmd(self): return self.startCmd def logVNFCmd(self): if self.startCmd: print self.startCmd with open('/tmp/vnfcmd.log', 'w') as f: f.write(str(self.startCmd)) f.close() def startVNF(self): '''Execute previously assembled VNF command output: -1: fork failed, high error code: invalid argument''' print self.startCmd #return os.system(self.startCmd) # return subprocess.call(['sh', '-c', self.startCmd]) proc = subprocess.Popen(['sh', '-c', self.startCmd]) self.click_proc = proc #blocking parent output, error = proc.communicate() exitcode = proc.wait() return output, error, exitcode def kill_click_proc(self): if self.click_proc is None: pass else: print "Kill click process, PID: %s" % self.click_proc.pid self.click_proc.kill()
def do_reload( self, line): "Reload VNF catalog" Catalog().load(line)
def complete_info( self, text, line, begidx, endidx): names = Catalog().get_db().keys() return [n for n in names if n.startswith(text)]
def add_VNFs(): """ add VNFs to catalog (required parameters should be given) """ #1. First single Click elements are added to the DB Catalog().add_VNF(vnf_name='FromDevice',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='ToDevice',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='Queue',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='Tee',vnf_type='Click',hidden='True') #Catalog().add_VNF(vnf_name='Counter',vnf_type='Click',clickPath='/home/click', # clickSource=['elements/standard/counter.cc','elements/standard/counter.cc']) Catalog().add_VNF(vnf_name='Counter',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='Classifier',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='IPClassifier',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='StripIPHeader',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='UnstripIPHeadet',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='Strip',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='Unstrip',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='ICMPPingSource',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='ARPQuerier',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='AggregateIPFlows',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='RFC2507Comp',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='RFC2507Decomp',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='IPAddRewriter',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='TCPOptimizer',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='MarkIPHeader',vnf_type='Click',hidden='True') Catalog().add_VNF(vnf_name='Print',vnf_type='Click',hidden='True') #2. Then the VNFs composed of several Click elements are added to the DB Catalog().add_VNF(vnf_name = 'simpleForwarder', vnf_type = 'Click', description = 'receive on the data interface and loop back the packet', icon = 'forward.png') Catalog().add_VNF(vnf_name = 'simpleObservationPoint', vnf_type = 'Click', description = 'A simple observation point in click', icon = 'search.png') Catalog().add_VNF(vnf_name = 'headerCompressor', vnf_type = 'Click', description = 'Compress IPv4/TCP headers as defined in RFC2507', icon = 'decompress_small.png') Catalog().add_VNF(vnf_name = 'headerDecompressor', vnf_type = 'Click', description = 'Decompress IPv4/TCP headers as defined in RFC2507', icon = 'compress2_small.png') Catalog().add_VNF(vnf_name = 'nat', vnf_type = 'Click', hidden = 'True', description = 'Provide the functionality of basic network address translator') Catalog().add_VNF(vnf_name = 'tcpRWINOptimizer', vnf_type = 'Click', description = 'TCP Optimizer', icon = 'forward.png') Catalog().add_VNF(vnf_name = 'testVNF', vnf_type = 'Click', description = 'A test VNF', icon = 'forward.png') Catalog().add_VNF(vnf_name = 'RlncOnTheFlyEncoder', vnf_type = 'Click', description = 'Rlnc encoder with kodo.', icon = 'forward.png') Catalog().add_VNF(vnf_name = 'RlncOnTheFlyDecoder', vnf_type = 'Click', description = 'Rlnc decoder with kodo', icon = 'forward.png') print Catalog().get_db()
def del_VNFs(vnf_list): for vnf in vnf_list: if Catalog().get_VNF(vnf_name = vnf) != []: Catalog().remove_VNF(vnf_name = vnf)