def __setup_arp_multicast(self,
                              node_id=1,
                              rid=1,
                              lags=[],
                              mgid=1,
                              mc_nids=[1],
                              l1_xids=[0]):
        ports = self.__find_node_ports()
        logger.info('Adding multicast entries to switch')
        mg_id_table = self.get_table('$pre.node')
        mg_id_table.entry_add(
            self.target,
            [mg_id_table.make_key([KeyTuple('$MULTICAST_NODE_ID', node_id)])],
            [
                mg_id_table.make_data([
                    DataTuple('$MULTICAST_RID', rid),
                    DataTuple('$DEV_PORT', int_arr_val=ports),
                    DataTuple('$MULTICAST_LAG_ID', int_arr_val=lags),
                ])
            ])
        logger.info('Done with node entries')

        mg_id_table = self.get_table('$pre.mgid')
        mg_id_table.entry_add(
            self.target, [mg_id_table.make_key([KeyTuple('$MGID', mgid)])], [
                mg_id_table.make_data([
                    DataTuple('$MULTICAST_NODE_ID', int_arr_val=mc_nids),
                    DataTuple('$MULTICAST_NODE_L1_XID_VALID',
                              bool_arr_val=[False]),
                    DataTuple('$MULTICAST_NODE_L1_XID', int_arr_val=l1_xids),
                ])
            ])
        logger.info('Done with MC entries')
Beispiel #2
0
 def stop_attack(self, **kwargs):
     logger.info('Adding attack [%s]', kwargs)
     action_name, dst_ipv4, dst_ipv6 = self.parse_attack(**kwargs)
     self.delete_table_entry(data_drop_tbl,
                             [
                                 KeyTuple(data_drop_tbl_key_1,
                                          kwargs['src_mac']),
                                 KeyTuple(data_drop_tbl_key_2, dst_ipv4),
                                 KeyTuple(data_drop_tbl_key_3, dst_ipv6),
                                 KeyTuple(data_drop_tbl_key_4,
                                          int(kwargs['dst_port']))
                             ])
Beispiel #3
0
    def __update_mgid_tbl(self, mgid, mc_nids, l1_xids):
        mg_id_table = self.get_table('$pre.mgid')
        mg_id_key = [mg_id_table.make_key([KeyTuple('$MGID', mgid)])]
        try:
            mg_id_table.entry_del(self.target, mg_id_key)
        except Exception as e:
            logger.debug('Ignore me - [%s]', e)
            pass

        try:
            mg_id_table.entry_add(self.target, mg_id_key, [
                mg_id_table.make_data([
                    DataTuple('$MULTICAST_NODE_ID', int_arr_val=mc_nids),
                    DataTuple('$MULTICAST_NODE_L1_XID_VALID',
                              bool_arr_val=[False]),
                    DataTuple('$MULTICAST_NODE_L1_XID', int_arr_val=l1_xids),
                ])
            ])
        except Exception as e:
            if 'ALREADY_EXISTS' in str(e):
                pass
            else:
                logger.error('Unexpected error inserting into table %s - [%s]',
                             '$pre.mgid', e)
                raise e
        logger.info('Done with MC entries')
Beispiel #4
0
    def __update_pre_tbl(self, node_id, ports, rid=1, lags=[]):
        logger.info('Deleting and adding multicast entries to $pre.node')
        pre_table = self.get_table('$pre.node')
        pre_key = [
            pre_table.make_key([KeyTuple('$MULTICAST_NODE_ID', node_id)])
        ]
        try:
            pre_table.entry_del(self.target, pre_key)
        except Exception as e:
            logger.debug('Ignore me - [%s]', e)
            pass

        try:
            pre_table.entry_add(self.target, pre_key, [
                pre_table.make_data([
                    DataTuple('$MULTICAST_RID', rid),
                    DataTuple('$DEV_PORT', int_arr_val=ports),
                    DataTuple('$MULTICAST_LAG_ID', int_arr_val=lags),
                ])
            ])
        except Exception as e:
            if 'ALREADY_EXISTS' in str(e):
                pass
            else:
                logger.error('Unexpected error inserting into table %s - [%s]',
                             '$pre.node', e)
                raise e
Beispiel #5
0
 def add_data_forward(self, dst_mac, ingress_port):
     logger.info(
         'Inserting port - [%s] with key - [%s] into %s',
         int(ingress_port), dst_mac, data_fwd_tbl)
     self.insert_table_entry(data_fwd_tbl,
                             data_fwd_action,
                             [KeyTuple(data_fwd_tbl_key, dst_mac)],
                             [DataTuple(data_fwd_action_val,
                                        int(ingress_port))])
Beispiel #6
0
 def add_data_forward(self, dst_mac, ingress_port):
     logger.info(
         'Inserting port - [%s] with key - [%s] into '
         'TpsCoreIngress.data_forward_t', ingress_port, dst_mac)
     self.insert_table_entry(data_fwd_tbl,
                             data_fwd_action,
                             [KeyTuple(data_fwd_tbl_key,
                                       value=dst_mac)],
                             [DataTuple(data_fwd_action_val,
                                        val=int(ingress_port))])
Beispiel #7
0
 def add_data_inspection(self, dev_id, dev_mac):
     logger.info(
         'Inserting dev_id - [%s] with key mac - [%s] into %s',
         dev_id, dev_mac, data_inspection_tbl)
     self.insert_table_entry(data_inspection_tbl,
                             data_inspection_action,
                             [KeyTuple(data_inspection_tbl_key, dev_mac)],
                             [
                                 DataTuple(data_inspection_action_val_1,
                                           int(dev_id)),
                                 DataTuple(data_inspection_action_val_2,
                                           int(self.int_device_id))
                             ])
Beispiel #8
0
    def set_trpt_sampling_value(self, sample_size):
        logger.info(
            'Setting up telemetry report sample size core device [%s] to [%s]',
            self.device_id, sample_size)

        sample_tbl = self.get_table(trpt_sample_tbl)
        sample_tbl.entry_add(
            self.target,
            [sample_tbl.make_key([KeyTuple(trpt_sample_key, 0)])],
            [sample_tbl.make_data([
                DataTuple(trpt_rate_field, sample_size),
            ])]
        )
Beispiel #9
0
 def remove_telemetry_rpt(self, ae_ip, port=UDP_INT_DST_PORT):
     logger.info(
         'Removing up telemetry report from core device [%s] with '
         'AE IP - [%s]', self.device_id, ae_ip)
     ip_addr = ipaddress.ip_address(ae_ip)
     logger.debug('ip_addr object - [%s]', ip_addr)
     try:
         self.delete_table_entry(
             telem_rpt_tbl,
             [KeyTuple(telem_rpt_tbl_key, value=port)])
     except Exception as e:
         if 'ALREADY_EXISTS' in str(e):
             pass
         else:
             raise e
Beispiel #10
0
    def __write_clone_entries(self, port, mirror_tbl_key=1):
        logger.info('Start mirroring operations on table [%s] to port [%s]',
                    "$mirror.cfg", port)
        mirror_cfg_table = self.get_table("$mirror.cfg")

        mirror_cfg_table.entry_add(
            self.target,
            [mirror_cfg_table.make_key([KeyTuple('$sid', mirror_tbl_key)])],
            [mirror_cfg_table.make_data([
                DataTuple('$direction', str_val="BOTH"),
                DataTuple('$ucast_egress_port', port),
                DataTuple('$ucast_egress_port_valid', bool_val=True),
                DataTuple('$session_enable', bool_val=True)
            ], '$normal')]
        )
Beispiel #11
0
    def get_arp_multicast_ports(self, node_id=1):
        logger.info('Retrieving multicast entries from switch')
        mg_id_table = self.get_table('$pre.node')
        match_keys = [
            mg_id_table.make_key([KeyTuple('$MULTICAST_NODE_ID', node_id)])
        ]
        entries = mg_id_table.entry_get(self.target, match_keys)

        out_ports = list()
        for data, key in entries:
            if '$DEV_PORT' in data:
                out_ports.append(data.to_dict()['$DEV_PORT'])

        logger.info('Multicast ports returned - [%s]', out_ports)
        return out_ports
Beispiel #12
0
 def read_ae_ip(self, port=UDP_INT_DST_PORT):
     trpt_table_obj = self.get_table(telem_rpt_tbl)
     ae_ip = None
     if trpt_table_obj:
         try:
             data, key = next(
                 trpt_table_obj.entry_get(
                     self.target,
                     [KeyTuple(telem_rpt_tbl_key, value=int(port))]))
             table_data = data.to_dict()
             logger.debug("Table [%s] data [%s]", )
             ae_ip = table_data["ae_ip"]
         except Exception as e:
             if 'field_dict' not in str(e):
                 logger.debug("Unable to access table entry info - [%s]", e)
     return ae_ip
Beispiel #13
0
    def add_switch_id(self):
        logger.info(
            'Inserting device ID [%s] into add_switch_id_t table',
            self.int_device_id)

        try:
            self.insert_table_entry(add_switch_id_tbl,
                                    add_switch_id_action,
                                    [KeyTuple(add_switch_id_tbl_key,
                                              value=UDP_INT_DST_PORT)],
                                    [DataTuple(add_switch_id_action_val,
                                               val=self.int_device_id)])
        except Exception as e:
            if 'ALREADY_EXISTS' in str(e):
                pass
            else:
                raise e
Beispiel #14
0
 def setup_telemetry_rpt(self, ae_ip, port):
     logger.info(
         'Setting up telemetry report on core device [%s] with '
         'AE IP - [%s]', self.device_id, ae_ip)
     ip_addr = ipaddress.ip_address(ae_ip)
     logger.debug('ip_addr object - [%s]', ip_addr)
     action_name = 'TpsCoreEgress.setup_telem_rpt_ipv{}'.format(
         ip_addr.version)
     try:
         self.insert_table_entry(
             telem_rpt_tbl,
             action_name,
             [KeyTuple(telem_rpt_tbl_key, value=int(port))],
             [DataTuple(telem_rpt_data, val=bytearray(ip_addr.packed))])
     except Exception as e:
         if 'ALREADY_EXISTS' in str(e):
             pass
         else:
             raise e
Beispiel #15
0
 def delete_clone_entries(self, mirror_tbl_key=1):
     mirror_cfg_table = self.get_table("$mirror.cfg")
     mirror_cfg_table.entry_del([
         mirror_cfg_table.make_key([KeyTuple('$sid', mirror_tbl_key)])])
Beispiel #16
0
 def del_data_forward(self, dst_mac):
     logger.info(
         'Deleting table entry with key - [%s] from %s',
         dst_mac, data_fwd_tbl)
     self.delete_table_entry(data_fwd_tbl,
                             [KeyTuple(data_fwd_tbl_key, value=dst_mac)])
Beispiel #17
0
 def del_data_inspection(self, dev_id, dev_mac):
     logger.info(
         'Deleting key mac - [%s] from %s',
         dev_id, dev_mac, data_inspection_tbl)
     self.delete_table_entry(data_inspection_tbl,
                             [KeyTuple(data_inspection_tbl_key, dev_mac)])