def broadcast_dis(interfaces, options=""): """Broadcast a DIS message on all interfaces""" global dis_timer logger.debug("checking if a DIS broadcast is required") if gv.dodag_cache.is_empty(): logger.debug("broadcasting DIS") broadcast(interfaces, str(DIS()) + str(options)) else: logger.debug("no DIS is required") dis_timer = Timer(DEFAULT_INTERVAL_BETWEEN_DIS, broadcast_dis, kwargs= {'interfaces':interfaces}) dis_timer.daemon = True dis_timer.start()
def broadcast_dis(interfaces, options=""): """Broadcast a DIS message on all interfaces""" global dis_timer logger.debug("checking if a DIS broadcast is required") if gv.dodag_cache.is_empty(): logger.debug("broadcasting DIS") broadcast(interfaces, str(DIS()) + str(options)) else: logger.debug("no DIS is required") dis_timer = Timer(DEFAULT_INTERVAL_BETWEEN_DIS, broadcast_dis, kwargs={'interfaces': interfaces}) dis_timer.daemon = True dis_timer.start()
def sendDIO(self, iface=None, destination=None, dodag_shutdown=False): """Send a DIO message: - iface: if specified, this is the interface where messages are going out, if not, message are broadcasted on all registered interfaces - destination: if this is a unicast DIO, destionation is the destination address. If destination is not specified, the message is sent to the RPL-all-routers multicast address - dodag_shutdown: this function also schedule a DAO message to be sent. During the shutdown procedure or when a DODAG version is phased out, this is not a desirable behavior, as the DAO should be sent right away. """ logger.info("sending DIO message for %s (version %d)" % (repr(Address(self.dodagID)), self.version.get_val())) if self.advertised_prefixes: extra_option = "".join([str(RPL_Option_Prefix_Information(prefix_len=64, L=0, A=1, R=0, prefix=prefix, valid_lifetime=0xFFFFFFFF, # infinite lifetime preferred_lifetime=0xFFFFFFFF)) for prefix in self.advertised_prefixes]) else: extra_option = "" DIO_message = str(DIO(instanceID=self.instanceID, version=self.version.get_val(), rank=self.rank, G=self.G, MOP=self.MOP, Prf=self.Prf, DTSN=self.DTSN.get_val(), flags=0, reserved=0, DODAGID=self.dodagID)) + \ str(RPL_Option_DODAG_Configuration(A=self.authenticated, PCS=self.PCS, DIOIntDoubl=self.DIOIntDoublings, DIOIntMin=self.DIOIntMin, DIORedun=self.DIORedundancyConst, MaxRankIncrease=self.MaxRankIncrease, MinHopRankIncrease=self.MinHopRankIncrease, OCP=self.OCP, DefLifetime=self.DftLft, LifetimeUnit=self.LftUnit)) +\ extra_option if iface and destination: self.interfaces[iface].send(destination, DIO_message) else: broadcast(self.interfaces, DIO_message) # DAO message are sent after a short interval when DIO messages are # sent if not self.is_dodagRoot and not dodag_shutdown: self.setDAOtimer() del DIO_message
print "I got it !" return True if elapsed_time > 60 * randcon: return False counting = 0 def count(success): if success: global counting counting = counting + 1 cryptogen = SystemRandom() num = cryptogen.randrange(len(contlist)) broadcaster = contlist[num] tools.broadcast(advclient, broadcaster["cont"], "gossip_test", "Hello!") contlist.remove(broadcaster) runMultiple(waitForGossipMessage, count) print str(counting) + " nodes got the gossip message" print "Starting to shutdown nodes" contlist.append({ "cont": bootstrap }) contlist.append({ "cont": broadcaster["cont"] }) tools.cleanUp(contlist)
def sendDAO(self, iface=None, destination=None, retransmit=False, nopath=False): """Send a DAO message to its DAO parent (by default) Build the target list on the fly nopath parameters indicates that the node must announce all its downward routes as no-path""" assert self.active or nopath logger.info("sending DAO message for %s (version %d)" % (repr(Address(self.dodagID)), self.version.get_val())) if not retransmit: self.last_DAOSequence += 1 # if no destination is specified, find the DAO parent if not destination: # here, destination is None if no DAO parent exists destination = self.preferred_parent try: iface = destination.iface destination = destination.address except: destination = None iface = None assert destination != ALL_RPL_NODES # build the RPL Target Options for the addresses allocated on the node targets_opt = "".join([str(RPL_Option_RPL_Target(prefix_len=128, target_prefix=str(Address(address)))) for (address, pref_len, nh_iface) in gv.address_cache]) # the Parent Address field is not needed because the node is in Storing Mode transit_inf_opt = str(RPL_Option_Transit_Information(path_control=0, path_sequence=self.last_PathSequence.get_val(), path_lifetime=0x00 if nopath else self.DftLft, parent_address="")) no_path_targets_opt = "" no_path_transit_inf_opt = "" if destination and Address(destination).is_RPL_all_nodes(): logger.debug("sending DAO message to All-RPL-Nodes multicast address: %s" % destination) DAO_header = str(DAO(instanceID=self.instanceID, K=0, DAOsequence=self.last_DAOSequence.get_val(), \ DODAGID=self.dodagID)) elif destination and Address(destination).is_linklocal(): # because the K flag is set, we set a timer for receiving a DAO-ACK self.DAO_ACK_source = destination self.DAO_ACK_source_iface = iface self.setDAO_ACKtimer() logger.debug("sending DAO message to a Link-Local address: %s" % destination) DAO_header = str(DAO(instanceID=self.instanceID, K=1, DAOsequence=self.last_DAOSequence.get_val(), \ DODAGID=self.dodagID)) with self.__lock: # build the RPL Target Options from the list of downward routes targets = [tuple(route.target.split("/")) for route in self.downward_routes] targets_opt += "".join([str(RPL_Option_RPL_Target(prefix_len=int(preflen), target_prefix=str(Address(prefix)))) for (prefix, preflen) in targets]) if self.no_path_routes_trans < DEFAULT_DAO_NO_PATH_TRANS and self.no_path_routes: logger.debug("advertising additional routes that need to be removed") self.no_path_routes_trans += 1 # there is no need to propagate the No-Path information when an alternative path exists locally reachable_targets = set([route.target for route in self.downward_routes]) no_path_targets = [tuple(route.target.split("/")) for route in self.no_path_routes if route.target not in reachable_targets] if no_path_targets: no_path_targets_opt = "".join([str(RPL_Option_RPL_Target(prefix_len=int(preflen), target_prefix=str(Address(prefix)))) for (prefix, preflen) in no_path_targets]) no_path_transit_inf_opt = str(RPL_Option_Transit_Information(path_control=0, path_sequence=self.last_PathSequence.get_val(), path_lifetime=0x00, parent_address="")) else: self.no_path_routes = set() else: logger.debug("destination address %s is not a Link-Local address or a Multicast address, dropping command" % destination) return if nopath: DAO_message = DAO_header + targets_opt + no_path_targets_opt + transit_inf_opt else: DAO_message = DAO_header + targets_opt + transit_inf_opt + no_path_targets_opt + no_path_transit_inf_opt if iface and destination: self.interfaces[iface].send(destination, DAO_message) else: broadcast(self.interfaces, DAO_message)