def _modify_address_helper(self, addressHelper, cidr_addr): """ modify the netbase, mask and and base of the address helper """ addr, netBase, mask = CIDR_to_subnet_mask(cidr_addr) netAddr = get_net_addr(addr, mask) addressHelper.SetBase( network=ns3.Ipv4Address(netBase), mask = ns3.Ipv4Mask(mask), base = ns3.Ipv4Address(netAddr), ) return addressHelper
def _modify_address_helper(self, addressHelper, cidr_addr): """ modify the netbase, mask and and base of the address helper """ addr, netBase, mask = CIDR_to_subnet_mask(cidr_addr) netAddr = get_net_addr(addr, mask) addressHelper.SetBase( network=ns3.Ipv4Address(netBase), mask=ns3.Ipv4Mask(mask), base=ns3.Ipv4Address(netAddr), ) return addressHelper
def init_net_device(self, net_settings, *args, **kwargs): """Initial the ip address and network devices """ self.net_settings = net_settings totlinks = self.inFile.LinksSize() p2p = ns3.PointToPointHelper() self.link_ndc_map = dict() for i in xrange(totlinks): Delay, DataRate = self.get_link_attr(i) p2p.SetChannelAttribute("Delay", ns.core.StringValue(Delay)) p2p.SetDeviceAttribute("DataRate", ns.core.StringValue(DataRate)) self.link_ndc_map[self.get_link_name(i)] = p2p.Install( self.linksC[i] ) # Create little subnets, one for each couple of nodes defaultAddressHelper = ns3.Ipv4AddressHelper() defaultAddr, defaultNetBase, defaultMask = CIDR_to_subnet_mask(net_settings['ipv4_net_addr_base']) netAddr = get_net_addr(defaultAddr, defaultMask) defaultAddressHelper.SetBase( network=ns3.Ipv4Address(defaultNetBase), mask = ns3.Ipv4Mask(defaultMask), base = ns3.Ipv4Address(netAddr), ) # FIXME, THE ORDER HERE WITH THE ORDER in FS CONFIGURE MAY BE # DIFFERENT addressHelper = ns3.Ipv4AddressHelper() ipic = [] #ip interface container for i in xrange(totlinks): ips = self.net_settings['link_to_ip_map'].get(self.get_link_name(i), None) # Use the default base when the ip address is not explictly specified, # create new network for each p2p link if not ips: raise Exception('Sorry, in current version of ManualTopologyNet ' + 'You have to specify the link_to_ip_map for ALL LINKS!') print(self.get_link_name(i), 'use default address helper') ipic.append( defaultAddressHelper.Assign(self.get_link_ndc(i)) ) addressHelper.NewNetwork() continue addressHelper = ns3.Ipv4AddressHelper() j = -1 ipic_tmp = [] for ip in ips: j += 1 print('address, ', ip) addressHelper = self._modify_address_helper(addressHelper, ip) ipc = addressHelper.Assign(ns3.NetDeviceContainer(self.get_link_ndc(i).Get(j))) ipic_tmp.append(ipc) ipic.append(ipic_tmp) self.p2p = p2p self.ipic = ipic # from ns.core import ofstream # _ascii = ofstream("wifi-ap.tr") # p2p.EnableAsciiAll("test") return ipic
def _init_addr_helper(self): """initialize the address helper""" ipv4_net_addr_base = self.net_desc.get('ipv4_net_addr_base', '10.0.7.4/24') addr, network, mask = CIDR_to_subnet_mask(ipv4_net_addr_base) base = get_net_addr(addr, mask) self.addr_helper = Ipv4AddressHelper(network, mask, base)
def init_net_device(self, net_settings, *args, **kwargs): """Initial the ip address and network devices """ self.net_settings = net_settings totlinks = self.inFile.LinksSize() p2p = ns3.PointToPointHelper() self.link_ndc_map = dict() for i in xrange(totlinks): Delay, DataRate = self.get_link_attr(i) p2p.SetChannelAttribute("Delay", ns.core.StringValue(Delay)) p2p.SetDeviceAttribute("DataRate", ns.core.StringValue(DataRate)) self.link_ndc_map[self.get_link_name(i)] = p2p.Install( self.linksC[i]) # Create little subnets, one for each couple of nodes defaultAddressHelper = ns3.Ipv4AddressHelper() defaultAddr, defaultNetBase, defaultMask = CIDR_to_subnet_mask( net_settings['ipv4_net_addr_base']) netAddr = get_net_addr(defaultAddr, defaultMask) defaultAddressHelper.SetBase( network=ns3.Ipv4Address(defaultNetBase), mask=ns3.Ipv4Mask(defaultMask), base=ns3.Ipv4Address(netAddr), ) # FIXME, THE ORDER HERE WITH THE ORDER in FS CONFIGURE MAY BE # DIFFERENT addressHelper = ns3.Ipv4AddressHelper() ipic = [] #ip interface container for i in xrange(totlinks): ips = self.net_settings['link_to_ip_map'].get( self.get_link_name(i), None) # Use the default base when the ip address is not explictly specified, # create new network for each p2p link if not ips: raise Exception( 'Sorry, in current version of ManualTopologyNet ' + 'You have to specify the link_to_ip_map for ALL LINKS!') print(self.get_link_name(i), 'use default address helper') ipic.append(defaultAddressHelper.Assign(self.get_link_ndc(i))) addressHelper.NewNetwork() continue addressHelper = ns3.Ipv4AddressHelper() j = -1 ipic_tmp = [] for ip in ips: j += 1 print('address, ', ip) addressHelper = self._modify_address_helper(addressHelper, ip) ipc = addressHelper.Assign( ns3.NetDeviceContainer(self.get_link_ndc(i).Get(j))) ipic_tmp.append(ipc) ipic.append(ipic_tmp) self.p2p = p2p self.ipic = ipic # from ns.core import ofstream # _ascii = ofstream("wifi-ap.tr") # p2p.EnableAsciiAll("test") return ipic