Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions dump/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os
import sys
import pkgutil
import importlib
from .executor import Executor


dump_modules = {}
pkg_dir = os.path.dirname(__file__)

# import child classes automatically
for (module_loader, name, ispkg) in pkgutil.iter_modules([pkg_dir]):
importlib.import_module('.' + name, __package__)

# Classes inheriting Executor
dump_modules = {cls.__name__.lower(): cls for cls in Executor.__subclasses__()}



15 changes: 15 additions & 0 deletions dump/plugins/executor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

from abc import ABC, abstractmethod

class Executor(ABC):

ARG_NAME = "id" # Arg Identifier
CONFIG_FILE = "" # Path to config file, if any

@abstractmethod
def execute(self):
pass

@abstractmethod
def get_all_args(self):
pass
110 changes: 110 additions & 0 deletions dump/plugins/port.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import os, sys
from .executor import Executor
from dump.redis_match import MatchEngine, MatchRequest
from dump.helper import display_template

class Port(Executor):

ARG_NAME = "port_name"

def __init__(self):
self.match_engine = MatchEngine()

def get_all_args(self):
req = MatchRequest()
req.db = "CONFIG_DB"
req.table = "PORT"
req.key_pattern = "*"
ret = self.match_engine.fetch(req)
all_ports = []
for key in ret["keys"]:
all_ports.append(key.split("|")[-1])
return all_ports


def execute(self, params_dict):
ret_temp = display_template(dbs=["CONFIG_DB", "APPL_DB", "ASIC_DB", "STATE_DB"])
port_name = params_dict[Port.ARG_NAME]
ret_temp = self.get_config_info(port_name, ret_temp)
ret_temp = self.get_appl_info(port_name, ret_temp)
ret_temp, port_asic_obj = self.get_asic_info_hostif(port_name, ret_temp)
ret_temp = self.get_asic_info_port(port_asic_obj, ret_temp)
ret_temp = self.get_state_info(port_name, ret_temp)
return ret_temp

def get_config_info(self, port_name, ret_temp):
req = MatchRequest()
req.db = "CONFIG_DB"
req.table = "PORT"
req.key_pattern = port_name
ret = self.match_engine.fetch(req)
if not ret["error"] and len(ret["keys"]) != 0:
ret_temp[req.db]["keys"] = ret["keys"]
else:
ret_temp[req.db]["tables_not_found"] = [req.table]
return ret_temp

def get_appl_info(self, port_name, ret_temp):
req = MatchRequest()
req.db = "APPL_DB"
req.table = "PORT_TABLE"
req.key_pattern = port_name
ret = self.match_engine.fetch(req)
if not ret["error"] and len(ret["keys"]) != 0:
ret_temp[req.db]["keys"] = ret["keys"]
else:
ret_temp[req.db]["tables_not_found"] = [req.table]
return ret_temp


def get_state_info(self, port_name, ret_temp):
req = MatchRequest()
req.db = "STATE_DB"
req.table = "PORT_TABLE"
req.key_pattern = port_name
ret = self.match_engine.fetch(req)
if not ret["error"] and len(ret["keys"]) != 0:
ret_temp[req.db]["keys"] = ret["keys"]
else:
ret_temp[req.db]["tables_not_found"] = [req.table]
return ret_temp

def get_asic_info_hostif(self, port_name, ret_temp):
req = MatchRequest()
req.db = "ASIC_DB"
req.table = "ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF"
req.key_pattern = "*"
req.field = "SAI_HOSTIF_ATTR_NAME"
req.value = port_name
req.return_fields = ["SAI_HOSTIF_ATTR_OBJ_ID"]
ret = self.match_engine.fetch(req)

asic_port_obj_id = ""

if not ret["error"] and len(ret["keys"]) != 0:
ret_temp[req.db]["keys"] = ret["keys"]
if ret["keys"][-1] in ret["return_values"] and "SAI_HOSTIF_ATTR_OBJ_ID" in ret["return_values"][ret["keys"][-1]]:
asic_port_obj_id = ret["return_values"][ret["keys"][-1]]["SAI_HOSTIF_ATTR_OBJ_ID"]
else:
ret_temp[req.db]["tables_not_found"] = [req.table]
return ret_temp, asic_port_obj_id


def get_asic_info_port(self, asic_port_obj_id, ret_temp):
if not asic_port_obj_id:
ret_temp["ASIC_DB"]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_PORT")
return ret_temp

req = MatchRequest()
req.db = "ASIC_DB"
req.table = "ASIC_STATE:SAI_OBJECT_TYPE_PORT"
req.key_pattern = asic_port_obj_id
ret = self.match_engine.fetch(req)
if not ret["error"] and len(ret["keys"]) != 0:
ret_temp[req.db]["keys"].append(ret["keys"][-1])
else:
ret_temp[req.db]["tables_not_found"].append("ASIC_STATE:SAI_OBJECT_TYPE_PORT")
return ret_temp



103 changes: 103 additions & 0 deletions tests/dump_tests/files/copp_cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"COPP_GROUP": {
"default": {
"queue": "0",
"meter_type":"packets",
"mode":"sr_tcm",
"cir":"600",
"cbs":"600",
"red_action":"drop"
},
"queue4_group1": {
"trap_action":"trap",
"trap_priority":"4",
"queue": "4"
},
"queue4_group2": {
"trap_action":"copy",
"trap_priority":"4",
"queue": "4",
"meter_type":"packets",
"mode":"sr_tcm",
"cir":"600",
"cbs":"600",
"red_action":"drop"
},
"queue4_group3": {
"trap_action":"trap",
"trap_priority":"4",
"queue": "4"
},
"queue1_group1": {
"trap_action":"trap",
"trap_priority":"1",
"queue": "1",
"meter_type":"packets",
"mode":"sr_tcm",
"cir":"6000",
"cbs":"6000",
"red_action":"drop"
},
"queue1_group2": {
"trap_action":"trap",
"trap_priority":"1",
"queue": "1",
"meter_type":"packets",
"mode":"sr_tcm",
"cir":"600",
"cbs":"600",
"red_action":"drop"
},
"queue2_group1": {
"cbs": "1000",
"cir": "1000",
"genetlink_mcgrp_name": "packets",
"genetlink_name": "psample",
"meter_type": "packets",
"mode": "sr_tcm",
"queue": "2",
"red_action": "drop",
"trap_action": "trap",
"trap_priority": "1"

}
},
"COPP_TRAP": {
"bgp": {
"trap_ids": "bgp,bgpv6",
"trap_group": "queue4_group1"
},
"lacp": {
"trap_ids": "lacp",
"trap_group": "queue4_group1"
},
"arp": {
"trap_ids": "arp_req,arp_resp,neigh_discovery",
"trap_group": "queue4_group2"
},
"lldp": {
"trap_ids": "lldp",
"trap_group": "queue4_group3"
},
"dhcp": {
"trap_ids": "dhcp,dhcpv6",
"trap_group": "queue4_group3"
},
"udld": {
"trap_ids": "udld",
"trap_group": "queue4_group3"
},
"ip2me": {
"trap_ids": "ip2me",
"trap_group": "queue1_group1"
},
"nat": {
"trap_ids": "src_nat_miss,dest_nat_miss",
"trap_group": "queue1_group2"
},
"sflow": {
"trap_group": "queue2_group1",
"trap_ids": "sample_packet"
}
}
}
36 changes: 36 additions & 0 deletions tests/dump_tests/files/port/appl_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{

"PORT_TABLE:Ethernet176": {
"index": "0",
"lanes": "0",
"alias": "etp45",
"speed": "25000",
"oper_status": "up",
"pfc_asym": "off",
"mtu": "9100",
"fec": "rs",
"admin_status": "up"
},
"PORT_TABLE:Ethernet160": {
"index": "0",
"lanes": "0",
"alias": "etp41",
"speed": "25000",
"oper_status": "up",
"pfc_asym": "off",
"mtu": "9100",
"fec": "rs",
"admin_status": "up"
},
"PORT_TABLE:Ethernet164": {
"index": "0",
"lanes": "0",
"alias": "etp42",
"speed": "25000",
"oper_status": "up",
"pfc_asym": "off",
"mtu": "9100",
"fec": "rs",
"admin_status": "up"
}
}
30 changes: 30 additions & 0 deletions tests/dump_tests/files/port/asic_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{

"ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd000000000a4d":{
"SAI_HOSTIF_ATTR_TYPE" : "SAI_HOSTIF_TYPE_NETDEV",
"SAI_HOSTIF_ATTR_OBJ_ID": "oid:0x100000000036a",
"SAI_HOSTIF_ATTR_NAME" : "Ethernet176",
"SAI_HOSTIF_ATTR_OPER_STATUS" : "true"
},
"ASIC_STATE:SAI_OBJECT_TYPE_PORT:oid:0x100000000036a": {
"SAI_PORT_ATTR_ADMIN_STATE" : "true",
"SAI_PORT_ATTR_SPEED" : "25000",
"SAI_PORT_ATTR_MTU" : "9122"
},
"ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd000000000a49":{
"SAI_HOSTIF_ATTR_TYPE" : "SAI_HOSTIF_TYPE_NETDEV",
"SAI_HOSTIF_ATTR_OBJ_ID": "oid:0x10000000002e6",
"SAI_HOSTIF_ATTR_NAME" : "Ethernet160",
"SAI_HOSTIF_ATTR_OPER_STATUS" : "true"
},
"ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd000000000a4a":{
"SAI_HOSTIF_ATTR_TYPE" : "SAI_HOSTIF_TYPE_NETDEV",
"SAI_HOSTIF_ATTR_OBJ_ID": "oid:0x1000000000307",
"SAI_HOSTIF_ATTR_OPER_STATUS" : "true"
},
"ASIC_STATE:SAI_OBJECT_TYPE_PORT:oid:0x1000000000307": {
"SAI_PORT_ATTR_ADMIN_STATE" : "true",
"SAI_PORT_ATTR_SPEED" : "25000",
"SAI_PORT_ATTR_MTU" : "9122"
}
}
30 changes: 30 additions & 0 deletions tests/dump_tests/files/port/config_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"PORT|Ethernet176": {
"admin_status" : "up",
"alias": "etp45",
"index": "45",
"lanes": "176",
"speed": "25000"
},
"PORT|Ethernet164": {
"admin_status" : "up",
"alias": "etp42",
"index": "42",
"lanes": "164",
"speed": "25000"
},
"PORT|Ethernet160": {
"admin_status" : "up",
"alias": "etp41",
"index": "41",
"lanes": "160",
"speed": "25000"
},
"PORT|Ethernet156": {
"admin_status" : "up",
"alias": "etp40",
"index": "40",
"lanes": "156",
"speed": "25000"
}
}
14 changes: 14 additions & 0 deletions tests/dump_tests/files/port/state_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"PORT_TABLE|Ethernet176":{
"state" : "ok",
"netdev_oper_status" : "up"
},
"PORT_TABLE|Ethernet160":{
"state" : "ok",
"netdev_oper_status" : "up"
},
"PORT_TABLE|Ethernet164":{
"state" : "ok",
"netdev_oper_status" : "up"
}
}
Empty file.
Loading