def process_link_status(self, sock, eventmask): """ Args: sock: eventmask: Returns: """ try: if sock is not None: if isinstance(sock, int) and eventmask == zmq.POLLIN: if sock != self.linksock.fileno(): self.logger.warn( "Got a unexpected socket event, the sock is not expected ") return data = self.linksock.recv(65535) interface, state = self._decode_link_state(data) if interface is None: self.logger.debug("Fail to decode interface state:%s", state) return self.logger.warn("receive msg: %s is %s", interface, state) Mcast.interface_state_change(interface=interface, state=state) except Exception as e: self.logger.warn("Exception happens when handle link status, error:" + str(e) + ", The Trace back is:\n" + traceback.format_exc()) return
def test_interface_check(self): address = ("127.0.0.1", "5.5.5.1", "229.1.1.255", 0) session_1 = ("127.0.0.1", "127.0.0.1", 1, 1) mcast = Mcast(address=address) mcast.join(session_1) time.sleep(1) mcast.rejoin() mcast.interface_state_change("lo", 'UP') self.assertEqual(mcast.interfaceList['lo'], Mcast.interface_up) mcast.interface_state_change("lo", 'DOWN') self.assertEqual(mcast.interfaceList['lo'], Mcast.interface_down) mcast.interface_state_change("lo", 'UP') self.assertEqual(mcast.interfaceList['lo'], Mcast.interface_up) for key in mcast.McastDb.keys(): mcast.McastDb[key].close()