def __init__(self, config, system, layer2, layer3): self.config = config self.system = system self.scheduler = system.get_scheduler() self.layer2 = layer2 self.layer3 = layer3 self.layer2._set_protocol(self) self.layer3._set_protocol(self) self.default_frag_rule = None # XXX: to be in rule_manager self.compressor = Compressor(self) self.decompressor = Decompressor(self) self.fragment_session = Session(self) self.reassemble_session = Session(self) if hasattr(config, "debug_level"): set_debug_output(True)
def __init__(self, config, system, layer2, layer3, role, unique_peer): assert role in ["device", "core-server"] self.config = config self.unique_peer = unique_peer self.role = role self.system = system self.scheduler = system.get_scheduler() self.layer2 = layer2 self.layer3 = layer3 self.layer2._set_protocol(self) self.layer3._set_protocol(self) self.compressor = Compressor(self) self.decompressor = Decompressor(self) self.session_manager = SessionManager(self, unique_peer) if hasattr(config, "debug_level"): set_debug_output(True)
def init_from_config(self): self.scheduler.add_event(0, self._notify_start, ()) if self.simul_config.get("seed") is not None: random.seed(self.simul_config["seed"]) self.frame_loss = PacketLossModel( **self.simul_config.get("loss", NO_LOSS_CONFIG)) with_dprint = bool(self.simul_config.get("enable-print", True)) gen_utils.set_debug_output(with_dprint) if not self.simul_config.get("enable-trace", True): gen_utils.set_trace_function(None) record_dir_name = self.simul_config.get("record.directory") should_record = bool(self.simul_config.get("record.enable", False)) if (record_dir_name is not None) and should_record: record_quiet = bool(self.simul_config.get("record.quiet")) obs = net_sim_record.SimulRecordingObserver(self) self.set_observer(obs) obs.start_record(record_dir_name, record_quiet) # XXX: should be at sim start.
def init_from_config(self): if self.simul_config.get("seed") is not None: random.seed(self.simul_config["seed"]) self.frame_loss = ConditionalTrue( **self.simul_config.get("loss", {"mode": "cycle"})) with_dprint = bool(self.simul_config.get("enable-print", True)) gen_utils.set_debug_output(with_dprint) if not self.simul_config.get("enable-trace", True): gen_utils.set_trace_function(None) record_dir_name = self.simul_config.get("record.directory") should_record = bool(self.simul_config.get("record.enable", False)) if (record_dir_name is not None) and should_record: record_quiet = bool(self.simul_config.get("record.quiet")) obs = net_sim_record.SimulRecordingObserver(self) self.set_observer(obs) obs.start_record(record_dir_name, record_quiet) # XXX: should be at sim start.
def frag_generic(rule, packet): # General configuration l2_mtu = 72 # bits data_size = 14 # bytes SF = 12 simul_config = { "log": True, } devaddr = b"\xaa\xbb\xcc\xdd" set_debug_output(True) rm0 = RuleManager() rm0.Add(devaddr, dev_info=rule) # Message packet_bbuf = BitBuffer(packet) tiles = TileList(rm0.FindFragmentationRule(devaddr), packet_bbuf) for t in tiles.get_all_tiles(): print(t) set_debug_output(False) return True
def frag_generic(rules_filename, packet_loss): # -------------------------------------------------- # General configuration l2_mtu = 72 # bits data_size = 14 # bytes SF = 12 simul_config = { "log": True, } # --------------------------------------------------------------------------- # Configuration packets loss if packet_loss: # Configuration with packet loss in noAck and ack-on-error loss_rate = 15 # in % collision_lambda = 0.1 background_frag_size = 54 loss_config = {"mode": "rate", "cycle": loss_rate} # loss_config = {"mode":"collision", "G":collision_lambda, "background_frag_size":background_frag_size} else: # Configuration without packet loss in noAck and ack-on-error loss_rate = None loss_config = None # --------------------------------------------------------------------------- # Init packet loss if loss_config is not None: simul_config["loss"] = loss_config # --------------------------------------------------------------------------- def make_node(sim, rule_manager, devaddr=None, extra_config={}, role=None): extra_config["unique-peer"] = True node = net_sim_core.SimulSCHCNode(sim, extra_config, role) node.protocol.set_rulemanager(rule_manager) if devaddr is None: devaddr = node.id node.layer2.set_devaddr(devaddr) return node # --------------------------------------------------------------------------- # Statistic module Statsct.initialize() Statsct.log("Statsct test") Statsct.set_packet_size(data_size) Statsct.set_SF(SF) # --------------------------------------------------------------------------- devaddr1 = b"\xaa\xbb\xcc\xdd" devaddr2 = b"\xaa\xbb\xcc\xee" dprint("---------Rules Device -----------") rm0 = RuleManager() # rm0.add_context(rule_context, compress_rule1, frag_rule3, frag_rule4) rm0.Add(device=devaddr1, file=rules_filename) rm0.Print() dprint("---------Rules gw -----------") rm1 = RuleManager() # rm1.add_context(rule_context, compress_rule1, frag_rule4, frag_rule3) rm1.Add(device=devaddr2, file=rules_filename) rm1.Print() # --------------------------------------------------------------------------- # Configuration of the simulation Statsct.get_results() sim = net_sim_core.Simul(simul_config) node0 = make_node(sim, rm0, devaddr1, role="device") # SCHC device node1 = make_node(sim, rm1, devaddr2, role="core-server") # SCHC gw sim.add_sym_link(node0, node1) node0.layer2.set_mtu(l2_mtu) node1.layer2.set_mtu(l2_mtu) # --------------------------------------------------------------------------- # Information about the devices dprint( "-------------------------------- SCHC device------------------------") dprint("SCHC device L3={} L2={} RM={}".format(node0.layer3.L3addr, node0.id, rm0.__dict__)) dprint( "-------------------------------- SCHC gw ---------------------------") dprint("SCHC gw L3={} L2={} RM={}".format(node1.layer3.L3addr, node1.id, rm1.__dict__)) dprint( "-------------------------------- Rules -----------------------------") dprint("rules -> {}, {}".format(rm0.__dict__, rm1.__dict__)) dprint("") # --------------------------------------------------------------------------- # Statistic configuration Statsct.setSourceAddress(node0.id) Statsct.setDestinationAddress(node1.id) # -------------------------------------------------- # Message coap = bytearray(b"`\x12\x34\x56\x00\x1e\x11\x1e\xfe\x80\x00" + b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" + b"\x00\x00\x01\xfe\x80\x00\x00\x00\x00\x00" + b"\x00\x00\x00\x00\x00\x00\x00\x00\x02\x16" + b"2\x163\x00\x1e\x00\x00A\x02\x00\x01\n\xb3" + b"foo\x03bar\x06ABCD==Fk=eth0\xff\x84\x01" + b"\x82 &Ehello") # --------------------------------------------------------------------------- # Simnulation node0.protocol.layer3.send_later(1, None, node1.layer3.L3addr, coap) old_stdout = sys.stdout set_debug_output(True) sys.stdout = io.StringIO() sim.run() simulation_output = sys.stdout.getvalue() sys.stdout = old_stdout set_debug_output(False) print(simulation_output) return simulation_output
action="store", dest="prog_name", default="GW", help="specify the name of this program.") ap.add_argument("-d", action="store_true", dest="debug_level", default=None, help="specify debug level.") config = ap.parse_args() update_config() # set the logger object. logger = set_logger(config) if config.debug_level > 0: set_debug_output(True) # create the schc protocol object. rule_manager = RuleManager() for x in config.rule_config: rule_manager.Add(device=x.get("devL2Addr"), file=x["rule_file"]) if config.debug_level > 1: rule_manager.Print() # schc_conf = get_schc_conf(config) system = AiohttpSystem(logger=logger, config=schc_conf) layer2 = AiohttpLowerLayer(system, config=schc_conf) layer3 = AiohttpUpperLayer(system, config=schc_conf) protocol = protocol.SCHCProtocol(schc_conf, system, layer2,