def setupProtection(self, data=None): self.data = data Log.info("Setup port protection") dt = DevTarget_t(0, hex_to_i16(0xFFFF)) p = port_down_packet() pktlen = self.port_pkt_len = len(p) self.tc.conn_mgr.pktgen_write_pkt_buffer(self.tc.hdl, dt, 0, pktlen, str(p)) offset = 0 # enable on all pipes for pipe in range(0, self.pal.pal_num_pipes_get(0)): port = (pipe << 7 | 68) self.tc.conn_mgr.pktgen_enable(self.tc.hdl, 0, (pipe << 7 | 68)) Log.debug("Enable pkt gen on port", port) config = PktGenAppCfg_t(trigger_type=PktGenTriggerType_t.PORT_DOWN, timer=0, src_port=68, buffer_offset=offset, length=pktlen) self.tc.conn_mgr.pktgen_cfg_app(self.tc.hdl, dt, 0, config) self.tc.conn_mgr.pktgen_app_enable(self.tc.hdl, dt, 0) offset=pktlen
def message_in(*args, **kwargs): """ Generic message_in handle function Triggers corresponding event :param kwargs: :return: """ packet = kwargs.get('packet') switch = kwargs.get('switch') try: pkt = Ether(packet.packet.payload) try: Configuration.get('system_done') except ConfigurationNotFound: return if pkt.type == 0xEE00: # its an port down packet Log.info("Port:", pkt[PortDown].port_num, "down", "on ingress", pkt[PortDown].pad1, "on pipe") Event.trigger("port_down", pkt=pkt) if pkt.type == 0xDD00: # its an topology packet Event.trigger("topology_packet_in", packet=pkt, switch=switch) if pkt.type == 0x800 and pkt[IP].proto == 2: # its an igmp packet igmp = pkt.payload pkt = proto.connection_pb2.GroupPacket(type=int(igmp.type), mc_address=str(igmp.gaddr), src_ip=str(igmp.src), switch=Configuration.get('name')) Event.trigger("igmp_packet_to_controller", pkt=pkt) Log.debug("Send igmp packet to controller") except Exception as e: # it's not an ethernet frame pass
def setPorts(self, data=None): for configuration in data[Configuration.get('name')]: p_id = self.pal.pal_port_front_panel_port_to_dev_port_get(0, configuration['port'], configuration['channel']) self.pal.pal_port_add(0, p_id, configuration['speed'], pal_fec_type_t.BF_FEC_TYP_NONE) self.pal.pal_port_an_set(0, p_id, 2) self.pal.pal_port_enable(0, p_id) if 'loopback' in configuration and configuration['loopback']: self.pal.pal_port_loopback_mode_set(0, p_id, 1) Log.debug("Set port", p_id, "to loopback")
def send_topology_packets(self): """ Send topology packet for given switch :return: """ sw = Configuration.get('name') # get bfr id off switch for identification in top packet switch = TopologyManager.get_device(sw) pkt = Ether(src='00:00:00:00:00:00', dst='ff:ff:ff:ff:ff:ff') pkt = pkt / TopologyDiscovery(identifier=switch.get_bfr_id(0), port=1, ip=str(switch.get_ip()), mac=str(switch.get_mac())) self.__baseController.get_connection().send_packet_out(str(pkt)) Log.debug("Send topology packet to switch", sw) # send topology packet periodically threading.Timer(2, self.send_topology_packets).start()
def update_mac_entry(self): """ Add mac rewriting rule for switch->dst_dev via port :param switch: switch where rule will be installed :param dst_dev: next_hop :param port: port which is used towards next_hop :return: """ valid_entries = [] device = TopologyManager.get_device(Configuration.get('name')) for device_name in device.get_device_to_port_mapping(): dev = TopologyManager.get_device(device_name) port = device.get_device_to_port(device_name) Log.debug("Mac:", Configuration.get('name'), "->", device_name, "via", port) entry = TableEntry( match_fields={"standard_metadata.egress_port": int(port)}, action_name="egress.mac_c.set_mac", action_params={ "srcAddr": device.get_mac(), "dstAddr": dev.get_mac() }) TableEntryManager.handle_table_entry( manager=self.table_manager, table_name="egress.mac_c.adjust_mac", table_entry=entry) valid_entries.append(entry.match_fields) Log.debug("Installed Mac rewriting rule for", Configuration.get('name')) # remove possible old entries self.table_manager.remove_invalid_entries( table_name="egress.mac_c.adjust_mac", valid_entries=valid_entries)
def setMirrorSession(self, data=None): ports = self.get_mirror_port(data) if ports is None: return for i, p in enumerate(ports): dt = DevTarget_t(0, hex_to_i16(0xFFFF)) session = 1000 + i info = mirror_session(MirrorType_e.PD_MIRROR_TYPE_NORM, Direction_e.PD_DIR_INGRESS, session, p, True) self.mirror.mirror_session_create(self.thrift_con.hdl, dt, info) self.thrift_con.conn_mgr.complete_operations(self.thrift_con.hdl) self.mirror.mirror_session_enable(self.thrift_con.hdl, Direction_e.PD_DIR_INGRESS, dt, 1000) self.thrift_con.conn_mgr.complete_operations(self.thrift_con.hdl) Log.debug("Create mirror session", session, "to port", p) self.pal.pal_port_loopback_mode_set(0, p, 1)
def buildDeviceConfig(self, **kwargs): Log.debug("before build device config") return p4config_pb2.P4DeviceConfig()