def setTopologyFile(self, InterfaceList, IPaddressList): subnet = str(self.Network[-3:]) DATA = {} DATA.update({'Device_details': {}}) for i in range(1, (self.Number_of_instances + 1)): Router = 'Router%d' % (i) DATA['Device_details'].update({ Router: { "Interface": InterfaceList[i], "IP_address": IPaddressList[i] + subnet } }) putData(DATA, 'Topology.json') print DATA return
def setBGPParameters(self): DATA = {} DATA.update({'BGP_Parameters': {}}) GlobalAS = self.data["globalAS"] for i in range(1, (self.Number_of_instances + 1)): Router = 'Router%d' % (i) RouterIDList = BGP.getRouterIDList(self.RouterIDNetwork) ASNumList = BGP.getASNumList(self.AS_Start) DATA['BGP_Parameters'].update({ Router: { 'GlobalAS': GlobalAS, 'RouterID': RouterIDList[i], 'ASNum': ASNumList[i] } }) putData(DATA, 'ProtocolSpecific.json') return
def setPeerDetails( Router): #Sets the Peer details into the ProtocolSpecific JSON File vardata = getData('variable.json') NumberOfDevices = vardata["NumberOfDevices"] start = 'Router1' data = getData('ProtocolSpecific.json') topodata = getData('Topology.json') data["BGP_Parameters"][Router].update({"PeerDetails": {}}) if Router == start: for i in range(1, NumberOfDevices): NDUT = 'Router' + str(i + 1) Link = "Link_Router1_" + NDUT PeerASNum = data["BGP_Parameters"][NDUT]["ASNum"] PeerInterface = topodata["Link_details"][Link][NDUT] PeerAddress = topodata["Device_details"][NDUT][PeerInterface] Peer = "Peer" + str(i) data["BGP_Parameters"][Router]['PeerDetails'].update({ Peer: { "ASNum": PeerASNum, "IP_Address": PeerAddress, "Interface": PeerInterface } }) putData(data, 'ProtocolSpecific.json') else: NDUT = 'Router1' Link = "Link_Router1_" + Router PeerInterface = topodata["Link_details"][Link][NDUT] PeerAddress = topodata["Device_details"][NDUT][PeerInterface] PeerASNum = data["BGP_Parameters"][Router]["ASNum"] data["BGP_Parameters"][Router]['PeerDetails'].update({ "Peer1": { "ASNum": PeerASNum, "IP_Address": PeerAddress, "Interface": PeerInterface } }) putData(data, 'ProtocolSpecific.json') return data
def setBGPParameters( self ): #Adds prerequisite BGP related parameters of all the devices to a file caleed Protocol Specific JSON file logToFile.info( " Setting up the ProtocolSpecific.json file with BGP related Parameters" ) DATA = {} DATA.update({'BGP_Parameters': {}}) RouterIDList = BGPConfiguration.getRouterIDList() ASNumList = BGPConfiguration.getASNumList(self.AS) for i in range(0, (self.NumberOfDevices)): Router = 'Router%d' % (i + 1) DATA['BGP_Parameters'].update( {Router: { 'RouterID': RouterIDList[i], 'ASNum': ASNumList[i] }}) putData(DATA, 'ProtocolSpecific.json') return
def getPeerDetails(Router): data = getData('variable.json') Number_of_instances = data["number_of_instances"] PeerAS = [] start = 'DUT1' end = 'DUT%d' %(Number_of_instances) data = getData('ProtocolSpecific.json') topodata = getData('topo.json') PeerDetails = {} data['BGP_Parameters'][0]['DUT1'].update({"PeerDetails" : []}) if DUT == start: DUT = 'DUT2' PeerASNum = data["BGP_Parameters"][0][DUT]["ASNum"] PeerAddress = topodata["Device_details"][0][DUT]["IP_address"] PeerInterface = topodata["Device_details"][0][DUT]["Interface"] PeerDetails = {"Peer1":{"ASNum" : PeerASNum, "IP_Address" : PeerAddress, "Interface" : PeerInterface}} data['BGP_Parameters'][0][DUT]['PeerDetails'].append(PeerDetails) putData(data,'ProtocolSpecific.json') elif DUT == end: DUT = 'DUT%d' % (Number_of_instances-1) PeerASNum = data["BGP_Parameters"][0][DUT]["ASNum"] PeerAddress = topodata["Device_details"][0][DUT]["IP_address"] PeerInterface = topodata["Device_details"][0][DUT]["Interface"] PeerDetails = {"Peer1":{"ASNum" : PeerASNum, "IP_Address" : PeerAddress, "Interface" : PeerInterface}} data['BGP_Parameters'][0][DUT]['PeerDetails'].append(PeerDetails) putData(data,'ProtocolSpecific.json') else: devno = DUT[3:] Peers = ['DUT%d','DUT%d'] %(devno-1,devno+1) count = 1 dictionary = {} for i in Peers: PeerASNum = data["BGP_Parameters"][0][i]["ASNum"] PeerAddress = topodata["Device_details"][0][i]["IP_address"] PeerInterface = topodata["Device_details"][0][i]["Interface"] dictionary = {"Peer"+str(count) : {"ASNum" : PeerASNum, "IP_Address" : PeerAddress, "Interface" : PeerInterface}} count = count+1 PeerDetails.update(dictionary) data['BGP_Parameters'][0][DUT]['PeerDetails'].append(PeerDetails) putData(data,'ProtocolSpecific.json') return
def setTopologyFile(self,intfList,IPaddressList): #Adds all the topology reated details to a file called Topology.json logToFile.info("Setting up the topology file") Network = self.data["Network"] subnet = Network.split("/") DATA = {} DATA.update({"Device_details" : {}}) for i in range(1,(self.NumberOfDevices+1)): Router = "Router"+str(i) DATA["Device_details"].update({Router : {}}) j = 0 ; i = 2 maxiter = len(intfList) while j != maxiter: if j % 2 == 0: DATA["Device_details"]["Router1"].update({intfList[j] : IPaddressList[j] + '/'+ subnet[1]}) j = j + 1 else: Router = "Router" + str(i) DATA["Device_details"][Router].update({intfList[j] : IPaddressList[j] + '/' + subnet[1]}) j = j + 1 i = i + 1 putData(DATA,'Topology.json') DATA.update({'Link_details' : {}}) for i in range(1,(self.NumberOfDevices)): DATA['Link_details'].update({"Link_Router1_Router" + str(i+1) : {}}) putData(DATA,'Topology.json') links = DATA["Link_details"].keys() links.sort() m = 0 ; n = 1 for i in links: DATA['Link_details'][i].update({"Router1" : intfList[m],"Router"+str(n+1) : intfList[m+1]}) m = m+2 n = n+1 putData(DATA,'Topology.json') logToFile.info(' Topology file is updated with below device details \n %s',DATA) return
def getPeerDetails(Router): vardata = getData('variable.json') Number_of_instances = vardata["number_of_instances"] start = 'Router1' end = 'Router%d' % (Number_of_instances) data = getData('ProtocolSpecific.json') topodata = getData('Topology.json') data["BGP_Parameters"][Router].update({"PeerDetails": {}}) if Router == start: NDUT = 'Router2' PeerASNum = data["BGP_Parameters"][NDUT]["ASNum"] PeerAddress = topodata["Device_details"][NDUT]["IP_address"] PeerInterface = topodata["Device_details"][NDUT]["Interface"] data["BGP_Parameters"][Router]['PeerDetails'].update({ "Peer1": { "ASNum": PeerASNum, "IP_Address": PeerAddress, "Interface": PeerInterface } }) putData(data, 'ProtocolSpecific.json') elif Router == end: NDUT = 'Router%d' % (Number_of_instances - 1) PeerASNum = data["BGP_Parameters"][NDUT]["ASNum"] PeerAddress = topodata["Device_details"][NDUT]["IP_address"] PeerInterface = topodata["Device_details"][NDUT]["Interface"] data["BGP_Parameters"][Router]['PeerDetails'].update({ "Peer1": { "ASNum": PeerASNum, "IP_Address": PeerAddress, "Interface": PeerInterface } }) putData(data, 'ProtocolSpecific.json') else: devno = int(Router[6:]) Peers = ['Router' + str(devno - 1), 'Router' + str(devno + 1)] count = 1 dictionary = {} for i in Peers: NDUT = i PeerASNum = data["BGP_Parameters"][NDUT]["ASNum"] PeerAddress = topodata["Device_details"][NDUT]["IP_address"] PeerInterface = topodata["Device_details"][NDUT]["Interface"] data["BGP_Parameters"][Router]['PeerDetails'].update({ "Peer" + str(count): { "ASNum": PeerASNum, "IP_Address": PeerAddress, "Interface": PeerInterface } }) count = count + 1 putData(data, 'ProtocolSpecific.json') return