def create_empty_net(self): logging.info('setup_empty_net') self.net = Mininet_wifi(accessPoint=OVSKernelAP) self.net.propagationModel(model="logDistance", exp=3) self.c1 = RemoteController('c1', ip='172.17.20.12', port=6633) self.net.addController(self.c1) return True
def __init__(self): self.ap_dict = {} self.sw_dict = {} self.host_dict = {} self.sta_dict = {} self.net = Mininet_wifi(accessPoint=OVSKernelAP) self.net.propagationModel(model="logDistance", exp=3) self.c1 = Controller('c1') self.add_nodes()
def topology(is_enable_cli=False): """ create a network. mode (str): miminet or containernet is_enable_cli (bool): running CLI """ c1 = RemoteController('c1', ip='172.17.20.12', port=6633) net = Mininet_wifi(accessPoint=OVSKernelAP) info("*** Starting network\n") net.build() c1.start() if is_enable_cli: info("*** Running CLI\n") CLI_wifi(net) info("*** Stopping network\n") net.stop()
class Topo(object): def __init__(self): self.ap_dict = {} self.sw_dict = {} self.host_dict = {} self.sta_dict = {} self.net = Mininet_wifi(accessPoint=OVSKernelAP) self.net.propagationModel(model="logDistance", exp=3) self.c1 = Controller('c1') self.add_nodes() def start(self): log.info("*** Starting network\n") # self.net.plotGraph(max_x=200, max_y=200) self.ts_netstart = time() # trigger attachment self.net.startMobility(time=0, repetitions=1) for sta_name, sta_obj in iteritems(self.sta_dict): self.net.mobility(sta_obj, 'start', time=1, position='0,0,0') self.net.mobility(sta_obj, 'stop', time=2, position='0,0,0') self.net.stopMobility(time=3) self.net.build() self.c1.start() for ap_name, ap_obj in iteritems(self.ap_dict): ap_obj.start([self.c1]) sleep(5) # wait for setup CLI_wifi(self.net) # TODO: clean this shit result = self.exec_cmd('h1', 'ping 10.0.0.13 -c 1') log.info(result) result = self.exec_cmd('sta1', 'ping 10.0.0.11 -c 1') log.info(result) result = self.exec_cmd('sta2', 'ping 10.0.0.12 -c 1') log.info(result) result = self.exec_cmd( 'h1', 'python main.py color_finder 10.0.0.11:18800 10.0.0.13:18800 &') log.info(result) result = self.exec_cmd( 'sta1', 'python main.py data_forwarder 172.17.0.2:18800 10.0.0.11:18800 True &' ) log.info(result) result = self.exec_cmd( 'sta2', 'python main.py data_forwarder 10.0.0.13:18800 192.168.56.102:18900 False &' ) log.info(result) def run_cli(self): log.info("*** Running CLI\n") CLI_wifi(self.net) def stop(self): log.info("*** Stopping network\n") self.net.stop() def exec_cmd(self, node_name, cmd): if node_name in self.sta_dict: node = self.sta_dict[node_name] elif node_name in self.host_dict: node = self.host_dict[node_name] else: assert False, 'no such node {}'.format(node_name) return node.cmd(cmd) def move_station(self, sta_name, next_pos=None, speed=None): assert sta_name in self.sta_dict sta = self.sta_dict[sta_name] if 'position' in sta.params: cur_x, cur_y, cur_z = sta.params['position'] cur_x, cur_y, cur_z = float(cur_x), float(cur_y), float(cur_z) else: cur_x, cur_y, cur_z = 0.0, 0.0, 0.0 if not next_pos: next_x, next_y, next_z = cur_x, cur_y, cur_z else: next_x, next_y, next_z = next_pos if not speed: duration = 1 else: duration = int( sqrt((next_x - cur_x)**2 + (next_y - cur_y)**2 + (next_z - cur_z)**2) / speed) log.info('[I] move {} from ({} {} {}) to ({} {} {}), dur={}\n'.format( sta_name, cur_x, cur_y, cur_z, next_x, next_y, next_z, duration)) sta.setPosition('{}, {}, {}'.format(next_x, next_y, next_z)) if duration > 0: sleep(duration) log.info('{} rssi: {}'.format(sta_name, sta.params['rssi'])) def add_nodes(self, mode='containernet'): """ add nodes to net. Args: mode (str): miminet or containernet Returns: ap_dict, sw_dict, host_dict, sta_dict """ log.info("*** Creating nodes\n") if mode == 'mininet': h1 = self.net.addHost('h1', cls=Node, mac='00:00:00:00:00:01', ip='10.0.0.11/8') sta1 = self.net.addStation('sta1', cls=Station, mac='00:00:00:00:00:02', ip='10.0.0.12/8') sta2 = self.net.addStation('sta2', cls=Station, mac='00:00:00:00:00:03', ip='10.0.0.13/8') else: dimage_name = 'kumokay/ubuntu_wifi:v4' h1 = self.net.addHost('h1', cls=Docker, dimage=dimage_name, mac='00:00:00:00:00:01', ip='10.0.0.11/8') sta1 = self.net.addStation('sta1', cls=DockerStation, dimage=dimage_name, mac='00:00:00:00:00:02', ip='10.0.0.12/8') sta2 = self.net.addStation('sta2', cls=DockerStation, dimage=dimage_name, mac='00:00:00:00:00:03', ip='10.0.0.13/8') ap1 = self.net.addAccessPoint('ap1', ssid='new-ssid', mode='g', channel='1', position='0,0,0', range=100) ap2 = self.net.addAccessPoint('ap2', ssid='new-ssid', mode='g', channel='1', position='-100,0,0', range=60) ap3 = self.net.addAccessPoint('ap3', ssid='new-ssid', mode='g', channel='1', position='-150,0,0', range=100) self.net.addController(self.c1) # add all nodes to dict self.ap_dict['ap1'] = ap1 self.ap_dict['ap2'] = ap2 self.ap_dict['ap3'] = ap3 self.host_dict['h1'] = h1 self.sta_dict['sta1'] = sta1 self.sta_dict['sta2'] = sta2 log.info("*** Configuring wifi nodes\n") self.net.configureWifiNodes() log.info("*** Associating and Creating links\n") self.net.addLink(ap1, h1, delay='5ms') self.net.addLink(ap1, ap2, delay='10ms') self.net.addLink(ap2, ap3, delay='10ms')
def topology(): "Create a network." c1 = RemoteController('c1', ip='172.17.20.11', port=6633) net = Mininet_wifi(accessPoint=OVSKernelAP) net.propagationModel(model="logDistance", exp=3) info("*** Creating nodes\n") #mode = 'mininet' mode = 'containernet' if mode == 'mininet': h1 = net.addHost('h1', cls=Node, mac='00:00:00:00:00:01', ip='10.0.0.11/8') sta1 = net.addStation('sta1', cls=Station, mac='00:00:00:00:00:02', ip='10.0.0.12/8') sta2 = net.addStation('sta2', cls=Station, mac='00:00:00:00:00:03', ip='10.0.0.13/8') else: dimage_name = 'kumokay/ubuntu14_wifi:latest' h1 = net.addHost('h1', cls=Docker, dimage=dimage_name, mac='00:00:00:00:00:01', ip='10.0.0.11/8') sta1 = net.addStation('sta1', cls=DockerStation, dimage=dimage_name, mac='00:00:00:00:00:02', ip='10.0.0.12/8') sta2 = net.addStation('sta2', cls=DockerStation, dimage=dimage_name, mac='00:00:00:00:00:03', ip='10.0.0.13/8') ap1 = net.addAccessPoint('ap1', ssid='new-ssid', mode='g', channel='1', position='0,0,0') net.addController(c1) info("*** Configuring wifi nodes\n") net.configureWifiNodes() info("*** Associating and Creating links\n") net.addLink(ap1, h1) # net.plotGraph(max_x=200, max_y=200) net.startMobility(time=0, repetitions=1) net.mobility(sta1, 'start', time=1, position='0.0,0.0,0.0') net.mobility(sta2, 'start', time=1, position='0.0,0.0,0.0') net.mobility(sta1, 'stop', time=22, position='40.0,40.0,0.0') net.mobility(sta2, 'stop', time=22, position='20.0,20.0,0.0') net.stopMobility(time=23) info("*** Starting network\n") net.build() c1.start() ap1.start([c1]) info("*** Running CLI\n") CLI_wifi(net) info("*** Stopping network\n") net.stop()
def topology(coord): "Create a network." net = Mininet_wifi(controller=Controller, accessPoint=OVSKernelAP) info("*** Creating nodes\n") h1 = net.addHost('h1', mac='00:00:00:00:00:01', ip='10.0.0.1/8') sta1 = net.addStation('sta1', mac='00:00:00:00:00:02', ip='10.0.0.2/8') sta2 = net.addStation('sta2', mac='00:00:00:00:00:03', ip='10.0.0.3/8') ap1 = net.addAccessPoint('ap1', ssid='new-ssid', mode='g', channel='1', position='45,40,0') c1 = net.addController('c1', controller=Controller) info("*** Configuring wifi nodes\n") net.configureWifiNodes() info("*** Associating and Creating links\n") net.addLink(ap1, h1) net.plotGraph(max_x=200, max_y=200) if coord: sta1.coord = ['40.0,30.0,0.0', '31.0,10.0,0.0', '31.0,30.0,0.0'] sta2.coord = ['40.0,40.0,0.0', '55.0,31.0,0.0', '55.0,81.0,0.0'] net.startMobility(time=0, repetitions=1) if coord: net.mobility(sta1, 'start', time=1) net.mobility(sta2, 'start', time=2) net.mobility(sta1, 'stop', time=12) net.mobility(sta2, 'stop', time=22) else: net.mobility(sta1, 'start', time=1, position='40.0,30.0,0.0') net.mobility(sta2, 'start', time=2, position='40.0,40.0,0.0') net.mobility(sta1, 'stop', time=12, position='31.0,10.0,0.0') net.mobility(sta2, 'stop', time=22, position='55.0,31.0,0.0') net.stopMobility(time=23) info("*** Starting network\n") net.build() c1.start() ap1.start([c1]) info("*** Running CLI\n") CLI_wifi(net) info("*** Stopping network\n") net.stop()
class MininetServer(object): # expect sequence: # -> create_empty_net # -> add_nodes # -> start_network # -> start_mobility # -> start_mobility # -> start_mobility # ... # -> stop_network # variables c1 = None net = None APs = {} Stations = {} Hosts = {} def create_empty_net(self): logging.info('setup_empty_net') self.net = Mininet_wifi(accessPoint=OVSKernelAP) self.net.propagationModel(model="logDistance", exp=3) self.c1 = RemoteController('c1', ip='172.17.20.12', port=6633) self.net.addController(self.c1) return True def add_nodes(self, dict_AP, dict_Station): logging.info('add_nodes') dimage_name = 'kumokay/ubuntu_wifi:v2' logging.debug('add APs: {}'.format(dict_AP)) for name in dict_AP: pos = dict_AP[name] self.APs[name] = self.net.addAccessPoint(name, ssid='new-ssid', mode='g', channel='1', position=pos) logging.debug('add Stations: {}'.format(dict_Station)) ip_lastbyte = 10 for name in dict_Station: pos = dict_Station[name] self.Stations[name] = self.net.addStation( name, cls=DockerStation, dimage=dimage_name, mac='00:00:00:00:00:{:x}'.format(ip_lastbyte), ip='10.0.0.{}/8'.format(ip_lastbyte), position=pos) ip_lastbyte += 1 logging.debug('configure wifi nodes') self.net.configureWifiNodes() host_per_ap = 1 logging.info('add Hosts: by default, each AP connected to 1 hosts') ip_lastbyte = 100 for ap_name in self.APs: for i in range(0, host_per_ap): host_name = '{}-h{}'.format(ap_name, i) self.Hosts[host_name] = self.net.addHost( host_name, cls=Docker, dimage=dimage_name, mac='00:00:00:00:00:{:x}'.format(ip_lastbyte), ip='10.0.0.{}/8'.format(ip_lastbyte)) ip_lastbyte += 1 self.net.addLink(self.APs[ap_name], self.Hosts[host_name]) return True def start_network(self): logging.info('start_network') self.net.build() self.c1.start() for ap_name in self.APs: self.APs[ap_name].start([self.c1]) return True def stop_network(self): logging.info('stop_network') self.net.stop() return True def start_mobility(self, station_name, from_pos, to_pos, velocity): logging.info('start_mobility') logging.debug(self.Stations) if station_name not in self.Stations: logging.warning('no such station: {}'.format(station_name)) return False logging.info('{} -> {}'.format(from_pos, to_pos)) v_from = Vector3r().init_from_string(from_pos) v_to = Vector3r().init_from_string(to_pos) logging.info('{} -> {}'.format(v_from, v_to)) distance = lib_geo.getDistance(v_to, v_from) logging.info('{}'.format(distance)) delta_t = int(distance / velocity) logging.info( 'move {} from {} to {}, velocity={}, dist={}, delta_t={}'.format( station_name, from_pos, to_pos, velocity, distance, delta_t)) station = self.Stations[station_name] self.net.startMobility(time=0, repetitions=0) self.net.mobility(station, 'start', time=1, position=from_pos) self.net.mobility(station, 'stop', time=delta_t + 1, position=to_pos) self.net.stopMobility(time=delta_t + 2) return True def start_cil(self): CLI_wifi(self.net) return True