def test_ruleman_01(): # XXX actually, it is not test code right now. RM = RuleManager() RM.add_context(context1, rule1, rule2, rule3) RM.add_context(context2, rule1) print(RM._db) #RM.add_rules(context1, [conflictingRule0]) #RM.add_rules(context1, [bogusRule0]) print(RM.find_context_bydevL2addr("AABBCCDD")) print(RM.find_context_bydstiid("2001:0db8:85a3::beef")) RM.find_rule_bypacket(context1, BitBuffer(int("10000111", 2).to_bytes(1, "big")))
class SCHC_server: def __init__(self, scheduler): #self.port = port #self.devEUI = devEUI self.port = None self.devEUI = None self.cont = 0 self.loss_config = None self.rule = [] self.context = "example/context-100.json" self.rule_comp = "example/comp-rule-100.json" self.rule_fragin2 = "example/frag-rule-201.json" #NoACK self.rule_fragout2 = "example/frag-rule-202.json" #NoACK self.rule_fragin = "example/frag-rule-101.json" #ACK-ON-Error self.rule_fragout = "example/frag-rule-102.json" #ACK-ON-Error for k in [ self.context, self.rule_comp, self.rule_fragin, self.rule_fragout, self.rule_fragin2, self.rule_fragout2 ]: with open(k) as fd: self.rule.append(json.loads(fd.read())) self.rule_manager = RuleManager() self.rule_manager.add_context(self.rule[0], self.rule[1], self.rule[2], self.rule[3], self.rule[4], self.rule[5]) #-------------------------------------------------------------------------- #simul self.l2_mtu = 56 self.layer_2 = SimulLayer2() self.layer_2.set_mtu(self.l2_mtu) self.layer_3 = SimulLayer3() self.scheduler = scheduler #self.scheduler = Scheduler() self.protocol = schc.SCHCProtocol(self.scheduler, self.layer_2, self.layer_3) self.protocol.set_rulemanager(self.rule_manager) self.protocol.set_dev_L2addr(0) #setear la direccion MAC self.sender_id = self.layer_2.mac_id #tengo que tener la mac del que envia #------------------------------------------------------------------------- def reassemble(self, Fragment): self.layer_2.event_receive_packet(self.sender_id, Fragment) def sendMessage(self, msg, ruleId): self.layer_3.send_later(1, 1, msg, ruleId)
packet_sizes = [80] tile_size = 49 #tile_size = 240 payload_ack_always = tile_size * 2 ack_on_error = True #--------------------------------------------------------------------------- """ Init stastct module """ Statsct.initialize() Statsct.log("Statsct test") Statsct.set_packet_size(data_size) Statsct.set_SF(SF) #--------------------------------------------------------------------------- #no-ack rm0 = RuleManager() rm0.add_context(rule_context, compress_rule, frag_rule3, frag_rule4) rm1 = RuleManager() rm1.add_context(rule_context, compress_rule, frag_rule4, frag_rule3) #ack-on-error if ack_on_error: rm0 = RuleManager() rm0.add_context(rule_context, compress_rule, frag_rule1, frag_rule2) rm1 = RuleManager() rm1.add_context(rule_context, compress_rule, frag_rule2, frag_rule1) #-------------------------------------------------- simul_config = {
node.protocol.set_rulemanager(rule_manager) node.layer2.set_devaddr(devaddr) return node #--------------------------------------------------------------------------- rule = [] for k in [ opt.context_file, opt.rule_comp_file, opt.rule_fragin_file, opt.rule_fragout_file ]: with open(k) as fd: rule.append(json.loads(fd.read())) rm0 = RuleManager() rm0.add_context(rule[0], rule[1], rule[2], rule[3]) rm1 = RuleManager() rm1.add_context(rule[0], rule[1], rule[3], rule[2]) simul_config = { "log": True, } if loss_config is not None: simul_config["loss"] = loss_config sim = simul.Simul(simul_config) devaddr = b"\xaa\xbb\xcc\xdd" node0 = make_node(sim, rm0, devaddr) # SCHC device node1 = make_node(sim, rm1, devaddr) # SCHC gw
help="specify debug level.") config = ap.parse_args() update_config() # set the logger object. logger = set_logger(logging, config) if not config.debug_level: requests.packages.urllib3.disable_warnings() # create the schc protocol object. rule = [] for k in [config.context_file, config.rule_comp_file, config.rule_fragin_file, config.rule_fragout_file]: with open(k) as fd: rule.append(json.loads(fd.read())) rule_manager = RuleManager() rule_manager.add_context(rule[0], rule[1], rule[2], rule[3]) # loop = asyncio.get_event_loop() if config.debug_level > 1: loop.set_debug(True) system = System(loop, logger=logger, config=config) layer2 = gwLayer2(system, config=config) layer3 = gwLayer3(system, config=config) protocol = schc.SCHCProtocol(config, system, layer2, layer3) protocol.set_rulemanager(rule_manager) # ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) ctx.load_cert_chain(config.my_cert) app = web.Application(loop=loop, debug=True) app.router.add_route("POST", "/ul", app_uplink)
#--------------------------------------------------------------------------- # Statistic module Statsct.initialize() Statsct.log("Statsct test") Statsct.set_packet_size(data_size) Statsct.set_SF(SF) #--------------------------------------------------------------------------- # Fragmentation mode compress_rule = None #no-ack rm0 = RuleManager() rm0.add_context(rule_context, compress_rule, frag_rule3, frag_rule4) rm1 = RuleManager() rm1.add_context(rule_context, compress_rule, frag_rule4, frag_rule3) #ack-on-error if ack_on_error: rm0 = RuleManager() rm0.add_context(rule_context, compress_rule, frag_rule1, frag_rule2) rm1 = RuleManager() rm1.add_context(rule_context, compress_rule, frag_rule2, frag_rule1) rm0.Add(file="example/comp-rule-100.json") rm1.Add(file="example/comp-rule-100.json")
rule3 = { "ruleID" : 7, "ruleLength" : 3, "profile": { "MICAlgorithm": "crc32", "MICWordSize": 8, "L2WordSize": 8 }, "fragmentation" : { "dir": "in", "FRMode" :"noAck" }, } conflictingRule0 = { "ruleID" : 15, "ruleLength" : 4, "compression" : {}, } RM = RuleManager() RM.add_context(context1, rule1,rule2,rule3) RM.add_context(context2, rule1) print(RM._db) #RM.add_rules(context1, [conflictingRule0]) #RM.add_rules(context1, [bogusRule0]) print(RM.find_context_bydevL2addr("AABBCCDD")) print(RM.find_context_bydstiid("2001:0db8:85a3::beef")) from bitarray import BitBuffer RM.find_rule_bypacket(context1, BitBuffer(int("10000111",2).to_bytes(1, "big")))