Documentation ¶
Index ¶
- Constants
- Variables
- func AddModelCpbltInfo() map[string]*mdlInfo
- func CallRpcMethod(path string, body []byte, dbs [db.MaxDB]*db.DB) ([]byte, error)
- func DbToYangType(yngTerminalNdDtType yang.TypeKind, fldXpath string, dbFldVal string) (interface{}, interface{}, error)
- func DbToYang_napt_mapping_key(objType string, key db.Key) (string, string, string, error)
- func DbValToInt(dbFldVal string, base int, size int, isUint bool) (interface{}, error)
- func GetAndXlateFromDB(uri string, ygRoot *ygot.GoStruct, dbs [db.MaxDB]*db.DB, txCache interface{}) ([]byte, error, bool)
- func GetModuleNmFromPath(uri string) (string, error)
- func GetOrdDBTblList(ygModuleNm string) ([]string, error)
- func GetOrdTblList(xfmrTbl string, uriModuleNm string) []string
- func GetTablesToWatch(xfmrTblList []string, uriModuleNm string) []string
- func GetXfmrOrdTblList(xfmrTbl string) []string
- func ParseIdentity(s string) (ptp_id ptp_id_bin, err error)
- func RemoveXPATHPredicates(s string) (string, error)
- func TraverseDb(dbs [db.MaxDB]*db.DB, spec KeySpec, ...) error
- func XfmrRemoveXPATHPredicates(xpath string) (string, error)
- func XlateFromDb(uri string, ygRoot *ygot.GoStruct, dbs [db.MaxDB]*db.DB, data RedisDbMap, ...) ([]byte, error, bool)
- func XlateFuncBind(name string, fn interface{}) (err error)
- func XlateFuncCall(name string, params ...interface{}) (result []reflect.Value, err error)
- func XlateToDb(path string, opcode int, d *db.DB, yg *ygot.GoStruct, yt *interface{}, ...) (map[int]map[db.DBNum]map[string]map[string]db.Value, error)
- func XlateUriToKeySpec(uri string, requestUri string, ygRoot *ygot.GoStruct, t *interface{}, ...) (*[]KeySpec, error)
- func YangToDb_napt_mapping_key(objType string, extAddress string, extPort string, proto string) (db.Key, error)
- func YangToDb_snmp_group_name_xfmr(inParams XfmrParams) (map[string]string, error)
- type Config
- type CounterData
- type Cpu
- type CpuState
- type E_InterfaceSubType
- type E_InterfaceType
- type E_Ptp_AddressTypeEnumeration
- type E_bgp_nbr_state_get_req_uri_t
- type FieldXfmrDbtoYang
- type FieldXfmrYangToDb
- type HostResult
- type IntfTblData
- type JSONSystem
- type KeySpec
- type KeyXfmrDbToYang
- type KeyXfmrYangToDb
- type NwInstMapKey
- type PathInfo
- type PopulateIntfCounters
- type PostXfmrFunc
- type Proc
- type ProcessState
- type RedisDbMap
- type RpcCallpoint
- type SubTreeXfmrDbToYang
- type SubTreeXfmrYangToDb
- type TableXfmrFunc
- type TblData
- type ValidateCallpoint
- type XfmrInterface
- type XfmrParams
Constants ¶
const ( LAG_TYPE = "lag-type" PORTCHANNEL_TABLE = "PORTCHANNEL" )
const ( MODE_UNSET intfModeType = iota ACCESS TRUNK )
const ( STP_GLOBAL_TABLE = "STP" STP_VLAN_TABLE = "STP_VLAN" STP_VLAN_PORT_TABLE = "STP_VLAN_PORT" STP_PORT_TABLE = "STP_PORT" PVST_MAX_INSTANCES = 255 )
const ( YANG_MODULE = "module" YANG_LIST = "list" YANG_CONTAINER = "container" YANG_LEAF = "leaf" YANG_LEAF_LIST = "leaf-list" YANG_CHOICE = "choice" YANG_CASE = "case" YANG_ANNOT_DB_NAME = "db-name" YANG_ANNOT_TABLE_NAME = "table-name" YANG_ANNOT_FIELD_NAME = "field-name" YANG_ANNOT_KEY_DELIM = "key-delimiter" YANG_ANNOT_TABLE_XFMR = "table-transformer" YANG_ANNOT_FIELD_XFMR = "field-transformer" YANG_ANNOT_KEY_XFMR = "key-transformer" YANG_ANNOT_POST_XFMR = "post-transformer" YANG_ANNOT_SUBTREE_XFMR = "subtree-transformer" YANG_ANNOT_VALIDATE_FUNC = "get-validate" REDIS_DB_TYPE_APPLN = "APPL_DB" REDIS_DB_TYPE_ASIC = "ASIC_DB" REDIS_DB_TYPE_CONFIG = "CONFIG_DB" REDIS_DB_TYPE_COUNTER = "COUNTERS_DB" REDIS_DB_TYPE_LOG_LVL = "LOGLEVEL_DB" REDIS_DB_TYPE_STATE = "STATE_DB" REDIS_DB_TYPE_FLX_COUNTER = "FLEX_COUNTER_DB" XPATH_SEP_FWD_SLASH = "/" XFMR_EMPTY_STRING = "" XFMR_NONE_STRING = "NONE" SONIC_TABLE_INDEX = 2 SONIC_FIELD_INDEX = 4 SONIC_MDL_PFX = "sonic" OC_MDL_PFX = "openconfig-" IETF_MDL_PFX = "ietf-" IANA_MDL_PFX = "iana-" YTDB_KEY_XFMR_RET_ARGS = 2 YTDB_KEY_XFMR_RET_VAL_INDX = 0 YTDB_KEY_XFMR_RET_ERR_INDX = 1 YTDB_SBT_XFMR_RET_ARGS = 2 YTDB_SBT_XFMR_RET_VAL_INDX = 0 YTDB_SBT_XFMR_RET_ERR_INDX = 1 YTDB_FLD_XFMR_RET_ARGS = 2 YTDB_FLD_XFMR_RET_VAL_INDX = 0 YTDB_FLD_XFMR_RET_ERR_INDX = 1 TBL_XFMR_RET_ARGS = 2 TBL_XFMR_RET_VAL_INDX = 0 TBL_XFMR_RET_ERR_INDX = 1 POST_XFMR_RET_ARGS = 2 POST_XFMR_RET_VAL_INDX = 0 POST_XFMR_RET_ERR_INDX = 1 )
const ( ACL_TABLE = "ACL_TABLE" RULE_TABLE = "ACL_RULE" DEFAULT_RULE = "DEFAULT_RULE" SONIC_ACL_TYPE_IPV4 = "L3" SONIC_ACL_TYPE_L2 = "L2" SONIC_ACL_TYPE_IPV6 = "L3V6" OPENCONFIG_ACL_TYPE_IPV4 = "ACL_IPV4" OPENCONFIG_ACL_TYPE_IPV6 = "ACL_IPV6" OPENCONFIG_ACL_TYPE_L2 = "ACL_L2" ACL_TYPE = "type" ACTION_DROP = "DROP" IP_TYPE_ANY = "ANY" MIN_PRIORITY = 1 MAX_PRIORITY = 65535 )
const ( FDB_TABLE = "FDB_TABLE" SONIC_ENTRY_TYPE_STATIC = "SAI_FDB_ENTRY_TYPE_STATIC" SONIC_ENTRY_TYPE_DYNAMIC = "SAI_FDB_ENTRY_TYPE_DYNAMIC" ENTRY_TYPE = "entry-type" )
const ( CFG_L2MC_TABLE = "CFG_L2MC_TABLE" CFG_L2MC_MROUTER_TABLE = "CFG_L2MC_MROUTER_TABLE" CFG_L2MC_STATIC_GROUP_TABLE = "CFG_L2MC_STATIC_GROUP_TABLE" CFG_L2MC_STATIC_MEMBER_TABLE = "CFG_L2MC_STATIC_MEMBER_TABLE" APP_L2MC_MROUTER_TABLE = "APP_L2MC_MROUTER_TABLE" APP_L2MC_MEMBER_TABLE = "APP_L2MC_MEMBER_TABLE" )
const ( PORT_INDEX = "index" PORT_MTU = "mtu" PORT_ADMIN_STATUS = "admin_status" PORT_SPEED = "speed" PORT_DESC = "description" PORT_OPER_STATUS = "oper_status" PORT_AUTONEG = "autoneg" VLAN_TN = "VLAN" VLAN_MEMBER_TN = "VLAN_MEMBER" VLAN_INTERFACE_TN = "VLAN_INTERFACE" PORTCHANNEL_TN = "PORTCHANNEL" PORTCHANNEL_INTERFACE_TN = "PORTCHANNEL_INTERFACE" PORTCHANNEL_MEMBER_TN = "PORTCHANNEL_MEMBER" LOOPBACK_INTERFACE_TN = "LOOPBACK_INTERFACE" UNNUMBERED = "unnumbered" )
const ( PIPE = "|" COLON = ":" ETHERNET = "Ethernet" MGMT = "eth" VLAN = "Vlan" PORTCHANNEL = "PortChannel" LOOPBACK = "Loopback" VXLAN = "vtep" )
const ( ADMIN_MODE = "admin_mode" NAT_GLOBAL_TN = "NAT_GLOBAL" ENABLED = "enabled" DISABLED = "disabled" ENABLE = "enable" INSTANCE_ID = "id" GLOBAL_KEY = "Values" NAT_TABLE = "NAT_TABLE" NAPT_TABLE = "NAPT_TABLE" STATIC_NAT = "STATIC_NAT" STATIC_NAPT = "STATIC_NAPT" NAT_TYPE = "nat_type" NAT_ENTRY_TYPE = "entry_type" STATIC = "static" DYNAMIC = "dynamic" SNAT = "snat" DNAT = "dnat" NAT_BINDINGS = "NAT_BINDINGS" NAPT_TWICE_TABLE = "NAPT_TWICE_TABLE" NAT_TWICE_TABLE = "NAT_TWICE_TABLE" )
const ( NEIGH_IPv4_PREFIX = "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/openconfig-if-ip:ipv4/neighbors" NEIGH_IPv4_PREFIX_IP = NEIGH_IPv4_PREFIX + "/neighbor" NEIGH_IPv4_PREFIX_STATE_IP = NEIGH_IPv4_PREFIX_IP + "/state/ip" NEIGH_IPv4_PREFIX_STATE_LL = NEIGH_IPv4_PREFIX_IP + "/state/link-layer-address" NEIGH_IPv6_PREFIX = "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/openconfig-if-ip:ipv6/neighbors" NEIGH_IPv6_PREFIX_IP = NEIGH_IPv6_PREFIX + "/neighbor" NEIGH_IPv6_PREFIX_STATE_IP = NEIGH_IPv6_PREFIX_IP + "/state/ip" NEIGH_IPv6_PREFIX_STATE_LL = NEIGH_IPv6_PREFIX_IP + "/state/link-layer-address" )
const ( SONIC_PREFIX_SET_MODE_IPV4 = "IPv4" SONIC_PREFIX_SET_MODE_IPV6 = "IPv6" SONIC_MATCH_SET_ACTION_ANY = "ANY" SONIC_MATCH_SET_ACTION_ALL = "ALL" )
const ( ZTP_STATUS_ADMIN_MODE = "admin_mode" ZTP_STATUS_SERVICE = "service" ZTP_STATUS_STATUS = "status" ZTP_STATUS_SOURCE = "source" ZTP_STATUS_RUNTIME = "runtime" ZTP_STATUS_TIMESTAMP = "timestamp" ZTP_STATUS_JSON_VERSION = "json_version" ZTP_STATUS_ACTIVITY_STRING = "activity_string" ZTP_CONFIG_SECTION_LIST = "config_section_list" ZTP_CONFIG_SECTION_STATUS = "cfg_status" ZTP_CONFIG_SECTION_NAME = "cfg_sectionname" ZTP_CONFIG_SECTION_RUNTIME = "cfg_runtime" ZTP_CONFIG_SECTION_TIMESTAMP = "cfg_timestamp" ZTP_CONFIG_SECTION_EXITCODE = "cfg_exitcode" ZTP_CONFIG_SECTION_IGNORE_RESULT = "cfg_ignoreresult" ZTP_CONFIG_SECTION_DESCRIPTION = "cfg_description" ZTP_CONFIG_SECTION_HALT_ON_FAILURE = "cfg_haltonfailure" ZTP_STATUS_ERROR = "error" )
App specific constants
const ( GET = 1 + iota CREATE REPLACE UPDATE DELETE MAXOPER )
const (
DEFAULT_NETWORK_INSTANCE_CONFIG_TYPE = "L3VRF"
)
const (
MGMT_VRF_ENABLE = "mgmtVrfEnabled"
)
const (
MGMT_VRF_NAME = "mgmt-vrf-name"
)
Variables ¶
var ACL_FORWARDING_ACTION_MAP = map[string]string{ strconv.FormatInt(int64(ocbinds.OpenconfigAcl_FORWARDING_ACTION_ACCEPT), 10): "FORWARD", strconv.FormatInt(int64(ocbinds.OpenconfigAcl_FORWARDING_ACTION_DROP), 10): "DROP", strconv.FormatInt(int64(ocbinds.OpenconfigAcl_FORWARDING_ACTION_REJECT), 10): "REDIRECT", }
E_OpenconfigAcl_FORWARDING_ACTION
var ACL_TYPE_MAP = map[string]string{ strconv.FormatInt(int64(ocbinds.OpenconfigAcl_ACL_TYPE_ACL_IPV4), 10): SONIC_ACL_TYPE_IPV4, strconv.FormatInt(int64(ocbinds.OpenconfigAcl_ACL_TYPE_ACL_IPV6), 10): SONIC_ACL_TYPE_IPV6, strconv.FormatInt(int64(ocbinds.OpenconfigAcl_ACL_TYPE_ACL_L2), 10): SONIC_ACL_TYPE_L2, }
E_OpenconfigAcl_ACL_TYPE
var APP_L2MC_MEMBER_TABLE_TS *db.TableSpec = &db.TableSpec{Name: APP_L2MC_MEMBER_TABLE}
var APP_L2MC_MROUTER_TABLE_TS *db.TableSpec = &db.TableSpec{Name: APP_L2MC_MROUTER_TABLE}
app db tables
var CFG_L2MC_MROUTER_TABLE_TS *db.TableSpec = &db.TableSpec{Name: CFG_L2MC_MROUTER_TABLE}
var CFG_L2MC_STATIC_GROUP_TABLE_TS *db.TableSpec = &db.TableSpec{Name: CFG_L2MC_STATIC_GROUP_TABLE}
var CFG_L2MC_STATIC_MEMBER_TABLE_TS *db.TableSpec = &db.TableSpec{Name: CFG_L2MC_STATIC_MEMBER_TABLE}
var CFG_L2MC_TABLE_TS *db.TableSpec = &db.TableSpec{Name: CFG_L2MC_TABLE}
config db tables
var DbToYang_snmp_member_key_xfmr = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) log.Info("DbToYang_snmp_member_key_xfmr uri: ", inParams.uri) log.Info("DbToYang_snmp_member_key_xfmr key: ", inParams.key) keys := strings.Split(inParams.key, "|") secName := keys[1] rmap["security-name"] = secName log.Info("DbToYang_snmp_member_key_xfmr Key Returned: ", rmap) return rmap, nil }
var ETHERTYPE_MAP = map[ocbinds.E_OpenconfigPacketMatchTypes_ETHERTYPE]uint32{ ocbinds.OpenconfigPacketMatchTypes_ETHERTYPE_ETHERTYPE_LLDP: 0x88CC, ocbinds.OpenconfigPacketMatchTypes_ETHERTYPE_ETHERTYPE_VLAN: 0x8100, ocbinds.OpenconfigPacketMatchTypes_ETHERTYPE_ETHERTYPE_ROCE: 0x8915, ocbinds.OpenconfigPacketMatchTypes_ETHERTYPE_ETHERTYPE_ARP: 0x0806, ocbinds.OpenconfigPacketMatchTypes_ETHERTYPE_ETHERTYPE_IPV4: 0x0800, ocbinds.OpenconfigPacketMatchTypes_ETHERTYPE_ETHERTYPE_IPV6: 0x86DD, ocbinds.OpenconfigPacketMatchTypes_ETHERTYPE_ETHERTYPE_MPLS: 0x8847, }
var (
ErrParamsNotAdapted = errors.New("The number of params is not adapted.")
)
var FDB_ENTRY_TYPE_MAP = map[string]string{ strconv.FormatInt(int64(ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Fdb_MacTable_Entries_Entry_State_EntryType_STATIC), 10): SONIC_ENTRY_TYPE_STATIC, strconv.FormatInt(int64(ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Fdb_MacTable_Entries_Entry_State_EntryType_DYNAMIC), 10): SONIC_ENTRY_TYPE_DYNAMIC, }
E_OpenconfigNetworkInstance_ENTRY_TYPE
var IP_PROTOCOL_MAP = map[string]string{ strconv.FormatInt(int64(ocbinds.OpenconfigPacketMatchTypes_IP_PROTOCOL_IP_ICMP), 10): "1", strconv.FormatInt(int64(ocbinds.OpenconfigPacketMatchTypes_IP_PROTOCOL_IP_IGMP), 10): "2", strconv.FormatInt(int64(ocbinds.OpenconfigPacketMatchTypes_IP_PROTOCOL_IP_TCP), 10): "6", strconv.FormatInt(int64(ocbinds.OpenconfigPacketMatchTypes_IP_PROTOCOL_IP_UDP), 10): "17", strconv.FormatInt(int64(ocbinds.OpenconfigPacketMatchTypes_IP_PROTOCOL_IP_RSVP), 10): "46", strconv.FormatInt(int64(ocbinds.OpenconfigPacketMatchTypes_IP_PROTOCOL_IP_GRE), 10): "47", strconv.FormatInt(int64(ocbinds.OpenconfigPacketMatchTypes_IP_PROTOCOL_IP_AUTH), 10): "51", strconv.FormatInt(int64(ocbinds.OpenconfigPacketMatchTypes_IP_PROTOCOL_IP_PIM), 10): "103", strconv.FormatInt(int64(ocbinds.OpenconfigPacketMatchTypes_IP_PROTOCOL_IP_L2TP), 10): "115", }
E_OpenconfigPacketMatchTypes_IP_PROTOCOL
var IntfTypeTblMap = map[E_InterfaceType]IntfTblData{ IntfTypeEthernet: IntfTblData{ CountersHdl: CounterData{OIDTN: "COUNTERS_PORT_NAME_MAP", CountersTN: "COUNTERS", PopulateCounters: populatePortCounters}, // contains filtered or unexported fields }, IntfTypeMgmt: IntfTblData{ CountersHdl: CounterData{OIDTN: "", CountersTN: "", PopulateCounters: populateMGMTPortCounters}, // contains filtered or unexported fields }, IntfTypePortChannel: IntfTblData{ CountersHdl: CounterData{OIDTN: "COUNTERS_PORT_NAME_MAP", CountersTN: "COUNTERS", PopulateCounters: populatePortCounters}, // contains filtered or unexported fields }, IntfTypeVlan: IntfTblData{ // contains filtered or unexported fields }, IntfTypeLoopback: IntfTblData{ // contains filtered or unexported fields }, }
var L2MC_TABLE_DEFAULT_FIELDS_MAP = map[string]string{
"enabled": "true",
"version": "2",
"query-interval": "125",
"last-member-query-interval": "1000",
"query-max-response-time": "10",
}
var LAG_TYPE_MAP = map[string]string{ strconv.FormatInt(int64(ocbinds.OpenconfigIfAggregate_AggregationType_LACP), 10): "false", strconv.FormatInt(int64(ocbinds.OpenconfigIfAggregate_AggregationType_STATIC), 10): "true", }
var MATCH_SET_ACTION_MAP = map[string]string{ strconv.FormatInt(int64(ocbinds.OpenconfigRoutingPolicy_MatchSetOptionsType_ALL), 10): SONIC_MATCH_SET_ACTION_ALL, strconv.FormatInt(int64(ocbinds.OpenconfigRoutingPolicy_MatchSetOptionsType_ANY), 10): SONIC_MATCH_SET_ACTION_ANY, }
ocbinds.E_OpenconfigRoutingPolicy_MatchSetOptionsType
var ModelsListFile = "models_list"
var NAT_ENTRY_TYPE_MAP = map[string]string{ strconv.FormatInt(int64(ocbinds.OpenconfigNat_NAT_ENTRY_TYPE_STATIC), 10): "static", strconv.FormatInt(int64(ocbinds.OpenconfigNat_NAT_ENTRY_TYPE_DYNAMIC), 10): "dynamic", }
var NAT_TYPE_MAP = map[string]string{ strconv.FormatInt(int64(ocbinds.OpenconfigNat_NAT_TYPE_SNAT), 10): "snat", strconv.FormatInt(int64(ocbinds.OpenconfigNat_NAT_TYPE_DNAT), 10): "dnat", }
var NwInstTblNameMapWithName = map[string]string{
"mgmt": "MGMT_VRF_CONFIG",
"Vrf": "VRF",
"default": "VRF",
"Vlan": "VLAN",
}
Top level network instance table name based on key name
var NwInstTblNameMapWithNameAndType = map[NwInstMapKey]string{
{NwInstName: "mgmt", NwInstType: "L3VRF"}: "MGMT_VRF_CONFIG",
{NwInstName: "Vrf", NwInstType: "L3VRF"}: "VRF",
{NwInstName: "default", NwInstType: "L3VRF"}: "VRF",
{NwInstName: "default", NwInstType: "DEFAULT_INSTANCE"}: "VRF",
{NwInstName: "Vlan", NwInstType: "L2L3"}: "VLAN",
}
Top level network instance table name based on key name and type
var PREFIX_SET_MODE_MAP = map[string]string{ strconv.FormatInt(int64(ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_PrefixSets_PrefixSet_Config_Mode_IPV4), 10): SONIC_PREFIX_SET_MODE_IPV4, strconv.FormatInt(int64(ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_PrefixSets_PrefixSet_Config_Mode_IPV6), 10): SONIC_PREFIX_SET_MODE_IPV6, }
E_OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_PrefixSets_PrefixSet_Config_Mode
var PTP_DELAY_MECH_MAP = map[string]string{ strconv.FormatInt(int64(ocbinds.IETFPtp_DelayMechanismEnumeration_e2e), 10): "E2E", strconv.FormatInt(int64(ocbinds.IETFPtp_DelayMechanismEnumeration_p2p), 10): "P2P", strconv.FormatInt(int64(ocbinds.IETFPtp_DelayMechanismEnumeration_UNSET), 10): "Auto", }
E_IETFPtp_DelayMechanismEnumeration
var TblInfoJsonFile = "sonic_table_info.json"
var XlateFuncs = make(map[string]reflect.Value)
var YangPath = "/usr/models/yang/" // OpenConfig-*.yang and sonic yang models path
var YangToDb_snmp_engine_key_xfmr = func(inParams XfmrParams) (string, error) { log.Info("YangToDb_snmp_engine_key_xfmr uri: ", inParams.uri) return "GLOBAL", nil }
var YangToDb_snmp_member_key_xfmr = func(inParams XfmrParams) (string, error) { var entry_key string log.Info("YangToDb_snmp_member_key_xfmr uri: ", inParams.uri) log.Info("YangToDb_snmp_member_key_xfmr key: ", inParams.key) pathInfo := NewPathInfo(inParams.uri) gName := pathInfo.Var("name") sName := pathInfo.Var("security-name") if len(sName) == 0 { entry_key = gName } else { entry_key = gName + "|" + sName } log.Info("YangToDb_snmp_member_key_xfmr Key Returned: ", entry_key) return entry_key, nil }
var YangToDb_udld_global_key_xfmr = func(inParams XfmrParams) (string, error) { log.Info("YangToDb_udld_global_key_xfmr: ", inParams.ygRoot, inParams.uri) return "GLOBAL", nil }
Functions ¶
func AddModelCpbltInfo ¶
func AddModelCpbltInfo() map[string]*mdlInfo
func CallRpcMethod ¶
func DbToYangType ¶
func DbValToInt ¶
func GetAndXlateFromDB ¶
func GetModuleNmFromPath ¶
func GetOrdDBTblList ¶
func GetOrdTblList ¶
func GetTablesToWatch ¶
func GetXfmrOrdTblList ¶
Table hierarchy read from json file
func ParseIdentity ¶
ParseIdentity parses an s with the following format 010203.0405.060708
func RemoveXPATHPredicates ¶
func TraverseDb ¶
func XlateFromDb ¶
func XlateFuncBind ¶
func XlateFuncCall ¶
func XlateUriToKeySpec ¶
func YangToDb_snmp_group_name_xfmr ¶
func YangToDb_snmp_group_name_xfmr(inParams XfmrParams) (map[string]string, error)
Types ¶
type CounterData ¶
type CounterData struct { OIDTN string CountersTN string PopulateCounters PopulateIntfCounters }
type E_InterfaceSubType ¶
type E_InterfaceSubType int64
const ( IntfSubTypeUnset E_InterfaceSubType = 0 IntfSubTypeVlanL2 E_InterfaceSubType = 1 InterfaceSubTypeVlanL3 E_InterfaceSubType = 2 )
type E_InterfaceType ¶
type E_InterfaceType int64
const ( IntfTypeUnset E_InterfaceType = 0 IntfTypeEthernet E_InterfaceType = 1 IntfTypeMgmt E_InterfaceType = 2 IntfTypeVlan E_InterfaceType = 3 IntfTypePortChannel E_InterfaceType = 4 IntfTypeLoopback E_InterfaceType = 5 IntfTypeVxlan E_InterfaceType = 6 )
type E_Ptp_AddressTypeEnumeration ¶
type E_Ptp_AddressTypeEnumeration int64
const ( PTP_ADDRESSTYPE_UNKNOWN E_Ptp_AddressTypeEnumeration = 0 PTP_ADDRESSTYPE_IP_IPV4 E_Ptp_AddressTypeEnumeration = 2 PTP_ADDRESSTYPE_IP_IPV6 E_Ptp_AddressTypeEnumeration = 3 PTP_ADDRESSTYPE_IP_MAC E_Ptp_AddressTypeEnumeration = 4 )
type E_bgp_nbr_state_get_req_uri_t ¶
type E_bgp_nbr_state_get_req_uri_t string
const ( E_bgp_nbr_state_get_req_uri_nbr_state E_bgp_nbr_state_get_req_uri_t = "GET_REQ_URI_BGP_NBR_STATE" E_bgp_nbr_state_get_req_uri_nbr_timers_state E_bgp_nbr_state_get_req_uri_t = "GET_REQ_URI_BGP_NBR_TIMERS_STATE" E_bgp_nbr_state_get_req_uri_nbr_transport_state E_bgp_nbr_state_get_req_uri_t = "GET_REQ_URI_BGP_NBR_TRANSPORT_STATE" )
type FieldXfmrDbtoYang ¶
type FieldXfmrDbtoYang func(inParams XfmrParams) (map[string]interface{}, error)
*
- FieldXfmrDbtoYang type is defined to use for conversion of DB field to Yang field
- Transformer function definition.
- Param: XfmrParams structure having Database info, operation, DB data in multidimensional map, output param YgotRoot
- Return: error *
var DbToYang_acl_destination_port_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_acl_destination_port_xfmr: ", data, inParams.ygRoot) if _, ok := data[RULE_TABLE]; !ok { err = errors.New("RULE_TABLE entry not found in the input param") return result, err } ruleTbl := data[RULE_TABLE] ruleInst := ruleTbl[inParams.key] port, ok := ruleInst.Field["L4_DST_PORT"] if ok { result["destination-port"] = port return result, nil } portRange, ok := ruleInst.Field["L4_DST_PORT_RANGE"] if ok { result["destination-port"] = portRange return result, nil } else { err = errors.New("DST PORT/PORT_RANGE field not found in DB") } return result, err }
var DbToYang_acl_entry_sequenceid_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_acl_entry_sequenceid_xfmr: ", inParams.key) res, err := DbToYang_acl_entry_key_xfmr(inParams) log.Info("acl-entry/config/sequence-id ", res) if err != nil { return res_map, err } if seqId, ok := res["sequence-id"]; !ok { log.Error("sequence-id not found in acl entry") return res_map, err } else { res_map["sequence-id"] = seqId } return res_map, err }
var DbToYang_acl_forwarding_action_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_acl_forwarding_action_xfmr", data, inParams.ygRoot) oc_action := findInMap(ACL_FORWARDING_ACTION_MAP, data[RULE_TABLE][inParams.key].Field["PACKET_ACTION"]) n, err := strconv.ParseInt(oc_action, 10, 64) result["forwarding-action"] = ocbinds.E_OpenconfigAcl_FORWARDING_ACTION(n).ΛMap()["E_OpenconfigAcl_FORWARDING_ACTION"][n].Name return result, err }
var DbToYang_acl_ip_protocol_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_acl_ip_protocol_xfmr", data, inParams.ygRoot) oc_protocol := findByValue(IP_PROTOCOL_MAP, data[RULE_TABLE][inParams.key].Field["IP_PROTOCOL"]) n, err := strconv.ParseInt(oc_protocol, 10, 64) result["protocol"] = ocbinds.E_OpenconfigPacketMatchTypes_IP_PROTOCOL(n).ΛMap()["E_OpenconfigPacketMatchTypes_IP_PROTOCOL"][n].Name return result, err }
var DbToYang_acl_l2_ethertype_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_acl_l2_ethertype_xfmr", data, inParams.ygRoot) if _, ok := data[RULE_TABLE]; !ok { err = errors.New("RULE_TABLE entry not found in the input param") return result, err } ruleTbl := data[RULE_TABLE] ruleInst := ruleTbl[inParams.key] etype, ok := ruleInst.Field["ETHER_TYPE"] if ok { etypeVal, _ := strconv.ParseUint(strings.Replace(etype, "0x", "", -1), 16, 32) result["protocol"] = getL2EtherType(etypeVal) } else { err = errors.New("ETHER_TYPE field not found in DB") } return result, nil }
var DbToYang_acl_set_name_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_acl_set_name_xfmr: ", inParams.key) aclName, _ := getOCAclKeysFromStrDBKey(inParams.key) res_map["name"] = aclName log.Info("acl-set/config/name ", res_map) return res_map, err }
var DbToYang_acl_source_port_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_acl_source_port_xfmr: ", data, inParams.ygRoot) result := make(map[string]interface{}) if _, ok := data[RULE_TABLE]; !ok { err = errors.New("RULE_TABLE entry not found in the input param") return result, err } ruleTbl := data[RULE_TABLE] ruleInst := ruleTbl[inParams.key] port, ok := ruleInst.Field["L4_SRC_PORT"] if ok { result["source-port"] = port return result, nil } portRange, ok := ruleInst.Field["L4_SRC_PORT_RANGE"] if ok { result["source-port"] = portRange return result, nil } else { err = errors.New("PORT/PORT_RANGE field not found in DB") } return result, err }
var DbToYang_acl_tcp_flags_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_acl_tcp_flags_xfmr: ", data, inParams.ygRoot) result := make(map[string]interface{}) if _, ok := data[RULE_TABLE]; !ok { err = errors.New("RULE_TABLE entry not found in the input param") return result, err } ruleTbl := data[RULE_TABLE] ruleInst := ruleTbl[inParams.key] tcpFlag, ok := ruleInst.Field["TCP_FLAGS"] if ok { result["tcp-flags"] = getTransportConfigTcpFlags(tcpFlag) return result, nil } return result, nil }
var DbToYang_acl_type_field_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_acl_type_field_xfmr", data, inParams.ygRoot) oc_acltype := findInMap(ACL_TYPE_MAP, data[ACL_TABLE][inParams.key].Field[ACL_TYPE]) n, err := strconv.ParseInt(oc_acltype, 10, 64) result[ACL_TYPE] = ocbinds.E_OpenconfigAcl_ACL_TYPE(n).ΛMap()["E_OpenconfigAcl_ACL_TYPE"][n].Name return result, err }
var DbToYang_as_path_set_name_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error key := inParams.key log.Info("DbToYang_as_path_set_name_fld_xfmr: ", key) setTblKey := strings.Split(key, "|") setName := setTblKey[0] res_map["as-path-set-name"] = setName log.Info("config/name ", res_map) return res_map, err }
var DbToYang_bgp_advertise_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) var afi_list []string log.Info(inParams.key) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_bgp_advertise_fld_xfmr : ", data, "inParams : ", inParams) pTbl := data["BGP_GLOBALS_AF"] log.Info("Table: ", pTbl) if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_bgp_advertise_fld_xfmr BGP AF not found : ", inParams.key) return result, errors.New("BGP AF not found : " + inParams.key) } GblAfData := pTbl[inParams.key] adv_ipv4_uni, ok := GblAfData.Field["advertise-ipv4-unicast"] if ok { if adv_ipv4_uni == "true" { afi_list = append(afi_list, "IPV4_UNICAST") } } else { log.Info("advertise-ipv4-unicast field not found in DB") } adv_ipv6_uni, ok := GblAfData.Field["advertise-ipv6-unicast"] if ok { if adv_ipv6_uni == "true" { afi_list = append(afi_list, "IPV6_UNICAST") } } else { log.Info("advertise-ipv6-unicast field not found in DB") } result["advertise-list"] = afi_list return result, err }
var DbToYang_bgp_dyn_neigh_listen_field_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error entry_key := inParams.key log.Info("DbToYang_bgp_dyn_neigh_listen_key_xfmr: ", entry_key) dynKey := strings.Split(entry_key, "|") rmap["prefix"] = dynKey[1] return rmap, err }
var DbToYang_bgp_gbl_afi_safi_addr_field_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error entry_key := inParams.key log.Info("DbToYang_bgp_gbl_afi_safi_addr_field_xfmr: ", entry_key) dynKey := strings.Split(entry_key, "|") rmap["prefix"] = dynKey[2] return rmap, err }
var DbToYang_bgp_gbl_afi_safi_field_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error entry_key := inParams.key log.Info("DbToYang_bgp_gbl_afi_safi_field_xfmr: ", entry_key) mpathKey := strings.Split(entry_key, "|") afi := "" switch mpathKey[1] { case "ipv4_unicast": afi = "IPV4_UNICAST" case "ipv6_unicast": afi = "IPV6_UNICAST" case "l2vpn_evpn": afi = "L2VPN_EVPN" default: return rmap, nil } rmap["afi-safi-name"] = afi return rmap, err }
var DbToYang_bgp_local_asn_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_bgp_local_asn_fld_xfmr: ") pTbl := data["BGP_GLOBALS"] if _, ok := pTbl[inParams.key]; !ok { return result, err } pGblKey := pTbl[inParams.key] curr_asn, ok := pGblKey.Field["local_asn"] if ok { local_asn64, _ := strconv.ParseUint(curr_asn, 10, 32) local_asn := uint32(local_asn64) result["as"] = local_asn } else { log.Info("Local ASN field not found in DB") } return result, err }
var DbToYang_bgp_nbr_address_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) entry_key := inParams.key nbrAddrKey := strings.Split(entry_key, "|") nbrAddr := nbrAddrKey[1] result["neighbor-address"] = nbrAddr return result, err }
var DbToYang_bgp_nbr_afi_safi_name_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error var nbrAfName string result := make(map[string]interface{}) entry_key := inParams.key nbrAfKey := strings.Split(entry_key, "|") switch nbrAfKey[2] { case "ipv4_unicast": nbrAfName = "IPV4_UNICAST" case "ipv6_unicast": nbrAfName = "IPV6_UNICAST" case "l2vpn_evpn": nbrAfName = "L2VPN_EVPN" default: return result, nil } result["afi-safi-name"] = nbrAfName return result, err }
var DbToYang_bgp_nbr_community_type_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_bgp_nbr_community_type_fld_xfmr : ", data, "inParams : ", inParams) pTbl := data["BGP_NEIGHBOR_AF"] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_bgp_nbr_community_type_fld_xfmr BGP Peer group not found : ", inParams.key) return result, errors.New("BGP neighbor not found : " + inParams.key) } pGrpKey := pTbl[inParams.key] community_type, ok := pGrpKey.Field["send_community"] if ok { if community_type == "standard" { result["send-community"] = "STANDARD" } else if community_type == "extended" { result["send-community"] = "EXTENDED" } else if community_type == "both" { result["send-community"] = "BOTH" } else if community_type == "none" { result["send-community"] = "NONE" } } else { log.Info("send_community not found in DB") } return result, err }
var DbToYang_bgp_nbr_orf_type_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_bgp_nbr_orf_type_fld_xfmr : ", data, "inParams : ", inParams) pTbl := data["BGP_NEIGHBOR_AF"] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_bgp_nbr_orf_type_fld_xfmr BGP neighbor not found : ", inParams.key) return result, errors.New("BGP neighbor not found : " + inParams.key) } pNbrKey := pTbl[inParams.key] orf_type, ok := pNbrKey.Field["cap_orf"] if ok { if orf_type == "send" { result["orf-type"] = "SEND" } else if orf_type == "receive" { result["orf-type"] = "RECEIVE" } else if orf_type == "both" { result["orf-type"] = "BOTH" } } else { log.Info("cap_orf_direction field not found in DB") } return result, err }
var DbToYang_bgp_nbr_peer_type_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_bgp_nbr_peer_type_fld_xfmr : ", data, "inParams : ", inParams) pTbl := data["BGP_NEIGHBOR"] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_bgp_nbr_peer_type_fld_xfmr BGP neighbor not found : ", inParams.key) return result, errors.New("BGP neighbor not found : " + inParams.key) } pGrpKey := pTbl[inParams.key] peer_type, ok := pGrpKey.Field["peer_type"] if ok { if peer_type == "internal" { result["peer-type"] = "INTERNAL" } else if peer_type == "external" { result["peer-type"] = "EXTERNAL" } } else { log.Info("peer_type field not found in DB") } return result, nil }
var DbToYang_bgp_nbr_tx_add_paths_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_bgp_nbr_tx_add_paths_fld_xfmr: ", data, "inParams : ", inParams) pTbl := data["BGP_NEIGHBOR_AF"] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_bgp_nbr_tx_add_paths_fld_xfmr BGP neighbor not found : ", inParams.key) return result, errors.New("BGP neighbor not found : " + inParams.key) } pNbrKey := pTbl[inParams.key] tx_add_paths_type, ok := pNbrKey.Field["tx_add_paths"] if ok { if tx_add_paths_type == "tx_all_paths" { result["tx-add-paths"] = "TX_ALL_PATHS" } else if tx_add_paths_type == "tx_best_path_per_as" { result["tx-add-paths"] = "TX_BEST_PATH_PER_AS" } } else { log.Info("Tx add Paths field not found in DB") } return result, err }
var DbToYang_bgp_pgrp_afi_safi_name_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) entry_key := inParams.key pgrpAfKey := strings.Split(entry_key, "|") pgrpAfName := "" switch pgrpAfKey[2] { case "ipv4_unicast": pgrpAfName = "IPV4_UNICAST" case "ipv6_unicast": pgrpAfName = "IPV6_UNICAST" case "l2vpn_evpn": pgrpAfName = "L2VPN_EVPN" } result["afi-safi-name"] = pgrpAfName return result, err }
var DbToYang_bgp_pgrp_community_type_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_bgp_pgrp_community_type_fld_xfmr : ", data, "inParams : ", inParams) pTbl := data["BGP_PEER_GROUP_AF"] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_bgp_pgrp_community_type_fld_xfmr BGP Peer group not found : ", inParams.key) return result, errors.New("BGP peer group not found : " + inParams.key) } pGrpKey := pTbl[inParams.key] community_type, ok := pGrpKey.Field["send_community"] if ok { if community_type == "standard" { result["send-community"] = "STANDARD" } else if community_type == "extended" { result["send-community"] = "EXTENDED" } else if community_type == "both" { result["send-community"] = "BOTH" } else if community_type == "none" { result["send-community"] = "NONE" } else if community_type == "large" { result["send-community"] = "LARGE" } else if community_type == "all" { result["send-community"] = "ALL" } } else { log.Info("send_community not found in DB") } return result, err }
var DbToYang_bgp_pgrp_name_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_bgp_pgrp_name_fld_xfmr : ", data, "inParams : ", inParams) entry_key := inParams.key peer_group_Key := strings.Split(entry_key, "|") peer_group_name := peer_group_Key[1] result["peer-group-name"] = peer_group_name return result, err }
var DbToYang_bgp_pgrp_orf_type_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_bgp_pgrp_orf_type_fld_xfmr : ", data, "inParams : ", inParams) pTbl := data["BGP_PEER_GROUP_AF"] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_bgp_pgrp_orf_type_fld_xfmr BGP PEER GROUP AF not found : ", inParams.key) return result, errors.New("BGP PEER GROUP AF not found : " + inParams.key) } pGrpKey := pTbl[inParams.key] orf_type, ok := pGrpKey.Field["cap_orf"] if ok { if orf_type == "send" { result["orf-type"] = "SEND" } else if orf_type == "receive" { result["orf-type"] = "RECEIVE" } else if orf_type == "both" { result["orf-type"] = "BOTH" } } else { log.Info("cap_orf_direction field not found in DB") } return result, err }
var DbToYang_bgp_pgrp_peer_type_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_bgp_pgrp_peer_type_fld_xfmr : ", data, "inParams : ", inParams) pTbl := data["BGP_PEER_GROUP"] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_bgp_pgrp_peer_type_fld_xfmr BGP peer-groups not found : ", inParams.key) return result, errors.New("BGP peer-groups not found : " + inParams.key) } pGrpKey := pTbl[inParams.key] peer_type, ok := pGrpKey.Field["peer_type"] if ok { if peer_type == "internal" { result["peer-type"] = "INTERNAL" } else if peer_type == "external" { result["peer-type"] = "EXTERNAL" } } else { log.Info("peer_type field not found in DB") } return result, err }
var DbToYang_bgp_pgrp_tx_add_paths_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_bgp_pgrp_tx_add_paths_fld_xfmr: ", data, "inParams : ", inParams) pTbl := data["BGP_PEER_GROUP_AF"] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_bgp_pgrp_tx_add_paths_fld_xfmr BGP peer group not found : ", inParams.key) return result, errors.New("BGP neighbor not found : " + inParams.key) } pNbrKey := pTbl[inParams.key] tx_add_paths_type, ok := pNbrKey.Field["tx_add_paths"] if ok { if tx_add_paths_type == "tx_all_paths" { result["tx-add-paths"] = "TX_ALL_PATHS" } else if tx_add_paths_type == "tx_best_path_per_as" { result["tx-add-paths"] = "TX_BEST_PATH_PER_AS" } } else { log.Info("Tx add Paths field not found in DB") } return result, err }
var DbToYang_bgp_rt_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) entry_key := inParams.key routeTargetKey := strings.Split(entry_key, "|") routeTarget := routeTargetKey[2] result["route-target"] = routeTarget return result, err }
var DbToYang_bgp_rt_type_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) result["route-target-type"] = "import" return result, err }
var DbToYang_bgp_vni_number_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) log.Info("DbToYang_bgp_vni_number_fld_xfmr: ", inParams.key) entry_key := inParams.key vniKey := strings.Split(entry_key, "|") vniNumber, _ := strconv.ParseFloat(vniKey[2], 64) result["vni-number"] = vniNumber return result, err }
var DbToYang_community_match_set_options_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) log.Info("DbToYang_community_match_set_options_fld_xfmr", inParams.ygRoot) data := (*inParams.dbDataMap)[inParams.curDb] opt, ok := data["COMMUNITY_SET"][inParams.key].Field["match_action"] if ok { match_opt := findInMap(MATCH_SET_ACTION_MAP, opt) n, err := strconv.ParseInt(match_opt, 10, 64) result["match-set-options"] = ocbinds.E_OpenconfigRoutingPolicy_MatchSetOptionsType(n).ΛMap()["E_OpenconfigRoutingPolicy_MatchSetOptionsType"][n].Name log.Info("DbToYang_community_match_set_options_fld_xfmr ", result["match-set-options"]) return result, err } return result, err }
var DbToYang_community_member_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) var result_community string data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_community_member_fld_xfmr", data, inParams.ygRoot, inParams.key) set_type := data["COMMUNITY_SET"][inParams.key].Field["set_type"] log.Info("DbToYang_community_member_fld_xfmr: type ", set_type) var Communities []interface{} community_list, ok := data["COMMUNITY_SET"][inParams.key].Field["community_member@"] if ok { log.Info("DbToYang_community_member_fld_xfmr: DB Memebers ", community_list) for _, community := range strings.Split(community_list, ",") { if set_type == "EXPANDED" { result_community = "REGEX:" } else { result_community = "" } if community == "local-AS" { result_community += "NO_EXPORT_SUBCONFED" } else if community == "no-advertise" { result_community += "NO_ADVERTISE" } else if community == "no-export" { result_community += "NO_EXPORT" } else if community == "no-peer" { result_community += "NOPEER" } else { result_community += community } log.Info("DbToYang_community_member_fld_xfmr: result_community ", result_community) Communities = append(Communities, result_community) } } result["community-member"] = Communities log.Info("DbToYang_community_member_fld_xfmr: Comminuty Memebers ", result["community-member"]) return result, err }
var DbToYang_community_set_name_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_community_set_name_fld_xfmr: ", inParams.key) key := inParams.key log.Info("DbToYang_community_set_name_fld_xfmr: ", key) setTblKey := strings.Split(key, "|") setName := setTblKey[0] res_map["community-set-name"] = setName log.Info("config/name ", res_map) return res_map, err }
var DbToYang_ext_community_match_set_options_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) log.Info("DbToYang_ext_community_match_set_options_fld_xfmr", inParams.ygRoot) data := (*inParams.dbDataMap)[inParams.curDb] opt, ok := data["EXTENDED_COMMUNITY_SET"][inParams.key].Field["match_action"] if ok { match_opt := findInMap(MATCH_SET_ACTION_MAP, opt) n, err := strconv.ParseInt(match_opt, 10, 64) result["match-set-options"] = ocbinds.E_OpenconfigRoutingPolicy_MatchSetOptionsType(n).ΛMap()["E_OpenconfigRoutingPolicy_MatchSetOptionsType"][n].Name log.Info("DbToYang_ext_community_match_set_options_fld_xfmr ", result["match-set-options"]) return result, err } return result, err }
var DbToYang_ext_community_member_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) var result_community string data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_ext_community_member_fld_xfmr", data, inParams.ygRoot, inParams.key) set_type := data["EXTENDED_COMMUNITY_SET"][inParams.key].Field["set_type"] log.Info("DbToYang_ext_community_member_fld_xfmr: type ", set_type) var Communities []interface{} community_list, ok := data["EXTENDED_COMMUNITY_SET"][inParams.key].Field["community_member@"] if ok { log.Info("DbToYang_ext_community_member_fld_xfmr: DB Memebers ", community_list) for _, community := range strings.Split(community_list, ",") { if set_type == "EXPANDED" { result_community = "REGEX:" } else { result_community = "" } result_community += community log.Info("DbToYang_ext_community_member_fld_xfmr: result_community ", result_community) Communities = append(Communities, result_community) } } result["ext-community-member"] = Communities log.Info("DbToYang_ext_community_member_fld_xfmr: Comminuty Memebers ", result["community-member"]) return result, err }
var DbToYang_ext_community_set_name_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_ext_community_set_name_fld_xfmr: ", inParams.key) key := inParams.key log.Info("DbToYang_ext_community_set_name_fld_xfmr: ", key) setTblKey := strings.Split(key, "|") setName := setTblKey[0] res_map["ext-community-set-name"] = setName log.Info("config/name ", res_map) return res_map, err }
var DbToYang_intf_admin_status_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] intfType, _, ierr := getIntfTypeByName(inParams.key) if intfType == IntfTypeUnset || ierr != nil { log.Info("DbToYang_intf_admin_status_xfmr - Invalid interface type IntfTypeUnset") return result, errors.New("Invalid interface type IntfTypeUnset") } if IntfTypeVxlan == intfType { return result, nil } intTbl := IntfTypeTblMap[intfType] tblName, _ := getPortTableNameByDBId(intTbl, inParams.curDb) if _, ok := data[tblName]; !ok { log.Info("DbToYang_intf_admin_status_xfmr table not found : ", tblName) return result, errors.New("table not found : " + tblName) } pTbl := data[tblName] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_intf_admin_status_xfmr Interface not found : ", inParams.key) return result, errors.New("Interface not found : " + inParams.key) } prtInst := pTbl[inParams.key] adminStatus, ok := prtInst.Field[PORT_ADMIN_STATUS] var status ocbinds.E_OpenconfigInterfaces_Interfaces_Interface_State_AdminStatus if ok { if adminStatus == "up" { status = ocbinds.OpenconfigInterfaces_Interfaces_Interface_State_AdminStatus_UP } else { status = ocbinds.OpenconfigInterfaces_Interfaces_Interface_State_AdminStatus_DOWN } result["admin-status"] = ocbinds.E_OpenconfigInterfaces_Interfaces_Interface_State_AdminStatus.ΛMap(status)["E_OpenconfigInterfaces_Interfaces_Interface_State_AdminStatus"][int64(status)].Name } else { log.Info("Admin status field not found in DB") } return result, err }
var DbToYang_intf_enabled_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] intfType, _, ierr := getIntfTypeByName(inParams.key) if intfType == IntfTypeUnset || ierr != nil { log.Info("DbToYang_intf_enabled_xfmr - Invalid interface type IntfTypeUnset") return result, errors.New("Invalid interface type IntfTypeUnset") } if IntfTypeVxlan == intfType { return result, nil } intTbl := IntfTypeTblMap[intfType] tblName, _ := getPortTableNameByDBId(intTbl, inParams.curDb) if _, ok := data[tblName]; !ok { log.Info("DbToYang_intf_enabled_xfmr table not found : ", tblName) return result, errors.New("table not found : " + tblName) } pTbl := data[tblName] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_intf_enabled_xfmr Interface not found : ", inParams.key) return result, errors.New("Interface not found : " + inParams.key) } prtInst := pTbl[inParams.key] adminStatus, ok := prtInst.Field[PORT_ADMIN_STATUS] if ok { if adminStatus == "up" { result["enabled"] = true } else { result["enabled"] = false } } else { log.Info("Admin status field not found in DB") } return result, err }
var DbToYang_intf_eth_auto_neg_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] intfType, _, ierr := getIntfTypeByName(inParams.key) if intfType == IntfTypeUnset || ierr != nil { log.Info("DbToYang_intf_eth_auto_neg_xfmr - Invalid interface type IntfTypeUnset") return result, errors.New("Invalid interface type IntfTypeUnset") } if IntfTypeVxlan == intfType { return result, nil } intTbl := IntfTypeTblMap[intfType] tblName, _ := getPortTableNameByDBId(intTbl, inParams.curDb) pTbl := data[tblName] prtInst := pTbl[inParams.key] autoNeg, ok := prtInst.Field[PORT_AUTONEG] if ok { if autoNeg == "true" { result["auto-negotiate"] = true } else { result["auto-negotiate"] = false } } else { log.Info("auto-negotiate field not found in DB") } return result, err }
var DbToYang_intf_eth_port_speed_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] intfType, _, ierr := getIntfTypeByName(inParams.key) if intfType == IntfTypeUnset || ierr != nil { log.Info("DbToYang_intf_eth_port_speed_xfmr - Invalid interface type IntfTypeUnset") return result, errors.New("Invalid interface type IntfTypeUnset") } if IntfTypeVxlan == intfType { return result, nil } intTbl := IntfTypeTblMap[intfType] tblName, _ := getPortTableNameByDBId(intTbl, inParams.curDb) pTbl := data[tblName] prtInst := pTbl[inParams.key] speed, ok := prtInst.Field[PORT_SPEED] portSpeed := ocbinds.OpenconfigIfEthernet_ETHERNET_SPEED_UNSET if ok { portSpeed, err = getDbToYangSpeed(speed) result["port-speed"] = ocbinds.E_OpenconfigIfEthernet_ETHERNET_SPEED.ΛMap(portSpeed)["E_OpenconfigIfEthernet_ETHERNET_SPEED"][int64(portSpeed)].Name } else { log.Info("Speed field not found in DB") } return result, err }
var DbToYang_intf_name_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { log.Info("Entering DbToYang_intf_name_xfmr") res_map := make(map[string]interface{}) pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") log.Info("Interface Name = ", ifName) res_map["name"] = ifName return res_map, nil }
var DbToYang_intf_oper_status_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) var prtInst db.Value data := (*inParams.dbDataMap)[inParams.curDb] intfType, _, ierr := getIntfTypeByName(inParams.key) if intfType == IntfTypeUnset || ierr != nil { log.Info("DbToYang_intf_oper_status_xfmr - Invalid interface type IntfTypeUnset") return result, errors.New("Invalid interface type IntfTypeUnset") } if IntfTypeVxlan == intfType { return result, nil } intTbl := IntfTypeTblMap[intfType] if intfType == IntfTypeMgmt { pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") entry, dbErr := inParams.dbs[db.StateDB].GetEntry(&db.TableSpec{Name: intTbl.stateDb.portTN}, db.Key{Comp: []string{ifName}}) if dbErr != nil { log.Info("Failed to read mgmt port status from state DB, " + intTbl.stateDb.portTN + " " + ifName) return result, dbErr } prtInst = entry } else { tblName, _ := getPortTableNameByDBId(intTbl, inParams.curDb) pTbl := data[tblName] prtInst = pTbl[inParams.key] } operStatus, ok := prtInst.Field[PORT_OPER_STATUS] var status ocbinds.E_OpenconfigInterfaces_Interfaces_Interface_State_OperStatus if ok { if operStatus == "up" { status = ocbinds.OpenconfigInterfaces_Interfaces_Interface_State_OperStatus_UP } else { status = ocbinds.OpenconfigInterfaces_Interfaces_Interface_State_OperStatus_DOWN } result["oper-status"] = ocbinds.E_OpenconfigInterfaces_Interfaces_Interface_State_OperStatus.ΛMap(status)["E_OpenconfigInterfaces_Interfaces_Interface_State_OperStatus"][int64(status)].Name } else { log.Info("Oper status field not found in DB") } return result, err }
var DbToYang_intf_type_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var ifName string intfsObj := getIntfsRoot(inParams.ygRoot) if intfsObj == nil || len(intfsObj.Interface) < 1 { return res_map, nil } else { for infK, _ := range intfsObj.Interface { ifName = infK } } intfType, _, _ := getIntfTypeByName(ifName) if IntfTypeVxlan == intfType { res_map["type"] = "IF_NVE" return res_map, nil } else { return res_map, nil } }
var DbToYang_lag_type_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) intfType, _, ierr := getIntfTypeByName(inParams.key) if ierr != nil || intfType != IntfTypePortChannel { return result, err } data := (*inParams.dbDataMap)[inParams.curDb] var agg_type ocbinds.E_OpenconfigIfAggregate_AggregationType agg_type = ocbinds.OpenconfigIfAggregate_AggregationType_LACP lag_type, ok := data[PORTCHANNEL_TABLE][inParams.key].Field["static"] if ok { if lag_type == "true" { agg_type = ocbinds.OpenconfigIfAggregate_AggregationType_STATIC } } result[LAG_TYPE] = ocbinds.E_OpenconfigIfAggregate_AggregationType.ΛMap(agg_type)["E_OpenconfigIfAggregate_AggregationType"][int64(agg_type)].Name log.Infof("Lag Type returned from Field Xfmr: %v\n", result) return result, err }
var DbToYang_mclag_domain_oper_status_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) log.Infof("DbToYang_mclag_domain_oper_status_fld_xfmr --> key: %v", inParams.key) stDb := inParams.dbs[db.StateDB] mclagEntry, _ := stDb.GetEntry(&db.TableSpec{Name: "MCLAG_TABLE"}, db.Key{Comp: []string{inParams.key}}) operStatus := mclagEntry.Get("oper_status") if operStatus == "up" { result["oper-status"], _ = ygot.EnumName(ocbinds.OpenconfigMclag_Mclag_MclagDomains_MclagDomain_State_OperStatus_OPER_UP) } else { result["oper-status"], _ = ygot.EnumName(ocbinds.OpenconfigMclag_Mclag_MclagDomains_MclagDomain_State_OperStatus_OPER_DOWN) } return result, err }
var DbToYang_mclag_domain_role_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) log.Infof("DbToYang_mclag_domain_role_fld_xfmr --> key: %v", inParams.key) stDb := inParams.dbs[db.StateDB] mclagEntry, _ := stDb.GetEntry(&db.TableSpec{Name: "MCLAG_TABLE"}, db.Key{Comp: []string{inParams.key}}) role := mclagEntry.Get("role") if role == "active" { result["role"], _ = ygot.EnumName(ocbinds.OpenconfigMclag_Mclag_MclagDomains_MclagDomain_State_Role_ROLE_ACTIVE) } else { result["role"], _ = ygot.EnumName(ocbinds.OpenconfigMclag_Mclag_MclagDomains_MclagDomain_State_Role_ROLE_STANDBY) } return result, err }
var DbToYang_mclag_domain_system_mac_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) log.Infof("DbToYang_mclag_domain_system_mac_fld_xfmr --> key: %v", inParams.key) stDb := inParams.dbs[db.StateDB] mclagEntry, _ := stDb.GetEntry(&db.TableSpec{Name: "MCLAG_TABLE"}, db.Key{Comp: []string{inParams.key}}) sysmac := mclagEntry.Get("system_mac") result["system-mac"] = &sysmac return result, err }
var DbToYang_mclag_domainid_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) log.Info("DbToYang_mclag_domainid_fld_xfmr: ", inParams.key) result["domain-id"], _ = strconv.ParseUint(inParams.key, 10, 32) return result, err }
var DbToYang_mclag_vlan_name_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) log.Info("DbToYang_mclag_vlan_name_fld_xfmr: ", inParams.key) result["name"] = inParams.key return result, err }
var DbToYang_nat_enable_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] pTbl := data[NAT_GLOBAL_TN] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_intf_enabled_xfmr Values entry not found : ", inParams.key) return result, errors.New("Global Values not found : " + inParams.key) } prtInst := pTbl[inParams.key] adminMode, ok := prtInst.Field["admin_mode"] if ok { if adminMode == ENABLED { result[ENABLE] = true } else { result[ENABLE] = false } } else { result[ENABLE] = false log.Info("Admin Mode field not found in DB") } return result, err }
var DbToYang_nat_entry_type_field_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_nat_entry_type_field_xfmr", data, inParams.ygRoot) targetUriPath, err := getYangPathFromUri(inParams.uri) var tblName string if strings.HasPrefix(targetUriPath, "/openconfig-nat:nat/instances/instance/napt-mapping-table/napt-mapping-entry") { tblName = NAPT_TABLE } else if strings.HasPrefix(targetUriPath, "/openconfig-nat:nat/instances/instance/napt-twice-mapping-table/napt-twice-entry") { tblName = NAPT_TWICE_TABLE } else if strings.HasPrefix(targetUriPath, "/openconfig-nat:nat/instances/instance/nat-twice-mapping-table/nat-twice-entry") { tblName = NAT_TWICE_TABLE } else { tblName = NAT_TABLE } if _, ok := data[tblName]; ok { if _, entOk := data[tblName][inParams.key]; entOk { entry := data[tblName][inParams.key] fldOk := entry.Has(NAT_ENTRY_TYPE) if fldOk == true { t := findInMap(NAT_ENTRY_TYPE_MAP, data[tblName][inParams.key].Field[NAT_ENTRY_TYPE]) var n int64 n, err = strconv.ParseInt(t, 10, 64) if err == nil { result["entry-type"] = ocbinds.E_OpenconfigNat_NAT_ENTRY_TYPE(n).ΛMap()["E_OpenconfigNat_NAT_ENTRY_TYPE"][n].Name } } } } return result, err }
var DbToYang_nat_ip_field_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] tblName := "NAT_POOL" if _, ok := data[tblName]; ok { if _, entOk := data[tblName][inParams.key]; entOk { entry := data[tblName][inParams.key] fldOk := entry.Has("nat_ip") if fldOk == true { ipStr := entry.Get("nat_ip") ipRange := strings.Contains(ipStr, "-") if ipRange == true { result["IP-ADDRESS-RANGE"] = ipStr } else { result["IP-ADDRESS"] = ipStr } } } } return result, err }
var DbToYang_nat_type_field_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_nat_type_field_xfmr", data, inParams.ygRoot) targetUriPath, err := getYangPathFromUri(inParams.uri) var tblName string if strings.HasPrefix(targetUriPath, "/openconfig-nat:nat/instances/instance/napt-mapping-table/napt-mapping-entry/config") { tblName = STATIC_NAPT } else if strings.HasPrefix(targetUriPath, "/openconfig-nat:nat/instances/instance/napt-mapping-table/napt-mapping-entry/state") { tblName = NAPT_TABLE } else if strings.HasPrefix(targetUriPath, "/openconfig-nat:nat/instances/instance/nat-mapping-table/nat-mapping-entry/config") { tblName = STATIC_NAT } else if strings.HasPrefix(targetUriPath, "/openconfig-nat:nat/instances/instance/nat-mapping-table/nat-mapping-entry/state") { tblName = NAT_TABLE } else if strings.HasPrefix(targetUriPath, "/openconfig-nat:nat/instances/instance/nat-acl-pool-binding/nat-acl-pool-binding-entry") { tblName = NAT_BINDINGS } else { log.Info("DbToYang_nat_type_field_xfmr: Invalid URI: %s\n", targetUriPath) return result, errors.New("Invalid URI " + targetUriPath) } if _, ok := data[tblName]; ok { if _, entOk := data[tblName][inParams.key]; entOk { entry := data[tblName][inParams.key] fldOk := entry.Has(NAT_TYPE) if fldOk == true { t := findInMap(NAT_TYPE_MAP, data[tblName][inParams.key].Field[NAT_TYPE]) var n int64 n, err = strconv.ParseInt(t, 10, 64) if err == nil { result["type"] = ocbinds.E_OpenconfigNat_NAT_TYPE(n).ΛMap()["E_OpenconfigNat_NAT_TYPE"][n].Name } } } } return result, err }
var DbToYang_network_instance_enabled_field_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_network_instance_enabled_field_xfmr: ") if mgmtVrfEnabledInDb(inParams) == "true" { res_map["enabled"] = true } else if mgmtVrfEnabledInDb(inParams) == "false" { res_map["enabled"] = false } return res_map, err }
DbToYang Field transformer for top level network instance config "enabled"
var DbToYang_nw_inst_vxlan_source_nve_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key if log.V(3) { log.Info("DbToYang_nw_inst_vxlan_source_nve_xfmr ==> entry_key ===> ", entry_key) } if entry_key != "" { keyList := strings.Split(entry_key, "|") if log.V(3) { log.Info("DbToYang_nw_inst_vxlan_source_nve_xfmr ==> keyList ===> ", keyList) } rmap["source-nve"] = keyList[0] } if log.V(3) { log.Info("DbToYang_nw_inst_vxlan_source_nve_xfmr ==> rmap ===> ", rmap) } return rmap, nil }
var DbToYang_nw_inst_vxlan_vni_id_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key if log.V(3) { log.Info("DbToYang_nw_inst_vxlan_vni_id_xfmr ==> entry_key ===> ", entry_key) } if entry_key != "" { keyList := strings.Split(entry_key, "|") if log.V(3) { log.Info("DbToYang_nw_inst_vxlan_vni_id_xfmr ==> keyList ===> ", keyList) } mapNameList := strings.Split(keyList[1], "_") vniId, _ := strconv.ParseInt(mapNameList[1], 10, 64) rmap["vni-id"] = uint32(vniId) } if log.V(3) { log.Info("DbToYang_nw_inst_vxlan_vni_id_xfmr ==> rmap ===> ", rmap) } return rmap, nil }
var DbToYang_prefix_action_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_prefix_action_fld_xfmr", data, "inParams : ", inParams) pTbl := data["PREFIX"] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_route_map_action_policy_result_xfmr table not found : ", inParams.key) return result, errors.New("Policy definition table not found : " + inParams.key) } niInst := pTbl[inParams.key] route_operation, ok := niInst.Field["action"] if ok { if route_operation == "permit" { result["action"] = "PERMIT" } else { result["action"] = "DENY" } } else { log.Info("DbToYang_prefix_action_fld_xfmr field not found in DB") } return result, err }
var DbToYang_prefix_ip_prefix_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_prefix_ip_prefix_fld_xfmr: ", inParams.key) key := inParams.key prefixKey := strings.Split(key, "|") ip_prefix := prefixKey[1] res_map["ip-prefix"] = ip_prefix log.Info("prefix-set/prefix/config/ip-prefix ", res_map) return res_map, err }
var DbToYang_prefix_masklength_range_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_prefix_masklength_range_fld_xfmr: ", inParams.key) key := inParams.key prefixKey := strings.Split(key, "|") mask := prefixKey[2] res_map["masklength-range"] = mask log.Info("prefix-set/prefix/config/masklength-range ", res_map) return res_map, err }
var DbToYang_prefix_set_mode_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_prefix_set_mode_fld_xfmr: Input", data, inParams.ygRoot) mode, ok := data["PREFIX_SET"][inParams.key].Field["mode"] if ok { oc_mode := findInMap(PREFIX_SET_MODE_MAP, mode) n, err := strconv.ParseInt(oc_mode, 10, 64) result["mode"] = ocbinds.E_OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_PrefixSets_PrefixSet_Config_Mode(n).ΛMap()["E_OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_PrefixSets_PrefixSet_Config_Mode"][n].Name log.Info("DbToYang_prefix_set_mode_fld_xfmr ", result) return result, err } return result, err }
var DbToYang_prefix_set_name_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_prefix_set_name_fld_xfmr: ", inParams.key) key := inParams.key log.Info("DbToYang_prefix_set_name_fld_xfmr: ", key) setTblKey := strings.Split(key, "|") setName := setTblKey[0] res_map["name"] = setName log.Info("prefix-set/config/name ", res_map) return res_map, err }
var DbToYang_ptp_boolean_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) var inval string data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_ptp_boolean_xfmr ygRoot: ", *inParams.ygRoot, " Xpath: ", inParams.uri, " data: ", data) _, field := filepath.Split(inParams.uri) if field == "two-step-flag" { inval = data["PTP_CLOCK"][inParams.key].Field[field] } else if field == "slave-only" { inval = data["PTP_CLOCK"][inParams.key].Field[field] } else if field == "parent-stats" { inval = data["PTP_PARENTDS"][inParams.key].Field[field] } else if field == "current-utc-offset-valid" { inval = data["PTP_TIMEPROPDS"][inParams.key].Field[field] } else if field == "leap59" { inval = data["PTP_TIMEPROPDS"][inParams.key].Field[field] } else if field == "leap61" { inval = data["PTP_TIMEPROPDS"][inParams.key].Field[field] } else if field == "time-traceable" { inval = data["PTP_TIMEPROPDS"][inParams.key].Field[field] } else if field == "frequency-traceable" { inval = data["PTP_TIMEPROPDS"][inParams.key].Field[field] } else if field == "ptp-timescale" { inval = data["PTP_TIMEPROPDS"][inParams.key].Field[field] } else if field == "faulty-flag" { inval = data["PTP_TC_PORT"][inParams.key].Field[field] } if inval == "0" { result[field] = false } else if inval == "1" { result[field] = true } return result, err }
var DbToYang_ptp_clock_identity_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) var ptp_id ptp_id_bin var field, identity, sEnc string data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_ptp_clock_identity_xfmr ygRoot: ", *inParams.ygRoot, " Xpath: ", inParams.uri, " data: ", data) if strings.Contains(inParams.uri, "grandmaster-identity") { field = "grandmaster-identity" identity = data["PTP_PARENTDS"][inParams.key].Field[field] } else if strings.Contains(inParams.uri, "parent-port-identity") { field = "clock-identity" identity = data["PTP_PARENTDS"][inParams.key].Field[field] } else if strings.Contains(inParams.uri, "transparent-clock-default-ds") { field = "clock-identity" identity = data["PTP_TC_CLOCK"][inParams.key].Field[field] } else if strings.Contains(inParams.uri, "default-ds") { field = "clock-identity" identity = data["PTP_CLOCK"][inParams.key].Field[field] } if len(identity) >= 18 { ptp_id, err = ParseIdentity(identity) sEnc = b64.StdEncoding.EncodeToString(ptp_id[:]) result[field] = sEnc } else { sEnc = "" } return result, err }
var DbToYang_ptp_clock_type_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_ptp_clock_type_xfmr ygRoot: ", *inParams.ygRoot, " Xpath: ", inParams.uri, " data: ", data) log.Info("DbToYang_ptp_clock_type_xfmr inParams.key: ", inParams.key) _, field := filepath.Split(inParams.uri) log.Info("DbToYang_ptp_clock_type_xfmr field: ", field) value := data["PTP_CLOCK"][inParams.key].Field[field] result[field] = value log.Info("DbToYang_ptp_clock_type_xfmr value: ", value) return result, err }
var DbToYang_ptp_delay_mech_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) var inval string var outval string data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_ptp_delay_mech_xfmr ygRoot: ", *inParams.ygRoot, " Xpath: ", inParams.uri, " data: ", data) _, field := filepath.Split(inParams.uri) if strings.Contains(inParams.uri, "port-ds-list") { inval = data["PTP_PORT"][inParams.key].Field[field] } else if strings.Contains(inParams.uri, "transparent-clock-default-ds") { inval = data["PTP_TC_CLOCK"][inParams.key].Field[field] } switch inval { case "1": outval = "e2e" case "2": outval = "p2p" default: outval = "" } log.Info("DbToYang_ptp_delay_mech_xfmr result: ", outval, " inval: ", inval) if outval != "" { result[field] = outval } return result, err }
var DbToYang_ptp_domain_number_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_ptp_domain_number_xfmr ygRoot: ", *inParams.ygRoot, " Xpath: ", inParams.uri, " data: ", data) log.Info("DbToYang_ptp_domain_number_xfmr inParams.key: ", inParams.key) _, field := filepath.Split(inParams.uri) log.Info("DbToYang_ptp_domain_number_xfmr field: ", field) value := data["PTP_CLOCK"][inParams.key].Field[field] result[field], _ = strconv.ParseUint(value, 10, 64) log.Info("DbToYang_ptp_domain_number_xfmr value: ", value) return result, err }
var DbToYang_ptp_domain_profile_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_ptp_domain_profile_xfmr ygRoot: ", *inParams.ygRoot, " Xpath: ", inParams.uri, " data: ", data) log.Info("DbToYang_ptp_domain_profile_xfmr inParams.key: ", inParams.key) _, field := filepath.Split(inParams.uri) log.Info("DbToYang_ptp_domain_profile_xfmr field: ", field) value := data["PTP_CLOCK"][inParams.key].Field[field] result[field] = value log.Info("DbToYang_ptp_domain_profile_xfmr value: ", value) return result, err }
var DbToYang_ptp_inst_number_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { /* do nothing */ var err error result := make(map[string]interface{}) return result, err }
var DbToYang_ptp_network_transport_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_ptp_network_transport_xfmr ygRoot: ", *inParams.ygRoot, " Xpath: ", inParams.uri, " data: ", data) log.Info("DbToYang_ptp_network_transport_xfmr inParams.key: ", inParams.key) _, field := filepath.Split(inParams.uri) log.Info("DbToYang_ptp_network_transport_xfmr field: ", field) value := data["PTP_CLOCK"][inParams.key].Field[field] result[field] = value log.Info("DbToYang_ptp_network_transport_xfmr value: ", value) return result, err }
var DbToYang_ptp_port_state_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error var inval string var outval string result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_ptp_port_state_xfmr :", data, inParams.ygRoot) inval = data["PTP_PORT"][inParams.key].Field["port-state"] switch inval { case "1": outval = "initializing" case "2": outval = "faulty" case "3": outval = "disabled" case "4": outval = "listening" case "5": outval = "pre-master" case "6": outval = "master" case "7": outval = "passive" case "8": outval = "uncalibrated" case "9": outval = "slave" default: goto done } result["port-state"] = outval done: return result, err }
var DbToYang_ptp_udp6_scope_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_ptp_udp6_scope_xfmr ygRoot: ", *inParams.ygRoot, " Xpath: ", inParams.uri, " data: ", data) log.Info("DbToYang_ptp_udp6_scope_xfmr inParams.key: ", inParams.key) _, field := filepath.Split(inParams.uri) log.Info("DbToYang_ptp_udp6_scope_xfmr field: ", field) log.Info("DbToYang_ptp_udp6_scope_xfmr data: ", data["PTP_CLOCK"][inParams.key].Field[field]) value, _ := strconv.ParseInt(strings.Replace(data["PTP_CLOCK"][inParams.key].Field[field], "0x", "", -1), 16, 64) result[field] = uint8(value) log.Info("DbToYang_ptp_udp6_scope_xfmr value: ", value) return result, err }
var DbToYang_ptp_unicast_multicast_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_ptp_unicast_multicast_xfmr ygRoot: ", *inParams.ygRoot, " Xpath: ", inParams.uri, " data: ", data) log.Info("DbToYang_ptp_unicast_multicast_xfmr inParams.key: ", inParams.key) _, field := filepath.Split(inParams.uri) log.Info("DbToYang_ptp_unicast_multicast_xfmr field: ", field) value := data["PTP_CLOCK"][inParams.key].Field[field] result[field] = value log.Info("DbToYang_ptp_unicast_multicast_xfmr value: ", value) return result, err }
var DbToYang_ptp_unicast_table_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_ptp_unicast_table_xfmr ygRoot: ", *inParams.ygRoot, " Xpath: ", inParams.uri, " data: ", data) log.Info("DbToYang_ptp_unicast_table_xfmr inParams.key: ", inParams.key) _, field := filepath.Split(inParams.uri) log.Info("DbToYang_ptp_unicast_table_xfmr field: ", field) value := data["PTP_PORT"][inParams.key].Field[field] result[field] = value log.Info("DbToYang_ptp_unicast_table_xfmr value: ", value) return result, err }
var DbToYang_route_map_action_policy_result_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_bgp_external_compare_router_id_xfmr", data, "inParams : ", inParams) pTbl := data["ROUTE_MAP"] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_route_map_action_policy_result_xfmr table not found : ", inParams.key) return result, errors.New("Policy definition table not found : " + inParams.key) } niInst := pTbl[inParams.key] route_operation, ok := niInst.Field["route_operation"] if ok { if route_operation == "permit" { result["policy-result"] = "ACCEPT_ROUTE" } else { result["policy-result"] = "REJECT_ROUTE" } } else { log.Info("DbToYang_route_map_action_policy_result_xfmr field not found in DB") } return result, err }
var DbToYang_route_map_field_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error entry_key := inParams.key log.Info("DbToYang_route_map_field_xfmr: ", entry_key) dynKey := strings.Split(entry_key, "|") rmap["name"] = dynKey[0] return rmap, err }
var DbToYang_route_map_key_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error entry_key := inParams.key log.Info("DbToYang_route_map_key_xfmr: ", entry_key) dynKey := strings.Split(entry_key, "|") rmap["name"] = dynKey[1] return rmap, err }
var DbToYang_route_map_match_protocol_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_route_map_match_protocol_xfmr", data, "inParams : ", inParams) pTbl := data["ROUTE_MAP"] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_route_map_match_protocol_xfmr table not found : ", inParams.key) return result, errors.New("Policy definition table not found : " + inParams.key) } niInst := pTbl[inParams.key] protocol, ok := niInst.Field["match_protocol"] if ok { switch protocol { case "bgp": result["install-protocol-eq"] = "BGP" case "connected": result["install-protocol-eq"] = "DIRECTLY_CONNECTED" case "isis": result["install-protocol-eq"] = "ISIS" case "ospf": result["install-protocol-eq"] = "OSPF" case "ospf3": result["install-protocol-eq"] = "OSPF3" case "static": result["install-protocol-eq"] = "STATIC" default: } } else { log.Info("DbToYang_route_map_match_protocol_xfmr field not found in DB") } return result, err }
var DbToYang_route_map_match_set_options_restrict_type_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) result["match-set-options"] = "ANY" return result, err }
var DbToYang_route_map_match_set_options_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) result["match-set-options"] = "ANY" return result, err }
var DbToYang_route_map_stmt_field_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error entry_key := inParams.key log.Info("DbToYang_route_map_stmt_field_xfmr: ", entry_key) dynKey := strings.Split(entry_key, "|") rmap["name"] = dynKey[1] return rmap, err }
var DbToYang_route_table_addr_family_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) entry_key := inParams.key key := strings.Split(entry_key, "|") family := key[3] af := "" if family == "ipv4" { af = "IPV4" } else if family == "ipv6" { af = "IPV6" } else { return result, errors.New("Unsupported family " + family) } result["address-family"] = af return result, err }
var DbToYang_sag_ipv4_enable_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] tblName := "IP" if _, ok := data[tblName]; !ok { log.Info("DbToYang_sag_ipv4_enable_xfmr table not found : ", tblName) return result, errors.New("table not found : " + tblName) } pTbl := data[tblName] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_sag_ipv4_enable_xfmr SAG not found : ", inParams.key) return result, errors.New("SAG not found : " + inParams.key) } prtInst := pTbl[inParams.key] adminStatus, ok := prtInst.Field["IPv4"] if ok { if adminStatus == "enable" { result["ipv4-enable"] = true } else { result["ipv4-enable"] = false } } else { log.Info("Admin status field not found in DB") } return result, err }
var DbToYang_sag_ipv6_enable_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { var err error result := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] tblName := "SAG_GLOBAL|IP" if _, ok := data[tblName]; !ok { log.Info("DbToYang_sag_ipv6_enable_xfmr table not found : ", tblName) return result, errors.New("table not found : " + tblName) } pTbl := data[tblName] if _, ok := pTbl[inParams.key]; !ok { log.Info("DbToYang_sag_ipv6_enable_xfmr SAG not found : ", inParams.key) return result, errors.New("SAG not found : " + inParams.key) } prtInst := pTbl[inParams.key] adminStatus, ok := prtInst.Field["IPv6"] if ok { if adminStatus == "enable" { result["ipv6-enable"] = true } else { result["ipv6-enable"] = false } } else { log.Info("Admin status field not found in DB") } return result, err }
var DbToYang_vlan_nd_suppress_fld_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) pathInfo := NewPathInfo(inParams.uri) vlanIdStr := pathInfo.Var("name") data := (*inParams.dbDataMap)[inParams.curDb] log.Infof("vlan_nd_suppress_fld_xfmr: key: %v, data: %v", vlanIdStr, data) if data != nil && len(data) > 0 { val := data["SUPPRESS_VLAN_NEIGH"][vlanIdStr] if val.Get("suppress") == "on" { res_map["arp-and-nd-suppress"], _ = ygot.EnumName(ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_NeighbourSuppress_Config_ArpAndNdSuppress_enable) } } return res_map, nil }
var DbToYang_vxlan_state_peer_tunnel_type_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) rmap["tunnel-type"] = "dynamic" if log.V(3) { log.Info("DbToYang_vxlan_state_peer_tunnel_type_xfmr ==> returning tunnel-type field ==> ", rmap) } return rmap, nil }
var DbToYang_vxlan_state_tunnel_info_tunnel_type_xfmr FieldXfmrDbtoYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) rmap["type"] = "dynamic" if log.V(3) { log.Info("DbToYang_vxlan_state_tunnel_info_tunnel_type_xfmr ==> returning type field ==> ", rmap) } return rmap, nil }
type FieldXfmrYangToDb ¶
type FieldXfmrYangToDb func(inParams XfmrParams) (map[string]string, error)
*
- FieldXfmrYangToDb type is defined to use for conversion of yang Field to DB field
- Transformer function definition.
- Param: Database info, YgotRoot, operation, Xpath
- Return: multi dimensional map to hold the DB data, error *
var YangToDb_acl_destination_port_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { res_map["L4_DST_PORT_RANGE"] = "" return res_map, err } destportType := reflect.TypeOf(inParams.param).Elem() log.Info("YangToDb_acl_ip_protocol_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " destportType: ", destportType) switch destportType { case reflect.TypeOf(ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_DestinationPort_Union_E_OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_DestinationPort{}): v := (inParams.param).(*ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_DestinationPort_Union_E_OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_DestinationPort) res_map["L4_DST_PORT"] = v.E_OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_DestinationPort.ΛMap()["E_OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_DestinationPort"][int64(v.E_OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_DestinationPort)].Name break case reflect.TypeOf(ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_DestinationPort_Union_String{}): v := (inParams.param).(*ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_DestinationPort_Union_String) res_map["L4_DST_PORT_RANGE"] = strings.Replace(v.String, "..", "-", 1) break case reflect.TypeOf(ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_DestinationPort_Union_Uint16{}): v := (inParams.param).(*ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_DestinationPort_Union_Uint16) res_map["L4_DST_PORT"] = strconv.FormatInt(int64(v.Uint16), 10) break } return res_map, err }
var YangToDb_acl_forwarding_action_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { res_map["PACKET_ACTION"] = "" return res_map, err } action, _ := inParams.param.(ocbinds.E_OpenconfigAcl_FORWARDING_ACTION) log.Info("YangToDb_acl_forwarding_action_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " forwarding_action: ", action) res_map["PACKET_ACTION"] = findInMap(ACL_FORWARDING_ACTION_MAP, strconv.FormatInt(int64(action), 10)) return res_map, err }
////////////////////////////////////////// Bi-directoonal overloaded methods //////////////////////////////////////////
var YangToDb_acl_ip_protocol_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { res_map["IP_PROTOCOL"] = "" return res_map, err } protocolType := reflect.TypeOf(inParams.param).Elem() log.Info("YangToDb_acl_ip_protocol_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " protocolType: ", protocolType) switch protocolType { case reflect.TypeOf(ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Ipv4_Config_Protocol_Union_E_OpenconfigPacketMatchTypes_IP_PROTOCOL{}): v := (inParams.param).(*ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Ipv4_Config_Protocol_Union_E_OpenconfigPacketMatchTypes_IP_PROTOCOL) res_map["IP_PROTOCOL"] = findInMap(IP_PROTOCOL_MAP, strconv.FormatInt(int64(v.E_OpenconfigPacketMatchTypes_IP_PROTOCOL), 10)) v = nil break case reflect.TypeOf(ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Ipv4_Config_Protocol_Union_Uint8{}): v := (inParams.param).(*ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Ipv4_Config_Protocol_Union_Uint8) res_map["IP_PROTOCOL"] = strconv.FormatInt(int64(v.Uint8), 10) break } return res_map, err }
var YangToDb_acl_l2_ethertype_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { res_map["ETHER_TYPE"] = "" return res_map, err } ethertypeType := reflect.TypeOf(inParams.param).Elem() log.Info("YangToDb_acl_ip_protocol_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " ethertypeType: ", ethertypeType) var b bytes.Buffer switch ethertypeType { case reflect.TypeOf(ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_L2_Config_Ethertype_Union_E_OpenconfigPacketMatchTypes_ETHERTYPE{}): v := (inParams.param).(*ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_L2_Config_Ethertype_Union_E_OpenconfigPacketMatchTypes_ETHERTYPE) fmt.Fprintf(&b, "0x%0.4x", ETHERTYPE_MAP[v.E_OpenconfigPacketMatchTypes_ETHERTYPE]) res_map["ETHER_TYPE"] = b.String() break case reflect.TypeOf(ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_L2_Config_Ethertype_Union_Uint16{}): v := (inParams.param).(*ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_L2_Config_Ethertype_Union_Uint16) fmt.Fprintf(&b, "0x%0.4x", v.Uint16) res_map["ETHER_TYPE"] = b.String() break } return res_map, err }
var YangToDb_acl_source_port_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { res_map["L4_SRC_PORT"] = "" return res_map, err } sourceportType := reflect.TypeOf(inParams.param).Elem() log.Info("YangToDb_acl_ip_protocol_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " sourceportType: ", sourceportType) switch sourceportType { case reflect.TypeOf(ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_SourcePort_Union_E_OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_SourcePort{}): v := (inParams.param).(*ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_SourcePort_Union_E_OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_SourcePort) res_map["L4_SRC_PORT"] = v.E_OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_SourcePort.ΛMap()["E_OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_SourcePort"][int64(v.E_OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_SourcePort)].Name break case reflect.TypeOf(ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_SourcePort_Union_String{}): v := (inParams.param).(*ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_SourcePort_Union_String) res_map["L4_SRC_PORT_RANGE"] = strings.Replace(v.String, "..", "-", 1) break case reflect.TypeOf(ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_SourcePort_Union_Uint16{}): v := (inParams.param).(*ocbinds.OpenconfigAcl_Acl_AclSets_AclSet_AclEntries_AclEntry_Transport_Config_SourcePort_Union_Uint16) res_map["L4_SRC_PORT"] = strconv.FormatInt(int64(v.Uint16), 10) break } return res_map, err }
var YangToDb_acl_tcp_flags_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error log.Info("YangToDb_acl_tcp_flags_xfmr: ") var tcpFlags uint32 = 0x00 var b bytes.Buffer if inParams.param == nil { res_map["TCP_FLAGS"] = b.String() return res_map, err } log.Info("YangToDb_acl_tcp_flags_xfmr: ", inParams.ygRoot, inParams.uri) v := reflect.ValueOf(inParams.param) flags := v.Interface().([]ocbinds.E_OpenconfigPacketMatchTypes_TCP_FLAGS) for _, flag := range flags { fmt.Println("TCP Flag name: " + flag.ΛMap()["E_OpenconfigPacketMatchTypes_TCP_FLAGS"][int64(flag)].Name) switch flag { case ocbinds.OpenconfigPacketMatchTypes_TCP_FLAGS_TCP_FIN: tcpFlags |= 0x01 break case ocbinds.OpenconfigPacketMatchTypes_TCP_FLAGS_TCP_SYN: tcpFlags |= 0x02 break case ocbinds.OpenconfigPacketMatchTypes_TCP_FLAGS_TCP_RST: tcpFlags |= 0x04 break case ocbinds.OpenconfigPacketMatchTypes_TCP_FLAGS_TCP_PSH: tcpFlags |= 0x08 break case ocbinds.OpenconfigPacketMatchTypes_TCP_FLAGS_TCP_ACK: tcpFlags |= 0x10 break case ocbinds.OpenconfigPacketMatchTypes_TCP_FLAGS_TCP_URG: tcpFlags |= 0x20 break case ocbinds.OpenconfigPacketMatchTypes_TCP_FLAGS_TCP_ECE: tcpFlags |= 0x40 break case ocbinds.OpenconfigPacketMatchTypes_TCP_FLAGS_TCP_CWR: tcpFlags |= 0x80 break } } fmt.Fprintf(&b, "0x%0.2x/0x%0.2x", tcpFlags, tcpFlags) res_map["TCP_FLAGS"] = b.String() return res_map, err }
var YangToDb_acl_type_field_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { res_map[ACL_TYPE] = "" return res_map, err } acltype, _ := inParams.param.(ocbinds.E_OpenconfigAcl_ACL_TYPE) log.Info("YangToDb_acl_type_field_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " acltype: ", acltype) res_map[ACL_TYPE] = findInMap(ACL_TYPE_MAP, strconv.FormatInt(int64(acltype), 10)) return res_map, err }
var YangToDb_as_path_set_name_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) log.Info("YangToDb_as_path_set_name_fld_xfmr: ", inParams.key) res_map["NULL"] = "NULL" return res_map, nil }
AS PATH SET API's
var YangToDb_auth_method_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { if log.V(3) { log.Info("YangToDb_auth_method_xfmr: root: ", inParams.ygRoot, ", uri: ", inParams.uri, "param: ", inParams.param) } var db_auth_method string auth_method, _ := inParams.param.([]ocbinds.OpenconfigSystem_System_Aaa_Authentication_Config_AuthenticationMethod_Union) for _, method := range auth_method { v := (method).(*ocbinds.OpenconfigSystem_System_Aaa_Authentication_Config_AuthenticationMethod_Union_String) log.Info("YangToDb_auth_method_xfmr: method - ", v.String) if len(db_auth_method) == 0 { db_auth_method = v.String } else { db_auth_method = db_auth_method + "," + v.String } } log.Info("YangToDb_auth_method_xfmr: auth-method: ", db_auth_method) res_map := make(map[string]string) res_map["login"] = db_auth_method return res_map, nil }
var YangToDb_bgp_advertise_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error afi_safi_list, _ := inParams.param.([]ocbinds.E_OpenconfigBgpTypes_AFI_SAFI_TYPE) log.Info("YangToDb_bgp_advertise_fld_xfmr: afi_safi_list:", afi_safi_list) for _, afi_safi := range afi_safi_list { if afi_safi == ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST { res_map["advertise-ipv4-unicast"] = "true" } else if afi_safi == ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST { res_map["advertise-ipv6-unicast"] = "true" } else { err = errors.New("Unsupported afi_safi") return res_map, err } } return res_map, nil }
var YangToDb_bgp_local_asn_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { rmap := make(map[string]string) var err error if inParams.param == nil { rmap["local_asn"] = "" return rmap, err } if inParams.oper == DELETE { rmap["local_asn"] = "" return rmap, nil } log.Info("YangToDb_bgp_local_asn_fld_xfmr") pathInfo := NewPathInfo(inParams.uri) niName := pathInfo.Var("name") asn, _ := inParams.param.(*uint32) curr_asn, err_val := bgp_global_get_local_asn(inParams.d, niName, "BGP_GLOBALS") if err_val == nil { local_asn64, err_conv := strconv.ParseUint(curr_asn, 10, 32) local_asn := uint32(local_asn64) if err_conv == nil && local_asn != *asn { log.Info("YangToDb_bgp_local_asn_fld_xfmr Local ASN is already present", local_asn, *asn) return rmap, tlerr.InvalidArgs("BGP is already running with AS number %s", strconv.FormatUint(local_asn64, 10)) } } rmap["local_asn"] = strconv.FormatUint(uint64(*asn), 10) return rmap, err }
var YangToDb_bgp_nbr_address_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) res_map["NULL"] = "NULL" return res_map, nil }
var YangToDb_bgp_nbr_afi_safi_name_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) res_map["NULL"] = "NULL" return res_map, nil }
var YangToDb_bgp_nbr_community_type_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { err = errors.New("No Params") return res_map, err } if inParams.oper == DELETE { subOpMap := make(map[db.DBNum]map[string]map[string]db.Value) if _, ok := subOpMap[db.ConfigDB]; !ok { subOpMap[db.ConfigDB] = make(map[string]map[string]db.Value) } if _, ok := subOpMap[db.ConfigDB]["BGP_NEIGHBOR_AF"]; !ok { subOpMap[db.ConfigDB]["BGP_NEIGHBOR_AF"] = make(map[string]db.Value) } subOpMap[db.ConfigDB]["BGP_NEIGHBOR_AF"][inParams.key] = db.Value{Field: make(map[string]string)} subOpMap[db.ConfigDB]["BGP_NEIGHBOR_AF"][inParams.key].Field["send_community"] = "both" inParams.subOpDataMap[UPDATE] = &subOpMap return res_map, nil } community_type, _ := inParams.param.(ocbinds.E_OpenconfigBgpExt_BgpExtCommunityType) log.Info("YangToDb_bgp_nbr_community_type_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " community_type: ", community_type) if community_type == ocbinds.OpenconfigBgpExt_BgpExtCommunityType_STANDARD { res_map["send_community"] = "standard" } else if community_type == ocbinds.OpenconfigBgpExt_BgpExtCommunityType_EXTENDED { res_map["send_community"] = "extended" } else if community_type == ocbinds.OpenconfigBgpExt_BgpExtCommunityType_BOTH { res_map["send_community"] = "both" } else if community_type == ocbinds.OpenconfigBgpExt_BgpExtCommunityType_NONE { res_map["send_community"] = "none" } else if community_type == ocbinds.OpenconfigBgpExt_BgpExtCommunityType_LARGE { res_map["send_community"] = "large" } else if community_type == ocbinds.OpenconfigBgpExt_BgpExtCommunityType_ALL { res_map["send_community"] = "all" } else { err = errors.New("send_community Missing") return res_map, err } return res_map, nil }
var YangToDb_bgp_nbr_orf_type_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { err = errors.New("No Params") return res_map, err } if inParams.oper == DELETE { res_map["cap_orf"] = "" return res_map, nil } orf_type, _ := inParams.param.(ocbinds.E_OpenconfigBgpExt_BgpOrfType) log.Info("YangToDb_bgp_nbr_orf_type_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " orf_type: ", orf_type) if orf_type == ocbinds.OpenconfigBgpExt_BgpOrfType_SEND { res_map["cap_orf"] = "send" } else if orf_type == ocbinds.OpenconfigBgpExt_BgpOrfType_RECEIVE { res_map["cap_orf"] = "receive" } else if orf_type == ocbinds.OpenconfigBgpExt_BgpOrfType_BOTH { res_map["cap_orf"] = "both" } else { err = errors.New("ORF type Missing") return res_map, err } return res_map, nil }
var YangToDb_bgp_nbr_peer_type_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { err = errors.New("No Params") return res_map, err } if inParams.oper == DELETE { res_map["peer_type"] = "" return res_map, nil } peer_type, _ := inParams.param.(ocbinds.E_OpenconfigBgp_PeerType) log.Info("YangToDb_bgp_nbr_peer_type_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " peer-type: ", peer_type) if peer_type == ocbinds.OpenconfigBgp_PeerType_INTERNAL { res_map["peer_type"] = "internal" } else if peer_type == ocbinds.OpenconfigBgp_PeerType_EXTERNAL { res_map["peer_type"] = "external" } else { err = errors.New("Peer Type Missing") return res_map, err } return res_map, nil }
var YangToDb_bgp_nbr_tx_add_paths_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { err = errors.New("No Params") return res_map, err } if inParams.oper == DELETE { res_map["tx_add_paths"] = "" return res_map, nil } tx_add_paths_type, _ := inParams.param.(ocbinds.E_OpenconfigBgpExt_TxAddPathsType) log.Info("YangToDb_bgp_nbr_tx_add_paths_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " add-paths-type: ", tx_add_paths_type) if tx_add_paths_type == ocbinds.OpenconfigBgpExt_TxAddPathsType_TX_ALL_PATHS { res_map["tx_add_paths"] = "tx_all_paths" } else if tx_add_paths_type == ocbinds.OpenconfigBgpExt_TxAddPathsType_TX_BEST_PATH_PER_AS { res_map["tx_add_paths"] = "tx_best_path_per_as" } else { err = errors.New("Invalid add Paths type Missing") return res_map, err } return res_map, err }
var YangToDb_bgp_pgrp_afi_safi_name_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) res_map["NULL"] = "NULL" return res_map, nil }
var YangToDb_bgp_pgrp_community_type_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { err = errors.New("No Params") return res_map, err } if inParams.oper == DELETE { subOpMap := make(map[db.DBNum]map[string]map[string]db.Value) if _, ok := subOpMap[db.ConfigDB]; !ok { subOpMap[db.ConfigDB] = make(map[string]map[string]db.Value) } if _, ok := subOpMap[db.ConfigDB]["BGP_PEER_GROUP_AF"]; !ok { subOpMap[db.ConfigDB]["BGP_PEER_GROUP_AF"] = make(map[string]db.Value) } subOpMap[db.ConfigDB]["BGP_PEER_GROUP_AF"][inParams.key] = db.Value{Field: make(map[string]string)} subOpMap[db.ConfigDB]["BGP_PEER_GROUP_AF"][inParams.key].Field["send_community"] = "both" inParams.subOpDataMap[UPDATE] = &subOpMap return res_map, nil } community_type, _ := inParams.param.(ocbinds.E_OpenconfigBgpExt_BgpExtCommunityType) log.Info("YangToDb_bgp_pgrp_community_type_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " community_type: ", community_type) if community_type == ocbinds.OpenconfigBgpExt_BgpExtCommunityType_STANDARD { res_map["send_community"] = "standard" } else if community_type == ocbinds.OpenconfigBgpExt_BgpExtCommunityType_EXTENDED { res_map["send_community"] = "extended" } else if community_type == ocbinds.OpenconfigBgpExt_BgpExtCommunityType_BOTH { res_map["send_community"] = "both" } else if community_type == ocbinds.OpenconfigBgpExt_BgpExtCommunityType_NONE { res_map["send_community"] = "none" } else if community_type == ocbinds.OpenconfigBgpExt_BgpExtCommunityType_LARGE { res_map["send_community"] = "large" } else if community_type == ocbinds.OpenconfigBgpExt_BgpExtCommunityType_ALL { res_map["send_community"] = "all" } else { err = errors.New("send_community Missing") return res_map, err } return res_map, nil }
var YangToDb_bgp_pgrp_name_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) res_map["NULL"] = "NULL" return res_map, nil }
var YangToDb_bgp_pgrp_orf_type_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { err = errors.New("No Params") return res_map, err } if inParams.oper == DELETE { res_map["cap_orf"] = "" return res_map, nil } orf_type, _ := inParams.param.(ocbinds.E_OpenconfigBgpExt_BgpOrfType) log.Info("YangToDb_bgp_pgrp_orf_type_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " orf_type: ", orf_type) if orf_type == ocbinds.OpenconfigBgpExt_BgpOrfType_SEND { res_map["cap_orf"] = "send" } else if orf_type == ocbinds.OpenconfigBgpExt_BgpOrfType_RECEIVE { res_map["cap_orf"] = "receive" } else if orf_type == ocbinds.OpenconfigBgpExt_BgpOrfType_BOTH { res_map["cap_orf"] = "both" } else { err = errors.New("ORF type Missing") return res_map, err } return res_map, nil }
var YangToDb_bgp_pgrp_peer_type_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { err = errors.New("No Params") return res_map, err } if inParams.oper == DELETE { res_map["peer_type"] = "" return res_map, nil } peer_type, _ := inParams.param.(ocbinds.E_OpenconfigBgp_PeerType) log.Info("YangToDb_bgp_pgrp_peer_type_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " peer-type: ", peer_type) if peer_type == ocbinds.OpenconfigBgp_PeerType_INTERNAL { res_map["peer_type"] = "internal" } else if peer_type == ocbinds.OpenconfigBgp_PeerType_EXTERNAL { res_map["peer_type"] = "external" } else { err = errors.New("Peer Type Missing") return res_map, err } return res_map, nil }
var YangToDb_bgp_pgrp_tx_add_paths_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { err = errors.New("No Params") return res_map, err } if inParams.oper == DELETE { res_map["tx_add_paths"] = "" return res_map, nil } tx_add_paths_type, _ := inParams.param.(ocbinds.E_OpenconfigBgpExt_TxAddPathsType) log.Info("YangToDb_pgrp_tx_add_paths_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " add-paths-type: ", tx_add_paths_type) if tx_add_paths_type == ocbinds.OpenconfigBgpExt_TxAddPathsType_TX_ALL_PATHS { res_map["tx_add_paths"] = "tx_all_paths" } else if tx_add_paths_type == ocbinds.OpenconfigBgpExt_TxAddPathsType_TX_BEST_PATH_PER_AS { res_map["tx_add_paths"] = "tx_best_path_per_as" } else { err = errors.New("Invalid add Paths type Missing") return res_map, err } return res_map, nil }
var YangToDb_bgp_rt_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) res_map["NULL"] = "NULL" return res_map, nil }
var YangToDb_bgp_rt_type_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) res_map["route-target-type"] = "import" return res_map, nil }
var YangToDb_bgp_vni_number_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) res_map["NULL"] = "NULL" return res_map, nil }
var YangToDb_community_match_set_options_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { res_map["match_action"] = "" return res_map, err } if inParams.oper == DELETE { res_map["match_action"] = "" return res_map, nil } log.Info("YangToDb_community_match_set_options_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri) pathInfo := NewPathInfo(inParams.uri) if len(pathInfo.Vars) < 1 { err = errors.New("Invalid Key length") log.Error("Invalid Key length", len(pathInfo.Vars)) return res_map, err } setName := pathInfo.Var("community-set-name") log.Info("YangToDb_community_match_set_options_fld_xfmr: setName ", setName) if len(setName) == 0 { err = errors.New("set name is missing") log.Error("Set Name is Missing") return res_map, err } prev_match_action, _ := community_set_match_options_get_by_set_name(inParams.d, setName, "COMMUNITY_SET") match_opt, _ := inParams.param.(ocbinds.E_OpenconfigRoutingPolicy_MatchSetOptionsType) new_match_action := findInMap(MATCH_SET_ACTION_MAP, strconv.FormatInt(int64(match_opt), 10)) log.Info("YangToDb_community_match_set_options_fld_xfmr: New match Opt: ", new_match_action) if len(prev_match_action) > 0 { if prev_match_action != new_match_action { log.Error("YangToDb_community_match_set_options_fld_xfmr: Match option difference, Error previous", prev_match_action, " new ", new_match_action) err = errors.New("Match option difference") return nil, err } else { prev_match_action = new_match_action } } res_map["match_action"] = new_match_action return res_map, err }
var YangToDb_community_member_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error var community_list string var new_type string var prev_type string log.Info("YangToDb_community_member_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, "inParams : ", inParams) if inParams.param == nil { res_map["community_member@"] = "" return res_map, errors.New("Invalid Inputs") } pathInfo := NewPathInfo(inParams.uri) if len(pathInfo.Vars) < 1 { err = errors.New("Invalid Key length") log.Error("Invalid Key length", len(pathInfo.Vars)) return res_map, err } setName := pathInfo.Var("community-set-name") log.Info("YangToDb_community_member_fld_xfmr: setName ", setName) if len(setName) == 0 { err = errors.New("set name is missing") log.Error("Set Name is Missing") return res_map, err } is_member_exits, _ := community_set_is_community_members_exits(inParams.d, setName, "COMMUNITY_SET", "community_member@") if is_member_exits == true { prev_type, _ = community_set_type_get_by_set_name(inParams.d, setName, "COMMUNITY_SET") log.Info("YangToDb_community_member_fld_xfmr: prev_type ", prev_type) } members := inParams.param.([]ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySets_CommunitySet_Config_CommunityMember_Union) for _, member := range members { memberType := reflect.TypeOf(member).Elem() log.Info("YangToDb_community_member_fld_xfmr: member - ", member, " memberType: ", memberType) var b bytes.Buffer switch memberType { case reflect.TypeOf(ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySets_CommunitySet_Config_CommunityMember_Union_E_OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY{}): v := (member).(*ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySets_CommunitySet_Config_CommunityMember_Union_E_OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY) switch v.E_OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY { case ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NOPEER: community_list += "no-peer" + "," break case ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_ADVERTISE: community_list += "no-advertise" + "," break case ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT: community_list += "no-export" + "," break case ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT_SUBCONFED: community_list += "local-AS" + "," break } new_type = "STANDARD" break case reflect.TypeOf(ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySets_CommunitySet_Config_CommunityMember_Union_Uint32{}): v := (member).(*ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySets_CommunitySet_Config_CommunityMember_Union_Uint32) fmt.Fprintf(&b, "%d", v.Uint32) community_list += b.String() + "," new_type = "STANDARD" break case reflect.TypeOf(ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySets_CommunitySet_Config_CommunityMember_Union_String{}): v := (member).(*ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_BgpDefinedSets_CommunitySets_CommunitySet_Config_CommunityMember_Union_String) has_regex := strings.HasPrefix(v.String, "REGEX:") if has_regex == true { new_type = "EXPANDED" } else { new_type = "STANDARD" } community_list += strings.TrimPrefix(v.String, "REGEX:") + "," break } log.Info("YangToDb_community_member_fld_xfmr: new_type: ", new_type, " prev_type ", prev_type) if (len(prev_type) > 0) && (prev_type != new_type) { log.Error("YangToDb_community_member_fld_xfmr: Type Difference Error, previous", prev_type, " newType: ", new_type) err = errors.New("Type difference, Quit Operation") return res_map, err } else { prev_type = new_type } } res_map["community_member@"] = strings.TrimSuffix(community_list, ",") if (inParams.oper != DELETE) && (prev_type != "") { res_map["set_type"] = prev_type } log.Info("YangToDb_community_member_fld_xfmr: ", res_map["community_member@"], " type ", res_map["set_type"]) return res_map, err }
var YangToDb_community_set_name_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) log.Info("YangToDb_community_set_name_fld_xfmr: ", inParams.key) res_map["NULL"] = "NULL" return res_map, nil }
COMMUNITY SET API's
var YangToDb_ext_community_match_set_options_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { res_map["match_action"] = "" return res_map, err } if inParams.oper == DELETE { res_map["match_action"] = "" return res_map, nil } log.Info("YangToDb_ext_community_match_set_options_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri) pathInfo := NewPathInfo(inParams.uri) if len(pathInfo.Vars) < 1 { err = errors.New("Invalid Key length") log.Error("Invalid Key length", len(pathInfo.Vars)) return res_map, err } setName := pathInfo.Var("ext-community-set-name") log.Info("YangToDb_ext_community_match_set_options_fld_xfmr: setName ", setName) if len(setName) == 0 { err = errors.New("set name is missing") log.Error("Set Name is Missing") return res_map, err } prev_match_action, _ := community_set_match_options_get_by_set_name(inParams.d, setName, "EXTENDED_COMMUNITY_SET") match_opt, _ := inParams.param.(ocbinds.E_OpenconfigRoutingPolicy_MatchSetOptionsType) new_match_action := findInMap(MATCH_SET_ACTION_MAP, strconv.FormatInt(int64(match_opt), 10)) log.Info("YangToDb_ext_community_match_set_options_fld_xfmr: New match Opt: ", new_match_action) if len(prev_match_action) > 0 { if prev_match_action != new_match_action { log.Error("YangToDb_ext_community_match_set_options_fld_xfmr: Match option difference, Error previous", prev_match_action, " new ", new_match_action) err = errors.New("Match option difference") return nil, err } else { prev_match_action = new_match_action } } res_map["match_action"] = new_match_action return res_map, err }
var YangToDb_ext_community_member_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error var community_list string var new_type string var prev_type string log.Info("YangToDb_ext_community_member_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, "inParams : ", inParams) if inParams.param == nil { res_map["community_member@"] = "" return res_map, errors.New("Invalid Inputs") } pathInfo := NewPathInfo(inParams.uri) if len(pathInfo.Vars) < 1 { err = errors.New("Invalid Key length") log.Error("Invalid Key length", len(pathInfo.Vars)) return res_map, err } setName := pathInfo.Var("ext-community-set-name") log.Info("YangToDb_ext_community_member_fld_xfmr: setName ", setName) if len(setName) == 0 { err = errors.New("set name is missing") log.Error("Set Name is Missing") return res_map, err } is_member_exits, _ := community_set_is_community_members_exits(inParams.d, setName, "EXTENDED_COMMUNITY_SET", "community_member@") if is_member_exits == true { prev_type, _ = community_set_type_get_by_set_name(inParams.d, setName, "EXTENDED_COMMUNITY_SET") log.Info("YangToDb_ext_community_member_fld_xfmr: prev_type ", prev_type) } members := inParams.param.([]string) log.Info("YangToDb_ext_community_member_fld_xfmr: members", members) for _, member := range members { has_regex := strings.HasPrefix(member, "REGEX:") if has_regex == true { new_type = "EXPANDED" } else { new_type = "STANDARD" } member = strings.TrimPrefix(member, "REGEX:") has_rt := strings.HasPrefix(member, "route-target") has_ro := strings.HasPrefix(member, "route-origin") if (new_type == "STANDARD") && (has_rt == false) && (has_ro == false) { err = errors.New("Community member is not of type route-target or route-origin") log.Error("Community member is not of type route-target or route-origin") return res_map, err } community_list += member + "," log.Info("YangToDb_ext_community_member_fld_xfmr: new_type: ", new_type, " prev_type ", prev_type) if (len(prev_type) > 0) && (prev_type != new_type) { log.Error("YangToDb_ext_community_member_fld_xfmr: Type Difference Error, previous", prev_type, " newType: ", new_type) err = errors.New("Type difference, Quit Operation") return res_map, err } else { prev_type = new_type } } res_map["community_member@"] = strings.TrimSuffix(community_list, ",") if (inParams.oper != DELETE) && (prev_type != "") { res_map["set_type"] = prev_type } log.Info("YangToDb_ext_community_member_fld_xfmr: ", res_map["community_member@"], " type ", res_map["set_type"]) return res_map, err }
var YangToDb_ext_community_set_name_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) log.Info("YangToDb_ext_community_set_name_fld_xfmr: ", inParams.key) res_map["NULL"] = "NULL" return res_map, nil }
EXTENDED COMMUNITY SET API's
var YangToDb_intf_enabled_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var ifName string intfsObj := getIntfsRoot(inParams.ygRoot) if intfsObj == nil || len(intfsObj.Interface) < 1 { return res_map, nil } else { for infK, _ := range intfsObj.Interface { ifName = infK } } intfType, _, _ := getIntfTypeByName(ifName) if IntfTypeVxlan == intfType { return res_map, nil } enabled, _ := inParams.param.(*bool) var enStr string if *enabled == true { enStr = "up" } else { enStr = "down" } res_map[PORT_ADMIN_STATUS] = enStr return res_map, nil }
var YangToDb_intf_name_empty_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error return res_map, err }
var YangToDb_intf_name_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") if strings.HasPrefix(ifName, VXLAN) == true { res_map["NULL"] = "NULL" } else if strings.HasPrefix(ifName, VLAN) == true { vlanId := ifName[len("Vlan"):len(ifName)] res_map["vlanid"] = vlanId } else if strings.HasPrefix(ifName, PORTCHANNEL) == true { res_map["NULL"] = "NULL" } else if strings.HasPrefix(ifName, LOOPBACK) == true { res_map["NULL"] = "NULL" } else if strings.HasPrefix(ifName, ETHERNET) == true { intTbl := IntfTypeTblMap[IntfTypeEthernet] err = validateIntfExists(inParams.d, intTbl.cfgDb.portTN, ifName) if err != nil { errStr := "Interface " + ifName + " cannot be configured." return res_map, tlerr.InvalidArgsError{Format: errStr} } } log.Info("YangToDb_intf_name_xfm: res_map:", res_map) return res_map, err }
var YangToDb_intf_type_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var ifName string intfsObj := getIntfsRoot(inParams.ygRoot) if intfsObj == nil || len(intfsObj.Interface) < 1 { return res_map, nil } else { for infK, _ := range intfsObj.Interface { ifName = infK } } intfType, _, _ := getIntfTypeByName(ifName) if IntfTypeVxlan == intfType { return res_map, nil } else { intfTypeVal, _ := inParams.param.(int64) intTypeValStr := strconv.FormatInt(intfTypeVal, 10) res_map["type"] = intTypeValStr return res_map, nil } }
var YangToDb_lag_fallback_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error err = can_configure_fallback(inParams) if err != nil { return res_map, err } fallback, _ := inParams.param.(*bool) res_map["fallback"] = strconv.FormatBool(*fallback) return res_map, nil }
Handle fallback config
var YangToDb_lag_min_links_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error pathInfo := NewPathInfo(inParams.uri) ifKey := pathInfo.Var("name") log.Infof("Received Min links config for path: %s; template: %s vars: %v ifKey: %s", pathInfo.Path, pathInfo.Template, pathInfo.Vars, ifKey) var links uint16 err = get_min_links(inParams.d, &ifKey, &links) if err == nil && links != *(inParams.param.(*uint16)) { errStr := "Cannot reconfigure min links for an existing PortChannel: " + ifKey log.Info(errStr) err = tlerr.InvalidArgsError{Format: errStr} return res_map, err } minLinks, _ := inParams.param.(*uint16) res_map["min_links"] = strconv.Itoa(int(*minLinks)) return res_map, nil }
Handle min-links config
var YangToDb_lag_type_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { result := make(map[string]string) var err error if inParams.param == nil { return result, err } pathInfo := NewPathInfo(inParams.uri) ifKey := pathInfo.Var("name") log.Infof("Received Mode configuration for path: %s; template: %s vars: %v ifKey: %s", pathInfo.Path, pathInfo.Template, pathInfo.Vars, ifKey) var mode string err = get_lag_type(inParams.d, &ifKey, &mode) t, _ := inParams.param.(ocbinds.E_OpenconfigIfAggregate_AggregationType) user_mode := findInMap(LAG_TYPE_MAP, strconv.FormatInt(int64(t), 10)) if err == nil && mode != user_mode { errStr := "Cannot configure Mode for an existing PortChannel: " + ifKey err = tlerr.InvalidArgsError{Format: errStr} return result, err } log.Info("YangToDb_lag_type_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " type: ", t) result["static"] = user_mode return result, nil }
var YangToDb_nat_enable_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) enabled, _ := inParams.param.(*bool) var enStr string if *enabled == true { enStr = ENABLED } else { enStr = DISABLED } res_map[ADMIN_MODE] = enStr return res_map, nil }
var YangToDb_nat_entry_type_field_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { result := make(map[string]string) var err error if inParams.param == nil { return result, err } t, _ := inParams.param.(ocbinds.E_OpenconfigNat_NAT_ENTRY_TYPE) log.Info("YangToDb_nat_entry_type_field_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " type: ", t) result[NAT_ENTRY_TYPE] = findInMap(NAT_ENTRY_TYPE_MAP, strconv.FormatInt(int64(t), 10)) return result, err }
var YangToDb_nat_ip_field_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) ipPtr, _ := inParams.param.(*string) res_map["nat_ip"] = *ipPtr return res_map, nil }
var YangToDb_nat_type_field_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { result := make(map[string]string) var err error if inParams.param == nil { return result, err } t, _ := inParams.param.(ocbinds.E_OpenconfigNat_NAT_TYPE) log.Info("YangToDb_nat_type_field_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " type: ", t) result[NAT_TYPE] = findInMap(NAT_TYPE_MAP, strconv.FormatInt(int64(t), 10)) return result, err }
var YangToDb_network_instance_description_field_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error log.Info("YangToDb_network_instance_description_field_xfmr") return res_map, err }
YangToDb Field transformer for description in the top level network instance config
var YangToDb_network_instance_enabled_addr_family_field_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error log.Info("YangToDb_network_instance_enabled_addr_fam_field_xfmr") return res_map, err }
YangToDb Field transformer for enabled_address_family in the top level network instance config
var YangToDb_network_instance_enabled_field_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error log.Info("YangToDb_network_instance_enabled_field_xfmr") nwInstObj := getNwInstRoot(inParams.ygRoot) if nwInstObj.NetworkInstance == nil { return res_map, errors.New("Network instance not set") } if strings.HasPrefix(inParams.key, "Vlan") { log.Infof("YangToDb Vlan key %s, do not add fallback attriubtes.", inParams.key) return res_map, err } pathInfo := NewPathInfo(inParams.uri) if len(pathInfo.Vars) < 1 { return res_map, errors.New("Invalid xpath, key attributes not found") } targetUriPath, err := getYangPathFromUri(pathInfo.Path) log.Info("YangToDb_network_instance_enabled_field_xfmr targetUri: ", targetUriPath) keyName := pathInfo.Var("name") if keyName != "mgmt" { log.Info("YangToDb_network_instance_enabled_field_xfmr, not mgmt vrf ", keyName) res_map["fallback"] = "false" return res_map, err } enabled, _ := inParams.param.(*bool) var enStr string if *enabled == true { enStr = "true" } else { enStr = "false" } res_map[MGMT_VRF_ENABLE] = enStr log.Info("YangToDb_network_instance_enabled_field_xfmr: ", res_map) return res_map, err }
YangToDB Field transformer for top level network instance config "enabled"
var YangToDb_network_instance_mtu_field_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error log.Info("YangToDb_network_instance_mtu_field_xfmr") return res_map, err }
YangToDb Field transformer for mtu in the top level network instance config
var YangToDb_network_instance_name_field_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error log.Info("YangToDb_network_instance_name_field_xfmr") if inParams.key != "" && strings.HasPrefix(inParams.key, "Vlan") { vlanIdStr := strings.TrimPrefix(inParams.key, "Vlan") res_map["vlanid"] = vlanIdStr } else { res_map["NULL"] = "NULL" } return res_map, err }
YangToDb Field transformer for name in the top level network instance config
var YangToDb_network_instance_name_key_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error log.Info("YangToDb_network_instance_name_key_xfmr") return res_map, err }
YangToDb Field transformer for name(key) in the top level network instance
var YangToDb_network_instance_route_distinguisher_field_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error log.Info("YangToDb_network_instance_route_distinguisher_field_xfmr") return res_map, err }
TBD for data vrf YangToDb Field transformer for route_distinguisher in the top level network instance config
var YangToDb_network_instance_router_id_field_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error log.Info("YangToDb_network_instance_router_id_field_xfmr") return res_map, err }
YangToDb Field transformer for router_id in the top level network instance config
var YangToDb_network_instance_type_field_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error log.Info("YangToDb_network_instance_type_field_xfmr") return res_map, err }
YangToDb Field transformer for type in the top level network instance config
var YangToDb_nw_inst_vxlan_source_nve_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if log.V(3) { log.Info("YangToDb_nw_inst_vxlan_source_nve_xfmr ==> printing target object request ==> ", inParams.param) } path, err := getVxlanNiUriPath(inParams.uri) if err != nil { return res_map, err } reqP := &vxlanReqProcessor{&inParams.requestUri, &inParams.uri, path, inParams.oper, (*inParams.ygRoot).(*ocbinds.Device), inParams.param, inParams.d, inParams.dbs, nil, nil, nil, nil, &inParams} if err = reqP.setVxlanNetInstObjFromReq(); err != nil { return res_map, err } if log.V(3) { log.Info("YangToDb_nw_inst_vxlan_source_nve_xfmr ==> printing vxlanNetInstObj object request ==> ", (*reqP.vxlanNetInstObj)) } niName := *(reqP.vxlanNetInstObj.Name) res_map["vlan"] = niName if log.V(3) { log.Info("YangToDb_nw_inst_vxlan_source_nve_xfmr ==> res_map ===> ", res_map) } return res_map, err }
var YangToDb_nw_inst_vxlan_vni_id_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if log.V(3) { log.Info("YangToDb_nw_inst_vxlan_vni_id_xfmr ==> printing target object inParams.uri ==> ", (inParams.uri)) } path, err := getVxlanNiUriPath(inParams.uri) if err != nil { return res_map, err } reqP := &vxlanReqProcessor{&inParams.requestUri, &inParams.uri, path, inParams.oper, (*inParams.ygRoot).(*ocbinds.Device), inParams.param, inParams.d, inParams.dbs, nil, nil, nil, nil, &inParams} if err := reqP.setVxlanNetInstObjFromReq(); err != nil { return nil, err } if log.V(3) { log.Info("YangToDb_nw_inst_vxlan_vni_id_xfmr ==> printing vxlanNetInstObj object request ==> ", (*reqP.vxlanNetInstObj)) } if reqP.vxlanNetInstObj.VxlanVniInstances == nil { return res_map, tlerr.NotFound("Resource Not Found") } for _, vxlanNiMap := range reqP.vxlanNetInstObj.VxlanVniInstances.VniInstance { res_map["vni"] = strconv.Itoa(int(*vxlanNiMap.Config.VniId)) break } if log.V(3) { log.Info("YangToDb_nw_inst_vxlan_vni_id_xfmr ==> res_map ===> ", res_map) } return res_map, err }
var YangToDb_prefix_action_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { return res_map, err } if inParams.oper == DELETE { res_map["action"] = "" return res_map, nil } action, _ := inParams.param.(ocbinds.E_OpenconfigRoutingPolicyExt_RoutingPolicyExtActionType) log.Info("YangToDb_prefix_action_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " route-operation: ", action) if action == ocbinds.OpenconfigRoutingPolicyExt_RoutingPolicyExtActionType_PERMIT { res_map["action"] = "permit" } else if action == ocbinds.OpenconfigRoutingPolicyExt_RoutingPolicyExtActionType_DENY { res_map["action"] = "deny" } return res_map, err }
var YangToDb_prefix_set_mode_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { res_map["mode"] = "" return res_map, err } if inParams.oper == DELETE { res_map["mode"] = "" return res_map, nil } pathInfo := NewPathInfo(inParams.uri) setName := pathInfo.Var("name") if len(setName) == 0 { err = errors.New("set name is missing") log.Error("Set Name is Missing") return res_map, err } is_prefixes_exits := prefixes_exits_by_set_name(inParams.d, setName, "PREFIX") log.Info("YangToDb_prefix_set_mode_fld_xfmr: setName ", setName, "is_prefixes_exits ", is_prefixes_exits) mode, _ := inParams.param.(ocbinds.E_OpenconfigRoutingPolicy_RoutingPolicy_DefinedSets_PrefixSets_PrefixSet_Config_Mode) log.Info("YangToDb_prefix_set_mode_fld_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " Mode: ", mode) new_mode := findInMap(PREFIX_SET_MODE_MAP, strconv.FormatInt(int64(mode), 10)) prev_mode, _ := prefix_set_mode_get_by_set_name(inParams.d, setName, "PREFIX_SET") log.Info("YangToDb_prefix_set_mode_fld_xfmr: prev_mode ", prev_mode, "new mode ", res_map["mode"], "is_prefixes_exits ", is_prefixes_exits) if (is_prefixes_exits == true) && (prev_mode != new_mode) { err = errors.New("Prefixes Configured already, Mode Change not supported") log.Error("Prefixes Configured already, Mode Change not supported") return res_map, err } res_map["mode"] = new_mode return res_map, err }
var YangToDb_ptp_boolean_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error var outval string if inParams.param == nil { log.Info("YangToDb_ptp_boolean_xfmr Error: ") return res_map, err } log.Info("YangToDb_ptp_boolean_xfmr : ", *inParams.ygRoot, " Xpath: ", inParams.uri) log.Info("YangToDb_ptp_boolean_xfmr inParams.key: ", inParams.key) log.Info("YangToDb_ptp_boolean_xfmr inParams.curDb: ", inParams.curDb) inval, _ := inParams.param.(*bool) _, field := filepath.Split(inParams.uri) log.Info("YangToDb_ptp_boolean_xfmr inval: ", *inval, " field: ", field) if *inval { outval = "1" } else { outval = "0" } log.Info("YangToDb_ptp_boolean_xfmr outval: ", outval, " field: ", field) res_map[field] = outval return res_map, err }
var YangToDb_ptp_clock_identity_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error var field string var identity []byte if inParams.param == nil { log.Info("YangToDb_ptp_clock_identity_xfmr Error: ") return res_map, err } log.Info("YangToDb_ptp_clock_identity_xfmr : ", *inParams.ygRoot, " Xpath: ", inParams.uri) log.Info("YangToDb_ptp_clock_identity_xfmr inParams.key: ", inParams.key) ptpObj := getPtpRoot(inParams.ygRoot) if strings.Contains(inParams.uri, "grandmaster-identity") { identity = ptpObj.InstanceList[0].ParentDs.GrandmasterIdentity field = "grandmaster-identity" } else if strings.Contains(inParams.uri, "parent-port-identity") { identity = ptpObj.InstanceList[0].ParentDs.ParentPortIdentity.ClockIdentity field = "clock-identity" } else if strings.Contains(inParams.uri, "default-ds") { identity = ptpObj.InstanceList[0].DefaultDs.ClockIdentity field = "clock-identity" } enc := fmt.Sprintf("%02x%02x%02x.%02x%02x.%02x%02x%02x", identity[0], identity[1], identity[2], identity[3], identity[4], identity[5], identity[6], identity[7]) log.Info("YangToDb_ptp_clock_identity_xfmr enc: ", enc, " field: ", field) res_map[field] = enc return res_map, err }
var YangToDb_ptp_clock_type_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var outval string var err error if inParams.param == nil { log.Info("YangToDb_ptp_clock_type_xfmr Error: ") return res_map, err } log.Info("YangToDb_ptp_clock_type_xfmr : ", *inParams.ygRoot, " Xpath: ", inParams.uri) log.Info("YangToDb_ptp_clock_type_xfmr inParams.key: ", inParams.key) pathInfo := NewPathInfo(inParams.uri) instance_id, _ := strconv.ParseUint(pathInfo.Var("instance-number"), 10, 64) log.Info("YangToDb_ptp_clock_type_xfmr instance_number : ", instance_id) ptpObj := getPtpRoot(inParams.ygRoot) outval = *ptpObj.InstanceList[uint32(instance_id)].DefaultDs.ClockType if outval == "P2P_TC" { return res_map, tlerr.InvalidArgsError{Format: "peer-to-peer-transparent-clock is not supported"} } log.Info("YangToDb_ptp_clock_type_xfmr outval: ", outval) _, field := filepath.Split(inParams.uri) domain_profile := "" network_transport := "" unicast_multicast := "" ts := db.TableSpec{Name: "PTP_CLOCK"} ca := make([]string, 1, 1) ca[0] = "GLOBAL" akey := db.Key{Comp: ca} entry, err := inParams.d.GetEntry(&ts, akey) if entry.Has("domain-profile") { domain_profile = entry.Get("domain-profile") } if entry.Has("network-transport") { network_transport = entry.Get("network-transport") } if entry.Has("unicast-multicast") { unicast_multicast = entry.Get("unicast-multicast") } log.Info("YangToDb_ptp_clock_type_xfmr domain_profile : ", domain_profile, " network-transport : ", network_transport, " unicast-multicast : ", unicast_multicast) if outval == "P2P_TC" || outval == "E2E_TC" { if domain_profile == "G.8275.x" { return res_map, tlerr.InvalidArgsError{Format: "transparent-clock not supported with G.8275.2"} } if domain_profile == "ieee1588" && unicast_multicast == "unicast" { return res_map, tlerr.InvalidArgsError{Format: "transparent-clock not supported with default profile and unicast"} } } if outval == "BC" { if domain_profile == "G.8275.x" && network_transport == "L2" { return res_map, tlerr.InvalidArgsError{Format: "boundary-clock not supported with G.8275.2 and L2"} } if domain_profile == "G.8275.x" && unicast_multicast == "multicast" { return res_map, tlerr.InvalidArgsError{Format: "boundary-clock not supported with G.8275.2 and multicast"} } if domain_profile == "G.8275.x" && network_transport == "UDPv6" { return res_map, tlerr.InvalidArgsError{Format: "boundary-clock not supported with G.8275.2 and ipv6"} } } log.Info("YangToDb_ptp_clock_type_xfmr outval: ", outval, " field: ", field) res_map[field] = outval return res_map, nil }
var YangToDb_ptp_delay_mech_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error var outval string if inParams.param == nil { log.Info("YangToDb_ptp_delay_mech_xfmr Error: ") return res_map, err } log.Info("YangToDb_ptp_delay_mech_xfmr : ", *inParams.ygRoot, " Xpath: ", inParams.uri) log.Info("YangToDb_ptp_delay_mech_xfmr inParams.key: ", inParams.key) inval, _ := inParams.param.(ocbinds.E_IETFPtp_DelayMechanismEnumeration) _, field := filepath.Split(inParams.uri) log.Info("YangToDb_ptp_delay_mech_xfmr outval: ", outval, " field: ", field) res_map[field] = findInMap(PTP_DELAY_MECH_MAP, strconv.FormatInt(int64(inval), 10)) return res_map, err }
var YangToDb_ptp_domain_number_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var outval uint8 var err error if inParams.param == nil { log.Info("YangToDb_ptp_domain_number_xfmr Error: ") return res_map, err } log.Info("YangToDb_ptp_domain_number_xfmr : ", *inParams.ygRoot, " Xpath: ", inParams.uri) log.Info("YangToDb_ptp_domain_number_xfmr inParams.key: ", inParams.key) pathInfo := NewPathInfo(inParams.uri) instance_id, _ := strconv.ParseUint(pathInfo.Var("instance-number"), 10, 64) log.Info("YangToDb_ptp_domain_number_xfmr instance_number : ", instance_id) ptpObj := getPtpRoot(inParams.ygRoot) outval = *ptpObj.InstanceList[uint32(instance_id)].DefaultDs.DomainNumber log.Info("YangToDb_ptp_domain_number_xfmr outval: ", outval) _, field := filepath.Split(inParams.uri) domain_profile := "" ts := db.TableSpec{Name: "PTP_CLOCK"} ca := make([]string, 1, 1) ca[0] = "GLOBAL" akey := db.Key{Comp: ca} entry, err := inParams.d.GetEntry(&ts, akey) if entry.Has("domain-profile") { domain_profile = entry.Get("domain-profile") } log.Info("YangToDb_ptp_domain_number_xfmr domain_profile : ", domain_profile) if domain_profile == "G.8275.x" { if outval < 44 || outval > 63 { return res_map, tlerr.InvalidArgsError{Format: "domain must be in range 44-63 with G.8275.2"} } } log.Info("YangToDb_ptp_domain_number_xfmr outval: ", outval, " field: ", field) res_map[field] = strconv.FormatInt(int64(outval), 10) return res_map, nil }
var YangToDb_ptp_domain_profile_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var outval string var err error if inParams.param == nil { log.Info("YangToDb_ptp_domain_profile_xfmr Error: ") return res_map, err } log.Info("YangToDb_ptp_domain_profile_xfmr : ", *inParams.ygRoot, " Xpath: ", inParams.uri) log.Info("YangToDb_ptp_domain_profile_xfmr inParams.key: ", inParams.key) pathInfo := NewPathInfo(inParams.uri) instance_id, _ := strconv.ParseUint(pathInfo.Var("instance-number"), 10, 64) log.Info("YangToDb_ptp_domain_profile_xfmr instance_number : ", instance_id) ptpObj := getPtpRoot(inParams.ygRoot) outval = *ptpObj.InstanceList[uint32(instance_id)].DefaultDs.DomainProfile if outval == "G.8275.1" { return res_map, tlerr.InvalidArgsError{Format: "g8275.1 is not supported"} } if outval == "G.8275.2" { outval = "G.8275.x" } log.Info("YangToDb_ptp_domain_profile_xfmr outval: ", outval) _, field := filepath.Split(inParams.uri) var domain_number uint64 network_transport := "" unicast_multicast := "" clock_type := "" ts := db.TableSpec{Name: "PTP_CLOCK"} ca := make([]string, 1, 1) ca[0] = "GLOBAL" akey := db.Key{Comp: ca} entry, err := inParams.d.GetEntry(&ts, akey) if entry.Has("domain-number") { domain_number, _ = strconv.ParseUint(entry.Get("domain-number"), 10, 64) } if entry.Has("network-transport") { network_transport = entry.Get("network-transport") } if entry.Has("unicast-multicast") { unicast_multicast = entry.Get("unicast-multicast") } if entry.Has("clock-type") { clock_type = entry.Get("clock-type") } log.Info("YangToDb_ptp_domain_profile_xfmr domain_number : ", domain_number, " network-transport : ", network_transport, " unicast-multicast : ", unicast_multicast, " clock-type : ", clock_type) if outval == "G.8275.x" { if clock_type == "BC" && network_transport == "L2" { return res_map, tlerr.InvalidArgsError{Format: "G.8275.2 not supported with L2 transport"} } if clock_type == "BC" && unicast_multicast == "multicast" { return res_map, tlerr.InvalidArgsError{Format: "G.8275.2 not supported with multicast transport"} } if clock_type == "BC" && (domain_number < 44 || domain_number > 63) { return res_map, tlerr.InvalidArgsError{Format: "domain must be in range 44-63 with G.8275.2"} } if clock_type == "BC" && network_transport == "UDPv6" { return res_map, tlerr.InvalidArgsError{Format: "ipv6 not supported with boundary-clock and G.8275.2"} } if clock_type == "P2P_TC" || clock_type == "E2E_TC" { return res_map, tlerr.InvalidArgsError{Format: "G.8275.2 not supported with transparent-clock"} } } if outval == "ieee1588" { if unicast_multicast == "unicast" && (clock_type == "PTP_TC" || clock_type == "E2E_TC") { return res_map, tlerr.InvalidArgsError{Format: "default profile not supported with transparent-clock and unicast"} } } log.Info("YangToDb_ptp_domain_profile_xfmr outval: ", outval, " field: ", field) res_map[field] = outval return res_map, nil }
var YangToDb_ptp_inst_number_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) res_map["NULL"] = "NULL" return res_map, nil }
var YangToDb_ptp_network_transport_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var outval string var err error if inParams.param == nil { log.Info("YangToDb_ptp_network_transport_xfmr Error: ") return res_map, err } log.Info("YangToDb_ptp_network_transport_xfmr : ", *inParams.ygRoot, " Xpath: ", inParams.uri) log.Info("YangToDb_ptp_network_transport_xfmr inParams.key: ", inParams.key) pathInfo := NewPathInfo(inParams.uri) instance_id, _ := strconv.ParseUint(pathInfo.Var("instance-number"), 10, 64) log.Info("YangToDb_ptp_network_transport_xfmr instance_number : ", instance_id) ptpObj := getPtpRoot(inParams.ygRoot) outval = *ptpObj.InstanceList[uint32(instance_id)].DefaultDs.NetworkTransport log.Info("YangToDb_ptp_network_transport_xfmr outval: ", outval) _, field := filepath.Split(inParams.uri) domain_profile := "" ts := db.TableSpec{Name: "PTP_CLOCK"} ca := make([]string, 1, 1) ca[0] = "GLOBAL" akey := db.Key{Comp: ca} entry, err := inParams.d.GetEntry(&ts, akey) if entry.Has("domain-profile") { domain_profile = entry.Get("domain-profile") } log.Info("YangToDb_ptp_network_transport_xfmr domain_profile : ", domain_profile) if outval == "L2" && domain_profile == "G.8275.x" { return res_map, tlerr.InvalidArgsError{Format: "L2 not supported with G.8275.2"} } log.Info("YangToDb_ptp_network_transport_xfmr outval: ", outval, " field: ", field) res_map[field] = outval return res_map, nil }
var YangToDb_ptp_port_state_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error var outval string if inParams.param == nil { log.Info("YangToDb_ptp_port_state_xfmr Error: ") return res_map, err } log.Info("YangToDb_ptp_port_state_xfmr : ", *inParams.ygRoot, " Xpath: ", inParams.uri) log.Info("YangToDb_ptp_port_state_xfmr inParams.key: ", inParams.key) inval, _ := inParams.param.(ocbinds.E_IETFPtp_PortStateEnumeration) _, field := filepath.Split(inParams.uri) switch inval { case ocbinds.IETFPtp_PortStateEnumeration_initializing: outval = "1" case ocbinds.IETFPtp_PortStateEnumeration_faulty: outval = "2" case ocbinds.IETFPtp_PortStateEnumeration_disabled: outval = "3" case ocbinds.IETFPtp_PortStateEnumeration_listening: outval = "4" case ocbinds.IETFPtp_PortStateEnumeration_pre_master: outval = "5" case ocbinds.IETFPtp_PortStateEnumeration_master: outval = "6" case ocbinds.IETFPtp_PortStateEnumeration_passive: outval = "7" case ocbinds.IETFPtp_PortStateEnumeration_uncalibrated: outval = "8" case ocbinds.IETFPtp_PortStateEnumeration_slave: outval = "9" } log.Info("YangToDb_ptp_port_state_xfmr outval: ", outval, " field: ", field) res_map[field] = outval return res_map, err }
var YangToDb_ptp_udp6_scope_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var inval uint8 var err error if inParams.param == nil { log.Info("YangToDb_ptp_udp6_scope_xfmr Error: ") return res_map, err } log.Info("YangToDb_ptp_udp6_scope_xfmr : ", *inParams.ygRoot, " Xpath: ", inParams.uri) log.Info("YangToDb_ptp_udp6_scope_xfmr inParams.key: ", inParams.key) pathInfo := NewPathInfo(inParams.uri) instance_id, _ := strconv.ParseUint(pathInfo.Var("instance-number"), 10, 64) port_number, _ := strconv.ParseUint(pathInfo.Var("port-number"), 10, 64) log.Info("YangToDb_ptp_udp6_scope_xfmr instance_number : ", instance_id, " port_number: ", port_number) ptpObj := getPtpRoot(inParams.ygRoot) inval = *ptpObj.InstanceList[uint32(instance_id)].DefaultDs.Udp6Scope log.Info("YangToDb_ptp_udp6_scope_xfmr inval: ", inval) _, field := filepath.Split(inParams.uri) if inval > 0xf { return res_map, tlerr.InvalidArgsError{Format: "Invalid value passed for udp6-scope"} } outval := fmt.Sprintf("0x%x", inval) log.Info("YangToDb_ptp_udp6_scope_xfmr outval: ", outval, " field: ", field) res_map[field] = outval return res_map, nil }
var YangToDb_ptp_unicast_multicast_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var outval string var err error if inParams.param == nil { log.Info("YangToDb_ptp_unicast_multicast_xfmr Error: ") return res_map, err } log.Info("YangToDb_ptp_unicast_multicast_xfmr : ", *inParams.ygRoot, " Xpath: ", inParams.uri) log.Info("YangToDb_ptp_unicast_multicast_xfmr inParams.key: ", inParams.key) pathInfo := NewPathInfo(inParams.uri) instance_id, _ := strconv.ParseUint(pathInfo.Var("instance-number"), 10, 64) log.Info("YangToDb_ptp_unicast_multicast_xfmr instance_number : ", instance_id) ptpObj := getPtpRoot(inParams.ygRoot) outval = *ptpObj.InstanceList[uint32(instance_id)].DefaultDs.UnicastMulticast log.Info("YangToDb_ptp_unicast_multicast_xfmr outval: ", outval) _, field := filepath.Split(inParams.uri) domain_profile := "" network_transport := "" clock_type := "" ts := db.TableSpec{Name: "PTP_CLOCK"} ca := make([]string, 1, 1) ca[0] = "GLOBAL" akey := db.Key{Comp: ca} entry, err := inParams.d.GetEntry(&ts, akey) if entry.Has("domain-profile") { domain_profile = entry.Get("domain-profile") } if entry.Has("network-transport") { network_transport = entry.Get("network-transport") } if entry.Has("clock-type") { clock_type = entry.Get("clock-type") } log.Info("YangToDb_ptp_unicast_multicast_xfmr domain_profile : ", domain_profile, " network_transport : ", network_transport, " clock_type : ", clock_type) if outval == "multicast" { if domain_profile == "G.8275.x" { return res_map, tlerr.InvalidArgsError{Format: "multicast not supported with G.8275.2"} } keys, tblErr := inParams.d.GetKeys(&db.TableSpec{Name: "PTP_PORT|GLOBAL"}) if tblErr == nil { for _, key := range keys { entry2, err2 := inParams.d.GetEntry(&db.TableSpec{Name: "PTP_PORT"}, key) if err2 == nil { if entry2.Has("unicast-table") { log.Info("YangToDb_ptp_unicast_multicast_xfmr unicast-table : ", entry2.Get("unicast-table")) if entry2.Get("unicast-table") != "" { return res_map, tlerr.InvalidArgsError{Format: "master table must be removed from " + key.Comp[1]} } } } } } } if outval == "unicast" { if domain_profile == "ieee1588" && (clock_type == "PTP_TC" || clock_type == "E2E_TC") { return res_map, tlerr.InvalidArgsError{Format: "unicast not supported with transparent-clock and default profile"} } if network_transport == "UDPv6" { return res_map, tlerr.InvalidArgsError{Format: "ipv6 not supported with unicast"} } } log.Info("YangToDb_ptp_unicast_multicast_xfmr outval: ", outval, " field: ", field) res_map[field] = outval return res_map, nil }
var YangToDb_ptp_unicast_table_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var outval string var err error if inParams.param == nil { log.Info("YangToDb_ptp_unicast_table_xfmr Error: ") return res_map, err } log.Info("YangToDb_ptp_unicast_table_xfmr : ", *inParams.ygRoot, " Xpath: ", inParams.uri) log.Info("YangToDb_ptp_unicast_table_xfmr inParams.key: ", inParams.key) pathInfo := NewPathInfo(inParams.uri) instance_id, _ := strconv.ParseUint(pathInfo.Var("instance-number"), 10, 64) port_number, _ := strconv.ParseUint(pathInfo.Var("port-number"), 10, 64) log.Info("YangToDb_ptp_unicast_table_xfmr instance_number : ", instance_id, " port_number: ", port_number) ptpObj := getPtpRoot(inParams.ygRoot) outval = *ptpObj.InstanceList[uint32(instance_id)].PortDsList[uint16(port_number)].UnicastTable log.Info("YangToDb_ptp_unicast_table_xfmr outval: ", outval) _, field := filepath.Split(inParams.uri) unicast_multicast := "" ts := db.TableSpec{Name: "PTP_CLOCK"} ca := make([]string, 1, 1) ca[0] = "GLOBAL" akey := db.Key{Comp: ca} entry, err := inParams.d.GetEntry(&ts, akey) if entry.Has("unicast-multicast") { unicast_multicast = entry.Get("unicast-multicast") } if unicast_multicast == "multicast" { return res_map, tlerr.InvalidArgsError{Format: "master-table is not needed in with multicast transport"} } if outval != "" { addresses := strings.Split(outval, ",") var prev_tmp E_Ptp_AddressTypeEnumeration var tmp E_Ptp_AddressTypeEnumeration var first bool first = true for _, address := range addresses { tmp = check_address(address) if PTP_ADDRESSTYPE_UNKNOWN == tmp { return res_map, tlerr.InvalidArgsError{Format: "Invalid value passed for unicast-table"} } if !first && tmp != prev_tmp { return res_map, tlerr.InvalidArgsError{Format: "Mismatched addresses passed in unicast-table"} } prev_tmp = tmp first = false } } log.Info("YangToDb_ptp_unicast_table_xfmr outval: ", outval, " field: ", field) res_map[field] = outval return res_map, nil }
var YangToDb_route_map_action_policy_result_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { return res_map, err } if inParams.oper == DELETE { res_map["route_operation"] = "" return res_map, nil } action, _ := inParams.param.(ocbinds.E_OpenconfigRoutingPolicy_PolicyResultType) log.Info("YangToDb_route_map_action_policy_result_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " route-operation: ", action) if action == ocbinds.OpenconfigRoutingPolicy_PolicyResultType_ACCEPT_ROUTE { res_map["route_operation"] = "permit" } else if action == ocbinds.OpenconfigRoutingPolicy_PolicyResultType_REJECT_ROUTE { res_map["route_operation"] = "deny" } return res_map, err }
var YangToDb_route_map_match_protocol_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { return res_map, err } if inParams.oper == DELETE { res_map["match_protocol"] = "" return res_map, nil } protocol, _ := inParams.param.(ocbinds.E_OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE) log.Info("YangToDb_route_map_match_protocol_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " protocol: ", protocol) switch protocol { case ocbinds.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_BGP: res_map["match_protocol"] = "bgp" case ocbinds.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_DIRECTLY_CONNECTED: res_map["match_protocol"] = "connected" case ocbinds.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_ISIS: res_map["match_protocol"] = "isis" case ocbinds.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_OSPF: res_map["match_protocol"] = "ospf" case ocbinds.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_OSPF3: res_map["match_protocol"] = "ospf3" case ocbinds.OpenconfigPolicyTypes_INSTALL_PROTOCOL_TYPE_STATIC: res_map["match_protocol"] = "static" default: } return res_map, err }
var YangToDb_route_map_match_set_options_restrict_type_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { return res_map, err } action, _ := inParams.param.(ocbinds.E_OpenconfigRoutingPolicy_MatchSetOptionsRestrictedType) log.Info("YangToDb_route_map_match_set_options_restrict_type_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " match-set-option: ", action) if action != ocbinds.OpenconfigRoutingPolicy_MatchSetOptionsRestrictedType_ANY { err = errors.New("Invalid match set option") return res_map, err } return res_map, err }
var YangToDb_route_map_match_set_options_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) var err error if inParams.param == nil { return res_map, err } action, _ := inParams.param.(ocbinds.E_OpenconfigRoutingPolicy_MatchSetOptionsType) log.Info("YangToDb_route_map_match_set_options_xfmr: ", inParams.ygRoot, " Xpath: ", inParams.uri, " match-set-option: ", action) if action != ocbinds.OpenconfigRoutingPolicy_MatchSetOptionsType_ANY { err = errors.New("Invalid match set option") return res_map, err } return res_map, err }
var YangToDb_route_table_addr_family_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) res_map["NULL"] = "NULL" return res_map, nil }
var YangToDb_sag_ipv4_enable_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) enabled, _ := inParams.param.(*bool) var enStr string if *enabled == true { enStr = "enable" } else { enStr = "disable" } res_map["IPv4"] = enStr return res_map, nil }
var YangToDb_sag_ipv6_enable_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) enabled, _ := inParams.param.(*bool) var enStr string if *enabled == true { enStr = "enable" } else { enStr = "disable" } res_map["IPv6"] = enStr return res_map, nil }
var YangToDb_vlan_nd_suppress_fld_xfmr FieldXfmrYangToDb = func(inParams XfmrParams) (map[string]string, error) { res_map := make(map[string]string) pathInfo := NewPathInfo(inParams.uri) vlanIdStr := pathInfo.Var("name") if !strings.HasPrefix(vlanIdStr, "Vlan") { return res_map, tlerr.InvalidArgs("Invalid key: %v", vlanIdStr) } log.Infof("YangToDb_vlan_nd_suppress_fld_xfmr: Params: %v", inParams.param) if inParams.param != nil { val, _ := inParams.param.(ocbinds.E_OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_NeighbourSuppress_Config_ArpAndNdSuppress) if val == ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_NeighbourSuppress_Config_ArpAndNdSuppress_enable { res_map["suppress"] = "on" } } return res_map, nil }
type HostResult ¶
type HostResult struct { Body []interface{} Err error }
HostResult contains the body of the response and the error if any, when the endpoint finishes servicing the D-Bus request.
func HostQuery ¶
func HostQuery(endpoint string, args ...interface{}) (result HostResult)
HostQuery calls the corresponding D-Bus endpoint on the host and returns any error and response body
type IntfTblData ¶
type IntfTblData struct { CountersHdl CounterData // contains filtered or unexported fields }
type JSONSystem ¶
type KeySpec ¶
type KeyXfmrDbToYang ¶
type KeyXfmrDbToYang func(inParams XfmrParams) (map[string]interface{}, error)
*
- KeyXfmrDbToYang type is defined to use for conversion of DB key to Yang key
- Transformer function definition.
- Param: XfmrParams structure having Database info, operation, Database keys to access db entry
- Return: multi dimensional map to hold the yang key attributes of complete xpath, error *
var DbToYang_acl_entry_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error entry_key := inParams.key log.Info("DbToYang_acl_entry_key_xfmr: ", entry_key) key := strings.Split(entry_key, "|") if len(key) < 2 { err = errors.New("Invalid key for acl entries.") log.Info("Invalid Keys for acl enmtries", entry_key) return rmap, err } dbAclRule := key[1] seqId := strings.Replace(dbAclRule, "RULE_", "", 1) rmap["sequence-id"], _ = strconv.ParseFloat(seqId, 64) return rmap, err }
var DbToYang_acl_set_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error var aclNameStr string var aclTypeStr string aclkey := inParams.key log.Info("DbToYang_acl_set_key_xfmr: ", aclkey) if strings.Contains(aclkey, "_"+OPENCONFIG_ACL_TYPE_IPV4) { aclNameStr = strings.Replace(aclkey, "_"+OPENCONFIG_ACL_TYPE_IPV4, "", 1) aclTypeStr = "ACL_IPV4" } else if strings.Contains(aclkey, "_"+OPENCONFIG_ACL_TYPE_IPV6) { aclNameStr = strings.Replace(aclkey, "_"+OPENCONFIG_ACL_TYPE_IPV6, "", 1) aclTypeStr = "ACL_IPV6" } else if strings.Contains(aclkey, "_"+OPENCONFIG_ACL_TYPE_L2) { aclNameStr = strings.Replace(aclkey, "_"+OPENCONFIG_ACL_TYPE_L2, "", 1) aclTypeStr = "ACL_L2" } else { err = errors.New("Invalid key for acl set.") log.Info("Invalid Keys for acl acl set", aclkey) } rmap["name"] = aclNameStr rmap["type"] = aclTypeStr return rmap, err }
var DbToYang_auth_method_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { if log.V(3) { log.Info("DbToYang_auth_method_xfmr: root: ", inParams.ygRoot, ", uri: ", inParams.uri) } var err error rmap := make(map[string]interface{}) data := (*inParams.dbDataMap)[inParams.curDb] db_auth_method, ok := data["AAA"][inParams.key].Field["login"] if ok { log.Info("DbToYang_auth_method_xfmr: db_auth_method: ", db_auth_method) rmap["authentication-method"] = strings.Split(db_auth_method, ",") } return rmap, err }
var DbToYang_bgp_af_nbr_proto_tbl_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { var afName string rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_bgp_af_nbr_proto_tbl_key_xfmr: ", entry_key) nbrAfKey := strings.Split(entry_key, "|") switch nbrAfKey[2] { case "ipv4_unicast": afName = "IPV4_UNICAST" case "ipv6_unicast": afName = "IPV6_UNICAST" case "l2vpn_evpn": afName = "L2VPN_EVPN" default: return rmap, nil } rmap["afi-safi-name"] = afName return rmap, nil }
var DbToYang_bgp_af_nbr_tbl_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { var afName string rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_bgp_af_nbr_tbl_key: ", entry_key) nbrAfKey := strings.Split(entry_key, "|") switch nbrAfKey[2] { case "ipv4_unicast": afName = "IPV4_UNICAST" case "ipv6_unicast": afName = "IPV6_UNICAST" case "l2vpn_evpn": afName = "L2VPN_EVPN" default: return rmap, nil } rmap["afi-safi-name"] = afName return rmap, nil }
var DbToYang_bgp_af_pgrp_proto_tbl_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_bgp_af_pgrp_proto_tbl_key_xfmr: ", entry_key) afPgrpKey := strings.Split(entry_key, "|") afName := "" switch afPgrpKey[2] { case "ipv4_unicast": afName = "IPV4_UNICAST" case "ipv6_unicast": afName = "IPV6_UNICAST" case "l2vpn_evpn": afName = "L2VPN_EVPN" } rmap["afi-safi-name"] = afName return rmap, nil }
var DbToYang_bgp_af_pgrp_tbl_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_bgp_af_pgrp_tbl_key: ", entry_key) afPgrpKey := strings.Split(entry_key, "|") afName := "" switch afPgrpKey[2] { case "ipv4_unicast": afName = "IPV4_UNICAST" case "ipv6_unicast": afName = "IPV6_UNICAST" case "l2vpn_evpn": afName = "L2VPN_EVPN" } rmap["afi-safi-name"] = afName return rmap, nil }
var DbToYang_bgp_dyn_neigh_listen_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_bgp_dyn_neigh_listen_key_xfmr: ", entry_key) dynKey := strings.Split(entry_key, "|") rmap["prefix"] = dynKey[1] log.Info("DbToYang_bgp_dyn_neigh_listen_key_xfmr: rmap:", rmap) return rmap, nil }
var DbToYang_bgp_evpn_rt_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_bgp_evpn_rt_key_xfmr: ", entry_key) routeTargetKey := strings.Split(entry_key, "|") routeTarget := routeTargetKey[2] rmap["route-target"] = routeTarget return rmap, nil }
var DbToYang_bgp_evpn_vni_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_bgp_evpn_vni_key_xfmr: ", entry_key) vniNumberKey := strings.Split(entry_key, "|") vniNumber, _ := strconv.ParseFloat(vniNumberKey[2], 64) rmap["vni-number"] = vniNumber log.Info("Rmap", rmap) return rmap, nil }
var DbToYang_bgp_evpn_vni_rt_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_bgp_evpn_vni_rt_key_xfmr: ", entry_key) vniRouteTargetKey := strings.Split(entry_key, "|") routeTarget := vniRouteTargetKey[3] rmap["route-target"] = routeTarget return rmap, nil }
var DbToYang_bgp_gbl_afi_safi_addr_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_bgp_gbl_afi_safi_addr_key_xfmr: ", entry_key) mpathKey := strings.Split(entry_key, "|") rmap["prefix"] = mpathKey[2] log.Info("DbToYang_bgp_gbl_afi_safi_addr_key_xfmr: rmap:", rmap) return rmap, nil }
var DbToYang_bgp_gbl_afi_safi_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_bgp_gbl_afi_safi_key_xfmr: ", entry_key) mpathKey := strings.Split(entry_key, "|") afi := "" switch mpathKey[1] { case "ipv4_unicast": afi = "IPV4_UNICAST" case "ipv6_unicast": afi = "IPV6_UNICAST" case "l2vpn_evpn": afi = "L2VPN_EVPN" default: return rmap, nil } rmap["afi-safi-name"] = afi log.Info("DbToYang_bgp_gbl_afi_safi_key_xfmr: rmap:", rmap) return rmap, nil }
var DbToYang_bgp_gbl_tbl_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error entry_key := inParams.key log.Info("DbToYang_bgp_gbl_tbl_key: ", entry_key) rmap["name"] = entry_key return rmap, err }
var DbToYang_bgp_nbr_tbl_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_bgp_nbr_tbl_key: ", entry_key) nbrKey := strings.Split(entry_key, "|") nbrName := nbrKey[1] rmap["neighbor-address"] = nbrName return rmap, nil }
var DbToYang_bgp_pgrp_tbl_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_bgp_pgrp_tbl_key: ", entry_key) pgrpKey := strings.Split(entry_key, "|") pgrpName := pgrpKey[1] rmap["peer-group-name"] = pgrpName return rmap, nil }
var DbToYang_global_sg_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_global_sg_key_xfmr: ", inParams.key) return res_map, err }
var DbToYang_igmp_snooping_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { fmt.Println("DbToYang_igmp_snooping_key_xfmr ==> ", inParams) rmap := make(map[string]interface{}) return rmap, nil }
var DbToYang_igmp_snooping_mrouter_config_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { fmt.Println("DbToYang_igmp_snooping_mrouter_config_key_xfmr ==> ", inParams) rmap := make(map[string]interface{}) return rmap, nil }
var DbToYang_igmp_snooping_mrouter_state_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { fmt.Println("DbToYang_igmp_snooping_mrouter_state_key_xfmr ==> ", inParams) rmap := make(map[string]interface{}) return rmap, nil }
var DbToYang_igmp_snooping_static_group_config_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { fmt.Println("DbToYang_igmp_snooping_static_group_config_key_xfmr ==> ", inParams) rmap := make(map[string]interface{}) return rmap, nil }
var DbToYang_igmp_snooping_static_member_state_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { fmt.Println("DbToYang_igmp_snooping_static_member_state_key_xfmr ==> ", inParams) rmap := make(map[string]interface{}) return rmap, nil }
var DbToYang_intf_counters_key KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error return rmap, err }
var DbToYang_intf_subintfs_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error rmap["index"] = 0 return rmap, err }
var DbToYang_intf_tbl_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { log.Info("Entering DbToYang_intf_tbl_key_xfmr") res_map := make(map[string]interface{}) log.Info("Interface Name = ", inParams.key) res_map["name"] = inParams.key return res_map, nil }
Code for DBToYang - Key xfmr
var DbToYang_napt_twice_mapping_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error var key_sep string nat_key := inParams.key key_sep = ":" key := strings.Split(nat_key, key_sep) if len(key) < 5 { err = errors.New("Invalid key for NAPT mapping entry.") log.Info("Invalid Keys, NAPT Mapping entry", nat_key) return rmap, err } oc_protocol := findProtocolByValue(protocol_map, key[0]) rmap["protocol"] = oc_protocol rmap["src-ip"] = key[1] rmap["src-port"], _ = strconv.Atoi(key[2]) rmap["dst-ip"] = key[3] rmap["dst-port"], _ = strconv.Atoi(key[4]) log.Info("DbToYang_nat_twice_mapping_key_xfmr : - ", rmap) return rmap, err }
var DbToYang_nat_binding_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error key := inParams.key rmap["name"] = key log.Info("YangToDb_nat_binding_key_xfmr : - ", rmap) return rmap, err }
var DbToYang_nat_global_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error return rmap, err }
var DbToYang_nat_instance_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error rmap[INSTANCE_ID] = 0 return rmap, err }
var DbToYang_nat_mapping_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error nat_key := inParams.key rmap["external-address"] = nat_key log.Info("DbToYang_nat_mapping_key_xfmr : - ", rmap) return rmap, err }
var DbToYang_nat_pool_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error key := inParams.key rmap["pool-name"] = key log.Info("YangToDb_nat_pool_key_xfmr : - ", rmap) return rmap, err }
var DbToYang_nat_twice_mapping_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error nat_key := inParams.key var key_sep string key_sep = ":" key := strings.Split(nat_key, key_sep) if len(key) < 2 { err = errors.New("Invalid key for NAT mapping entry.") log.Info("Invalid Keys, NAT Mapping entry", nat_key) return rmap, err } rmap["src-ip"] = key[0] rmap["dst-ip"] = key[1] log.Info("DbToYang_nat_twice_mapping_key_xfmr : - ", rmap) return rmap, err }
var DbToYang_neigh_tbl_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error log.Info("DbToYang_neigh_tbl_key_xfmr - inParams: ", inParams) mykey := strings.Split(inParams.key, ":") rmap["ip"] = inParams.key[(len(mykey[0]) + 1):] return rmap, err }
var DbToYang_network_instance_description_field_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_network_instance_description_field_xfmr") return res_map, err }
DbToYang Field transformer for description in the top level network instance config
var DbToYang_network_instance_enabled_addr_family_field_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_network_instance_enabled_addr_fam_field_xfmr") return res_map, err }
DbToYang Field transformer for enabled_address_family in the top level network instance config
var DbToYang_network_instance_mtu_field_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_network_instance_mtu_field_xfmr") return res_map, err }
DbToYang Field transformer for mtu in the top level network instance config
var DbToYang_network_instance_name_field_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_network_instance_name_field_xfmr") if inParams.key != "" { if ((inParams.key == "default") || (strings.HasPrefix(inParams.key, "Vrf"))) && (isVrfDbTbl(inParams) == true) { res_map["name"] = inParams.key } else if (strings.HasPrefix(inParams.key, "vrf_global")) && (isMgmtVrfDbTbl(inParams) == true) { res_map["name"] = "mgmt" } } else { log.Info("DbToYang_network_instance_name_field_xfmr, empty key") } return res_map, err }
DbToYang Field transformer for name in the top level network instance config
var DbToYang_network_instance_protocol_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key dynKey := strings.Split(entry_key, "|") rmap["identifier"] = dynKey[0] rmap["name"] = dynKey[1] return rmap, nil }
var DbToYang_network_instance_route_distinguisher_field_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_network_instance_route_distinguisher_field_xfmr") return res_map, err }
TBD for data vrf DbToYang Field transformer for route_distinguisher in the top level network instance config
var DbToYang_network_instance_router_id_field_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_network_instance_router_id_field_xfmr") return res_map, err }
DbToYang Field transformer for router_id in the top level network instance config
var DbToYang_network_instance_table_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_network_instance_table_key_xfmr: ", inParams.key) if inParams.key != "" { if (inParams.key == "default") || (strings.HasPrefix(inParams.key, "Vrf")) { res_map["name"] = inParams.key } else if strings.HasPrefix(inParams.key, "vrf_global") { res_map["name"] = "mgmt" } } else { log.Info("DbToYang_network_instance_table_key_xfmr, empty key") } return res_map, err }
DbToYang key transformer for top level network instance
var DbToYang_network_instance_type_field_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) var err error log.Info("DbToYang_network_instance_type_field_xfmr") if ((inParams.key == "vrf_global") && (isMgmtVrfDbTbl(inParams) == true)) || ((strings.HasPrefix(inParams.key, "Vrf")) && (isVrfDbTbl(inParams) == true)) { res_map["type"] = "L3VRF" } else if (inParams.key == "default") && (isVrfDbTbl(inParams) == true) { res_map["type"] = "DEFAULT_INSTANCE" } else if strings.HasPrefix(inParams.key, "Vlan") { res_map["type"] = "L2L3" } return res_map, err }
DbToYang Field transformer for type in the top level network instance config
var DbToYang_nw_inst_vxlan_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key if log.V(3) { log.Info("DbToYang_nw_inst_vxlan_key_xfmr ==> entry_key ===> ", entry_key) } if entry_key != "" { keyList := strings.Split(entry_key, "|") if log.V(3) { log.Info("DbToYang_nw_inst_vxlan_key_xfmr ==> keyList ===> ", keyList) } rmap["source-nve"] = keyList[0] mapNameList := strings.Split(keyList[1], "_") vniId, _ := strconv.ParseInt(mapNameList[1], 10, 64) rmap["vni-id"] = uint32(vniId) } if log.V(3) { log.Info("DbToYang_nw_inst_vxlan_key_xfmr ==> rmap ===> ", rmap) } return rmap, nil }
var DbToYang_prefix_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) key := inParams.key log.Info("DbToYang_prefix_key_xfmr: ", key) prefixTblKey := strings.Split(key, "|") ipPrefix := prefixTblKey[1] masklenrange := prefixTblKey[2] rmap["ip-prefix"] = ipPrefix rmap["masklength-range"] = masklenrange log.Info("DbToYang_prefix_key_xfmr: ipPrefix ", ipPrefix, "masklength-range ", masklenrange) return rmap, nil }
var DbToYang_ptp_entry_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error log.Info("DbToYang_ptp_entry_key_xfmr root, uri: ", inParams.ygRoot, inParams.uri) return rmap, err }
var DbToYang_ptp_global_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error log.Info("DbToYang_ptp_global_key_xfmr root, uri: ", inParams.ygRoot, inParams.uri) rmap["instance-number"] = 0 return rmap, err }
var DbToYang_ptp_port_entry_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error var port_num string var is_vlan bool log.Info("DbToYang_ptp_port_entry_key_xfmr root, uri: ", inParams.ygRoot, inParams.uri) entry_key := inParams.key log.Info("DbToYang_ptp_port_entry_key_xfmr: ", entry_key) portName := entry_key if strings.Contains(portName, "Ethernet") { port_num = strings.Replace(portName, "GLOBAL|Ethernet", "", 1) is_vlan = false } else { port_num = strings.Replace(portName, "GLOBAL|Vlan", "", 1) is_vlan = true } port_num_int, _ := strconv.ParseInt(port_num, 10, 16) if is_vlan { port_num_int += 1000 } rmap["port-number"] = port_num_int log.Info("DbToYang_ptp_port_entry_key_xfmr port-number: ", port_num) return rmap, err }
var DbToYang_ptp_tcport_entry_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) var err error log.Info("DbToYang_ptp_tcport_entry_key_xfmr root, uri: ", inParams.ygRoot, inParams.uri) entry_key := inParams.key log.Info("DbToYang_ptp_tcport_entry_key_xfmr: ", entry_key) portName := entry_key port_num := strings.Replace(portName, "Ethernet", "", 1) rmap["port-number"], _ = strconv.ParseInt(port_num, 10, 16) log.Info("DbToYang_ptp_tcport_entry_key_xfmr port-number: ", port_num) return rmap, err }
var DbToYang_route_table_conn_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_route_table_conn_key_xfmr: ", entry_key) key := strings.Split(entry_key, "|") source := key[1] destination := key[2] family := key[3] var src_proto string var dst_proto string var af string if source == "connected" { src_proto = "DIRECTLY_CONNECTED" } else if source == "static" { src_proto = "STATIC" } else if source == "ospf" { src_proto = "OSPF" } else if source == "ospf3" { src_proto = "OSPF3" } else { return rmap, errors.New("Unsupported src protocol " + source) } if destination == "bgp" { dst_proto = "BGP" } else { return rmap, errors.New("Unsupported dst protocol " + destination) } if family == "ipv4" { af = "IPV4" } else if family == "ipv6" { af = "IPV6" } else { return rmap, errors.New("Unsupported family " + family) } rmap["src-protocol"] = src_proto rmap["dst-protocol"] = dst_proto rmap["address-family"] = af return rmap, nil }
var DbToYang_sag_global_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_sag_global_key_xfmr: ", entry_key) rmap["name"] = "default" log.Info("DbToYang_sag_global_key_xfmr") return rmap, nil }
var DbToYang_sag_ipv4_if_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_sag_ipv4_if_key_xfmr: ", entry_key) sagKey := strings.Split(entry_key, "|") ifname := sagKey[1] rmap["name"] = ifname rmap["index"] = 0 log.Info("DbToYang_sag_ipv4_if_key_xfmr: ifname ", ifname) return rmap, nil }
var DbToYang_sag_ipv6_if_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) entry_key := inParams.key log.Info("DbToYang_sag_ipv6_if_key_xfmr: ", entry_key) sagKey := strings.Split(entry_key, "|") ifname := sagKey[1] rmap["name"] = ifname rmap["index"] = 0 log.Info("DbToYang_sag_ipv6_if_key_xfmr: ifname ", ifname) return rmap, nil }
var DbToYang_server_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}, 1) var err error log.Info("DbToYang_server_key_xfmr: ", inParams.key) res_map["address"] = inParams.key return res_map, err }
var DbToYang_sys_config_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { rmap := make(map[string]interface{}) log.Info("DbToYang_sys_config_key_xfmr root, uri: ", inParams.ygRoot, inParams.uri) return rmap, nil }
var DbToYang_vlan_nd_suppress_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { res_map := make(map[string]interface{}) log.Info("Vlan Name = ", inParams.key) res_map["name"] = inParams.key return res_map, nil }
var DbToYang_vxlan_state_tunnel_info_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { log.Info("DbToYang_vxlan_state_tunnel_info_key_xfmr ==> inParams.key => ", inParams.key) pathOrigInfo := NewPathInfo(inParams.requestUri) peerIpOrigStr := pathOrigInfo.Var("peer-ip") log.Info("DbToYang_vxlan_state_tunnel_info_key_xfmr ==> peerIpOrigStr => ", peerIpOrigStr) rmap := make(map[string]interface{}) if inParams.key != "" { keyListTmp := strings.Split(inParams.key, "EVPN_") if peerIpOrigStr != "" && peerIpOrigStr != keyListTmp[1] { log.Info("DbToYang_vxlan_state_tunnel_info_key_xfmr ==> returning ERROR => peer-ip not exist => ", peerIpOrigStr) return rmap, tlerr.NotFound("Resource Not Found") } if log.V(3) { log.Info("DbToYang_vxlan_state_tunnel_info_key_xfmr ==> keyListTmp => ", keyListTmp) } if len(keyListTmp) == 2 { rmap["peer-ip"] = keyListTmp[1] } } log.Info("DbToYang_vxlan_state_tunnel_info_key_xfmr ==> returning RESTULT map rmap => ", rmap) return rmap, nil }
var DbToYang_vxlan_vni_state_peer_info_key_xfmr KeyXfmrDbToYang = func(inParams XfmrParams) (map[string]interface{}, error) { log.Info("DbToYang_vxlan_vni_state_peer_info_key_xfmr Entering ==> ", inParams) rmap := make(map[string]interface{}) if inParams.key != "" { log.Info("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> inParams.key => ", inParams.key) evpnKeyList := strings.Split(inParams.key, ":") log.Info("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> evpnKeyList => ", evpnKeyList) var VXLAN_TUNNEL_TABLE_TS *db.TableSpec = &db.TableSpec{Name: "VXLAN_TUNNEL"} tunnelTblData, err := configDbPtr.GetTable(VXLAN_TUNNEL_TABLE_TS) if err != nil { log.Error("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> returning ERROR => ", err) return rmap, tlerr.NotFound("Resource Not Found") } log.Info("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> tunnelTblData ==> ", tunnelTblData) tunnelKeys, err := tunnelTblData.GetKeys() if err != nil || len(tunnelKeys) != 1 { log.Error("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> returning ERROR => ", err) return rmap, tlerr.NotFound("Resource Not Found") } log.Info("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> tunnelKeys ==> ", tunnelKeys) tunnelEntry, err := tunnelTblData.GetEntry(tunnelKeys[0]) log.Info("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> tunnelEntry ==> ", tunnelEntry) if err != nil || len(tunnelEntry.Field) == 0 { log.Error("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> returning ERROR") return rmap, tlerr.NotFound("Resource Not Found") } var VXLAN_TUNNEL_MAP_TABLE_TS *db.TableSpec = &db.TableSpec{Name: "VXLAN_TUNNEL_MAP"} tunnelMapKeyStr := tunnelKeys[0].Comp[0] + "|map_" + "*_" + evpnKeyList[0] log.Info("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> tunnelMapKeyStr ==> ", tunnelMapKeyStr) tblVxlanMapKeys, err := configDbPtr.GetKeysPattern(VXLAN_TUNNEL_MAP_TABLE_TS, db.Key{[]string{tunnelMapKeyStr}}) log.Info("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> tblVxlanMapKeys ==> ", tblVxlanMapKeys) if len(tblVxlanMapKeys) != 1 { log.Error("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> returning ERROR") return rmap, tlerr.NotFound("Resource Not Found") } log.Info("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> tblVxlanMapKeys ==> ", tblVxlanMapKeys) log.Info("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> tblVxlanMapKeys[1].Comp[0] ==> ", tblVxlanMapKeys[0].Comp[1]) tunnelMapList := strings.Split(tblVxlanMapKeys[0].Comp[1], "_") log.Info("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> tunnelMapList ==> ", tunnelMapList) if len(tunnelMapList) != 3 { log.Error("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> returning ERROR") return rmap, tlerr.NotFound("Resource Not Found") } vniIdInt, _ := strconv.ParseInt(tunnelMapList[1], 10, 64) rmap["vni-id"] = uint32(vniIdInt) rmap["source-ip"] = tunnelEntry.Field["src_ip"] rmap["peer-ip"] = evpnKeyList[1] log.Info("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> final result map ==> ", rmap) return rmap, nil } else { log.Error("DbToYang_vxlan_vni_state_peer_info_key_xfmr ==> returning ERROR ==> Resource Not Found with empty result => ", rmap) return rmap, tlerr.NotFound("Resource Not Found") } }
type KeyXfmrYangToDb ¶
type KeyXfmrYangToDb func(inParams XfmrParams) (string, error)
*
- KeyXfmrYangToDb type is defined to use for conversion of Yang key to DB Key
- Transformer function definition.
- Param: XfmrParams structure having Database info, YgotRoot, operation, Xpath
- Return: Database keys to access db entry, error *
var YangToDb_acl_entry_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var entry_key string var err error var oc_aclType ocbinds.E_OpenconfigAcl_ACL_TYPE log.Info("YangToDb_acl_entry_key_xfmr: ", inParams.ygRoot, inParams.uri) pathInfo := NewPathInfo(inParams.uri) if len(pathInfo.Vars) < 3 { err = errors.New("Invalid xpath, key attributes not found") return entry_key, err } oc_aclType, err = getAclTypeOCEnumFromName(pathInfo.Var("type")) if err != nil { err = errors.New("OC Acl type name to OC Acl Enum failed") return entry_key, err } aclkey := getAclKeyStrFromOCKey(pathInfo.Var("name"), oc_aclType) var rulekey string if strings.Contains(pathInfo.Template, "/acl-entry{sequence-id}") { rulekey = "RULE_" + pathInfo.Var("sequence-id") } entry_key = aclkey + "|" + rulekey log.Info("YangToDb_acl_entry_key_xfmr - entry_key : ", entry_key) return entry_key, err }
var YangToDb_acl_set_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var aclkey string var err error var oc_aclType ocbinds.E_OpenconfigAcl_ACL_TYPE log.Info("YangToDb_acl_set_key_xfmr: ", inParams.ygRoot, inParams.uri) pathInfo := NewPathInfo(inParams.uri) if len(pathInfo.Vars) < 2 { err = errors.New("Invalid xpath, key attributes not found") return aclkey, err } oc_aclType, err = getAclTypeOCEnumFromName(pathInfo.Var("type")) if err != nil { err = errors.New("OC Acl type name to OC Acl Enum failed") return aclkey, err } aclkey = getAclKeyStrFromOCKey(pathInfo.Var("name"), oc_aclType) log.Info("YangToDb_acl_set_key_xfmr - acl_set_key : ", aclkey) return aclkey, err }
var YangToDb_auth_set_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { return "authentication", nil }
var YangToDb_bgp_af_nbr_proto_tbl_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error var vrfName string log.Info("YangToDb_bgp_af_nbr_proto_tbl_key_xfmr***", inParams.uri) pathInfo := NewPathInfo(inParams.uri) vrfName = pathInfo.Var("name") bgpId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") pNbr := pathInfo.Var("neighbor-address") afName := pathInfo.Var("afi-safi-name") if len(pathInfo.Vars) < 4 { err = errors.New("Invalid Key length") log.Info("Invalid Key length", len(pathInfo.Vars)) return vrfName, err } if len(vrfName) == 0 { err = errors.New("vrf name is missing") log.Info("VRF Name is Missing") return vrfName, err } if strings.Contains(bgpId, "BGP") == false { err = errors.New("BGP ID is missing") log.Info("BGP ID is missing") return bgpId, err } if len(protoName) == 0 { err = errors.New("Protocol Name is missing") log.Info("Protocol Name is Missing") return protoName, err } if len(pNbr) == 0 { err = errors.New("Neighbor missing") log.Info("Neighbo Missing") return pNbr, err } if len(afName) == 0 { err = errors.New("AFI SAFI is missing") log.Info("AFI SAFI is Missing") return afName, err } if strings.Contains(afName, "IPV4_UNICAST") { afName = "ipv4_unicast" if strings.Contains(inParams.uri, "ipv6-unicast") || strings.Contains(inParams.uri, "l2vpn-evpn") { err = errors.New("IPV4_UNICAST supported only on ipv4-config container") log.Info("IPV4_UNICAST supported only on ipv4-config container: ", afName) return afName, err } } else if strings.Contains(afName, "IPV6_UNICAST") { afName = "ipv6_unicast" if strings.Contains(inParams.uri, "ipv4-unicast") || strings.Contains(inParams.uri, "l2vpn-evpn") { err = errors.New("IPV6_UNICAST supported only on ipv6-config container") log.Info("IPV6_UNICAST supported only on ipv6-config container: ", afName) return afName, err } } else if strings.Contains(afName, "L2VPN_EVPN") { afName = "l2vpn_evpn" if strings.Contains(inParams.uri, "ipv6-unicast") || strings.Contains(inParams.uri, "ipv4-unicast") { err = errors.New("L2VPN_EVPN supported only on l2vpn-evpn container") log.Info("L2VPN_EVPN supported only on l2vpn-evpn container: ", afName) return afName, err } } else { err = errors.New("Unsupported AFI SAFI") log.Info("Unsupported AFI SAFI ", afName) return afName, err } log.Info("URI VRF ", vrfName) log.Info("URI Nbr ", pNbr) log.Info("URI AFI SAFI ", afName) var nbrAfKey string nbrAfKey = vrfName + "|" + pNbr + "|" + afName log.Info("YangToDb_bgp_af_nbr_proto_tbl_key_xfmr: nbrAfKey:", nbrAfKey) return nbrAfKey, nil }
var YangToDb_bgp_af_nbr_tbl_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error var vrfName string log.Info("YangToDb_bgp_af_nbr_tbl_key_xfmr ***", inParams.uri) pathInfo := NewPathInfo(inParams.uri) vrfName = pathInfo.Var("name") bgpId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") pNbr := pathInfo.Var("neighbor-address") afName := pathInfo.Var("afi-safi-name") if len(pathInfo.Vars) < 4 { err = errors.New("Invalid Key length") log.Info("Invalid Key length", len(pathInfo.Vars)) return vrfName, err } if len(vrfName) == 0 { err = errors.New("vrf name is missing") log.Info("VRF Name is Missing") return vrfName, err } if strings.Contains(bgpId, "BGP") == false { err = errors.New("BGP ID is missing") log.Info("BGP ID is missing") return bgpId, err } if len(protoName) == 0 { err = errors.New("Protocol Name is missing") log.Info("Protocol Name is Missing") return protoName, err } if len(pNbr) == 0 { err = errors.New("Neighbor is missing") log.Info("Neighbor is Missing") return pNbr, err } if len(afName) == 0 { err = errors.New("AFI SAFI is missing") log.Info("AFI SAFI is Missing") return afName, err } if strings.Contains(afName, "IPV4_UNICAST") { afName = "ipv4_unicast" } else if strings.Contains(afName, "IPV6_UNICAST") { afName = "ipv6_unicast" } else if strings.Contains(afName, "L2VPN_EVPN") { afName = "l2vpn_evpn" } else { err = errors.New("Unsupported AFI SAFI") log.Info("Unsupported AFI SAFI ", afName) return afName, err } log.Info("URI VRF ", vrfName) log.Info("URI Nbr ", pNbr) log.Info("URI AFI SAFI ", afName) var nbrAfKey string nbrAfKey = vrfName + "|" + pNbr + "|" + afName log.Info("YangToDb_bgp_af_nbr_tbl_key_xfmr: afPgrpKey:", nbrAfKey) return nbrAfKey, nil }
var YangToDb_bgp_af_pgrp_proto_tbl_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error var vrfName string log.Info("YangToDb_bgp_af_pgrp_proto_tbl_key_xfmr***", inParams.uri) pathInfo := NewPathInfo(inParams.uri) vrfName = pathInfo.Var("name") bgpId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") pGrpName := pathInfo.Var("peer-group-name") afName := pathInfo.Var("afi-safi-name") if len(pathInfo.Vars) < 4 { err = errors.New("Invalid Key length") log.Info("Invalid Key length", len(pathInfo.Vars)) return vrfName, err } if len(vrfName) == 0 { err = errors.New("vrf name is missing") log.Info("VRF Name is Missing") return vrfName, err } if strings.Contains(bgpId, "BGP") == false { err = errors.New("BGP ID is missing") log.Info("BGP ID is missing") return bgpId, err } if len(protoName) == 0 { err = errors.New("Protocol Name is missing") log.Info("Protocol Name is Missing") return protoName, err } if len(pGrpName) == 0 { err = errors.New("Peer Group Name is missing") log.Info("Peer Group Name is Missing") return pGrpName, err } if len(afName) == 0 { err = errors.New("AFI SAFI is missing") log.Info("AFI SAFI is Missing") return pGrpName, err } if strings.Contains(afName, "IPV4_UNICAST") { afName = "ipv4_unicast" if strings.Contains(inParams.uri, "ipv6-unicast") || strings.Contains(inParams.uri, "l2vpn-evpn") { err = errors.New("IPV4_UNICAST supported only on ipv4-config container") log.Info("IPV4_UNICAST supported only on ipv4-config container: ", afName) return afName, err } } else if strings.Contains(afName, "IPV6_UNICAST") { afName = "ipv6_unicast" if strings.Contains(inParams.uri, "ipv4-unicast") || strings.Contains(inParams.uri, "l2vpn-evpn") { err = errors.New("IPV6_UNICAST supported only on ipv6-config container") log.Info("IPV6_UNICAST supported only on ipv6-config container: ", afName) return afName, err } } else if strings.Contains(afName, "L2VPN_EVPN") { afName = "l2vpn_evpn" if strings.Contains(inParams.uri, "ipv6-unicast") || strings.Contains(inParams.uri, "ipv4-unicast") { err = errors.New("L2VPN_EVPN supported only on l2vpn-evpn container") log.Info("L2VPN_EVPN supported only on l2vpn-evpn container: ", afName) return afName, err } } else { err = errors.New("Unsupported AFI SAFI") log.Info("Unsupported AFI SAFI ", afName) return afName, err } log.Info("URI VRF ", vrfName) log.Info("URI Peer Group ", pGrpName) log.Info("URI AFI SAFI ", afName) var afPgrpKey string afPgrpKey = vrfName + "|" + pGrpName + "|" + afName log.Info("YangToDb_bgp_af_pgrp_tbl_key_xfmr: afPgrpKey:", afPgrpKey) return afPgrpKey, nil }
var YangToDb_bgp_af_pgrp_tbl_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error var vrfName string log.Info("YangToDb_bgp_af_pgrp_tbl_key_xfmr ***", inParams.uri) pathInfo := NewPathInfo(inParams.uri) vrfName = pathInfo.Var("name") bgpId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") pGrpName := pathInfo.Var("peer-group-name") afName := pathInfo.Var("afi-safi-name") if len(pathInfo.Vars) < 4 { err = errors.New("Invalid Key length") log.Info("Invalid Key length", len(pathInfo.Vars)) return vrfName, err } if len(vrfName) == 0 { err = errors.New("vrf name is missing") log.Info("VRF Name is Missing") return vrfName, err } if strings.Contains(bgpId, "BGP") == false { err = errors.New("BGP ID is missing") log.Info("BGP ID is missing") return bgpId, err } if len(protoName) == 0 { err = errors.New("Protocol Name is missing") log.Info("Protocol Name is Missing") return protoName, err } if len(pGrpName) == 0 { err = errors.New("Peer Group Name is missing") log.Info("Peer Group Name is Missing") return pGrpName, err } if len(afName) == 0 { err = errors.New("AFI SAFI is missing") log.Info("AFI SAFI is Missing") return pGrpName, err } if strings.Contains(afName, "IPV4_UNICAST") { afName = "ipv4_unicast" } else if strings.Contains(afName, "IPV6_UNICAST") { afName = "ipv6_unicast" } else if strings.Contains(afName, "L2VPN_EVPN") { afName = "l2vpn_evpn" } else { err = errors.New("Unsupported AFI SAFI") log.Info("Unsupported AFI SAFI ", afName) return afName, err } log.Info("URI VRF ", vrfName) log.Info("URI Peer Group ", pGrpName) log.Info("URI AFI SAFI ", afName) var afPgrpKey string afPgrpKey = vrfName + "|" + pGrpName + "|" + afName log.Info("YangToDb_bgp_af_pgrp_tbl_key_xfmr: afPgrpKey:", afPgrpKey) return afPgrpKey, nil }
var YangToDb_bgp_dyn_neigh_listen_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { log.Info("YangToDb_bgp_dyn_neigh_listen_key_xfmr key: ", inParams.uri) pathInfo := NewPathInfo(inParams.uri) niName := pathInfo.Var("name") bgpId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") prefix := pathInfo.Var("prefix") if len(pathInfo.Vars) < 4 { return "", errors.New("Invalid Key length") } if len(niName) == 0 { return "", errors.New("vrf name is missing") } if strings.Contains(bgpId, "BGP") == false { return "", errors.New("BGP ID is missing") } if len(protoName) == 0 { return "", errors.New("Protocol Name is missing") } key := niName + "|" + prefix log.Info("YangToDb_bgp_dyn_neigh_listen_key_xfmr key: ", key) return key, nil }
var YangToDb_bgp_evpn_rt_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error var vrfName string log.Info("YangToDb_bgp_evpn_rt_key_xfmr ***", inParams.uri) pathInfo := NewPathInfo(inParams.uri) vrfName = pathInfo.Var("name") bgpId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") routeTarget := pathInfo.Var("route-target") afName := pathInfo.Var("afi-safi-name") if len(pathInfo.Vars) < 4 { err = errors.New("Invalid Key length") log.Info("Invalid Key length", len(pathInfo.Vars)) return vrfName, err } if len(vrfName) == 0 { err = errors.New("vrf name is missing") log.Info("VRF Name is Missing") return vrfName, err } if strings.Contains(bgpId, "BGP") == false { err = errors.New("BGP ID is missing") log.Info("BGP ID is missing") return bgpId, err } if len(protoName) == 0 { err = errors.New("Protocol Name is missing") log.Info("Protocol Name is Missing") return protoName, err } if len(routeTarget) == 0 { err = errors.New("routeTarget is missing") log.Info("routeTarget is Missing") return routeTarget, err } if len(afName) == 0 { err = errors.New("AFI SAFI is missing") log.Info("AFI SAFI is Missing") return afName, err } if strings.Contains(afName, "IPV4_UNICAST") { afName = "IPV4_UNICAST" } else if strings.Contains(afName, "IPV6_UNICAST") { afName = "IPV6_UNICAST" } else if strings.Contains(afName, "L2VPN_EVPN") { afName = "L2VPN_EVPN" } else { err = errors.New("Unsupported AFI SAFI") log.Info("Unsupported AFI SAFI ", afName) return afName, err } log.Info("URI VRF ", vrfName) log.Info("URI Route Target ", routeTarget) log.Info("URI AFI SAFI ", afName) var routeTargetKey string routeTargetKey = vrfName + "|" + afName + "|" + routeTarget log.Info("YangToDb_bgp_evpn_rt_key_xfmr: routeTargetKey:", routeTargetKey) return routeTargetKey, nil }
var YangToDb_bgp_evpn_vni_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error var vrfName string log.Info("YangToDb_bgp_evpn_vni_key_xfmr ***", inParams.uri) pathInfo := NewPathInfo(inParams.uri) vrfName = pathInfo.Var("name") bgpId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") vniNumber := pathInfo.Var("vni-number") afName := pathInfo.Var("afi-safi-name") if len(pathInfo.Vars) < 4 { err = errors.New("Invalid Key length") log.Info("Invalid Key length", len(pathInfo.Vars)) return vrfName, err } if len(vrfName) == 0 { err = errors.New("vrf name is missing") log.Info("VRF Name is Missing") return vrfName, err } if strings.Contains(bgpId, "BGP") == false { err = errors.New("BGP ID is missing") log.Info("BGP ID is missing") return bgpId, err } if len(protoName) == 0 { err = errors.New("Protocol Name is missing") log.Info("Protocol Name is Missing") return protoName, err } if len(vniNumber) == 0 { err = errors.New("VNI number is missing") log.Info("VNI number is Missing") return vniNumber, err } if len(afName) == 0 { err = errors.New("AFI SAFI is missing") log.Info("AFI SAFI is Missing") return afName, err } if strings.Contains(afName, "IPV4_UNICAST") { afName = "IPV4_UNICAST" } else if strings.Contains(afName, "IPV6_UNICAST") { afName = "IPV6_UNICAST" } else if strings.Contains(afName, "L2VPN_EVPN") { afName = "L2VPN_EVPN" } else { err = errors.New("Unsupported AFI SAFI") log.Info("Unsupported AFI SAFI ", afName) return afName, err } log.Info("URI VRF ", vrfName) log.Info("URI VNI NUMBER ", vniNumber) log.Info("URI AFI SAFI ", afName) var vniTableKey string vniTableKey = vrfName + "|" + afName + "|" + vniNumber log.Info("YangToDb_bgp_evpn_vni_key_xfmr: vniTableKey:", vniTableKey) return vniTableKey, nil }
var YangToDb_bgp_evpn_vni_rt_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error var vrfName string log.Info("YangToDb_bgp_evpn_vni_rt_key_xfmr ***", inParams.uri) pathInfo := NewPathInfo(inParams.uri) vrfName = pathInfo.Var("name") bgpId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") vniNumber := pathInfo.Var("vni-number") afName := pathInfo.Var("afi-safi-name") routeTarget := pathInfo.Var("route-target") if len(pathInfo.Vars) < 5 { err = errors.New("Invalid Key length") log.Info("Invalid Key length", len(pathInfo.Vars)) return vrfName, err } if len(vrfName) == 0 { err = errors.New("vrf name is missing") log.Info("VRF Name is Missing") return vrfName, err } if strings.Contains(bgpId, "BGP") == false { err = errors.New("BGP ID is missing") log.Info("BGP ID is missing") return bgpId, err } if len(protoName) == 0 { err = errors.New("Protocol Name is missing") log.Info("Protocol Name is Missing") return protoName, err } if len(vniNumber) == 0 { err = errors.New("vniNumber is missing") log.Info("vniNumber is Missing") return vniNumber, err } if len(afName) == 0 { err = errors.New("AFI SAFI is missing") log.Info("AFI SAFI is Missing") return afName, err } if len(routeTarget) == 0 { err = errors.New("Route-target is missing") log.Info("route-target is Missing") return routeTarget, err } if strings.Contains(afName, "IPV4_UNICAST") { afName = "IPV4_UNICAST" } else if strings.Contains(afName, "IPV6_UNICAST") { afName = "IPV6_UNICAST" } else if strings.Contains(afName, "L2VPN_EVPN") { afName = "L2VPN_EVPN" } else { err = errors.New("Unsupported AFI SAFI") log.Info("Unsupported AFI SAFI ", afName) return afName, err } log.Info("URI VRF ", vrfName) log.Info("URI VNI NUMBER ", vniNumber) log.Info("URI AFI SAFI ", afName) log.Info("URI Route-target ", routeTarget) var vniRouteTargetKey string vniRouteTargetKey = vrfName + "|" + afName + "|" + vniNumber + "|" + routeTarget log.Info("YangToDb_bgp_evpn_vni_rt_key_xfmr: vniRouteTargetKey:", vniRouteTargetKey) return vniRouteTargetKey, nil }
var YangToDb_bgp_gbl_afi_safi_addr_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { pathInfo := NewPathInfo(inParams.uri) niName := pathInfo.Var("name") bgpId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") afName := pathInfo.Var("afi-safi-name") prefix := pathInfo.Var("prefix") afi := "" var err error if len(pathInfo.Vars) < 5 { return afi, errors.New("Invalid Key length") } if len(niName) == 0 { return afi, errors.New("vrf name is missing") } if strings.Contains(bgpId, "BGP") == false { return afi, errors.New("BGP ID is missing") } if len(protoName) == 0 { return afi, errors.New("Protocol Name is missing") } if strings.Contains(afName, "IPV4_UNICAST") { afi = "ipv4_unicast" } else if strings.Contains(afName, "IPV6_UNICAST") { afi = "ipv6_unicast" } else if strings.Contains(afName, "L2VPN_EVPN") { afi = "l2vpn_evpn" } else { log.Info("Unsupported AFI type " + afName) return afi, errors.New("Unsupported AFI type " + afName) } if strings.Contains(afName, "IPV4_UNICAST") { afName = "IPV4_UNICAST" if strings.Contains(inParams.uri, "ipv6-unicast") || strings.Contains(inParams.uri, "l2vpn-evpn") { err = errors.New("IPV4_UNICAST supported only on ipv4-config container") log.Info("IPV4_UNICAST supported only on ipv4-config container: ", afName) return afName, err } } else if strings.Contains(afName, "IPV6_UNICAST") { afName = "IPV6_UNICAST" if strings.Contains(inParams.uri, "ipv4-unicast") || strings.Contains(inParams.uri, "l2vpn-evpn") { err = errors.New("IPV6_UNICAST supported only on ipv6-config container") log.Info("IPV6_UNICAST supported only on ipv6-config container: ", afName) return afName, err } } else if strings.Contains(afName, "L2VPN_EVPN") { afName = "L2VPN_EVPN" if strings.Contains(inParams.uri, "ipv6-unicast") || strings.Contains(inParams.uri, "ipv4-unicast") { err = errors.New("L2VPN_EVPN supported only on l2vpn-evpn container") log.Info("L2VPN_EVPN supported only on l2vpn-evpn container: ", afName) return afName, err } } else { err = errors.New("Unsupported AFI SAFI") log.Info("Unsupported AFI SAFI ", afName) return afName, err } key := niName + "|" + afi + "|" + prefix log.Info("YangToDb_bgp_gbl_afi_safi_addr_key_xfmr AFI key: ", key) return key, nil }
var YangToDb_bgp_gbl_afi_safi_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { pathInfo := NewPathInfo(inParams.uri) niName := pathInfo.Var("name") bgpId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") afName := pathInfo.Var("afi-safi-name") afi := "" var err error if len(pathInfo.Vars) < 4 { return afi, errors.New("Invalid Key length") } if len(niName) == 0 { return afi, errors.New("vrf name is missing") } if strings.Contains(bgpId, "BGP") == false { return afi, errors.New("BGP ID is missing") } if len(protoName) == 0 { return afi, errors.New("Protocol Name is missing") } if strings.Contains(afName, "IPV4_UNICAST") { afi = "ipv4_unicast" } else if strings.Contains(afName, "IPV6_UNICAST") { afi = "ipv6_unicast" } else if strings.Contains(afName, "L2VPN_EVPN") { afi = "l2vpn_evpn" } else { log.Info("Unsupported AFI type " + afName) return afi, errors.New("Unsupported AFI type " + afName) } if strings.Contains(afName, "IPV4_UNICAST") { afName = "IPV4_UNICAST" if strings.Contains(inParams.uri, "ipv6-unicast") || strings.Contains(inParams.uri, "l2vpn-evpn") { err = errors.New("IPV4_UNICAST supported only on ipv4-config container") log.Info("IPV4_UNICAST supported only on ipv4-config container: ", afName) return afName, err } } else if strings.Contains(afName, "IPV6_UNICAST") { afName = "IPV6_UNICAST" if strings.Contains(inParams.uri, "ipv4-unicast") || strings.Contains(inParams.uri, "l2vpn-evpn") { err = errors.New("IPV6_UNICAST supported only on ipv6-config container") log.Info("IPV6_UNICAST supported only on ipv6-config container: ", afName) return afName, err } } else if strings.Contains(afName, "L2VPN_EVPN") { afName = "L2VPN_EVPN" if strings.Contains(inParams.uri, "ipv6-unicast") || strings.Contains(inParams.uri, "ipv4-unicast") { err = errors.New("L2VPN_EVPN supported only on l2vpn-evpn container") log.Info("L2VPN_EVPN supported only on l2vpn-evpn container: ", afName) return afName, err } } else { err = errors.New("Unsupported AFI SAFI") log.Info("Unsupported AFI SAFI ", afName) return afName, err } key := niName + "|" + afi log.Info("AFI key: ", key) return key, nil }
var YangToDb_bgp_gbl_tbl_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error pathInfo := NewPathInfo(inParams.uri) niName := pathInfo.Var("name") bgpId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") if len(pathInfo.Vars) < 3 { return "", errors.New("Invalid Key length") } if len(niName) == 0 { return "", errors.New("vrf name is missing") } if strings.Contains(bgpId, "BGP") == false { return "", errors.New("BGP ID is missing") } if len(protoName) == 0 { return "", errors.New("Protocol Name is missing") } log.Info("URI VRF ", niName) if inParams.oper == DELETE && niName == "default" { xpath, _ := XfmrRemoveXPATHPredicates(inParams.requestUri) switch xpath { case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/global": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/global/config": log.Info("DELELE op for niName: ", niName, " XPATH: ", xpath) bgpGblTblTs := &db.TableSpec{Name: "BGP_GLOBALS"} if bgpGblTblKeys, err := inParams.d.GetKeys(bgpGblTblTs); err == nil { for _, key := range bgpGblTblKeys { if key.Get(0) == niName && len(bgpGblTblKeys) > 1 { return "", tlerr.NotSupported("Delete not allowed, since non-default-VRF BGP-instance present in system") } } } } } return niName, err }
var YangToDb_bgp_nbr_tbl_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error var vrfName string log.Info("YangToDb_bgp_nbr_tbl_key_xfmr: ", inParams.uri) pathInfo := NewPathInfo(inParams.uri) vrfName = pathInfo.Var("name") bgpId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") pNbrAddr := pathInfo.Var("neighbor-address") if len(pathInfo.Vars) < 3 { err = errors.New("Invalid Key length") log.Info("Invalid Key length", len(pathInfo.Vars)) return vrfName, err } if len(vrfName) == 0 { err = errors.New("vrf name is missing") log.Info("VRF Name is Missing") return "", err } if strings.Contains(bgpId, "BGP") == false { err = errors.New("BGP ID is missing") log.Info("BGP ID is missing") return "", err } if len(protoName) == 0 { err = errors.New("Protocol Name is missing") log.Info("Protocol Name is Missing") return "", err } if len(pNbrAddr) == 0 { err = errors.New("Neighbor address is missing") log.Info("Neighbor address is Missing") return "", nil } log.Info("URI VRF", vrfName) log.Info("URI Neighbor address", pNbrAddr) var pNbrKey string pNbrKey = vrfName + "|" + pNbrAddr log.Info("YangToDb_bgp_nbr_tbl_key_xfmr: pNbrKey:", pNbrKey) return pNbrKey, nil }
var YangToDb_bgp_pgrp_tbl_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error var vrfName string log.Info("YangToDb_bgp_pgrp_tbl_key_xfmr ***", inParams.uri) pathInfo := NewPathInfo(inParams.uri) vrfName = pathInfo.Var("name") bgpId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") pGrpName := pathInfo.Var("peer-group-name") if len(pathInfo.Vars) < 3 { err = errors.New("Invalid Key length") log.Info("Invalid Key length", len(pathInfo.Vars)) return vrfName, err } if len(vrfName) == 0 { err = errors.New("vrf name is missing") log.Info("VRF Name is Missing") return vrfName, err } if strings.Contains(bgpId, "BGP") == false { err = errors.New("BGP ID is missing") log.Info("BGP ID is missing") return bgpId, err } if len(protoName) == 0 { err = errors.New("Protocol Name is missing") log.Info("Protocol Name is Missing") return protoName, err } if len(pGrpName) == 0 { err = errors.New("Peer Group Name is missing") log.Info("Peer Group Name is Missing") return pGrpName, err } log.Info("URI VRF", vrfName) log.Info("URI Peer Group", pGrpName) var pGrpKey string pGrpKey = vrfName + "|" + pGrpName log.Info("YangToDb_bgp_pgrp_tbl_key_xfmr: pGrpKey:", pGrpKey) return pGrpKey, nil }
var YangToDb_global_sg_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { if log.V(3) { log.Info("YangToDb_global_sg_key_xfmr: root: ", inParams.ygRoot, ", uri: ", inParams.uri) } return "global", nil }
var YangToDb_igmp_snooping_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { fmt.Println("YangToDb_igmp_snooping_key_xfmr ==> ", inParams) return "", nil }
var YangToDb_igmp_snooping_mrouter_config_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { fmt.Println("YangToDb_igmp_snooping_mrouter_config_key_xfmr ==> ", inParams) return "", nil }
var YangToDb_igmp_snooping_mrouter_state_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { fmt.Println("YangToDb_igmp_snooping_mrouter_state_key_xfmr ==> ", inParams) return "", nil }
var YangToDb_igmp_snooping_static_group_config_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { fmt.Println("YangToDb_igmp_snooping_static_group_config_key_xfmr ==> ", inParams) return "", nil }
var YangToDb_igmp_snooping_static_member_state_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { fmt.Println("YangToDb_igmp_snooping_static_member_state_key_xfmr ==> ", inParams) return "", nil }
var YangToDb_intf_counters_key KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var entry_key string var err error pathInfo := NewPathInfo(inParams.uri) intfName := pathInfo.Var("name") oid, oiderr := getIntfCountersTblKey(inParams.dbs[inParams.curDb], intfName) if oiderr == nil { entry_key = oid } return entry_key, err }
var YangToDb_intf_subintfs_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var subintf_key string var err error pathInfo := NewPathInfo(inParams.uri) idx := pathInfo.Var("index") if idx != "0" { errStr := "Invalid sub-interface index: " + idx log.Error(errStr) err := tlerr.InvalidArgsError{Format: errStr} return idx, err } return subintf_key, err }
var YangToDb_intf_tbl_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { log.Info("Entering YangToDb_intf_tbl_key_xfmr") var err error pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") log.Info("Intf name: ", ifName) log.Info("Exiting YangToDb_intf_tbl_key_xfmr") intfType, _, ierr := getIntfTypeByName(ifName) if ierr != nil { log.Errorf("Extracting Interface type for Interface: %s failed!", ifName) return "", tlerr.New(ierr.Error()) } requestUriPath, err := getYangPathFromUri(inParams.requestUri) log.Info("inParams.requestUri: ", requestUriPath) err = performIfNameKeyXfmrOp(&inParams, &requestUriPath, &ifName, intfType) if err != nil { return "", tlerr.InvalidArgsError{Format: err.Error()} } return ifName, err }
var YangToDb_napt_twice_mapping_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var napt_key string var err error var key_sep string pathInfo := NewPathInfo(inParams.uri) proto := pathInfo.Var("protocol") srcIp := pathInfo.Var("src-ip") srcPort := pathInfo.Var("src-port") dstIp := pathInfo.Var("dst-ip") dstPort := pathInfo.Var("dst-port") if proto == "" || srcIp == "" || srcPort == "" || dstIp == "" || dstPort == "" { log.Info("YangToDb_napt_twice_mapping_key_xfmr : Invalid key params.") return napt_key, nil } protocol, _ := strconv.Atoi(proto) if _, ok := protocol_map[uint8(protocol)]; !ok { log.Info("YangToDb_napt_twice_mapping_key_xfmr - Invalid protocol : ", protocol) return napt_key, nil } key_sep = ":" napt_key = protocol_map[uint8(protocol)] + key_sep + srcIp + key_sep + srcPort + key_sep + dstIp + key_sep + dstPort log.Info("YangToDb_napt_twice_mapping_key_xfmr : Key : ", napt_key) return napt_key, err }
var YangToDb_nat_binding_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var key string var err error pathInfo := NewPathInfo(inParams.uri) name := pathInfo.Var("name") key = name log.Info("YangToDb_nat_binding_key_xfmr : Key : ", key) return key, err }
var YangToDb_nat_global_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var nat_global_key string var err error nat_global_key = GLOBAL_KEY return nat_global_key, err }
var YangToDb_nat_instance_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var nat_inst_key string var err error nat_inst_key = "0" return nat_inst_key, err }
var YangToDb_nat_mapping_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var nat_key string var err error pathInfo := NewPathInfo(inParams.uri) extAddress := pathInfo.Var("external-address") nat_key = extAddress log.Info("YangToDb_nat_mapping_key_xfmr : Key : ", nat_key) return nat_key, err }
var YangToDb_nat_pool_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var key string var err error pathInfo := NewPathInfo(inParams.uri) name := pathInfo.Var("pool-name") key = name log.Info("YangToDb_nat_pool_key_xfmr: Key : ", key) return key, err }
var YangToDb_nat_twice_mapping_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var nat_key string var err error var key_sep string pathInfo := NewPathInfo(inParams.uri) srcIp := pathInfo.Var("src-ip") dstIp := pathInfo.Var("dst-ip") if srcIp == "" || dstIp == "" { log.Info("YangToDb_nat_twice_mapping_key_xfmr : Invalid key params.") return nat_key, err } key_sep = ":" nat_key = srcIp + key_sep + dstIp log.Info("YangToDb_nat_twice_mapping_key_xfmr : Key : ", nat_key) return nat_key, err }
var YangToDb_nat_zone_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var key string var err error pathInfo := NewPathInfo(inParams.uri) name := pathInfo.Var("zone-id") key = name log.Info("YangToDb_nat_zone_key_xfmr : Key : ", key) return key, err }
var YangToDb_neigh_tbl_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var neightbl_key string var err error log.Info("YangToDb_neigh_tbl_key_xfmr - inParams: ", inParams) pathInfo := NewPathInfo(inParams.uri) intfName := pathInfo.Var("name") ipAddr := pathInfo.Var("ip") neightbl_key = intfName + ":" + ipAddr log.Info("YangToDb_neigh_tbl_key_xfmr - key returned: ", neightbl_key) return neightbl_key, err }
var YangToDb_network_instance_protocol_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var key string log.Info("YangToDb_network_instance_protocol_key_xfmr - URI: ", inParams.uri) if inParams.oper == GET { pathInfo := NewPathInfo(inParams.uri) protoId := pathInfo.Var("identifier") protoName := pathInfo.Var("name#2") key = protoId + "|" + protoName } log.Info("returned Key: ", key) return key, nil }
var YangToDb_network_instance_table_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var vrfTbl_key string var err error log.Info("YangToDb_network_instance_table_key_xfmr: ") pathInfo := NewPathInfo(inParams.uri) vrfTbl_key = getVrfTblKeyByName(pathInfo.Var("name")) log.Info("YangToDb_network_instance_table_key_xfmr: ", vrfTbl_key) if (inParams.oper == CREATE) || (inParams.oper == REPLACE) || (inParams.oper == UPDATE) || (inParams.oper == DELETE) { keyName := pathInfo.Var("name") if keyName == "mgmt" { subOpMap := make(map[db.DBNum]map[string]map[string]db.Value) resMap := make(map[string]map[string]db.Value) sshVrfMap := make(map[string]db.Value) sshVrfDbValues := db.Value{Field: map[string]string{}} (&sshVrfDbValues).Set("port", "22") sshVrfMap["mgmt"] = sshVrfDbValues log.Infof("ssh server vrf %v", sshVrfMap) resMap["SSH_SERVER_VRF"] = sshVrfMap subOpMap[db.ConfigDB] = resMap inParams.subOpDataMap[inParams.oper] = &subOpMap } } return vrfTbl_key, err }
YangToDB key transformer for top level network instance
var YangToDb_nw_inst_vxlan_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error if log.V(3) { log.Info("YangToDb_nw_inst_vxlan_key_xfmr ==> printing target object request ==> ", (inParams.param)) } path, err := getVxlanNiUriPath(inParams.uri) if err != nil { return "", err } reqP := &vxlanReqProcessor{&inParams.requestUri, &inParams.uri, path, inParams.oper, (*inParams.ygRoot).(*ocbinds.Device), inParams.param, inParams.d, inParams.dbs, nil, nil, nil, nil, &inParams} if err = reqP.setVxlanNetInstObjFromReq(); err != nil { return "", err } if log.V(3) { log.Info("YangToDb_nw_inst_vxlan_key_xfmr ==> printing vxlanNetInstObj object request ==> ", (*reqP.vxlanNetInstObj)) } var keyStr string var srcVetpName string var vniIdStr string if reqP.opcode == 5 || reqP.opcode == 1 { pathInfo := NewPathInfo(inParams.uri) srcVetpName = pathInfo.Var("source-nve") vniIdStr = pathInfo.Var("vni-id") if reqP.vxlanNetInstObj.VxlanVniInstances == nil || len(reqP.vxlanNetInstObj.VxlanVniInstances.VniInstance) == 0 && srcVetpName == "" { log.Error("YangToDb_nw_inst_vxlan_key_xfmr ==> returning EMPTY key, since there is no key in the request") return "", nil } } if srcVetpName == "" && vniIdStr == "" { if reqP.vxlanNetInstObj.VxlanVniInstances == nil { log.Error("YangToDb_nw_inst_vxlan_key_xfmr ==> returning EMPTY key, since there is no key in the request") return "", tlerr.NotFound("Resource Not Found") } for _, vxlanNiObj := range reqP.vxlanNetInstObj.VxlanVniInstances.VniInstance { srcVetpName = *vxlanNiObj.SourceNve vniIdStr = strconv.Itoa(int(*vxlanNiObj.VniId)) break } } niName := *(reqP.vxlanNetInstObj.Name) if log.V(3) { log.Info("YangToDb_nw_inst_vxlan_key_xfmr ==> niName ===> ", niName) } keyStr = srcVetpName + "|" + "map_" + vniIdStr + "_" + niName if log.V(3) { log.Info("YangToDb_nw_inst_vxlan_key_xfmr ==> keyStr ===> ", keyStr) } return keyStr, nil }
var YangToDb_prefix_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error var setName string var ipPrefix string var masklenrange string var prefixTblKey string log.Info("YangToDb_prefix_key_xfmr: ", inParams.ygRoot, inParams.uri) pathInfo := NewPathInfo(inParams.uri) if (inParams.oper == DELETE) && (len(pathInfo.Vars) == 1) { setName = pathInfo.Var("name") if len(setName) == 0 { err = errors.New("YangToDb_prefix_key_xfmr: Prefix set name is missing") log.Error("YangToDb_prefix_key_xfmr: Prefix set name is Missing") return setName, err } return "NULL", nil } else { if len(pathInfo.Vars) < 3 { err = errors.New("Invalid xpath, key attributes not found") log.Error("YangToDb_prefix_key_xfmr: Prefix keys are Missing, numKeys ", len(pathInfo.Vars)) return prefixTblKey, err } setName = pathInfo.Var("name") ipPrefix = pathInfo.Var("ip-prefix") masklenrange = pathInfo.Var("masklength-range") if len(setName) == 0 { err = errors.New("YangToDb_prefix_key_xfmr: Prefix set name is missing") log.Info("YangToDb_prefix_key_xfmr: Prefix set name is Missing") return setName, err } if len(ipPrefix) == 0 { err = errors.New("YangToDb_prefix_key_xfmr: ipPrefix is missing") log.Info("YangToDb_prefix_key_xfmr: ipPrefix is Missing") return ipPrefix, err } if len(masklenrange) == 0 { err = errors.New("YangToDb_prefix_key_xfmr: masklenrange is missing") log.Info("YangToDb_prefix_key_xfmr: masklength-range is Missing") return masklenrange, err } log.Info("YangToDb_prefix_key_xfmr: in prefix: ", ipPrefix) prefix_mask := strings.Split(ipPrefix, "/") if !validIPv6(prefix_mask[0]) && !validIPv4(prefix_mask[0]) { err = errors.New("YangToDb_prefix_key_xfmr: Invalid IP address") return ipPrefix, err } if masklenrange != "exact" { length, _ := strconv.Atoi(prefix_mask[1]) m_range := strings.Split(masklenrange, "..") ge, _ := strconv.Atoi(m_range[0]) le, _ := strconv.Atoi(m_range[1]) log.Infof("YangToDb_prefix_key_xfmr: mask length %d ge %d le %d", length, ge, le) if (ge <= le) != true { err = errors.New("Invalid maskrange, ge-value <= ge-value") log.Error("YangToDb_prefix_key_xfmr: Invalid maskrange, make sure len < ge-value <= ge-value") return ipPrefix, err } } prefixTblKey = setName + "|" + ipPrefix + "|" + masklenrange } log.Info("YangToDb_prefix_key_xfmr: prefixTblKey: ", prefixTblKey) return prefixTblKey, nil }
var YangToDb_ptp_entry_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var entry_key string var err error log.Info("YangToDb_ptp_entry_key_xfmr: ", inParams.ygRoot, " XPath ", inParams.uri, " key: ", inParams.key) pathInfo := NewPathInfo(inParams.uri) log.Info("YangToDb_ptp_entry_key_xfmr len(pathInfo.Vars): ", len(pathInfo.Vars)) if len(pathInfo.Vars) < 1 { err = errors.New("Invalid xpath, key attributes not found") return entry_key, err } inkey, _ := strconv.ParseUint(pathInfo.Var("instance-number"), 10, 64) if inkey > 0 { err = errors.New("Invalid input instance-number") return entry_key, err } entry_key = "GLOBAL" log.Info("YangToDb_ptp_entry_key_xfmr - entry_key : ", entry_key) return entry_key, err }
////////////////////////////////////////// Bi-directoonal overloaded methods //////////////////////////////////////////
var YangToDb_ptp_global_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var entry_key string var err error log.Info("YangToDb_ptp_global_key_xfmr: ", inParams.ygRoot, inParams.uri) entry_key = "GLOBAL" log.Info("YangToDb_ptp_global_key_xfmr - entry_key : ", entry_key) return entry_key, err }
var YangToDb_ptp_port_entry_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var entry_key string var underlying_interface string var err error log.Info("YangToDb_ptp_port_entry_key_xfmr root, uri: ", inParams.ygRoot, inParams.uri) pathInfo := NewPathInfo(inParams.uri) log.Info("YangToDb_ptp_port_entry_key_xfmr len(pathInfo.Vars): ", len(pathInfo.Vars)) log.Info("YangToDb_ptp_port_entry_key_xfmr pathInfo.Vars: ", pathInfo.Vars) if len(pathInfo.Vars) < 2 { err = errors.New("Invalid xpath, key attributes not found") return entry_key, err } instance_id, _ := strconv.ParseUint(pathInfo.Var("instance-number"), 10, 64) port_number_str := pathInfo.Var("port-number") port_number, _ := strconv.ParseUint(port_number_str, 10, 64) ptpObj := getPtpRoot(inParams.ygRoot) pDsList := ptpObj.InstanceList[uint32(instance_id)].PortDsList log.Info("YangToDb_ptp_port_entry_key_xfmr len(pDsList) : ", len(pDsList)) if 0 != len(pDsList) && nil != pDsList[uint16(port_number)].UnderlyingInterface && "" != *pDsList[uint16(port_number)].UnderlyingInterface { underlying_interface = *pDsList[uint16(port_number)].UnderlyingInterface log.Info("YangToDb_ptp_port_entry_key_xfmr underlying-interface: ", underlying_interface) if port_number < 1000 { if port_number_str != strings.Replace(underlying_interface, "Ethernet", "", 1) { log.Info("YangToDb_ptp_port_entry_key_xfmr : underlying-interface port-number mismatch") return entry_key, errors.New("underlying-interface port-number mismatch") } } else { if strconv.FormatInt(int64(port_number-1000), 10) != strings.Replace(underlying_interface, "Vlan", "", 1) { log.Info("YangToDb_ptp_port_entry_key_xfmr : underlying-interface port-number mismatch") return entry_key, errors.New("underlying-interface port-number mismatch") } } } else { if port_number < 1000 { underlying_interface = "Ethernet" + port_number_str } else { underlying_interface = "Vlan" + strconv.FormatInt(int64(port_number-1000), 10) } } log.Info("YangToDb_ptp_port_entry_key_xfmr pathInfo.Var:port-number: ", pathInfo.Var("port-number")) entry_key = "GLOBAL|" + underlying_interface log.Info("YangToDb_ptp_port_entry_key_xfmr - entry_key : ", entry_key) return entry_key, err }
var YangToDb_ptp_tcport_entry_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var entry_key string var err error log.Info("YangToDb_ptp_tcport_entry_key_xfmr root, uri: ", inParams.ygRoot, inParams.uri) pathInfo := NewPathInfo(inParams.uri) log.Info("YangToDb_ptp_tcport_entry_key_xfmr len(pathInfo.Vars): ", len(pathInfo.Vars)) if len(pathInfo.Vars) < 1 { err = errors.New("Invalid xpath, key attributes not found") return entry_key, err } log.Info("YangToDb_ptp_tcport_entry_key_xfmr pathInfo.Var:port-number: ", pathInfo.Var("port-number")) entry_key = "Ethernet" + pathInfo.Var("port-number") log.Info("YangToDb_ptp_tcport_entry_key_xfmr - entry_key : ", entry_key) return entry_key, err }
var YangToDb_route_map_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var entry_key string var err error pathInfo := NewPathInfo(inParams.uri) rtMapName := pathInfo.Var("name") stmtName := pathInfo.Var("name#2") if len(stmtName) == 0 { return entry_key, err } _, err = strconv.ParseUint(stmtName, 10, 16) if err != nil { log.Info("URI route-map invalid statement name type, use values in range (1-65535)", stmtName) return entry_key, tlerr.InvalidArgs("Statement '%s' not supported, use values in range (1-65535)", stmtName) } entry_key = rtMapName + "|" + stmtName log.Info("URI route-map ", entry_key) return entry_key, err }
var YangToDb_route_table_conn_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error log.Info("YangToDb_route_table_conn_key_xfmr***", inParams.uri) pathInfo := NewPathInfo(inParams.uri) niName := pathInfo.Var("name") srcProto := pathInfo.Var("src-protocol") dstProto := pathInfo.Var("dst-protocol") afName := pathInfo.Var("address-family") if len(pathInfo.Vars) < 3 { return "", nil } if len(niName) == 0 { err = errors.New("vrf name is missing") log.Info("VRF Name is Missing") return niName, err } var family string var source string var destination string if strings.Contains(afName, "IPV4") { family = "ipv4" } else if strings.Contains(afName, "IPV6") { family = "ipv6" } else { log.Info("Unsupported address-family " + afName) return family, errors.New("Unsupported address-family " + afName) } if strings.Contains(srcProto, "DIRECTLY_CONNECTED") { source = "connected" } else if strings.Contains(srcProto, "OSPF3") { source = "ospf3" } else if strings.Contains(srcProto, "OSPF") { source = "ospf" } else if strings.Contains(srcProto, "STATIC") { source = "static" } else { log.Info("Unsupported protocol " + srcProto) return family, errors.New("Unsupported protocol " + srcProto) } if strings.Contains(dstProto, "BGP") { destination = "bgp" } else { log.Info("Unsupported protocol " + dstProto) return family, errors.New("Unsupported protocol " + dstProto) } key := niName + "|" + source + "|" + destination + "|" + family log.Info("TableConnection key: ", key) return key, nil }
var YangToDb_sag_global_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { log.Info("YangToDb_sag_global_key_xfmr ***", inParams.uri) var sagTableKey string sagTableKey = "IP" log.Info("YangToDb_sag_global_key_xfmr: sagTableKey:", sagTableKey) return sagTableKey, nil }
var YangToDb_sag_ipv4_if_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error var ifname string log.Info("YangToDb_sag_ipv4_if_key_xfmr ***", inParams.uri) pathInfo := NewPathInfo(inParams.uri) ifname = pathInfo.Var("name") ifindex := pathInfo.Var("index") if len(pathInfo.Vars) < 2 { err = errors.New("Invalid Key length") log.Info("Invalid Key length", len(pathInfo.Vars)) return ifname, err } if len(ifname) == 0 { err = errors.New("SAG interface name is missing") log.Info("SAG interface name is Missing") return ifname, err } if len(ifindex) == 0 { err = errors.New("SAG subinterface index is missing") log.Info("SAG subinterface index is missing") return ifindex, err } log.Info("URI Interface ", ifname) log.Info("URI Ifindex ", ifindex) var sagTableKey string sagTableKey = ifname + "|" + "IPv4" log.Info("YangToDb_sag_ipv4_if_key_xfmr: sagTableKey:", sagTableKey) return sagTableKey, nil }
var YangToDb_sag_ipv6_if_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { var err error var ifname string log.Info("YangToDb_sag_ipv6_if_key_xfmr ***", inParams.uri) pathInfo := NewPathInfo(inParams.uri) ifname = pathInfo.Var("name") ifindex := pathInfo.Var("index") if len(pathInfo.Vars) < 2 { err = errors.New("Invalid Key length") log.Info("Invalid Key length", len(pathInfo.Vars)) return ifname, err } if len(ifname) == 0 { err = errors.New("SAG interface name is missing") log.Info("SAG interface name is Missing") return ifname, err } if len(ifindex) == 0 { err = errors.New("SAG subinterface index is missing") log.Info("SAG subinterface index is missing") return ifindex, err } log.Info("URI Interface ", ifname) log.Info("URI Ifindex ", ifindex) var sagTableKey string sagTableKey = ifname + "|" + "IPv6" log.Info("YangToDb_sag_ipv6_if_key_xfmr: sagTableKey:", sagTableKey) return sagTableKey, nil }
var YangToDb_server_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { if log.V(3) { log.Info("YangToDb_server_key_xfmr: root: ", inParams.ygRoot, ", uri: ", inParams.uri) } pathInfo := NewPathInfo(inParams.uri) serverkey := pathInfo.Var("address") return serverkey, nil }
var YangToDb_sys_config_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { log.Info("YangToDb_sys_config_key_xfmr: ", inParams.uri) dvKey := "localhost" return dvKey, nil }
var YangToDb_vlan_nd_suppress_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { pathInfo := NewPathInfo(inParams.uri) vlanIdStr := pathInfo.Var("name") if !strings.HasPrefix(vlanIdStr, "Vlan") { return "", tlerr.InvalidArgs("Invalid key: %v", vlanIdStr) } return vlanIdStr, nil }
var YangToDb_vxlan_state_tunnel_info_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { log.Info("YangToDb_vxlan_state_tunnel_info_key_xfmr ==>inParams.uri => ", inParams.uri) log.Info("YangToDb_vxlan_state_tunnel_info_key_xfmr ==>inParams.requestUri => ", inParams.requestUri) pathInfo := NewPathInfo(inParams.uri) peerIpStr := pathInfo.Var("peer-ip") log.Info("YangToDb_vxlan_state_tunnel_info_key_xfmr ==> peerIpStr => ", peerIpStr) pathOrigInfo := NewPathInfo(inParams.requestUri) peerIpOrigStr := pathOrigInfo.Var("peer-ip") log.Info("YangToDb_vxlan_state_tunnel_info_key_xfmr ==> peerIpOrigStr => ", peerIpOrigStr) if peerIpOrigStr != "" { var VXLAN_TUNNEL_TABLE_STATE_TS *db.TableSpec = &db.TableSpec{Name: "VXLAN_TUNNEL_TABLE"} evpnPeerkeyStr := "EVPN_" + peerIpOrigStr if log.V(3) { log.Info("YangToDb_vxlan_state_tunnel_info_key_xfmr ==> evpnPeerkeyStr ==> ", evpnPeerkeyStr) } _, err := stateDbPtr.GetEntry(VXLAN_TUNNEL_TABLE_STATE_TS, db.Key{[]string{evpnPeerkeyStr}}) if err != nil { log.Info("YangToDb_vxlan_state_tunnel_info_key_xfmr ==> returning error ==> ", err) return "VXLAN_TUNNEL_TABLE", tlerr.NotFound("Resource Not Found") } } if peerIpStr != "" { evpnPeerkeyStr := "EVPN_" + peerIpStr if log.V(3) { log.Info("YangToDb_vxlan_state_tunnel_info_key_xfmr ==> returning KEY => ", evpnPeerkeyStr) } return evpnPeerkeyStr, nil } else { return "", nil } }
var YangToDb_vxlan_vni_state_peer_info_key_xfmr KeyXfmrYangToDb = func(inParams XfmrParams) (string, error) { if log.V(3) { log.Info("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==>inParams.uri => ", inParams.uri) log.Info("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==>inParams.requestUri => ", inParams.requestUri) } pathInfo := NewPathInfo(inParams.uri) vniIdStr := pathInfo.Var("vni-id") srcIpStr := pathInfo.Var("source-ip") peerIpStr := pathInfo.Var("peer-ip") log.Info("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==>vniIdStr => ", vniIdStr) log.Info("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==>srcIpStr => ", srcIpStr) log.Info("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==>peerIpStr => ", peerIpStr) if vniIdStr != "" { var VXLAN_TUNNEL_TABLE_TS *db.TableSpec = &db.TableSpec{Name: "VXLAN_TUNNEL"} tunnelTblData, err := configDbPtr.GetTable(VXLAN_TUNNEL_TABLE_TS) if err != nil { retErr := tlerr.NotFound("Resource Not Found") log.Error("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> returning err ==> ", err) return "EVPN_REMOTE_VNI_TABLE", retErr } log.Info("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> tunnelTblData ==> ", tunnelTblData) tunnelKeys, err := tunnelTblData.GetKeys() if err != nil || len(tunnelKeys) != 1 { retErr := tlerr.NotFound("Resource Not Found") log.Error("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> returning ERROr ==> ", err) return "EVPN_REMOTE_VNI_TABLE", retErr } if log.V(3) { log.Info("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> tunnelKeys ==> ", tunnelKeys) } tunnelEntry, err := tunnelTblData.GetEntry(tunnelKeys[0]) if log.V(3) { log.Info("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> tunnelEntry ==> ", tunnelEntry) } if err != nil || len(tunnelEntry.Field) == 0 { retErr := tlerr.NotFound("Resource Not Found") log.Error("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> returning ERROr ==> ", err) return "EVPN_REMOTE_VNI_TABLE", retErr } if tunnelEntry.Field["src_ip"] != srcIpStr { log.Error("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> srcIpStr mismatch") retErr := tlerr.NotFound("Resource Not Found") log.Error("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> returning ERROr ==> ", retErr) return "EVPN_REMOTE_VNI_TABLE", retErr } var VXLAN_TUNNEL_MAP_TABLE_TS *db.TableSpec = &db.TableSpec{Name: "VXLAN_TUNNEL_MAP"} tunnelMapKeyStr := tunnelKeys[0].Comp[0] + "|map_" + vniIdStr + "_Vlan*" log.Info("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> tunnelMapKeyStr ==> ", tunnelMapKeyStr) tblVxlanMapKeys, err := configDbPtr.GetKeysPattern(VXLAN_TUNNEL_MAP_TABLE_TS, db.Key{[]string{tunnelMapKeyStr}}) if log.V(3) { log.Info("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> tblVxlanMapKeys ==> ", tblVxlanMapKeys) } if err != nil || len(tblVxlanMapKeys) != 1 { retErr := tlerr.NotFound("Resource Not Found") log.Error("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> returning ERROr ==> ", err) return "EVPN_REMOTE_VNI_TABLE", retErr } log.Info("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> tblVxlanMapKeys ==> ", tblVxlanMapKeys) vlanIdList := strings.Split(tblVxlanMapKeys[0].Comp[1], "_Vlan") log.Info("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> vlanIdList ==> ", vlanIdList) if len(vlanIdList) != 2 { retErr := tlerr.NotFound("Resource Not Found") log.Error("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> returning ERROr ==> ", retErr) return "EVPN_REMOTE_VNI_TABLE", retErr } var APP_EVPN_REMOTE_VNI_TABLE_TS *db.TableSpec = &db.TableSpec{Name: "EVPN_REMOTE_VNI_TABLE"} remote_ip := peerIpStr evpnRemoteKey, err := applDbPtr.GetEntry(APP_EVPN_REMOTE_VNI_TABLE_TS, db.Key{[]string{"Vlan" + vlanIdList[1], remote_ip}}) log.Info("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> evpnRemoteKey ==> ", evpnRemoteKey) if err == nil && len(evpnRemoteKey.Field) > 0 { retKey := "Vlan" + vlanIdList[1] + ":" + remote_ip log.Error("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> final retKey ==> ", retKey) return retKey, nil } else { retErr := tlerr.NotFound("Resource Not Found") log.Error("YangToDb_vxlan_vni_state_peer_info_key_xfmr ==> returning ERROr ==> ", retErr) return "EVPN_REMOTE_VNI_TABLE", retErr } } return "", nil }
type NwInstMapKey ¶
type PathInfo ¶
PathInfo structure contains parsed path information.
func NewPathInfo ¶
NewPathInfo parses given path string into a PathInfo structure.
type PopulateIntfCounters ¶
type PopulateIntfCounters func(inParams XfmrParams, counters interface{}) error
type PostXfmrFunc ¶
*
- PostXfmrFunc type is defined to use for handling any default handling operations required as part of the CREATE
- Transformer function definition.
- Param: XfmrParams structure having database pointers, current db, operation, DB data in multidimensional map, YgotRoot, uri
- Return: Multi dimensional map to hold the DB data Map (tblName, key and Fields), error *
type ProcessState ¶
type RpcCallpoint ¶
*
- RpcCallpoint is used to invoke a callback for action
- Param : []byte input payload, dbi indices
- Return : []byte output payload, error *
type SubTreeXfmrDbToYang ¶
type SubTreeXfmrDbToYang func(inParams XfmrParams) error
*
- SubTreeXfmrDbToYang type is defined to use for handling the DB to Yang subtree
- Transformer function definition.
- Param : XfmrParams structure having Database pointers, current db, operation, DB data in multidimensional map, output param YgotRoot, uri
- Return : error *
var DbToYang_acl_port_bindings_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_acl_port_bindings_xfmr: ", data, inParams.ygRoot) aclTbl := data["ACL_TABLE"] var ruleTbl map[string]map[string]db.Value ruleTbl = make(map[string]map[string]db.Value) for key, element := range data["ACL_RULE"] { tokens := strings.Split(key, "|") if ruleTbl[tokens[0]] == nil { ruleTbl[tokens[0]] = make(map[string]db.Value) } ruleTbl[tokens[0]][tokens[1]] = db.Value{Field: make(map[string]string)} ruleTbl[tokens[0]][tokens[1]] = element } pathInfo := NewPathInfo(inParams.uri) acl := getAclRoot(inParams.ygRoot) targetUriPath, _ := getYangPathFromUri(pathInfo.Path) if isSubtreeRequest(pathInfo.Template, "/openconfig-acl:acl/interfaces/interface{}") { for intfId := range acl.Interfaces.Interface { intfData := acl.Interfaces.Interface[intfId] ygot.BuildEmptyTree(intfData) if isSubtreeRequest(targetUriPath, "/openconfig-acl:acl/interfaces/interface/ingress-acl-sets") { err = getAclBindingInfoForInterfaceData(aclTbl, ruleTbl, intfData, intfId, "INGRESS") } else if isSubtreeRequest(targetUriPath, "/openconfig-acl:acl/interfaces/interface/egress-acl-sets") { err = getAclBindingInfoForInterfaceData(aclTbl, ruleTbl, intfData, intfId, "EGRESS") } else { err = getAclBindingInfoForInterfaceData(aclTbl, ruleTbl, intfData, intfId, "INGRESS") if err != nil { return err } err = getAclBindingInfoForInterfaceData(aclTbl, ruleTbl, intfData, intfId, "EGRESS") } } } else { err = getAllBindingsInfo(aclTbl, ruleTbl, inParams.ygRoot) } return err }
var DbToYang_bfd_state_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error cmn_log := "GET: xfmr for BFD peers state" bfd_obj, get_err := validate_bfd_get(inParams, cmn_log) if get_err != nil { return get_err } err = get_bfd_peers(bfd_obj, inParams) return err }
var DbToYang_bgp_evpn_vni_state_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error cmn_log := "GET: xfmr for BGP EVPN VNI state" vni_obj, vni_key, get_err := validate_vni_get(inParams, cmn_log) if get_err != nil { return get_err } err = get_specific_vni_state(vni_obj, inParams.dbs[db.ConfigDB], &vni_key) return err }
var DbToYang_bgp_gbl_state_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error oper_err := errors.New("Opertational error") cmn_log := "GET: xfmr for BGP-Global State" bgp_obj, niName, err := getBgpRoot(inParams) if err != nil { log.Errorf("%s failed !! Error:%s", cmn_log, err) return oper_err } bgpGbl_obj := bgp_obj.Global if bgpGbl_obj == nil { log.Errorf("%s failed !! Error: BGP-Global container missing", cmn_log) return oper_err } ygot.BuildEmptyTree(bgpGbl_obj) bgpGblState_obj := bgpGbl_obj.State if bgpGblState_obj == nil { log.Errorf("%s failed !! Error: BGP-Global-State container missing", cmn_log) return oper_err } ygot.BuildEmptyTree(bgpGblState_obj) if cfgDbEntry, cfgdb_get_err := get_spec_bgp_glb_cfg_tbl_entry(inParams.dbs[db.ConfigDB], niName); cfgdb_get_err == nil { if value, ok := cfgDbEntry["local_asn"]; ok { if _local_asn_u64, err := strconv.ParseUint(value, 10, 32); err == nil { _local_asn_u32 := uint32(_local_asn_u64) bgpGblState_obj.As = &_local_asn_u32 } } if value, ok := cfgDbEntry["router_id"]; ok { bgpGblState_obj.RouterId = &value } if value, ok := cfgDbEntry["rr_clnt_to_clnt_reflection"]; ok { _clntToClntReflection, _ := strconv.ParseBool(value) bgpGblState_obj.ClntToClntReflection = &_clntToClntReflection } if value, ok := cfgDbEntry["coalesce_time"]; ok { if _coalesceTime_u64, err := strconv.ParseUint(value, 10, 32); err == nil { _coalesceTime_u32 := uint32(_coalesceTime_u64) bgpGblState_obj.CoalesceTime = &_coalesceTime_u32 } } if value, ok := cfgDbEntry["deterministic_med"]; ok { _deterministicMed, _ := strconv.ParseBool(value) bgpGblState_obj.DeterministicMed = &_deterministicMed } if value, ok := cfgDbEntry["disable_ebgp_connected_rt_check"]; ok { _disableEbgpConnectedRouteCheck, _ := strconv.ParseBool(value) bgpGblState_obj.DisableEbgpConnectedRouteCheck = &_disableEbgpConnectedRouteCheck } if value, ok := cfgDbEntry["fast_external_failover"]; ok { _fastExternalFailover, _ := strconv.ParseBool(value) bgpGblState_obj.FastExternalFailover = &_fastExternalFailover } if value, ok := cfgDbEntry["graceful_shutdown"]; ok { _gracefulShutdown, _ := strconv.ParseBool(value) bgpGblState_obj.GracefulShutdown = &_gracefulShutdown } if value, ok := cfgDbEntry["holdtime"]; ok { _holdTime, _ := strconv.ParseFloat(value, 64) bgpGblState_obj.HoldTime = &_holdTime } if value, ok := cfgDbEntry["keepalive"]; ok { _keepaliveInterval, _ := strconv.ParseFloat(value, 64) bgpGblState_obj.KeepaliveInterval = &_keepaliveInterval } if value, ok := cfgDbEntry["max_dynamic_neighbors"]; ok { if _maxDynamicNeighbors_u64, err := strconv.ParseUint(value, 10, 32); err == nil { _maxDynamicNeighbors_u16 := uint16(_maxDynamicNeighbors_u64) bgpGblState_obj.MaxDynamicNeighbors = &_maxDynamicNeighbors_u16 } } if value, ok := cfgDbEntry["network_import_check"]; ok { _networkImportCheck, _ := strconv.ParseBool(value) bgpGblState_obj.NetworkImportCheck = &_networkImportCheck } if value, ok := cfgDbEntry["read_quanta"]; ok { if _readQuanta_u64, err := strconv.ParseUint(value, 10, 32); err == nil { _readQuanta_u8 := uint8(_readQuanta_u64) bgpGblState_obj.ReadQuanta = &_readQuanta_u8 } } if value, ok := cfgDbEntry["route_map_process_delay"]; ok { if _routeMapProcessDelay_u64, err := strconv.ParseUint(value, 10, 32); err == nil { _routeMapProcessDelay_u16 := uint16(_routeMapProcessDelay_u64) bgpGblState_obj.RouteMapProcessDelay = &_routeMapProcessDelay_u16 } } if value, ok := cfgDbEntry["write_quanta"]; ok { if _writeQuanta_u64, err := strconv.ParseUint(value, 10, 32); err == nil { _writeQuanta_u8 := uint8(_writeQuanta_u64) bgpGblState_obj.WriteQuanta = &_writeQuanta_u8 } } } vtysh_cmd := "show ip bgp vrf " + niName + " summary json" bgpGblJson, cmd_err := exec_vtysh_cmd(vtysh_cmd) if cmd_err != nil { log.Errorf("Failed to fetch BGP global info for niName:%s. Err: %s", niName, cmd_err) return oper_err } bgpGblDataJson, ok := bgpGblJson["ipv4Unicast"].(map[string]interface{}) if ok { if value, ok := bgpGblDataJson["as"]; ok { _localAs := uint32(value.(float64)) bgpGblState_obj.As = &_localAs } if value, ok := bgpGblDataJson["routerId"].(string); ok { bgpGblState_obj.RouterId = &value } } return err }
var DbToYang_bgp_nbrs_nbr_af_state_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error var nbrKey string cmn_log := "GET: xfmr for BGP-nbrs-nbr-af state" nbrs_af_state_obj, nbr_af_key, get_err := validate_nbr_af_state_get(inParams, cmn_log) if get_err != nil { return get_err } var afiSafi_cmd string switch nbr_af_key.afiSafiNameEnum { case ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST: afiSafi_cmd = "ipv4" case ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST: afiSafi_cmd = "ipv6" } if cfgDbEntry, cfgdb_get_err := get_spec_nbr_af_cfg_tbl_entry(inParams.dbs[db.ConfigDB], &nbr_af_key); cfgdb_get_err == nil { nbrs_af_state_obj.AfiSafiName = nbr_af_key.afiSafiNameEnum if value, ok := cfgDbEntry["admin_status"]; ok { _enabled, _ := strconv.ParseBool(value) nbrs_af_state_obj.Enabled = &_enabled } if value, ok := cfgDbEntry["soft_reconfiguration_in"]; ok { _softReconfigurationIn, _ := strconv.ParseBool(value) nbrs_af_state_obj.SoftReconfigurationIn = &_softReconfigurationIn } if value, ok := cfgDbEntry["unsuppress_map_name"]; ok { nbrs_af_state_obj.UnsuppressMapName = &value } if value, ok := cfgDbEntry["weight"]; ok { if _weight_u64, err := strconv.ParseUint(value, 10, 32); err == nil { _weight_u32 := uint32(_weight_u64) nbrs_af_state_obj.Weight = &_weight_u32 } } if value, ok := cfgDbEntry["as_override"]; ok { _asOverride, _ := strconv.ParseBool(value) nbrs_af_state_obj.AsOverride = &_asOverride } if value, ok := cfgDbEntry["send_community"]; ok { switch value { case "standard": nbrs_af_state_obj.SendCommunity = ocbinds.OpenconfigBgpExt_BgpExtCommunityType_STANDARD case "extended": nbrs_af_state_obj.SendCommunity = ocbinds.OpenconfigBgpExt_BgpExtCommunityType_EXTENDED case "both": nbrs_af_state_obj.SendCommunity = ocbinds.OpenconfigBgpExt_BgpExtCommunityType_BOTH case "none": nbrs_af_state_obj.SendCommunity = ocbinds.OpenconfigBgpExt_BgpExtCommunityType_NONE case "large": nbrs_af_state_obj.SendCommunity = ocbinds.OpenconfigBgpExt_BgpExtCommunityType_LARGE case "all": nbrs_af_state_obj.SendCommunity = ocbinds.OpenconfigBgpExt_BgpExtCommunityType_ALL } } if value, ok := cfgDbEntry["rrclient"]; ok { _routeReflectorClient, _ := strconv.ParseBool(value) nbrs_af_state_obj.RouteReflectorClient = &_routeReflectorClient } } vtysh_cmd := "show ip bgp vrf " + nbr_af_key.niName + " " + afiSafi_cmd + " neighbors " + nbr_af_key.nbrAddr + " json" nbrMapJson, nbr_cmd_err := exec_vtysh_cmd(vtysh_cmd) if nbr_cmd_err != nil { log.Errorf("Failed to fetch bgp neighbors state info for niName:%s nbrAddr:%s afi-safi-name:%s. Err: %s, Cmd: %s\n", nbr_af_key.niName, nbr_af_key.nbrAddr, afiSafi_cmd, nbr_cmd_err, vtysh_cmd) return nil } if net.ParseIP(nbr_af_key.nbrAddr) == nil { nbrKey = nbr_af_key.nbrAddr } else { nbrKey = net.ParseIP(nbr_af_key.nbrAddr).String() } frrNbrDataJson, ok := nbrMapJson[nbrKey].(map[string]interface{}) if !ok { log.Errorf("Failed data from bgp neighbors state info for niName:%s nbrAddr:%s afi-safi-name:%s. Err: %s vtysh_cmd: %s \n", nbr_af_key.niName, nbr_af_key.nbrAddr, afiSafi_cmd, nbr_cmd_err, vtysh_cmd) return nil } _active := false var _prefixes ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_Bgp_Neighbors_Neighbor_AfiSafis_AfiSafi_State_Prefixes var _activeRcvdPrefixes, _activeSentPrefixes uint32 nbrs_af_state_obj.AfiSafiName = nbr_af_key.afiSafiNameEnum if AddrFamilyMap, ok := frrNbrDataJson["addressFamilyInfo"].(map[string]interface{}); ok { log.Info("Family dump: %v %d", AddrFamilyMap, nbrs_af_state_obj.AfiSafiName) if nbrs_af_state_obj.AfiSafiName == ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST { if ipv4UnicastMap, ok := AddrFamilyMap["ipv4Unicast"].(map[string]interface{}); ok { log.Info("IPv4 dump: %v", AddrFamilyMap) _active = true if value, ok := ipv4UnicastMap["acceptedPrefixCounter"]; ok { _activeRcvdPrefixes = uint32(value.(float64)) log.Info("IPv4 dump recd: %d", _activeRcvdPrefixes) _prefixes.Received = &_activeRcvdPrefixes } if value, ok := ipv4UnicastMap["sentPrefixCounter"]; ok { _activeSentPrefixes = uint32(value.(float64)) _prefixes.Sent = &_activeSentPrefixes log.Info("IPv4 dump set: %d", _activeSentPrefixes) } } } else if nbrs_af_state_obj.AfiSafiName == ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST { if ipv6UnicastMap, ok := AddrFamilyMap["ipv6Unicast"].(map[string]interface{}); ok { _active = true if value, ok := ipv6UnicastMap["acceptedPrefixCounter"]; ok { _activeRcvdPrefixes = uint32(value.(float64)) _prefixes.Received = &_activeRcvdPrefixes } if value, ok := ipv6UnicastMap["sentPrefixCounter"]; ok { _activeSentPrefixes = uint32(value.(float64)) _prefixes.Sent = &_activeSentPrefixes } } } } vtysh_cmd = "show ip bgp vrf " + nbr_af_key.niName + " " + afiSafi_cmd + " neighbors " + nbr_af_key.nbrAddr + " received-routes json" rcvdRoutesJson, rcvd_cmd_err := exec_vtysh_cmd(vtysh_cmd) if rcvd_cmd_err != nil { log.Errorf("Failed check to fetch bgp neighbors received-routes state info for niName:%s nbrAddr:%s afi-safi-name:%s. Err: %s\n", nbr_af_key.niName, nbr_af_key.nbrAddr, afiSafi_cmd, rcvd_cmd_err) } if rcvd_cmd_err == nil { var _receivedPrePolicy uint32 if value, ok := rcvdRoutesJson["totalPrefixCounter"]; ok { _active = true _receivedPrePolicy = uint32(value.(float64)) _prefixes.ReceivedPrePolicy = &_receivedPrePolicy } } nbrs_af_state_obj.Active = &_active nbrs_af_state_obj.Prefixes = &_prefixes return err }
var DbToYang_bgp_nbrs_nbr_auth_password_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error var bgp_obj *ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_Bgp bgp_obj, niName, err := getBgpRoot(inParams) if err != nil { log.Errorf("BGP root get failed!") return err } pathInfo := NewPathInfo(inParams.uri) targetUriPath, _ := getYangPathFromUri(pathInfo.Path) nbrAddr := pathInfo.Var("neighbor-address") log.Infof("DbToYang_bgp_nbrs_nbr_auth_password_xfmr VRF:%s nbrAddr:%s URI:%s", niName, nbrAddr, targetUriPath) nbrs_obj := bgp_obj.Neighbors if nbrs_obj == nil { log.Errorf("Error: Neighbors container missing") return err } nbr_obj, ok := nbrs_obj.Neighbor[nbrAddr] if !ok { log.Infof("%s Neighbor object missing, add new", nbrAddr) nbr_obj, _ = nbrs_obj.NewNeighbor(nbrAddr) } ygot.BuildEmptyTree(nbr_obj) var nbr_key _xfmr_bgp_nbr_state_key nbr_key.niName = niName nbr_key.nbrAddr = nbrAddr if cfgDbEntry, cfgdb_get_err := get_spec_nbr_cfg_tbl_entry(inParams.dbs[db.ConfigDB], &nbr_key); cfgdb_get_err == nil { if value, ok := cfgDbEntry["auth_password"]; ok { nbr_obj.AuthPassword.Config.Password = &value nbr_obj.AuthPassword.State.Password = &value encrypted := true nbr_obj.AuthPassword.Config.Encrypted = &encrypted nbr_obj.AuthPassword.State.Encrypted = &encrypted } } return err }
var DbToYang_bgp_nbrs_nbr_state_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error cmn_log := "GET: xfmr for BGP-nbrs state" get_req_uri_type := E_bgp_nbr_state_get_req_uri_nbr_state pathInfo := NewPathInfo(inParams.uri) targetUriPath, err := getYangPathFromUri(pathInfo.Path) switch targetUriPath { case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/timers/state": cmn_log = "GET: xfmr for BGP-nbrs timers state" get_req_uri_type = E_bgp_nbr_state_get_req_uri_nbr_timers_state case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/neighbors/neighbor/transport/state": cmn_log = "GET: xfmr for BGP-nbrs transport state" get_req_uri_type = E_bgp_nbr_state_get_req_uri_nbr_transport_state } nbr_obj, nbr_key, get_err := validate_nbr_state_get(inParams, cmn_log) if get_err != nil { log.Info("Neighbor state get subtree error: ", get_err) return get_err } err = get_specific_nbr_state(get_req_uri_type, nbr_obj, inParams.dbs[db.ConfigDB], &nbr_key) return err }
var DbToYang_bgp_peer_group_mbrs_state_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error cmn_log := "GET: xfmr for BGP Peer Group members state" pgrp_obj, pgrp_key, get_err := validate_pgrp_state_get(inParams, cmn_log) if get_err != nil { log.Info("Peer Group members state get subtree error: ", get_err) return get_err } err = get_specific_pgrp_state(pgrp_obj, &pgrp_key) return err }
var DbToYang_bgp_pgrp_auth_password_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error var bgp_obj *ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_Bgp bgp_obj, niName, err := getBgpRoot(inParams) if err != nil { log.Errorf("BGP root get failed!") return err } pathInfo := NewPathInfo(inParams.uri) targetUriPath, _ := getYangPathFromUri(pathInfo.Path) pgrp := pathInfo.Var("peer-group-name") log.Infof("DbToYang_bgp_pgrp_auth_password_xfmr VRF:%s Peer group:%s URI:%s", niName, pgrp, targetUriPath) pgrps_obj := bgp_obj.PeerGroups if pgrps_obj == nil { log.Errorf("Error: PeerGroup container missing") return err } pgrp_obj, ok := pgrps_obj.PeerGroup[pgrp] if !ok { log.Infof("%s PeerGroup object missing, add new", pgrp) pgrp_obj, _ = pgrps_obj.NewPeerGroup(pgrp) } ygot.BuildEmptyTree(pgrp_obj) pgrpCfgTblTs := &db.TableSpec{Name: "BGP_PEER_GROUP"} pgrpEntryKey := db.Key{Comp: []string{niName, pgrp}} var entryValue db.Value if entryValue, err = inParams.dbs[db.ConfigDB].GetEntry(pgrpCfgTblTs, pgrpEntryKey); err != nil { return err } if value, ok := entryValue.Field["auth_password"]; ok { pgrp_obj.AuthPassword.Config.Password = &value pgrp_obj.AuthPassword.State.Password = &value encrypted := true pgrp_obj.AuthPassword.Config.Encrypted = &encrypted pgrp_obj.AuthPassword.State.Encrypted = &encrypted } return err }
var DbToYang_bgp_routes_get_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error oper_err := errors.New("Opertational error") cmn_log := "GET: xfmr for BGP-RIB" var bgp_obj *ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_Bgp var rib_key _xfmr_bgp_rib_key bgp_obj, rib_key.niName, err = getBgpRoot(inParams) if err != nil { log.Errorf("%s failed !! Error:%s", cmn_log, err) return oper_err } bgpRib_obj := bgp_obj.Rib if bgpRib_obj == nil { log.Errorf("%s failed !! Error: BGP RIB container missing", cmn_log) return oper_err } pathInfo := NewPathInfo(inParams.uri) targetUriPath, err := getYangPathFromUri(pathInfo.Path) rib_key.afiSafiName = pathInfo.Var("afi-safi-name") rib_key.prefix = pathInfo.Var("prefix") rib_key.origin = pathInfo.Var("origin") rib_key.pathIdKey = pathInfo.Var("path-id") _pathId, err := strconv.Atoi(pathInfo.Var("path-id")) rib_key.pathId = uint32(_pathId) rib_key.nbrAddr = pathInfo.Var("neighbor-address") dbg_log := cmn_log + " Path: " + targetUriPath log.Info(dbg_log) switch targetUriPath { case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis": err = get_all_bgp_rib_objs(bgpRib_obj, &rib_key, &dbg_log) if err != nil { return oper_err } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi": if rib_key.afiSafiName == "" { err = get_all_bgp_rib_objs(bgpRib_obj, &rib_key, &dbg_log) if err != nil { return oper_err } } else { switch rib_key.afiSafiName { case "IPV4_UNICAST": err = get_all_ipv4_bgp_rib_objs(bgpRib_obj, &rib_key, &dbg_log) if err != nil { return oper_err } case "IPV6_UNICAST": err = get_all_ipv6_bgp_rib_objs(bgpRib_obj, &rib_key, &dbg_log) if err != nil { return oper_err } } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast": if rib_key.afiSafiName == "IPV4_UNICAST" { err = get_all_ipv4_bgp_rib_objs(bgpRib_obj, &rib_key, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast": if rib_key.afiSafiName == "IPV6_UNICAST" { err = get_all_ipv6_bgp_rib_objs(bgpRib_obj, &rib_key, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/loc-rib": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/loc-rib/routes": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/loc-rib/routes/route": if rib_key.afiSafiName == "IPV4_UNICAST" { err = hdl_get_bgp_local_rib(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/loc-rib": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/loc-rib/routes": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/loc-rib/routes/route": if rib_key.afiSafiName == "IPV6_UNICAST" { err = hdl_get_bgp_local_rib(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/neighbors": if rib_key.afiSafiName == "IPV4_UNICAST" { err = hdl_get_all_bgp_nbrs_adj_rib(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/neighbors/neighbor": if rib_key.afiSafiName == "IPV4_UNICAST" { if rib_key.nbrAddr == "" { err = hdl_get_all_bgp_nbrs_adj_rib(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, &dbg_log) if err != nil { return oper_err } } else { err = get_all_bgp_nbrs_adj_rib_for_specific_nbr(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, &dbg_log) if err != nil { return oper_err } } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/neighbors/neighbor/adj-rib-in-pre": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/neighbors/neighbor/adj-rib-in-pre/routes": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/neighbors/neighbor/adj-rib-in-pre/routes/route": if rib_key.afiSafiName == "IPV4_UNICAST" { err = hdl_get_bgp_nbrs_adj_rib_in_pre(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/neighbors/neighbor/adj-rib-in-post": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/neighbors/neighbor/adj-rib-in-post/routes": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/neighbors/neighbor/adj-rib-in-post/routes/route": if rib_key.afiSafiName == "IPV4_UNICAST" { err = hdl_get_bgp_nbrs_adj_rib_in_post(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/neighbors/neighbor/adj-rib-out-post": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/neighbors/neighbor/adj-rib-out-post/routes": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/neighbors/neighbor/adj-rib-out-post/routes/route": if rib_key.afiSafiName == "IPV4_UNICAST" { err = hdl_get_bgp_nbrs_adj_rib_out_post(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv4-unicast/openconfig-rib-bgp-ext:loc-rib-prefix/routes/route": if rib_key.afiSafiName == "IPV4_UNICAST" && rib_key.prefix != "" { err = hdl_get_bgp_local_rib_prefix(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV4_UNICAST, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/neighbors": if rib_key.afiSafiName == "IPV6_UNICAST" { err = hdl_get_all_bgp_nbrs_adj_rib(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/neighbors/neighbor": if rib_key.afiSafiName == "IPV6_UNICAST" { if rib_key.nbrAddr == "" { err = hdl_get_all_bgp_nbrs_adj_rib(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST, &dbg_log) if err != nil { return oper_err } } else { err = get_all_bgp_nbrs_adj_rib_for_specific_nbr(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST, &dbg_log) if err != nil { return oper_err } } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/neighbors/neighbor/adj-rib-in-pre": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/neighbors/neighbor/adj-rib-in-pre/routes": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/neighbors/neighbor/adj-rib-in-pre/routes/route": if rib_key.afiSafiName == "IPV6_UNICAST" { err = hdl_get_bgp_nbrs_adj_rib_in_pre(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/neighbors/neighbor/adj-rib-in-post": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/neighbors/neighbor/adj-rib-in-post/routes": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/neighbors/neighbor/adj-rib-in-post/routes/route": if rib_key.afiSafiName == "IPV6_UNICAST" { err = hdl_get_bgp_nbrs_adj_rib_in_post(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/neighbors/neighbor/adj-rib-out-post": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/neighbors/neighbor/adj-rib-out-post/routes": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/neighbors/neighbor/adj-rib-out-post/routes/route": if rib_key.afiSafiName == "IPV6_UNICAST" { err = hdl_get_bgp_nbrs_adj_rib_out_post(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/ipv6-unicast/openconfig-rib-bgp-ext:loc-rib-prefix/routes/route": if rib_key.afiSafiName == "IPV6_UNICAST" && rib_key.prefix != "" { err = hdl_get_bgp_local_rib_prefix(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_IPV6_UNICAST, &dbg_log) if err != nil { return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/openconfig-bgp-evpn-ext:l2vpn-evpn": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/openconfig-bgp-evpn-ext:l2vpn-evpn/loc-rib": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/openconfig-bgp-evpn-ext:l2vpn-evpn/loc-rib/routes": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/openconfig-bgp-evpn-ext:l2vpn-evpn/loc-rib/routes/route": if (rib_key.afiSafiName == "") || (rib_key.afiSafiName == "L2VPN_EVPN") { err = hdl_get_bgp_l2vpn_evpn_local_rib(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_L2VPN_EVPN, &dbg_log) if err != nil { log.Errorf("%s L2VPN_EVPN failed !! Error: BGP RIB container missing", cmn_log) return oper_err } } case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/openconfig-bgp-evpn-ext:l2vpn-evpn/neighbors": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/openconfig-bgp-evpn-ext:l2vpn-evpn/neighbors/neighbor": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/openconfig-bgp-evpn-ext:l2vpn-evpn/neighbors/neighbor/adj-rib-in-pre": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/openconfig-bgp-evpn-ext:l2vpn-evpn/neighbors/neighbor/adj-rib-in-pre/routes": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/openconfig-bgp-evpn-ext:l2vpn-evpn/neighbors/neighbor/adj-rib-in-pre/routes/route": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/openconfig-bgp-evpn-ext:l2vpn-evpn/neighbors/neighbor/adj-rib-out-post": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/openconfig-bgp-evpn-ext:l2vpn-evpn/neighbors/neighbor/adj-rib-out-post/routes": fallthrough case "/openconfig-network-instance:network-instances/network-instance/protocols/protocol/bgp/rib/afi-safis/afi-safi/openconfig-bgp-evpn-ext:l2vpn-evpn/neighbors/neighbor/adj-rib-out-post/routes/route": if rib_key.afiSafiName == "L2VPN_EVPN" { err = hdl_get_all_bgp_nbrs_evpn_adj_rib(bgpRib_obj, &rib_key, ocbinds.OpenconfigBgpTypes_AFI_SAFI_TYPE_L2VPN_EVPN, &dbg_log) if err != nil { return oper_err } } } return err }
var DbToYang_fdb_mac_table_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error pathInfo := NewPathInfo(inParams.uri) instance := pathInfo.Var("name") vlan := pathInfo.Var("vlan") macAddress := pathInfo.Var("mac-address") if strings.HasPrefix(instance, "Vrf") { return nil } targetUriPath, err := getYangPathFromUri(inParams.uri) log.Info("targetUriPath is ", targetUriPath) macTbl := getFdbMacTableRoot(inParams.ygRoot, instance, true) if macTbl == nil { log.Info("DbToYang_fdb_mac_table_xfmr - getFdbMacTableRoot returned nil, for URI: ", inParams.uri) return errors.New("Not able to get FDB MacTable root.") } ygot.BuildEmptyTree(macTbl) if vlan == "" || macAddress == "" { err = fdbMacTableGetAll(inParams) } else { vlanString := strings.HasPrefix(vlan, "Vlan") if vlanString == true { vlan = strings.Replace(vlan, "", "Vlan", 0) } oidToVlan, brPrtOidToIntfOid, fdbMap, err := getASICStateMaps(inParams.dbs[db.AsicDB]) if err != nil { log.Error("getASICStateMaps failed.") return err } oidInfMap, _ := getOidToIntfNameMap(inParams.dbs[db.CountersDB]) err = fdbMacTableGetEntry(inParams, vlan, macAddress, oidInfMap, oidToVlan, brPrtOidToIntfOid, fdbMap, macTbl) } return err }
var DbToYang_igmp_snooping_subtree_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { fmt.Println("DbToYang_igmp_snooping_subtree_xfmr entering => ", inParams) path, err := getUriPath(inParams.uri) pathInfo := NewPathInfo(inParams.uri) niName := pathInfo.Var("name") protoId := pathInfo.Var("identifier") if strings.Contains(protoId, "IGMP_SNOOPING") == false { return errors.New("IGMP Proto ID is missing") } if err != nil { return err } else if niName != "default" { fmt.Println("YangToDb_igmp_snooping_subtree_xfmr - called with incorrect network-instance - name => ", niName, " and returning error..") return tlerr.NotFound("Resource Not Found") } reqP := &reqProcessor{&inParams.uri, path, inParams.oper, (*inParams.ygRoot).(*ocbinds.Device), inParams.param, inParams.d, inParams.dbs, nil, nil, nil, nil} fmt.Println("YangToDb_igmp_snooping_subtree_xfmr => translateToDb == reqP.uri => ", *reqP.uri) if err := reqP.setIGMPSnoopingObjFromReq(); err != nil { return err } if reqP.igmpsObj != nil { fmt.Println("YangToDb_igmp_snooping_subtree_xfmr ==> printing IGMPSnooping object request ==> ") pretty.Print(*reqP.igmpsObj) } reqP.targetNode, err = getYangNode(reqP.uriPath) if err != nil { return tlerr.InvalidArgs("Invalid request - error: %v", err) } return reqP.translateToYgotObj() }
var DbToYang_intf_get_counters_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error intfsObj := getIntfsRoot(inParams.ygRoot) pathInfo := NewPathInfo(inParams.uri) intfName := pathInfo.Var("name") targetUriPath, err := getYangPathFromUri(inParams.uri) log.Info("targetUriPath is ", targetUriPath) if strings.Contains(targetUriPath, "/openconfig-interfaces:interfaces/interface/state/counters") == false { log.Info("%s is redundant", targetUriPath) return err } intfType, _, ierr := getIntfTypeByName(intfName) if intfType == IntfTypeUnset || ierr != nil { log.Info("DbToYang_intf_get_counters_xfmr - Invalid interface type IntfTypeUnset") return errors.New("Invalid interface type IntfTypeUnset") } intTbl := IntfTypeTblMap[intfType] if intTbl.CountersHdl.PopulateCounters == nil { log.Infof("Counters for Interface: %s not supported!", intfName) return nil } var state_counters *ocbinds.OpenconfigInterfaces_Interfaces_Interface_State_Counters if intfsObj != nil && intfsObj.Interface != nil && len(intfsObj.Interface) > 0 { var ok bool = false var intfObj *ocbinds.OpenconfigInterfaces_Interfaces_Interface if intfObj, ok = intfsObj.Interface[intfName]; !ok { intfObj, _ = intfsObj.NewInterface(intfName) ygot.BuildEmptyTree(intfObj) } ygot.BuildEmptyTree(intfObj) if intfObj.State == nil || intfObj.State.Counters == nil { ygot.BuildEmptyTree(intfObj.State) } state_counters = intfObj.State.Counters } else { ygot.BuildEmptyTree(intfsObj) intfObj, _ := intfsObj.NewInterface(intfName) ygot.BuildEmptyTree(intfObj) state_counters = intfObj.State.Counters } err = intTbl.CountersHdl.PopulateCounters(inParams, state_counters) log.Info("DbToYang_intf_get_counters_xfmr - ", state_counters) return err }
var DbToYang_intf_get_ether_counters_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error intfsObj := getIntfsRoot(inParams.ygRoot) pathInfo := NewPathInfo(inParams.uri) intfName := pathInfo.Var("name") targetUriPath, err := getYangPathFromUri(inParams.uri) intfType, _, ierr := getIntfTypeByName(intfName) if intfType == IntfTypeUnset || ierr != nil { log.Info("DbToYang_intf_get_ether_counters_xfmr - Invalid interface type IntfTypeUnset") return errors.New("Invalid interface type IntfTypeUnset") } if intfType == IntfTypeMgmt { log.Info("DbToYang_intf_get_ether_counters_xfmr - Ether Stats not supported.") return errors.New("Ethernet counters not supported.") } if (strings.Contains(targetUriPath, "/openconfig-interfaces:interfaces/interface/ethernet/state/counters") == false) && (strings.Contains(targetUriPath, "/openconfig-interfaces:interfaces/interface/openconfig-if-ethernet:ethernet/state/counters") == false) { log.Info("%s is redundant", targetUriPath) return err } var intfObj *ocbinds.OpenconfigInterfaces_Interfaces_Interface var eth_counters *ocbinds.OpenconfigInterfaces_Interfaces_Interface_Ethernet_State_Counters if intfsObj != nil && intfsObj.Interface != nil && len(intfsObj.Interface) > 0 { var ok bool = false if intfObj, ok = intfsObj.Interface[intfName]; !ok { intfObj, _ = intfsObj.NewInterface(intfName) } ygot.BuildEmptyTree(intfObj) } else { ygot.BuildEmptyTree(intfsObj) intfObj, _ = intfsObj.NewInterface(intfName) ygot.BuildEmptyTree(intfObj) } ygot.BuildEmptyTree(intfObj.Ethernet) ygot.BuildEmptyTree(intfObj.Ethernet.State) ygot.BuildEmptyTree(intfObj.Ethernet.State.Counters) eth_counters = intfObj.Ethernet.State.Counters return populatePortCounters(inParams, eth_counters) }
var DbToYang_intf_ip_addr_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error intfsObj := getIntfsRoot(inParams.ygRoot) pathInfo := NewPathInfo(inParams.uri) intfName := pathInfo.Var("name") targetUriPath, err := getYangPathFromUri(inParams.uri) log.Info("targetUriPath is ", targetUriPath) var intfObj *ocbinds.OpenconfigInterfaces_Interfaces_Interface if strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/subinterfaces") { if intfsObj != nil && intfsObj.Interface != nil && len(intfsObj.Interface) > 0 { var ok bool = false if intfObj, ok = intfsObj.Interface[intfName]; !ok { intfObj, _ = intfsObj.NewInterface(intfName) } ygot.BuildEmptyTree(intfObj) if intfObj.Subinterfaces == nil { ygot.BuildEmptyTree(intfObj.Subinterfaces) } } else { ygot.BuildEmptyTree(intfsObj) intfObj, _ = intfsObj.NewInterface(intfName) ygot.BuildEmptyTree(intfObj) } } else { err = errors.New("Invalid URI : " + targetUriPath) } err = handleIntfIPGetByTargetURI(inParams, targetUriPath, intfName, intfObj) return err }
var DbToYang_intf_lag_state_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error intfsObj := getIntfsRoot(inParams.ygRoot) if intfsObj == nil || intfsObj.Interface == nil { errStr := "Failed to Get root object!" log.Errorf(errStr) return errors.New(errStr) } pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") if _, ok := intfsObj.Interface[ifName]; !ok { obj, _ := intfsObj.NewInterface(ifName) ygot.BuildEmptyTree(obj) } intfObj := intfsObj.Interface[ifName] if intfObj.Aggregation == nil { return errors.New("Not a valid request") } if intfObj.Aggregation.State == nil { return errors.New("Not a valid PortChannel Get request") } intfType, _, err := getIntfTypeByName(ifName) if intfType != IntfTypePortChannel || err != nil { intfTypeStr := strconv.Itoa(int(intfType)) errStr := "TableXfmrFunc - Invalid interface type" + intfTypeStr log.Error(errStr) return errors.New(errStr) } intTbl := IntfTypeTblMap[IntfTypePortChannel] err = validateLagExists(inParams.d, &intTbl.cfgDb.portTN, &ifName) if err != nil { return err } targetUriPath, err := getYangPathFromUri(inParams.uri) log.Info("targetUriPath is ", targetUriPath) lagInfoMap := make(map[string]db.Value) ocAggregationStateVal := intfObj.Aggregation.State err = fillLagInfoForIntf(inParams.d, &ifName, lagInfoMap) if err != nil { log.Errorf("Failed to get info: %s failed!", ifName) return err } log.Info("Succesfully completed DB map population!", lagInfoMap) switch targetUriPath { case "/openconfig-interfaces:interfaces/interface/openconfig-if-aggregate:aggregation/state/min-links": log.Info("Get is for min-links") attr := "min-links" err = getLagStateAttr(&attr, &ifName, lagInfoMap, ocAggregationStateVal) if err != nil { return err } case "/openconfig-interfaces:interfaces/interface/openconfig-if-aggregate:aggregation/state/lag-type": log.Info("Get is for lag type") attr := "mode" err = getLagStateAttr(&attr, &ifName, lagInfoMap, ocAggregationStateVal) if err != nil { return err } case "/openconfig-interfaces:interfaces/interface/openconfig-if-aggregate:aggregation/state/openconfig-interfaces-ext:fallback": log.Info("Get is for fallback") attr := "fallback" err = getLagStateAttr(&attr, &ifName, lagInfoMap, ocAggregationStateVal) if err != nil { return err } case "/openconfig-interfaces:interfaces/interface/openconfig-if-aggregate:aggregation/state/member": log.Info("Get is for member") attr := "member" err = getLagStateAttr(&attr, &ifName, lagInfoMap, ocAggregationStateVal) if err != nil { return err } case "/openconfig-interfaces:interfaces/interface/openconfig-if-aggregate:aggregation/state": log.Info("Get is for State Container!") err = getLagState(&ifName, lagInfoMap, ocAggregationStateVal) if err != nil { return err } default: log.Infof(targetUriPath + " - Not an supported Get attribute") } return err }
PortChannel GET operation
var DbToYang_intf_nat_zone_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error intfsObj := getIntfsRoot(inParams.ygRoot) pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") targetUriPath, err := getYangPathFromUri(inParams.uri) log.Info("targetUriPath is ", targetUriPath) var intfObj *ocbinds.OpenconfigInterfaces_Interfaces_Interface intfType, _, ierr := getIntfTypeByName(ifName) if intfType == IntfTypeUnset || ierr != nil { errStr := "Invalid interface type IntfTypeUnset" log.Info("YangToDb_intf_subintf_ip_xfmr : " + errStr) return errors.New(errStr) } intTbl := IntfTypeTblMap[intfType] config, state := false, false if strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/openconfig-interfaces-ext:nat-zone/config") || strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/nat-zone/config") { config = true } else if strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/openconfig-interfaces-ext:nat-zone/state") || strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/nat-zone/state") { state = true } else if strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/openconfig-interfaces-ext:nat-zone") || strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/nat-zone") { config = true state = true } else { return errors.New("DbToYang_intf_nat_zone_xfmr : Invalid URI, " + inParams.uri) } if intfsObj != nil && intfsObj.Interface != nil && len(intfsObj.Interface) > 0 { var ok bool = false if intfObj, ok = intfsObj.Interface[ifName]; !ok { intfObj, _ = intfsObj.NewInterface(ifName) } } else { ygot.BuildEmptyTree(intfsObj) intfObj, _ = intfsObj.NewInterface(ifName) } ygot.BuildEmptyTree(intfObj) ygot.BuildEmptyTree(intfObj.NatZone) if config == true { ygot.BuildEmptyTree(intfObj.NatZone.Config) entry, dbErr := inParams.dbs[db.ConfigDB].GetEntry(&db.TableSpec{Name: intTbl.cfgDb.intfTN}, db.Key{Comp: []string{ifName}}) if dbErr != nil { log.Info("Failed to read DB entry, " + intTbl.cfgDb.intfTN + " " + ifName) return nil } if entry.Has("nat_zone") { var natZone uint8 value, _ := strconv.Atoi(entry.Get("nat_zone")) natZone = uint8(value) intfObj.NatZone.Config.NatZone = &natZone } else { intfObj.NatZone.Config.NatZone = nil } } if state == true { ygot.BuildEmptyTree(intfObj.NatZone.State) entry, dbErr := inParams.dbs[db.ApplDB].GetEntry(&db.TableSpec{Name: intTbl.appDb.intfTN}, db.Key{Comp: []string{ifName}}) if dbErr != nil { log.Info("Failed to read DB entry, " + intTbl.appDb.intfTN + " " + ifName) return nil } if entry.Has("nat_zone") { var natZone uint8 value, _ := strconv.Atoi(entry.Get("nat_zone")) natZone = uint8(value) intfObj.NatZone.State.NatZone = &natZone } else { intfObj.NatZone.State.NatZone = nil } } return err }
var DbToYang_intf_sag_ip_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error intfsObj := getIntfsRoot(inParams.ygRoot) pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") targetUriPath, err := getYangPathFromUri(inParams.uri) log.Info("targetUriPath is ", targetUriPath) var intfObj *ocbinds.OpenconfigInterfaces_Interfaces_Interface intfType, _, ierr := getIntfTypeByName(ifName) if intfType == IntfTypeUnset || ierr != nil { errStr := "Invalid interface type IntfTypeUnset" log.Info("DbToYang_intf_sag_ip_xfmr : " + errStr) return errors.New(errStr) } ipv4_req := false ipv6_req := false var sagIPKey string if strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/openconfig-if-ip:ipv4/openconfig-interfaces-ext:sag-ipv4/config/static-anycast-gateway") { ipv4_req = true sagIPKey = ifName + "|IPv4" } else if strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/openconfig-if-ip:ipv6/openconfig-interfaces-ext:sag-ipv6/config/static-anycast-gateway") { ipv6_req = true sagIPKey = ifName + "|IPv6" } if ipv4_req || ipv6_req { if intfsObj != nil && intfsObj.Interface != nil && len(intfsObj.Interface) > 0 { var ok bool = false if intfObj, ok = intfsObj.Interface[ifName]; !ok { intfObj, _ = intfsObj.NewInterface(ifName) } } else { ygot.BuildEmptyTree(intfsObj) intfObj, _ = intfsObj.NewInterface(ifName) } ygot.BuildEmptyTree(intfObj) var subIntf *ocbinds.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces_Subinterface if _, ok := intfObj.Subinterfaces.Subinterface[0]; !ok { subIntf, err = intfObj.Subinterfaces.NewSubinterface(0) if err != nil { log.Error("Creation of subinterface subtree failed!") return err } } subIntf = intfObj.Subinterfaces.Subinterface[0] ygot.BuildEmptyTree(subIntf) sagIPEntry, _ := inParams.d.GetEntry(&db.TableSpec{Name: "SAG"}, db.Key{Comp: []string{sagIPKey}}) sagGwIPList := sagIPEntry.Get("gwip@") sagGwIPMap := strings.Split(sagGwIPList, ",") if ipv4_req { subIntf.Ipv4.SagIpv4.Config.StaticAnycastGateway = sagGwIPMap } else if ipv6_req { subIntf.Ipv6.SagIpv6.Config.StaticAnycastGateway = sagGwIPMap } } return err }
var DbToYang_intf_vxlan_config_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { if log.V(3) { log.Info("Entering DbToYang_intf_vxlan_config_xfmr ===> inParams.uri => ", inParams.uri) } path, err := getIntfUriPath(inParams.uri) if err != nil { return err } reqP := &vxlanReqProcessor{&inParams.requestUri, &inParams.uri, path, inParams.oper, (*inParams.ygRoot).(*ocbinds.Device), inParams.param, inParams.d, inParams.dbs, nil, nil, nil, nil, &inParams} if err := reqP.setIntfObjFromReq(); err != nil { return err } if reqP.intfObject != nil && reqP.intfObject.Name != nil { if log.V(3) { log.Info("DbToYang_intf_vxlan_config_xfmr ==> printing intf object request ==> ", (*reqP.intfObject)) } vxlanIntfName := *reqP.intfObject.Name if log.V(3) { log.Info("DbToYang_intf_vxlan_config_xfmr ==> vxlanIntfName ==> ", vxlanIntfName) } if vxlanIntfName != "" { var VXLAN_TUNNEL_TABLE_TS *db.TableSpec = &db.TableSpec{Name: "VXLAN_TUNNEL"} dbv, err := reqP.db.GetEntry(VXLAN_TUNNEL_TABLE_TS, db.Key{[]string{vxlanIntfName}}) if log.V(3) { log.Info("DbToYang_intf_vxlan_config_xfmr ======== GetEntry ===> dbv => ", dbv) } if err != nil { return tlerr.NotFound("Resource Not Found") } srcIpStr := dbv.Field["src_ip"] if log.V(3) { log.Info("DbToYang_intf_vxlan_config_xfmr ======== srcIpStr ===> ", srcIpStr) } if srcIpStr != "" { ygot.BuildEmptyTree(reqP.intfObject) if reqP.intfObject.VxlanIf != nil { if log.V(3) { log.Info("DbToYang_intf_vxlan_config_xfmr ======== reqP.intfObject.VxlanIf.Config => ", reqP.intfObject.VxlanIf.Config) } ygot.BuildEmptyTree(reqP.intfObject.VxlanIf) if log.V(3) { log.Info("DbToYang_intf_vxlan_config_xfmr ======== reqP.intfObject.VxlanIf.Config => ", reqP.intfObject.VxlanIf.Config) } reqP.intfObject.VxlanIf.Config.SourceVtepIp = &srcIpStr if log.V(3) { log.Info("DbToYang_intf_vxlan_config_xfmr ======== reqP.vxlanIntfConfigObj.SourceVtepIp ===> ", reqP.intfObject.VxlanIf.Config.SourceVtepIp) } } else { log.Error("DbToYang_intf_vxlan_config_xfmr ======== reqP.intfObject.VxlanIf is nil") } } } } return nil }
var DbToYang_ipv4_route_get_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error var aftsObj *ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Afts var niName string var prefix string aftsObj, niName, prefix, err = getIpRoot(inParams) _ = niName if err != nil { return err } aftsObjIpv4 := aftsObj.Ipv4Unicast if aftsObjIpv4 == nil { return errors.New("Network-instance IPv4 unicast object missing") } var outputJson map[string]interface{} cmd := "show ip route vrf " + niName if len(prefix) > 0 { cmd += " " cmd += prefix } cmd += " json" log.Infof("vty cmd [%s]", cmd) if outputJson, err = exec_vtysh_cmd(cmd); err == nil { for prfxKey, prfxVal := range outputJson { err = fill_ipv4_entry(prfxVal.([]interface{}), prfxKey, aftsObjIpv4) if err != nil { return err } } } return err }
var DbToYang_ipv6_route_get_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error var aftsObj *ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Afts var niName string var prefix string aftsObj, niName, prefix, err = getIpRoot(inParams) _ = niName if err != nil { return err } aftsObjIpv6 := aftsObj.Ipv6Unicast if aftsObjIpv6 == nil { return errors.New("Network-instance IPv6 unicast object missing") } var outputJson map[string]interface{} cmd := "show ipv6 route vrf " + niName if len(prefix) > 0 { cmd += " " cmd += prefix } cmd += " json" log.Infof("vty cmd [%s]", cmd) if outputJson, err = exec_vtysh_cmd(cmd); err == nil { for prfxKey, prfxVal := range outputJson { err = fill_ipv6_entry(prfxVal.([]interface{}), prfxKey, aftsObjIpv6) if err != nil { return err } } } return err }
var DbToYang_lacp_get_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { lacpIntfsObj := getLacpRoot(inParams.ygRoot) var members *ocbinds.OpenconfigLacp_Lacp_Interfaces_Interface_Members var member *ocbinds.OpenconfigLacp_Lacp_Interfaces_Interface_Members_Member var lacpintfObj *ocbinds.OpenconfigLacp_Lacp_Interfaces_Interface var ok bool pathInfo := NewPathInfo(inParams.uri) ifKey := pathInfo.Var("name") ifMemKey := pathInfo.Var("interface") targetUriPath, err := getYangPathFromUri(pathInfo.Path) if err != nil { log.Warningf("Get Yang Path from URI failed") return err } log.Infof("Received GET for path: %s; template: %s vars: %v targetUriPath: %s ifKey: %s", pathInfo.Path, pathInfo.Template, pathInfo.Vars, targetUriPath, ifKey) if isSubtreeRequest(targetUriPath, "/openconfig-lacp:lacp/interfaces/interface/members/member") { if lacpintfObj, ok = lacpIntfsObj.Interfaces.Interface[ifKey]; !ok { errStr := "PortChannel Instance doesn't exist" log.Info(errStr) return errors.New(errStr) } members = lacpintfObj.Members if members != nil && ifMemKey != "" { if member, ok = members.Member[ifMemKey]; !ok { errStr := "PortChannel Member Instance doesn't exist" log.Info(errStr) return errors.New(errStr) } ygot.BuildEmptyTree(member) return populateLacpMember(ifKey, ifMemKey, member) } } else if isSubtreeRequest(targetUriPath, "/openconfig-lacp:lacp/interfaces/interface/members") { if lacpintfObj, ok = lacpIntfsObj.Interfaces.Interface[ifKey]; !ok { errStr := "PortChannel Instance doesn't exist" log.Info(errStr) return errors.New(errStr) } members = lacpintfObj.Members if members != nil && ifKey != "" { return populateLacpMembers(ifKey, members) } } else if isSubtreeRequest(targetUriPath, "/openconfig-lacp:lacp/interfaces/interface") { if lacpIntfsObj.Interfaces.Interface != nil && len(lacpIntfsObj.Interfaces.Interface) > 0 && ifKey != "" { lacpintfObj, ok = lacpIntfsObj.Interfaces.Interface[ifKey] if !ok { lacpintfObj, _ = lacpIntfsObj.Interfaces.NewInterface(ifKey) } ygot.BuildEmptyTree(lacpintfObj) return populateLacpData(ifKey, lacpintfObj.State, lacpintfObj.Members) } } else if isSubtreeRequest(targetUriPath, "/openconfig-lacp:lacp/interfaces") { ygot.BuildEmptyTree(lacpIntfsObj) var lagTblTs = &db.TableSpec{Name: "LAG_TABLE"} var appDb = inParams.dbs[db.ApplDB] tbl, err := appDb.GetTable(lagTblTs) if err != nil { log.Error("App-DB get for list of portchannels failed!") return err } keys, _ := tbl.GetKeys() for _, key := range keys { ifKey := key.Get(0) lacpintfObj, ok = lacpIntfsObj.Interfaces.Interface[ifKey] if !ok { lacpintfObj, _ = lacpIntfsObj.Interfaces.NewInterface(ifKey) } ygot.BuildEmptyTree(lacpintfObj) populateLacpData(ifKey, lacpintfObj.State, lacpintfObj.Members) } } else { log.Info("Unsupported Path") } return nil }
var DbToYang_mclag_interface_subtree_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error data := (*inParams.dbDataMap)[inParams.curDb] mclagObj := getMclagRoot(inParams.ygRoot) pathInfo := NewPathInfo(inParams.uri) log.Info("DbToYang_mclag_interface_subtree_xfmr: ", data, inParams.ygRoot) if isSubtreeRequest(pathInfo.Template, "/openconfig-mclag:mclag/interfaces/interface{name}") { mclagIntfKeys, _ := inParams.d.GetKeys(&db.TableSpec{Name: "MCLAG_INTERFACE"}) if len(mclagIntfKeys) > 0 { for _, intfKey := range mclagIntfKeys { ifname := intfKey.Get(1) if ifname == pathInfo.Var("name") && mclagObj.Interfaces != nil { for k, _ := range mclagObj.Interfaces.Interface { intfData := mclagObj.Interfaces.Interface[k] fillMclagIntfDetails(inParams, ifname, intfKey.Get(0), intfData) } } } } } else { var mclagIntfData map[string]map[string]string mclagIntfTbl := data["MCLAG_INTERFACE"] mclagIntfData = make(map[string]map[string]string) for key, _ := range mclagIntfTbl { tokens := strings.Split(key, "|") ifname := tokens[1] mclagIntfData[ifname] = make(map[string]string) mclagIntfData[ifname]["domainid"] = tokens[0] mclagIntfData[ifname]["ifname"] = ifname } for intfId := range mclagIntfData { if mclagObj.Interfaces == nil { ygot.BuildEmptyTree(mclagObj) } intfData, _ := mclagObj.Interfaces.NewInterface(intfId) fillMclagIntfDetails(inParams, mclagIntfData[intfId]["ifname"], mclagIntfData[intfId]["domainid"], intfData) } } return err }
var DbToYang_napt_mapping_subtree_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error {
return _DbToYang_napt_mapping_subtree_xfmr(inParams)
}
var DbToYang_nat_mapping_subtree_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error {
return _DbToYang_nat_mapping_subtree_xfmr(inParams)
}
var DbToYang_neigh_tbl_get_all_ipv4_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error var ok bool data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_neigh_tbl_get_all_ipv4_xfmr - data:", data) pathInfo := NewPathInfo(inParams.uri) targetUriPath, err := getYangPathFromUri(pathInfo.Path) log.Info("DbToYang_neigh_tbl_get_all_ipv4_xfmr - targetUriPath: ", targetUriPath) var intfObj *ocbinds.OpenconfigInterfaces_Interfaces_Interface var subIntfObj *ocbinds.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces_Subinterface var neighObj *ocbinds.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces_Subinterface_Ipv4_Neighbors_Neighbor intfsObj := getIntfsRoot(inParams.ygRoot) intfNameRcvd := pathInfo.Var("name") ipAddrRcvd := pathInfo.Var("ip") if intfObj, ok = intfsObj.Interface[intfNameRcvd]; !ok { intfObj, err = intfsObj.NewInterface(intfNameRcvd) if err != nil { log.Error("Creation of interface subtree failed!") return err } } ygot.BuildEmptyTree(intfObj) if subIntfObj, ok = intfObj.Subinterfaces.Subinterface[0]; !ok { subIntfObj, err = intfObj.Subinterfaces.NewSubinterface(0) if err != nil { log.Error("Creation of subinterface subtree failed!") return err } } ygot.BuildEmptyTree(subIntfObj) for key, entry := range data["NEIGH_TABLE"] { var ipAddr string tokens := strings.Split(key, ":") intfName := tokens[0] ipAddr = key[len(intfName)+1:] linkAddr := data["NEIGH_TABLE"][key].Field["neigh"] if linkAddr == "" { log.Info("No mac-address found for IP: ", ipAddr) continue } addrFamily := data["NEIGH_TABLE"][key].Field["family"] if addrFamily == "" { log.Info("No address family found for IP: ", ipAddr) continue } if (strings.Contains(targetUriPath, "ipv4") && addrFamily != "IPv4") || intfName != intfNameRcvd || (ipAddrRcvd != "" && ipAddrRcvd != ipAddr) { log.Info("Skipping entry: ", entry, "for interface: ", intfName, " and IP:", ipAddr, "interface received: ", intfNameRcvd, " IP received: ", ipAddrRcvd) continue } else if strings.HasPrefix(targetUriPath, NEIGH_IPv4_PREFIX_STATE_LL) { if neighObj, ok = subIntfObj.Ipv4.Neighbors.Neighbor[ipAddr]; !ok { neighObj, err = subIntfObj.Ipv4.Neighbors.NewNeighbor(ipAddr) if err != nil { log.Error("Creation of neighbor subtree failed!") return err } } ygot.BuildEmptyTree(neighObj) neighObj.State.LinkLayerAddress = &linkAddr break } else if strings.HasPrefix(targetUriPath, NEIGH_IPv4_PREFIX_STATE_IP) { if neighObj, ok = subIntfObj.Ipv4.Neighbors.Neighbor[ipAddr]; !ok { neighObj, err = subIntfObj.Ipv4.Neighbors.NewNeighbor(ipAddr) if err != nil { log.Error("Creation of neighbor subtree failed!") return err } } ygot.BuildEmptyTree(neighObj) neighObj.State.Ip = &ipAddr break } else if strings.HasPrefix(targetUriPath, NEIGH_IPv4_PREFIX_IP) { if neighObj, ok = subIntfObj.Ipv4.Neighbors.Neighbor[ipAddr]; !ok { neighObj, err = subIntfObj.Ipv4.Neighbors.NewNeighbor(ipAddr) if err != nil { log.Error("Creation of neighbor subtree failed!") return err } } ygot.BuildEmptyTree(neighObj) neighObj.State.Ip = &ipAddr neighObj.State.LinkLayerAddress = &linkAddr neighObj.State.Origin = 0 break } else if strings.HasPrefix(targetUriPath, NEIGH_IPv4_PREFIX) { if neighObj, ok = subIntfObj.Ipv4.Neighbors.Neighbor[ipAddr]; !ok { neighObj, err = subIntfObj.Ipv4.Neighbors.NewNeighbor(ipAddr) if err != nil { log.Error("Creation of neighbor subtree failed!") return err } } ygot.BuildEmptyTree(neighObj) neighObj.State.Ip = &ipAddr neighObj.State.LinkLayerAddress = &linkAddr neighObj.State.Origin = 0 } } return err }
var DbToYang_neigh_tbl_get_all_ipv6_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error var ok bool data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_neigh_tbl_get_all_ipv6_xfmr - data: ", data) pathInfo := NewPathInfo(inParams.uri) targetUriPath, err := getYangPathFromUri(pathInfo.Path) log.Info("DbToYang_neigh_tbl_get_all_ipv6_xfmr - targetUriPath: ", targetUriPath) var intfObj *ocbinds.OpenconfigInterfaces_Interfaces_Interface var subIntfObj *ocbinds.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces_Subinterface var neighObj *ocbinds.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces_Subinterface_Ipv6_Neighbors_Neighbor intfsObj := getIntfsRoot(inParams.ygRoot) intfNameRcvd := pathInfo.Var("name") ipAddrRcvd := pathInfo.Var("ip") if intfObj, ok = intfsObj.Interface[intfNameRcvd]; !ok { intfObj, err = intfsObj.NewInterface(intfNameRcvd) if err != nil { log.Error("Creation of interface subtree failed!") return err } } ygot.BuildEmptyTree(intfObj) if subIntfObj, ok = intfObj.Subinterfaces.Subinterface[0]; !ok { subIntfObj, err = intfObj.Subinterfaces.NewSubinterface(0) if err != nil { log.Error("Creation of subinterface subtree failed!") return err } } ygot.BuildEmptyTree(subIntfObj) for key, entry := range data["NEIGH_TABLE"] { var ipAddr string tokens := strings.Split(key, ":") intfName := tokens[0] ipAddr = key[len(intfName)+1:] linkAddr := data["NEIGH_TABLE"][key].Field["neigh"] if linkAddr == "" { log.Info("No mac-address found for IP: ", ipAddr) continue } addrFamily := data["NEIGH_TABLE"][key].Field["family"] if addrFamily == "" { log.Info("No address family found for IP: ", ipAddr) continue } if (strings.Contains(targetUriPath, "ipv6") && addrFamily != "IPv6") || intfName != intfNameRcvd || (ipAddrRcvd != "" && ipAddrRcvd != ipAddr) { log.Info("Skipping entry: ", entry, "for interface: ", intfName, " and IP:", ipAddr, "interface received: ", intfNameRcvd, " IP received: ", ipAddrRcvd) continue } else if strings.HasPrefix(targetUriPath, NEIGH_IPv6_PREFIX_STATE_LL) { if neighObj, ok = subIntfObj.Ipv6.Neighbors.Neighbor[ipAddr]; !ok { neighObj, err = subIntfObj.Ipv6.Neighbors.NewNeighbor(ipAddr) if err != nil { log.Error("Creation of neighbor subtree failed!") return err } } ygot.BuildEmptyTree(neighObj) neighObj.State.LinkLayerAddress = &linkAddr break } else if strings.HasPrefix(targetUriPath, NEIGH_IPv6_PREFIX_STATE_IP) { if neighObj, ok = subIntfObj.Ipv6.Neighbors.Neighbor[ipAddr]; !ok { neighObj, err = subIntfObj.Ipv6.Neighbors.NewNeighbor(ipAddr) if err != nil { log.Error("Creation of neighbor subtree failed!") return err } } ygot.BuildEmptyTree(neighObj) neighObj.State.Ip = &ipAddr break } else if strings.HasPrefix(targetUriPath, NEIGH_IPv6_PREFIX_IP) { if neighObj, ok = subIntfObj.Ipv6.Neighbors.Neighbor[ipAddr]; !ok { neighObj, err = subIntfObj.Ipv6.Neighbors.NewNeighbor(ipAddr) if err != nil { log.Error("Creation of neighbor subtree failed!") return err } } ygot.BuildEmptyTree(neighObj) neighObj.State.Ip = &ipAddr neighObj.State.LinkLayerAddress = &linkAddr neighObj.State.IsRouter = true neighObj.State.NeighborState = 0 neighObj.State.Origin = 0 break } else if strings.HasPrefix(targetUriPath, NEIGH_IPv6_PREFIX) { if neighObj, ok = subIntfObj.Ipv6.Neighbors.Neighbor[ipAddr]; !ok { neighObj, err = subIntfObj.Ipv6.Neighbors.NewNeighbor(ipAddr) if err != nil { log.Error("Creation of neighbor subtree failed!") return err } } ygot.BuildEmptyTree(neighObj) neighObj.State.Ip = &ipAddr neighObj.State.LinkLayerAddress = &linkAddr neighObj.State.IsRouter = true neighObj.State.NeighborState = 0 neighObj.State.Origin = 0 } } return err }
var DbToYang_netinst_vlans_subtree_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error var vlansObj *ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Vlans var niName string var vlanName string var vlanId uint16 log.Infof("DbToYang_netinst_vlans_subtree_xfmr: ") vlansObj, niName, vlanName, vlanId, err = getUriAttributes(inParams) if err != nil { return err } if strings.HasPrefix(niName, "Vrf") { return nil } tblName := "VLAN" dbspec := &db.TableSpec{Name: tblName} if len(vlanName) > 0 { if strings.HasPrefix(niName, "Vlan") && vlanName != niName { log.Infof("vlan_tbl_key_xfmr: vlanTbl_key %s, ntwk_inst %s ", vlanName, niName) return err } dbEntry, derr := inParams.d.GetEntry(dbspec, db.Key{Comp: []string{vlanName}}) if derr != nil { log.Infof(" dbEntry get failure for Key %s", vlanName) return errors.New("Operational Error") } VlansVlanObj := vlansObj.Vlan[vlanId] err = dbToYangFillVlanEntry(VlansVlanObj, vlanName, vlanId, dbEntry) } else { var keys []db.Key if keys, err = inParams.d.GetKeys(&db.TableSpec{Name: tblName, CompCt: 2}); err != nil { return errors.New("Operational Error") } for _, key := range keys { dbEntry, dbErr := inParams.d.GetEntry(dbspec, key) if dbErr != nil { log.Error("DB GetEntry failed for key : ", key) continue } vlanName = key.Comp[0] vlanIdStr := dbEntry.Field["vlanid"] vlanId64, _ := strconv.ParseUint(vlanIdStr, 10, 16) vlanId = uint16(vlanId64) if strings.HasPrefix(niName, "Vlan") && vlanName != niName { log.Infof("vlan_tbl_key_xfmr: vlanTbl_key %s, ntwk_inst %s ", vlanName, niName) continue } VlansVlanObj, _ := vlansObj.NewVlan(vlanId) if err = dbToYangFillVlanEntry(VlansVlanObj, vlanName, vlanId, dbEntry); err != nil { log.Error("dbToYangFillVlanEntry failure for %s", vlanName) } } } return err }
var DbToYang_network_instance_interface_binding_subtree_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error intf_tbl_name_list := [4]string{"INTERFACE", "LOOPBACK_INTERFACE", "VLAN_INTERFACE", "PORTCHANNEL_INTERFACE"} log.Info("DbToYang_network_instance_interface_binding_subtree_xfmr:") nwInstTree := getNwInstRoot(inParams.ygRoot) log.Infof("DbToYang_network_instance_interface_binding_subtree_xfmr: ygRoot %v ", nwInstTree) pathInfo := NewPathInfo(inParams.uri) pathNwInstName := pathInfo.Var("name") pathIntfId := pathInfo.Var("id") log.Infof("DbToYang_network_instance_interface_binding_subtree_xfmr, key(:%v) id(:%v)", pathNwInstName, pathIntfId) targetUriPath, _ := getYangPathFromUri(pathInfo.Path) log.Info("DbToYang_network_instance_interface_binding_subtree_xfmr, targeturiPath: ", targetUriPath) if pathNwInstName == "mgmt" { log.Info("DbToYang_network_instance_interface_binding_subtree_xfmr, no intf binding for: ", pathNwInstName) return err } if (pathNwInstName != "") && (pathIntfId != "") { intf_type, _, err := getIntfTypeByName(pathIntfId) if err != nil { log.Info("DbToYang_network_instance_interface_binding_subtree_xfmr: unknown intf type for ", pathIntfId) return err } intTbl := IntfTypeTblMap[intf_type] intf_tbl_name, _ := getIntfTableNameByDBId(intTbl, inParams.curDb) log.Info("DbToYang_network_instance_interface_binding_subtree_xfmr: intf tbl name: ", intf_tbl_name) intfTable := &db.TableSpec{Name: intf_tbl_name} intfEntry, err1 := inParams.d.GetEntry(intfTable, db.Key{Comp: []string{pathIntfId}}) if err1 != nil { log.Infof("DbToYang_network_instance_interface_binding_subtree_xfmr, no entry found for key(:%v) id(:%v)", pathNwInstName, pathIntfId) return err } vrfName_str := (&intfEntry).Get("vrf_name") if (vrfName_str == "") && (pathNwInstName == "default") { err2 := validateL3ConfigExists(inParams.d, &pathIntfId) if err2 == nil { log.Infof("DbToYang_network_instance_interface_binding_subtree_xfmr, default instance, %v not L3 intf", pathIntfId) return err } vrfName_str = "default" } else if vrfName_str != pathNwInstName { log.Info("DbToYang_network_instance_interface_binding_subtree_xfmr, vrf name not matching for key(:%v) id(:%v)", pathNwInstName, pathIntfId) return err } intfData, _ := nwInstTree.NetworkInstance[vrfName_str].Interfaces.Interface[pathIntfId] if intfData.Config == nil { ygot.BuildEmptyTree(intfData) } intfData.Config.Id = intfData.Id intfData.State.Id = intfData.Id log.Infof("DbToYang_network_instance_interface_binding_subtree_xfmr: vrf_name %v intf %v ygRoot %v ", vrfName_str, pathIntfId, nwInstTree) } else { for _, tblName := range intf_tbl_name_list { intfTable := &db.TableSpec{Name: tblName} intfKeys, err := inParams.d.GetKeys(intfTable) if err != nil { log.Info("DbToYang_network_instance_interface_binding_subtree_xfmr: error getting keys from ", tblName) return errors.New("Unable to get interface table keys") } for i, _ := range intfKeys { if (len(intfKeys[i].Comp)) > 1 { continue } intfEntry, _ := inParams.d.GetEntry(intfTable, intfKeys[i]) vrfName_str := (&intfEntry).Get("vrf_name") if ((pathNwInstName != "") && (pathNwInstName != "default") && (pathNwInstName != vrfName_str)) || ((pathNwInstName == "default") && (vrfName_str != "")) { continue } if vrfName_str == "" { tempIntfName := intfKeys[i].Comp err3 := validateL3ConfigExists(inParams.d, &tempIntfName[0]) if err3 == nil { continue } else { vrfName_str = "default" } } log.Infof("DbToYang_network_instance_interface_binding_subtree_xfmr: nwInst %v vrfname_str %v", pathNwInstName, vrfName_str) nwInstData, ok := nwInstTree.NetworkInstance[vrfName_str] if !ok { nwInstData, _ = nwInstTree.NewNetworkInstance(vrfName_str) ygot.BuildEmptyTree(nwInstData) } if nwInstTree.NetworkInstance[vrfName_str].Interfaces == nil { ygot.BuildEmptyTree(nwInstTree.NetworkInstance[vrfName_str]) } intfName := intfKeys[i].Comp var intfData *ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Interfaces_Interface if nwInstTree.NetworkInstance[vrfName_str].Interfaces.Interface == nil { intfData, _ = nwInstData.Interfaces.NewInterface(intfName[0]) ygot.BuildEmptyTree(intfData) } intfData, ok = nwInstTree.NetworkInstance[vrfName_str].Interfaces.Interface[intfName[0]] if !ok { intfData, _ = nwInstData.Interfaces.NewInterface(intfName[0]) ygot.BuildEmptyTree(intfData) } intfData.Config.Id = intfData.Id intfData.State.Id = intfData.Id log.Infof("DbToYang_network_instance_interface_binding_subtree_xfmr: vrf_name %v intf %v ygRoot %v ", vrfName_str, intfName[0], nwInstTree) } } } return err }
DbtoYang subtree transformer for network instance interface binding
var DbToYang_route_map_bgp_action_set_community SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error rtPolDefsObj := getRoutingPolicyRoot(inParams.ygRoot) if rtPolDefsObj == nil || rtPolDefsObj.PolicyDefinitions == nil || len(rtPolDefsObj.PolicyDefinitions.PolicyDefinition) < 1 { log.Info("YangToDb_route_map_bgp_action_set_community : Routing policy definitions list is empty.") return errors.New("Routing policy definitions list is empty") } data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_route_map_bgp_action_set_community: ", data, inParams.ygRoot) pathInfo := NewPathInfo(inParams.uri) rtPolicyName := pathInfo.Var("name") rtStmtName := pathInfo.Var("name#2") targetUriPath, _ := getYangPathFromUri(pathInfo.Path) log.Info("targetUriPath is ", targetUriPath) if rtPolicyName == "" || rtStmtName == "" { return errors.New("Routing policy keys are not present") } rtPolDefObj := rtPolDefsObj.PolicyDefinitions.PolicyDefinition[rtPolicyName] if rtPolDefObj == nil { rtPolDefObj, _ = rtPolDefsObj.PolicyDefinitions.NewPolicyDefinition(rtPolicyName) } ygot.BuildEmptyTree(rtPolDefObj) rtStmtObj := rtPolDefObj.Statements.Statement[rtStmtName] if rtStmtObj == nil { rtStmtObj, _ = rtPolDefObj.Statements.NewStatement(rtStmtName) } ygot.BuildEmptyTree(rtStmtObj) if rtStmtObj.Actions == nil || rtStmtObj.Actions.BgpActions == nil || rtStmtObj.Actions.BgpActions.SetCommunity == nil { return errors.New("Routing policy invalid action parameters") } rtStmtActionCommObj := rtStmtObj.Actions.BgpActions.SetCommunity if rtStmtActionCommObj == nil { return errors.New("Routing policy invalid action parameters") } entry_key := rtPolicyName + "|" + rtStmtName ygot.BuildEmptyTree(rtStmtActionCommObj) pTbl := data["ROUTE_MAP"] if _, ok := pTbl[entry_key]; !ok { log.Info("DbToYang_intf_enabled_xfmr Interface not found : ") return errors.New("Route map entry not found : ") } rtMapInst := pTbl[entry_key] if targetUriPath == "/openconfig-routing-policy:routing-policy/policy-definitions/policy-definition/statements/statement/actions/openconfig-bgp-policy:bgp-actions/set-community" { communityInlineVal, ok := rtMapInst.Field["set_community_inline@"] log.Info("DbToYang_route_map_bgp_action_set_community: ", communityInlineVal) if ok { rtStmtActionCommObj.Config.Method = ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Config_Method_INLINE var CfgCommunities []ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_Config_Communities_Union var StateCommunities []ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_State_Communities_Union for _, comm_val := range strings.Split(communityInlineVal, ",") { log.Info("DbToYang_route_map_bgp_action_set_community individual community value: ", comm_val) if comm_val == "no-peer" { cfg_val, _ := rtStmtActionCommObj.Inline.Config.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_Config_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NOPEER) state_val, _ := rtStmtActionCommObj.Inline.State.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_State_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NOPEER) CfgCommunities = append(CfgCommunities, cfg_val) StateCommunities = append(StateCommunities, state_val) } else if comm_val == "no-advertise" { cfg_val, _ := rtStmtActionCommObj.Inline.Config.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_Config_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_ADVERTISE) state_val, _ := rtStmtActionCommObj.Inline.State.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_State_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_ADVERTISE) CfgCommunities = append(CfgCommunities, cfg_val) StateCommunities = append(StateCommunities, state_val) } else if comm_val == "no-export" { cfg_val, _ := rtStmtActionCommObj.Inline.Config.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_Config_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT) state_val, _ := rtStmtActionCommObj.Inline.State.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_State_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT) CfgCommunities = append(CfgCommunities, cfg_val) StateCommunities = append(StateCommunities, state_val) } else if comm_val == "local-AS" { cfg_val, _ := rtStmtActionCommObj.Inline.Config.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_Config_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT_SUBCONFED) state_val, _ := rtStmtActionCommObj.Inline.State.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_State_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT_SUBCONFED) CfgCommunities = append(CfgCommunities, cfg_val) StateCommunities = append(StateCommunities, state_val) } else { n, err := strconv.ParseInt(comm_val, 10, 32) if err == nil { n := uint32(n) cfg_val, _ := rtStmtActionCommObj.Inline.Config.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_Config_Communities_Union(n) state_val, _ := rtStmtActionCommObj.Inline.State.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_State_Communities_Union(n) CfgCommunities = append(CfgCommunities, cfg_val) StateCommunities = append(StateCommunities, state_val) } else { cfg_val, _ := rtStmtActionCommObj.Inline.Config.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_Config_Communities_Union(comm_val) state_val, _ := rtStmtActionCommObj.Inline.State.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_State_Communities_Union(comm_val) CfgCommunities = append(CfgCommunities, cfg_val) StateCommunities = append(StateCommunities, state_val) } } } rtStmtActionCommObj.Inline.Config.Communities = CfgCommunities rtStmtActionCommObj.Inline.State.Communities = StateCommunities } else { rtStmtActionCommObj.Config.Method = ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Config_Method_REFERENCE communityRef, ok := rtMapInst.Field["set_community_ref"] log.Info("DbToYang_route_map_bgp_action_set_community reference: ", communityRef) if ok { rtStmtActionCommObj.Reference.Config.CommunitySetRef = &communityRef rtStmtActionCommObj.Reference.State.CommunitySetRef = &communityRef } } rtStmtActionCommObj.Config.Options = ocbinds.OpenconfigBgpPolicy_BgpSetCommunityOptionType_ADD rtStmtActionCommObj.State.Method = rtStmtActionCommObj.Config.Method rtStmtActionCommObj.State.Options = rtStmtActionCommObj.Config.Options } return err }
var DbToYang_route_map_bgp_action_set_ext_community SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error rtPolDefsObj := getRoutingPolicyRoot(inParams.ygRoot) if rtPolDefsObj == nil || rtPolDefsObj.PolicyDefinitions == nil || len(rtPolDefsObj.PolicyDefinitions.PolicyDefinition) < 1 { log.Info("YangToDb_route_map_bgp_action_set_community : Routing policy definitions list is empty.") return errors.New("Routing policy definitions list is empty") } data := (*inParams.dbDataMap)[inParams.curDb] log.Info("DbToYang_route_map_bgp_action_set_community: ", data, inParams.ygRoot) pathInfo := NewPathInfo(inParams.uri) rtPolicyName := pathInfo.Var("name") rtStmtName := pathInfo.Var("name#2") targetUriPath, _ := getYangPathFromUri(pathInfo.Path) log.Info("targetUriPath is ", targetUriPath) if rtPolicyName == "" || rtStmtName == "" { return errors.New("Routing policy keys are not present") } rtPolDefObj := rtPolDefsObj.PolicyDefinitions.PolicyDefinition[rtPolicyName] if rtPolDefObj == nil { rtPolDefObj, _ = rtPolDefsObj.PolicyDefinitions.NewPolicyDefinition(rtPolicyName) } ygot.BuildEmptyTree(rtPolDefObj) rtStmtObj := rtPolDefObj.Statements.Statement[rtStmtName] if rtStmtObj == nil { rtStmtObj, _ = rtPolDefObj.Statements.NewStatement(rtStmtName) } ygot.BuildEmptyTree(rtStmtObj) if rtStmtObj.Actions == nil || rtStmtObj.Actions.BgpActions == nil || rtStmtObj.Actions.BgpActions.SetExtCommunity == nil { return errors.New("Routing policy invalid action parameters") } rtStmtActionCommObj := rtStmtObj.Actions.BgpActions.SetExtCommunity if rtStmtActionCommObj == nil { return errors.New("Routing policy invalid action parameters") } entry_key := rtPolicyName + "|" + rtStmtName ygot.BuildEmptyTree(rtStmtActionCommObj) pTbl := data["ROUTE_MAP"] if _, ok := pTbl[entry_key]; !ok { log.Info("DbToYang_intf_enabled_xfmr Interface not found : ") return errors.New("Route map entry not found : ") } rtMapInst := pTbl[entry_key] if targetUriPath == "/openconfig-routing-policy:routing-policy/policy-definitions/policy-definition/statements/statement/actions/openconfig-bgp-policy:bgp-actions/set-ext-community" { communityInlineVal, ok := rtMapInst.Field["set_ext_community_inline@"] log.Info("DbToYang_route_map_bgp_action_set_ext_community inline value: ", communityInlineVal) if ok { rtStmtActionCommObj.Config.Method = ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Config_Method_INLINE var CfgCommunities []ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_Config_Communities_Union var StateCommunities []ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_State_Communities_Union for _, comm_val := range strings.Split(communityInlineVal, ",") { if comm_val == "no-peer" { cfg_val, _ := rtStmtActionCommObj.Inline.Config.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_Config_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NOPEER) state_val, _ := rtStmtActionCommObj.Inline.State.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_State_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NOPEER) CfgCommunities = append(CfgCommunities, cfg_val) StateCommunities = append(StateCommunities, state_val) } else if comm_val == "no-advertise" { cfg_val, _ := rtStmtActionCommObj.Inline.Config.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_Config_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_ADVERTISE) state_val, _ := rtStmtActionCommObj.Inline.State.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_State_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_ADVERTISE) CfgCommunities = append(CfgCommunities, cfg_val) StateCommunities = append(StateCommunities, state_val) } else if comm_val == "no-export" { cfg_val, _ := rtStmtActionCommObj.Inline.Config.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_Config_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT) state_val, _ := rtStmtActionCommObj.Inline.State.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_State_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT) CfgCommunities = append(CfgCommunities, cfg_val) StateCommunities = append(StateCommunities, state_val) } else if comm_val == "local-AS" { cfg_val, _ := rtStmtActionCommObj.Inline.Config.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_Config_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT_SUBCONFED) state_val, _ := rtStmtActionCommObj.Inline.State.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_State_Communities_Union(ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT_SUBCONFED) CfgCommunities = append(CfgCommunities, cfg_val) StateCommunities = append(StateCommunities, state_val) } else { cfg_val, _ := rtStmtActionCommObj.Inline.Config.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_Config_Communities_Union(comm_val) state_val, _ := rtStmtActionCommObj.Inline.State.To_OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_State_Communities_Union(comm_val) CfgCommunities = append(CfgCommunities, cfg_val) StateCommunities = append(StateCommunities, state_val) } } rtStmtActionCommObj.Inline.Config.Communities = CfgCommunities rtStmtActionCommObj.Inline.State.Communities = StateCommunities } else { rtStmtActionCommObj.Config.Method = ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Config_Method_REFERENCE communityRef, ok := rtMapInst.Field["set_ext_community_ref"] log.Info("DbToYang_route_map_bgp_action_set_ext_community reference value: ", communityRef) if ok { rtStmtActionCommObj.Reference.Config.ExtCommunitySetRef = &communityRef rtStmtActionCommObj.Reference.State.ExtCommunitySetRef = &communityRef } } rtStmtActionCommObj.Config.Options = ocbinds.OpenconfigBgpPolicy_BgpSetCommunityOptionType_ADD rtStmtActionCommObj.State.Method = rtStmtActionCommObj.Config.Method rtStmtActionCommObj.State.Options = rtStmtActionCommObj.Config.Options } return err }
var DbToYang_sw_vlans_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error var swVlan swVlanMemberPort_t intfsObj := getIntfsRoot(inParams.ygRoot) if intfsObj == nil { errStr := "Nil root object received for Ethernet-Switched VLAN Get!" log.Errorf(errStr) return errors.New(errStr) } pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") log.Infof("Ethernet-Switched Vlan Get observed for Interface: %s", ifName) intfType, _, err := getIntfTypeByName(ifName) if intfType != IntfTypeEthernet && intfType != IntfTypePortChannel || err != nil { if intfType == IntfTypeVxlan { return nil } else { intfTypeStr := strconv.Itoa(int(intfType)) errStr := "TableXfmrFunc - Invalid interface type" + intfTypeStr log.Error(errStr) return errors.New(errStr) } } if (strings.Contains(inParams.uri, "ethernet") && (intfType == IntfTypePortChannel)) || (strings.Contains(inParams.uri, "aggregation") && (intfType == IntfTypeEthernet)) { return nil } targetUriPath, err := getYangPathFromUri(inParams.uri) log.Info("targetUriPath is ", targetUriPath) intfObj := intfsObj.Interface[ifName] if intfObj == nil { intfObj, _ = intfsObj.NewInterface(ifName) ygot.BuildEmptyTree(intfObj) } if intfObj.Ethernet == nil && intfObj.Aggregation == nil { return errors.New("Wrong GET request for switched-vlan!") } if intfObj.Ethernet != nil { if intfObj.Ethernet.SwitchedVlan == nil { ygot.BuildEmptyTree(intfObj.Ethernet) } swVlan.swEthMember = intfObj.Ethernet.SwitchedVlan } if intfObj.Aggregation != nil { if intfObj.Aggregation.SwitchedVlan == nil { ygot.BuildEmptyTree(intfObj.Aggregation) } swVlan.swPortChannelMember = intfObj.Aggregation.SwitchedVlan } switch intfType { case IntfTypeEthernet: if intfObj.Ethernet == nil { errStr := "Switched-vlan state tree not built correctly for Interface: " + ifName log.Error(errStr) return errors.New(errStr) } if intfObj.Ethernet.SwitchedVlan == nil { ygot.BuildEmptyTree(intfObj.Ethernet) } vlanMemberMap := make(map[string]map[string]db.Value) err = fillDBSwitchedVlanInfoForIntf(inParams.d, &ifName, vlanMemberMap) if err != nil { log.Errorf("Filiing Switched Vlan Info for Interface: %s failed!", ifName) return err } log.Info("Succesfully completed DB population for Ethernet!") attrPresent, err := getSpecificSwitchedVlanStateAttr(&targetUriPath, &ifName, vlanMemberMap, &swVlan, intfType) if err != nil { return err } if !attrPresent { log.Infof("Get is for Switched Vlan State Container!") switch targetUriPath { case "/openconfig-interfaces:interfaces/interface/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config": err = getSwitchedVlanState(&ifName, vlanMemberMap, &swVlan, intfType, true) if err != nil { return err } case "/openconfig-interfaces:interfaces/interface/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/state": err = getSwitchedVlanState(&ifName, vlanMemberMap, &swVlan, intfType, false) if err != nil { return err } case "/openconfig-interfaces:interfaces/interface/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan": fallthrough case "/openconfig-interfaces:interfaces/interface/openconfig-if-ethernet:ethernet/switched-vlan": fallthrough case "/openconfig-interfaces:interfaces/interface/ethernet/switched-vlan": err = getSwitchedVlanState(&ifName, vlanMemberMap, &swVlan, intfType, true) if err != nil { return err } err = getSwitchedVlanState(&ifName, vlanMemberMap, &swVlan, intfType, false) if err != nil { return err } } } case IntfTypePortChannel: if intfObj.Aggregation == nil { errStr := "Switched-vlan state tree not built correctly for Interface: " + ifName log.Error(errStr) return errors.New(errStr) } if intfObj.Aggregation.SwitchedVlan == nil { ygot.BuildEmptyTree(intfObj.Aggregation) } vlanMemberMap := make(map[string]map[string]db.Value) err = fillDBSwitchedVlanInfoForIntf(inParams.d, &ifName, vlanMemberMap) if err != nil { log.Errorf("Filiing Switched Vlan Info for Interface: %s failed!", ifName) return err } log.Info("Succesfully completed DB population for Port-Channel!") attrPresent, err := getSpecificSwitchedVlanStateAttr(&targetUriPath, &ifName, vlanMemberMap, &swVlan, intfType) if err != nil { return err } if !attrPresent { log.Infof("Get is for Switched Vlan State Container!") switch targetUriPath { case "/openconfig-interfaces:interfaces/interface/openconfig-if-aggregate:aggregation/openconfig-vlan:switched-vlan/config": err = getSwitchedVlanState(&ifName, vlanMemberMap, &swVlan, intfType, true) if err != nil { return err } case "/openconfig-interfaces:interfaces/interface/openconfig-if-aggregate:aggregation/openconfig-vlan:switched-vlan/state": err = getSwitchedVlanState(&ifName, vlanMemberMap, &swVlan, intfType, false) if err != nil { return err } case "/openconfig-interfaces:interfaces/interface/openconfig-if-aggregate:aggregation/openconfig-vlan:switched-vlan": fallthrough case "/openconfig-interfaces:interfaces/interface/openconfig-if-aggregate:aggregation/switched-vlan": fallthrough case "/openconfig-interfaces:interfaces/interface/aggregation/switched-vlan": err = getSwitchedVlanState(&ifName, vlanMemberMap, &swVlan, intfType, true) if err != nil { return err } err = getSwitchedVlanState(&ifName, vlanMemberMap, &swVlan, intfType, false) if err != nil { return err } } } } return err }
Subtree transformer supports GET operation
var DbToYang_sys_cpus_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error sysObj := getAppRootObject(inParams) jsonsystem, err := getSystemInfoFromFile() if err != nil { log.Infof("getSystemInfoFromFile failed") return err } if sysObj.Cpus == nil { ygot.BuildEmptyTree(sysObj) } path := NewPathInfo(inParams.uri) val := path.Vars["index"] if len(val) != 0 { cpu, _ := strconv.Atoi(val) log.Info("Cpu id: ", cpu, ", max is ", len(jsonsystem.Cpus)) if cpu >= 0 && cpu < len(jsonsystem.Cpus) { for _, value := range sysObj.Cpus.Cpu { ygot.BuildEmptyTree(value) getSystemCpu(cpu, jsonsystem.Cpus[cpu], value) } } else { log.Info("Cpu id: ", cpu, "is invalid, max is ", len(jsonsystem.Cpus)) } } else { getSystemCpus(&jsonsystem, sysObj.Cpus) } return err }
var DbToYang_sys_memory_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error sysObj := getAppRootObject(inParams) jsonsystem, err := getSystemInfoFromFile() if err != nil { log.Infof("getSystemInfoFromFile failed") return err } ygot.BuildEmptyTree(sysObj) sysObj.Memory.State = &ocbinds.OpenconfigSystem_System_Memory_State{} getSystemMemory(&jsonsystem, sysObj.Memory.State) return err }
var DbToYang_sys_procs_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error sysObj := getAppRootObject(inParams) jsonsystem, err := getSystemInfoFromFile() if err != nil { log.Infof("getSystemInfoFromFile failed") return err } ygot.BuildEmptyTree(sysObj) path := NewPathInfo(inParams.uri) val := path.Vars["pid"] pid := 0 if len(val) != 0 { pid, _ = strconv.Atoi(val) } getSystemProcesses(&jsonsystem, sysObj.Processes, uint64(pid)) return err }
var DbToYang_sys_state_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error sysObj := getAppRootObject(inParams) jsonsystem, err := getSystemInfoFromFile() if err != nil { log.Infof("getSystemInfoFromFile failed") return err } ygot.BuildEmptyTree(sysObj) getSystemState(&jsonsystem, sysObj.State) return err }
var DbToYang_unnumbered_intf_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error intfsObj := getIntfsRoot(inParams.ygRoot) pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") targetUriPath, err := getYangPathFromUri(inParams.uri) log.Info("targetUriPath is ", targetUriPath) var intfObj *ocbinds.OpenconfigInterfaces_Interfaces_Interface intfType, _, ierr := getIntfTypeByName(ifName) if intfType == IntfTypeUnset || ierr != nil { errStr := "Invalid interface type IntfTypeUnset" log.Info("DbToYang_unnumbered_intf_xfmr: " + errStr) return errors.New(errStr) } intTbl := IntfTypeTblMap[intfType] if strings.HasPrefix(targetUriPath, "/openconfig-interfaces:interfaces/interface/subinterfaces/subinterface/openconfig-if-ip:ipv4/unnumbered/interface-ref/config/interface") { if intfsObj != nil && intfsObj.Interface != nil && len(intfsObj.Interface) > 0 { var ok bool = false if intfObj, ok = intfsObj.Interface[ifName]; !ok { intfObj, _ = intfsObj.NewInterface(ifName) } } else { ygot.BuildEmptyTree(intfsObj) intfObj, _ = intfsObj.NewInterface(ifName) } ygot.BuildEmptyTree(intfObj) var subIntf *ocbinds.OpenconfigInterfaces_Interfaces_Interface_Subinterfaces_Subinterface if _, ok := intfObj.Subinterfaces.Subinterface[0]; !ok { subIntf, err = intfObj.Subinterfaces.NewSubinterface(0) if err != nil { log.Error("Creation of subinterface subtree failed!") return err } } subIntf = intfObj.Subinterfaces.Subinterface[0] ygot.BuildEmptyTree(subIntf) entry, dbErr := inParams.d.GetEntry(&db.TableSpec{Name: intTbl.cfgDb.intfTN}, db.Key{Comp: []string{ifName}}) if dbErr != nil { log.Info("Failed to read DB entry, " + intTbl.cfgDb.intfTN + " " + ifName) return nil } if entry.Has(UNNUMBERED) { value := entry.Get(UNNUMBERED) subIntf.Ipv4.Unnumbered.InterfaceRef.Config.Interface = &value } } return err }
var DbToYang_vxlan_vni_instance_subtree_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { var err error pathInfo := NewPathInfo(inParams.uri) if log.V(3) { log.Info("DbToYang_vxlan_vni_instance_subtree_xfmr: ", pathInfo.Template) } path, err := getVxlanNiUriPath(inParams.uri) if err != nil { return err } reqP := &vxlanReqProcessor{&inParams.requestUri, &inParams.uri, path, inParams.oper, (*inParams.ygRoot).(*ocbinds.Device), inParams.param, inParams.d, inParams.dbs, nil, nil, nil, nil, &inParams} if err := reqP.setVxlanNetInstObjFromReq(); err != nil { return err } var vniIdStr string var vtepName string var tblKeyStr string var tblName string configDb := inParams.dbs[db.ConfigDB] niName := pathInfo.Var("name") if strings.HasPrefix(niName, "Vlan") { tblName = "VXLAN_TUNNEL_MAP" } else if strings.HasPrefix(niName, "Vrf") { tblName = "VRF" } else { log.Errorf("Invalid Network Instance name: %s", niName) return tlerr.InvalidArgs("Invalid Network Instance name: %s", niName) } pathInfoOrig := NewPathInfo(inParams.requestUri) if log.V(3) { log.Info("DbToYang_vxlan_vni_instance_subtree_xfmr: pathInfoOrig => ", pathInfoOrig) } vniIdKeyStr := pathInfoOrig.Var("vni-id") srcNveKeyStr := pathInfoOrig.Var("source-nve") if log.V(3) { log.Info("DbToYang_vxlan_vni_instance_subtree_xfmr: vniIdKeyStr in URI => ", vniIdKeyStr) log.Info("DbToYang_vxlan_vni_instance_subtree_xfmr: srcNveKeyStr in URI => ", srcNveKeyStr) } if vniIdKeyStr != "" && srcNveKeyStr != "" { if tblName == "VXLAN_TUNNEL_MAP" { var VXLAN_TUNNEL_MAP_TS *db.TableSpec = &db.TableSpec{Name: tblName} tunnelMapKeyStr := "map_" + vniIdKeyStr + "_" + niName if log.V(3) { log.Info("DbToYang_vxlan_vni_instance_subtree_xfmr: tunnelMapKeyStr => ", tunnelMapKeyStr) } _, err := reqP.db.GetEntry(VXLAN_TUNNEL_MAP_TS, db.Key{Comp: []string{srcNveKeyStr, tunnelMapKeyStr}}) if log.V(3) { log.Info("DbToYang_vxlan_vni_instance_subtree_xfmr: tblVxlanMapKeys => err => ", err) } if err != nil { log.Error("DbToYang_vxlan_vni_instance_subtree_xfmr ==> returning ERROR, since the key doesn't exist") return tlerr.NotFound("Resource Not Found") } } } if isSubtreeRequest(pathInfo.Template, "/openconfig-network-instance:network-instances/network-instance{name}/openconfig-vxlan:vxlan-vni-instances/vni-instance{vni-id}{source-nve}") { vniIdStr = pathInfo.Var("vni-id") vtepName = pathInfo.Var("source-nve") if strings.HasPrefix(niName, "Vlan") { tblKeyStr = vtepName + "|" + "map_" + vniIdStr + "_" + niName } else if strings.HasPrefix(niName, "Vrf") { tblKeyStr = niName } dbEntry, err := configDb.GetEntry(&db.TableSpec{Name: tblName}, db.Key{Comp: []string{tblKeyStr}}) if err != nil { return err } if dbEntry.Get("vni") != vniIdStr { log.Errorf("Network instance %s not associated with vni %s", niName, vniIdStr) return tlerr.NotFound("Resource Not Found") } if reqP.vxlanNetInstObj.VxlanVniInstances != nil || len(reqP.vxlanNetInstObj.VxlanVniInstances.VniInstance) > 0 { for vniKey := range reqP.vxlanNetInstObj.VxlanVniInstances.VniInstance { vniInst := reqP.vxlanNetInstObj.VxlanVniInstances.VniInstance[vniKey] vniId := vniKey.VniId srcNve := vniKey.SourceNve fillVniInstanceDetails(niName, vniId, srcNve, vniInst) } } } else if isSubtreeRequest(pathInfo.Template, "/openconfig-network-instance:network-instances/network-instance{name}/openconfig-vxlan:vxlan-vni-instances") { dbKeys, err := configDb.GetKeys(&db.TableSpec{Name: tblName}) if err != nil { return err } if len(dbKeys) > 0 { for _, dbkey := range dbKeys { var vniId uint32 if strings.HasPrefix(niName, "Vlan") { vtepName = dbkey.Get(0) mapNameList := strings.Split(dbkey.Get(1), "_") vniNum, _ := strconv.ParseUint(mapNameList[1], 10, 32) vniId = uint32(vniNum) } else if strings.HasPrefix(niName, "Vrf") { vrfEntry, err := configDb.GetEntry(&db.TableSpec{Name: tblName}, db.Key{Comp: []string{niName}}) if err != nil { return err } if vrfEntry.Has("vni") { vniIdStr = vrfEntry.Get("vni") vniNum, _ := strconv.ParseUint(vniIdStr, 10, 32) vniId = uint32(vniNum) vtepEntries, _ := configDb.GetKeys(&db.TableSpec{Name: "VXLAN_TUNNEL"}) if len(vtepEntries) > 0 { vtepKey := vtepEntries[0] vtepName = vtepKey.Get(0) } } else { log.Errorf("Network instance %s not associated with vni %s", niName, vniIdStr) return tlerr.NotFound("Resource Not Found") } } vniInst, _ := reqP.vxlanNetInstObj.VxlanVniInstances.NewVniInstance(vniId, vtepName) fillVniInstanceDetails(niName, vniId, vtepName, vniInst) } } else { log.Errorf("Network instance %s not found", niName) } } return err }
var DbToYang_ztp_config_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { ztpObj := getZtpRoot(inParams.ygRoot) log.Info("TableXfmrFunc - Uri ZTP: ", inParams.uri) pathInfo := NewPathInfo(inParams.uri) targetUriPath, err := getYangPathFromUri(pathInfo.Path) log.Info("TARGET URI PATH ZTP:", targetUriPath) act := "getcfg" mess, err := ztpAction(act) if err != nil { log.Info("Error from host service:", err) } log.Info("Message from host:", mess) if ztpObj.Config == nil { ygot.BuildEmptyTree(ztpObj) } configObj := ztpObj.Config ygot.BuildEmptyTree(configObj) var temp bool if mess == "disabled" { temp = false } if mess == "enabled" { temp = true } configObj.AdminMode = &temp return err }
var DbToYang_ztp_status_xfmr SubTreeXfmrDbToYang = func(inParams XfmrParams) error { ztpObj := getZtpRoot(inParams.ygRoot) pathInfo := NewPathInfo(inParams.uri) targetUriPath, err := getYangPathFromUri(pathInfo.Path) if targetUriPath == "/openconfig-ztp:ztp/state" { log.Info("TARGET URI PATH ZTP:", targetUriPath) log.Info("TableXfmrFunc - Uri ZTP: ", inParams.uri) log.Info("type of ZTP-ROOT OBJECT:", reflect.TypeOf(ztpObj)) err = getZtpStatus(ztpObj) return err } else { return nil } }
type SubTreeXfmrYangToDb ¶
*
- SubTreeXfmrYangToDb type is defined to use for handling the yang subtree to DB
- Transformer function definition.
- Param: XfmrParams structure having Database info, YgotRoot, operation, Xpath
- Return: multi dimensional map to hold the DB data, error *
var YangToDb_acl_port_bindings_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error res_map := make(map[string]map[string]db.Value) aclTableMap := make(map[string]db.Value) log.Info("YangToDb_acl_port_bindings_xfmr: ", inParams.ygRoot, inParams.uri) aclObj := getAclRoot(inParams.ygRoot) if aclObj.Interfaces == nil { return res_map, err } aclInterfacesMap := make(map[string][]string) for intfId, _ := range aclObj.Interfaces.Interface { intf := aclObj.Interfaces.Interface[intfId] if intf != nil { if intf.IngressAclSets != nil && len(intf.IngressAclSets.IngressAclSet) > 0 { for inAclKey, _ := range intf.IngressAclSets.IngressAclSet { aclName := getAclKeyStrFromOCKey(inAclKey.SetName, inAclKey.Type) aclInterfacesMap[aclName] = append(aclInterfacesMap[aclName], *intf.Id) _, ok := aclTableMap[aclName] if !ok { aclTableMap[aclName] = db.Value{Field: make(map[string]string)} } aclTableMap[aclName].Field["stage"] = "INGRESS" } } if intf.EgressAclSets != nil && len(intf.EgressAclSets.EgressAclSet) > 0 { for outAclKey, _ := range intf.EgressAclSets.EgressAclSet { aclName := getAclKeyStrFromOCKey(outAclKey.SetName, outAclKey.Type) aclInterfacesMap[aclName] = append(aclInterfacesMap[aclName], *intf.Id) _, ok := aclTableMap[aclName] if !ok { aclTableMap[aclName] = db.Value{Field: make(map[string]string)} } aclTableMap[aclName].Field["stage"] = "EGRESS" } } } } for k, _ := range aclInterfacesMap { val := aclTableMap[k] (&val).SetList("ports", aclInterfacesMap[k]) } res_map[ACL_TABLE] = aclTableMap return res_map, err }
var YangToDb_bgp_nbrs_nbr_auth_password_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error res_map := make(map[string]map[string]db.Value) authmap := make(map[string]db.Value) var bgp_obj *ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_Bgp bgp_obj, niName, err := getBgpRoot(inParams) if err != nil { log.Errorf("BGP root get failed!") return res_map, err } pathInfo := NewPathInfo(inParams.uri) targetUriPath, _ := getYangPathFromUri(pathInfo.Path) nbrAddr := pathInfo.Var("neighbor-address") log.Infof("YangToDb_bgp_nbrs_nbr_auth_password_xfmr VRF:%s nbrAddr:%s URI:%s", niName, nbrAddr, targetUriPath) nbrs_obj := bgp_obj.Neighbors if nbrs_obj == nil { log.Errorf("Error: Neighbors container missing") return res_map, err } nbr_obj, ok := nbrs_obj.Neighbor[nbrAddr] if !ok { log.Infof("%s Neighbor object missing, add new", nbrAddr) return res_map, err } entry_key := niName + "|" + nbrAddr if nbr_obj.AuthPassword.Config != nil && nbr_obj.AuthPassword.Config.Password != nil && (inParams.oper != DELETE) { auth_password := nbr_obj.AuthPassword.Config.Password encrypted := nbr_obj.AuthPassword.Config.Encrypted log.Infof("Neighbor password:%d encrypted:%s", *auth_password, *encrypted) encrypted_password := *auth_password if encrypted == nil || (encrypted != nil && *encrypted == false) { cmd := "show bgp encrypt " + *auth_password + " json" bgpNeighPasswordJson, cmd_err := exec_vtysh_cmd(cmd) if cmd_err != nil { log.Errorf("Failed !! Error:%s", cmd_err) return res_map, err } encrypted_password, ok = bgpNeighPasswordJson["Encrypted_string"].(string) if !ok { return res_map, err } log.Infof("Neighbor password:%s encrypted:%s", *auth_password, encrypted_password) } authmap[entry_key] = db.Value{Field: make(map[string]string)} authmap[entry_key].Field["auth_password"] = encrypted_password } else if inParams.oper == DELETE { authmap[entry_key] = db.Value{Field: make(map[string]string)} authmap[entry_key].Field["auth_password"] = "" } res_map["BGP_NEIGHBOR"] = authmap return res_map, err }
var YangToDb_bgp_pgrp_auth_password_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error res_map := make(map[string]map[string]db.Value) authmap := make(map[string]db.Value) var bgp_obj *ocbinds.OpenconfigNetworkInstance_NetworkInstances_NetworkInstance_Protocols_Protocol_Bgp bgp_obj, niName, err := getBgpRoot(inParams) if err != nil { log.Errorf("BGP root get failed!") return res_map, err } pathInfo := NewPathInfo(inParams.uri) targetUriPath, _ := getYangPathFromUri(pathInfo.Path) pgrp := pathInfo.Var("peer-group-name") log.Infof("YangToDb_bgp_pgrp_auth_password_xfmr VRF:%s peer group:%s URI:%s", niName, pgrp, targetUriPath) pgrps_obj := bgp_obj.PeerGroups if pgrps_obj == nil { log.Errorf("Error: PeerGroups container missing") return res_map, err } pgrp_obj, ok := pgrps_obj.PeerGroup[pgrp] if !ok { log.Infof("%s Peer group object missing, add new", pgrp) return res_map, err } entry_key := niName + "|" + pgrp if pgrp_obj.AuthPassword.Config != nil && pgrp_obj.AuthPassword.Config.Password != nil && (inParams.oper != DELETE) { auth_password := pgrp_obj.AuthPassword.Config.Password encrypted := pgrp_obj.AuthPassword.Config.Encrypted log.Infof("PeerGroup password:%d encrypted:%s", *auth_password, *encrypted) encrypted_password := *auth_password if encrypted == nil || (encrypted != nil && *encrypted == false) { cmd := "show bgp encrypt " + *auth_password + " json" bgpPgrpPasswordJson, cmd_err := exec_vtysh_cmd(cmd) if cmd_err != nil { log.Errorf("Failed !! Error:%s", cmd_err) return res_map, err } encrypted_password, ok = bgpPgrpPasswordJson["Encrypted_string"].(string) if !ok { return res_map, err } } log.Infof("PeerGroup password:%s encrypted:%s", *auth_password, encrypted_password) authmap[entry_key] = db.Value{Field: make(map[string]string)} authmap[entry_key].Field["auth_password"] = encrypted_password } else if inParams.oper == DELETE { authmap[entry_key] = db.Value{Field: make(map[string]string)} authmap[entry_key].Field["auth_password"] = "" } res_map["BGP_PEER_GROUP"] = authmap return res_map, err }
var YangToDb_igmp_snooping_subtree_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { fmt.Println("YangToDb_igmp_snooping_subtree_xfmr entering => ", inParams) path, err := getUriPath(inParams.uri) pathInfo := NewPathInfo(inParams.uri) niName := pathInfo.Var("name") protoId := pathInfo.Var("identifier") if strings.Contains(protoId, "IGMP_SNOOPING") == false { return nil, errors.New("IGMP Proto ID is missing") } if err != nil { return nil, err } else if niName != "default" { fmt.Println("YangToDb_igmp_snooping_subtree_xfmr - called with incorrect network-instance - name => ", niName, " and returning error..") return nil, tlerr.NotFound("Resource Not Found") } reqP := &reqProcessor{&inParams.uri, path, inParams.oper, (*inParams.ygRoot).(*ocbinds.Device), inParams.param, inParams.d, inParams.dbs, nil, nil, nil, nil} fmt.Println("YangToDb_igmp_snooping_subtree_xfmr => translateToDb == reqP.uri => ", *reqP.uri) if err := reqP.setIGMPSnoopingObjFromReq(); err != nil { return nil, err } fmt.Println("YangToDb_igmp_snooping_subtree_xfmr ==> printing IGMPSnooping object request ==> ") pretty.Print(*reqP.igmpsObj) res_map, err := reqP.translateToDb() if err == nil { return *res_map, nil } else { return nil, err } }
var YangToDb_intf_eth_port_config_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { memMap := make(map[string]map[string]db.Value) pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") intfType, _, _ := getIntfTypeByName(ifName) if IntfTypeVxlan == intfType { return memMap, nil } intfsObj := getIntfsRoot(inParams.ygRoot) intfObj := intfsObj.Interface[ifName] if intfObj.Ethernet == nil { return nil, errors.New("Invalid request") } if intfObj.Ethernet.Config == nil { return nil, errors.New("Invalid config request") } var err error intfType, _, ierr := getIntfTypeByName(ifName) if ierr != nil { errStr := "Invalid Interface" err = tlerr.InvalidArgsError{Format: errStr} return nil, err } if intfObj.Ethernet.Config.AggregateId != nil { if strings.HasPrefix(ifName, ETHERNET) == false { return nil, errors.New("Invalid config request") } intTbl := IntfTypeTblMap[IntfTypePortChannel] tblName, _ := getMemTableNameByDBId(intTbl, inParams.curDb) var lagStr string switch inParams.oper { case CREATE: case UPDATE: log.Info("Add member port") lagId := intfObj.Ethernet.Config.AggregateId lagStr = "PortChannel" + (*lagId) intfType, _, err := getIntfTypeByName(ifName) if intfType != IntfTypeEthernet || err != nil { intfTypeStr := strconv.Itoa(int(intfType)) errStr := "Invalid interface type" + intfTypeStr log.Error(errStr) return nil, tlerr.InvalidArgsError{Format: errStr} } err = validateLagExists(inParams.d, &intTbl.cfgDb.portTN, &lagStr) if err != nil { errStr := "Invalid PortChannel: " + lagStr err = tlerr.InvalidArgsError{Format: errStr} return nil, err } err = validateIntfAssociatedWithPortChannel(inParams.d, &ifName) if err != nil { return nil, err } err = validateIntfAssociatedWithVlan(inParams.d, &ifName) if err != nil { return nil, err } err = validateL3ConfigExists(inParams.d, &ifName) if err != nil { return nil, tlerr.InvalidArgsError{Format: err.Error()} } case DELETE: log.Info("Delete member port") lagKeys, err := inParams.d.GetKeys(&db.TableSpec{Name: tblName}) if err != nil { log.Info("No entries in PORTCHANNEL_MEMBER TABLE") return nil, errors.New("No entries in PORTCHANNEL_MEMBER TABLE") } var flag bool = false for i, _ := range lagKeys { if ifName == lagKeys[i].Get(1) { log.Info("Found Entry in PORTCHANNEL_MEMBER TABLE") flag = true lagStr = lagKeys[i].Get(0) log.Info("Given interface part of PortChannel", lagStr) break } } if flag == false { log.Info("Given Interface not part of any PortChannel") err = errors.New("Given Interface not part of any PortChannel") return nil, err } } m := make(map[string]string) value := db.Value{Field: m} m["NULL"] = "NULL" intfKey := lagStr + "|" + ifName if _, ok := memMap[tblName]; !ok { memMap[tblName] = make(map[string]db.Value) } memMap[tblName][intfKey] = value } if intfObj.Ethernet.Config.PortSpeed != 0 { if intfType != IntfTypeMgmt { return nil, errors.New("PortSpeed config not supported for given interface type") } res_map := make(map[string]string) value := db.Value{Field: res_map} intTbl := IntfTypeTblMap[IntfTypeMgmt] portSpeed := intfObj.Ethernet.Config.PortSpeed val, ok := intfOCToSpeedMap[portSpeed] if ok { res_map[PORT_SPEED] = val } else { err = errors.New("Invalid/Unsupported speed.") } if _, ok := memMap[intTbl.cfgDb.portTN]; !ok { memMap[intTbl.cfgDb.portTN] = make(map[string]db.Value) } memMap[intTbl.cfgDb.portTN][ifName] = value } if intfObj.Ethernet.Config.AutoNegotiate != nil { if intfType != IntfTypeMgmt { return nil, errors.New("AutoNegotiate config not supported for given Interface type") } res_map := make(map[string]string) value := db.Value{Field: res_map} intTbl := IntfTypeTblMap[IntfTypeMgmt] autoNeg := intfObj.Ethernet.Config.AutoNegotiate var enStr string if *autoNeg == true { enStr = "true" } else { enStr = "false" } res_map[PORT_AUTONEG] = enStr if _, ok := memMap[intTbl.cfgDb.portTN]; !ok { memMap[intTbl.cfgDb.portTN] = make(map[string]db.Value) } memMap[intTbl.cfgDb.portTN][ifName] = value } return memMap, err }
Handle port-speed, auto-neg and aggregate-id config
var YangToDb_intf_ip_addr_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err, oerr error subOpMap := make(map[db.DBNum]map[string]map[string]db.Value) subIntfmap := make(map[string]map[string]db.Value) subIntfmap_del := make(map[string]map[string]db.Value) var value db.Value var overlapIP string pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") intfType, _, ierr := getIntfTypeByName(ifName) if IntfTypeVxlan == intfType { return subIntfmap, nil } intfsObj := getIntfsRoot(inParams.ygRoot) if intfsObj == nil || len(intfsObj.Interface) < 1 { log.Info("YangToDb_intf_subintf_ip_xfmr : IntfsObj/interface list is empty.") return subIntfmap, errors.New("IntfsObj/Interface is not specified") } if ifName == "" { errStr := "Interface KEY not present" log.Info("YangToDb_intf_subintf_ip_xfmr : " + errStr) return subIntfmap, errors.New(errStr) } if intfType == IntfTypeUnset || ierr != nil { errStr := "Invalid interface type IntfTypeUnset" log.Info("YangToDb_intf_subintf_ip_xfmr : " + errStr) return subIntfmap, errors.New(errStr) } if intfType == IntfTypeEthernet || intfType == IntfTypePortChannel { err = validateIntfAssociatedWithVlan(inParams.d, &ifName) if err != nil { return subIntfmap, err } } if intfType == IntfTypeEthernet { err = validateIntfAssociatedWithPortChannel(inParams.d, &ifName) if err != nil { errStr := "IP config is not permitted on LAG member port." return subIntfmap, tlerr.InvalidArgsError{Format: errStr} } } if _, ok := intfsObj.Interface[ifName]; !ok { errStr := "Interface entry not found in Ygot tree, ifname: " + ifName log.Info("YangToDb_intf_subintf_ip_xfmr : " + errStr) return subIntfmap, errors.New(errStr) } intfObj := intfsObj.Interface[ifName] if intfObj.Subinterfaces == nil || len(intfObj.Subinterfaces.Subinterface) < 1 { errStr := "SubInterface node is not set" log.Info("YangToDb_intf_subintf_ip_xfmr : " + errStr) return subIntfmap, errors.New(errStr) } if _, ok := intfObj.Subinterfaces.Subinterface[0]; !ok { log.Info("YangToDb_intf_subintf_ip_xfmr : No IP address handling required") return subIntfmap, err } intTbl := IntfTypeTblMap[intfType] tblName, _ := getIntfTableNameByDBId(intTbl, inParams.curDb) subIntfObj := intfObj.Subinterfaces.Subinterface[0] if inParams.oper == DELETE { return intf_ip_addr_del(inParams.d, ifName, tblName, subIntfObj) } entry, dbErr := inParams.d.GetEntry(&db.TableSpec{Name: intTbl.cfgDb.intfTN}, db.Key{Comp: []string{ifName}}) if dbErr != nil || !entry.IsPopulated() { ifdb := make(map[string]string) ifdb["NULL"] = "NULL" value := db.Value{Field: ifdb} if _, ok := subIntfmap[tblName]; !ok { subIntfmap[tblName] = make(map[string]db.Value) } subIntfmap[tblName][ifName] = value } if subIntfObj.Ipv4 != nil && subIntfObj.Ipv4.Addresses != nil { for ip, _ := range subIntfObj.Ipv4.Addresses.Address { addr := subIntfObj.Ipv4.Addresses.Address[ip] if addr.Config != nil { if addr.Config.Ip == nil { addr.Config.Ip = new(string) *addr.Config.Ip = ip } log.Info("Ip:=", *addr.Config.Ip) if addr.Config.PrefixLength == nil { log.Error("Prefix Length empty!") errStr := "Prefix Length not present" err = tlerr.InvalidArgsError{Format: errStr} return subIntfmap, err } log.Info("prefix:=", *addr.Config.PrefixLength) if !validIPv4(*addr.Config.Ip) { errStr := "Invalid IPv4 address " + *addr.Config.Ip err = tlerr.InvalidArgsError{Format: errStr} return subIntfmap, err } err = validateIpPrefixForIntfType(intfType, addr.Config.Ip, addr.Config.PrefixLength, true) if err != nil { return subIntfmap, err } ipPref := *addr.Config.Ip + "/" + strconv.Itoa(int(*addr.Config.PrefixLength)) overlapIP, oerr = validateIpOverlap(inParams.d, ifName, ipPref, tblName) intf_key := intf_intf_tbl_key_gen(ifName, *addr.Config.Ip, int(*addr.Config.PrefixLength), "|") m := make(map[string]string) if addr.Config.GwAddr != nil { if intfType != IntfTypeMgmt { errStr := "GwAddr config is not supported " + ifName log.Info("GwAddr config is not supported for intfType: ", intfType, " ", ifName) return subIntfmap, errors.New(errStr) } if !validIPv4(*addr.Config.GwAddr) { errStr := "Invalid IPv4 Gateway address " + *addr.Config.GwAddr err = tlerr.InvalidArgsError{Format: errStr} return subIntfmap, err } m["gwaddr"] = *addr.Config.GwAddr } else { m["NULL"] = "NULL" } value := db.Value{Field: m} if _, ok := subIntfmap[tblName]; !ok { subIntfmap[tblName] = make(map[string]db.Value) } subIntfmap[tblName][intf_key] = value if log.V(3) { log.Info("tblName :", tblName, " intf_key: ", intf_key, " data : ", value) } } } } if subIntfObj.Ipv6 != nil && subIntfObj.Ipv6.Addresses != nil { for ip, _ := range subIntfObj.Ipv6.Addresses.Address { addr := subIntfObj.Ipv6.Addresses.Address[ip] if addr.Config != nil { if addr.Config.Ip == nil { addr.Config.Ip = new(string) *addr.Config.Ip = ip } log.Info("Ipv6 IP:=", *addr.Config.Ip) if addr.Config.PrefixLength == nil { log.Error("Prefix Length empty!") errStr := "Prefix Length not present" err = tlerr.InvalidArgsError{Format: errStr} return subIntfmap, err } log.Info("Ipv6 prefix:=", *addr.Config.PrefixLength) if !validIPv6(*addr.Config.Ip) { errStr := "Invalid IPv6 address " + *addr.Config.Ip err = tlerr.InvalidArgsError{Format: errStr} return subIntfmap, err } err = validateIpPrefixForIntfType(intfType, addr.Config.Ip, addr.Config.PrefixLength, false) if err != nil { return subIntfmap, err } ipPref := *addr.Config.Ip + "/" + strconv.Itoa(int(*addr.Config.PrefixLength)) overlapIP, oerr = validateIpOverlap(inParams.d, ifName, ipPref, tblName) intf_key := intf_intf_tbl_key_gen(ifName, *addr.Config.Ip, int(*addr.Config.PrefixLength), "|") m := make(map[string]string) if addr.Config.GwAddr != nil { if intfType != IntfTypeMgmt { errStr := "GwAddr config is not supported " + ifName log.Info("GwAddr config is not supported for intfType: ", intfType, " ", ifName) return subIntfmap, errors.New(errStr) } if !validIPv6(*addr.Config.GwAddr) { errStr := "Invalid IPv6 Gateway address " + *addr.Config.GwAddr err = tlerr.InvalidArgsError{Format: errStr} return subIntfmap, err } m["gwaddr"] = *addr.Config.GwAddr } else { m["NULL"] = "NULL" } value := db.Value{Field: m} if _, ok := subIntfmap[tblName]; !ok { subIntfmap[tblName] = make(map[string]db.Value) } subIntfmap[tblName][intf_key] = value log.Info("tblName :", tblName, "intf_key: ", intf_key, "data : ", value) } } } if oerr != nil { if overlapIP == "" { log.Error(oerr) return nil, tlerr.InvalidArgsError{Format: oerr.Error()} } else { subIntfmap_del[tblName] = make(map[string]db.Value) key := ifName + "|" + overlapIP subIntfmap_del[tblName][key] = value subOpMap[db.ConfigDB] = subIntfmap_del log.Info("subOpMap: ", subOpMap) inParams.subOpDataMap[DELETE] = &subOpMap } } log.Info("YangToDb_intf_subintf_ip_xfmr : subIntfmap : ", subIntfmap) return subIntfmap, err }
var YangToDb_intf_nat_zone_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error natZoneMap := make(map[string]map[string]db.Value) intfsObj := getIntfsRoot(inParams.ygRoot) if intfsObj == nil || len(intfsObj.Interface) < 1 { log.Info("YangToDb_intf_nat_zone_xfmr: IntfsObj/interface list is empty.") return natZoneMap, errors.New("IntfsObj/Interface is not specified") } pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") if ifName == "" { errStr := "Interface KEY not present" log.Info("YangToDb_intf_nat_zone_xfmr : " + errStr) return natZoneMap, errors.New(errStr) } if _, ok := intfsObj.Interface[ifName]; !ok { errStr := "Interface entry not found in Ygot tree, ifname: " + ifName log.Info("YangToDb_intf_nat_zone_xfmr : " + errStr) return natZoneMap, errors.New(errStr) } intfObj := intfsObj.Interface[ifName] if intfObj.NatZone == nil || intfObj.NatZone.Config == nil || intfObj.NatZone.Config.NatZone == nil { log.Info("YangToDb Interface nat zone config is not valid - ", ifName) return natZoneMap, errors.New("YangToDb Interface nat zone config is not valid - " + ifName) } intfType, _, ierr := getIntfTypeByName(ifName) if intfType == IntfTypeUnset || ierr != nil { errStr := "Invalid interface type IntfTypeUnset" log.Info("YangToDb_intf_nat_zone_xfmr : " + errStr) return natZoneMap, errors.New(errStr) } intTbl := IntfTypeTblMap[intfType] tblName, _ := getIntfTableNameByDBId(intTbl, inParams.curDb) entry, dbErr := inParams.d.GetEntry(&db.TableSpec{Name: tblName}, db.Key{Comp: []string{ifName}}) if dbErr != nil { log.Info("Failed to read DB entry, " + tblName + " " + ifName) return natZoneMap, dbErr } if inParams.oper == DELETE { if entry.Has("nat_zone") == false { log.Info("NAT zone config not present, " + tblName + " " + ifName) return natZoneMap, errors.New("Note zone config not present, " + tblName + " " + ifName) } if _, ok := natZoneMap[tblName]; !ok { natZoneMap[tblName] = make(map[string]db.Value) } m := make(map[string]string) data := db.Value{Field: m} data.Set("nat_zone", "") natZoneMap[tblName][ifName] = data } else { m := make(map[string]string) data := db.Value{Field: m} data.Set("nat_zone", strconv.Itoa(int(*intfObj.NatZone.Config.NatZone))) if _, ok := natZoneMap[tblName]; !ok { natZoneMap[tblName] = make(map[string]db.Value) } natZoneMap[tblName][ifName] = data } log.Info("NAT Zone map :", natZoneMap) return natZoneMap, err }
var YangToDb_intf_sag_ip_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error subIntfmap := make(map[string]map[string]db.Value) intfsObj := getIntfsRoot(inParams.ygRoot) if intfsObj == nil || len(intfsObj.Interface) < 1 { log.Info("YangToDb_intf_sag_ip_xfmr: IntfsObj/interface list is empty.") return subIntfmap, errors.New("IntfsObj/Interface is not specified") } pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") log.Info("YangToDb_intf_sag_ip_xfmr Ifname: " + ifName) if ifName == "" { errStr := "Interface KEY not present" log.Info("YangToDb_intf_sag_ip_xfmr: " + errStr) return subIntfmap, errors.New(errStr) } if _, ok := intfsObj.Interface[ifName]; !ok { errStr := "Interface entry not found in Ygot tree, ifname: " + ifName log.Info("YangToDb_intf_sag_ip_xfmr: " + errStr) return subIntfmap, errors.New(errStr) } intfObj := intfsObj.Interface[ifName] if intfObj.Subinterfaces == nil || len(intfObj.Subinterfaces.Subinterface) < 1 { errStr := "SubInterface node is not set" log.Info("YangToDb_intf_sag_ip_xfmr: " + errStr) return subIntfmap, errors.New(errStr) } if _, ok := intfObj.Subinterfaces.Subinterface[0]; !ok { log.Info("YangToDb_intf_sag_ip_xfmr : Not required for sub intf") return subIntfmap, err } intfType, _, ierr := getIntfTypeByName(ifName) if intfType == IntfTypeUnset || ierr != nil { errStr := "Invalid interface type IntfTypeUnset" log.Info("YangToDb_intf_sag_ip_xfmr: " + errStr) return subIntfmap, errors.New(errStr) } intTbl := IntfTypeTblMap[intfType] tblName, _ := getIntfTableNameByDBId(intTbl, inParams.curDb) subIntfObj := intfObj.Subinterfaces.Subinterface[0] var gwIPListStr string sagIPMap := make(map[string]db.Value) vlanIntfMap := make(map[string]db.Value) vlanIntfMap[ifName] = db.Value{Field: make(map[string]string)} vlanEntry, _ := inParams.d.GetEntry(&db.TableSpec{Name: intTbl.cfgDb.intfTN}, db.Key{Comp: []string{ifName}}) if subIntfObj.Ipv4 != nil && subIntfObj.Ipv4.SagIpv4 != nil { sagIpv4Obj := subIntfObj.Ipv4.SagIpv4 if sagIpv4Obj.Config != nil { log.Info("SAG IP:=", sagIpv4Obj.Config.StaticAnycastGateway) sagIPv4Key := ifName + "|IPv4" sagIPv4Entry, _ := inParams.d.GetEntry(&db.TableSpec{Name: "SAG"}, db.Key{Comp: []string{sagIPv4Key}}) if inParams.oper == DELETE { gwIPListStr = sagIpv4Obj.Config.StaticAnycastGateway[0] if sagIPv4Entry.IsPopulated() { if strings.Count(sagIPv4Entry.Field["gwip@"], ",") == 0 { if len(vlanEntry.Field) == 1 { if _, ok := vlanEntry.Field["NULL"]; ok { subIntfmap[tblName] = vlanIntfMap } } } } } else { if !vlanEntry.IsPopulated() { vlanIntfMap[ifName].Field["NULL"] = "NULL" subIntfmap[tblName] = vlanIntfMap } if sagIPv4Entry.IsPopulated() { gwIPListStr, _ = sagIPv4Entry.Field["gwip@"] gwIPListStr = gwIPListStr + "," + sagIpv4Obj.Config.StaticAnycastGateway[0] } else { gwIPListStr = sagIpv4Obj.Config.StaticAnycastGateway[0] } } sagIPMap[sagIPv4Key] = db.Value{Field: make(map[string]string)} sagIPMap[sagIPv4Key].Field["gwip@"] = gwIPListStr subIntfmap["SAG"] = sagIPMap } } if subIntfObj.Ipv6 != nil && subIntfObj.Ipv6.SagIpv6 != nil { sagIpv6Obj := subIntfObj.Ipv6.SagIpv6 if sagIpv6Obj.Config != nil { log.Info("SAG IP:=", sagIpv6Obj.Config.StaticAnycastGateway) sagIPv6Key := ifName + "|IPv6" sagIPv6Entry, _ := inParams.d.GetEntry(&db.TableSpec{Name: "SAG"}, db.Key{Comp: []string{sagIPv6Key}}) if inParams.oper == DELETE { gwIPListStr = sagIpv6Obj.Config.StaticAnycastGateway[0] if sagIPv6Entry.IsPopulated() { if strings.Count(sagIPv6Entry.Field["gwip@"], ",") == 0 { if len(vlanEntry.Field) == 1 { if _, ok := vlanEntry.Field["NULL"]; ok { subIntfmap[tblName] = vlanIntfMap } } } } } else { if !vlanEntry.IsPopulated() { vlanIntfMap[ifName].Field["NULL"] = "NULL" subIntfmap[tblName] = vlanIntfMap } if sagIPv6Entry.IsPopulated() { gwIPListStr, _ = sagIPv6Entry.Field["gwip@"] gwIPListStr = gwIPListStr + "," + sagIpv6Obj.Config.StaticAnycastGateway[0] } else { gwIPListStr = sagIpv6Obj.Config.StaticAnycastGateway[0] } } sagIPMap[sagIPv6Key] = db.Value{Field: make(map[string]string)} sagIPMap[sagIPv6Key].Field["gwip@"] = gwIPListStr subIntfmap["SAG"] = sagIPMap } } log.Info("YangToDb_intf_sag_ip_xfmr : subIntfmap : ", subIntfmap) return subIntfmap, err }
var YangToDb_intf_vxlan_config_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error if log.V(3) { log.Info("YangToDb_intf_vxlan_config_xfmr entering => inParams.uri => ", inParams.uri) } path, err := getIntfUriPath(inParams.uri) if err != nil { return nil, err } reqP := &vxlanReqProcessor{&inParams.requestUri, &inParams.uri, path, inParams.oper, (*inParams.ygRoot).(*ocbinds.Device), inParams.param, inParams.d, inParams.dbs, nil, nil, nil, nil, &inParams} if err := reqP.setVxlanIntfFromReq(); err != nil { return nil, err } if log.V(3) { log.Info("YangToDb_intf_vxlan_config_xfmr ==> printing vxlanIntfConfigPath object request ==> ", (*reqP.vxlanIntfConfigObj)) } if err := reqP.setIntfObjFromReq(); err != nil { return nil, err } if log.V(3) { log.Info("YangToDb_intf_vxlan_config_xfmr ==> printing intf object request ==> ", (*reqP.intfObject)) } res_map, err := reqP.translateToDb() if err == nil { return *res_map, nil } else { return nil, err } }
var YangToDb_mclag_interface_subtree_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error res_map := make(map[string]map[string]db.Value) mclagIntfTblMap := make(map[string]db.Value) log.Info("YangToDb_mclag_interface_subtree_xfmr: ", inParams.ygRoot, inParams.uri) mclagObj := getMclagRoot(inParams.ygRoot) if mclagObj.Interfaces == nil { return res_map, err } for intfId, _ := range mclagObj.Interfaces.Interface { intf := mclagObj.Interfaces.Interface[intfId] if intf != nil { var mclagdomainId int if intf.Config != nil { mclagdomainId = int(*intf.Config.MclagDomainId) } else { mclagIntfKeys, _ := inParams.d.GetKeys(&db.TableSpec{Name: "MCLAG_INTERFACE"}) if len(mclagIntfKeys) > 0 { for _, intfKey := range mclagIntfKeys { if intfKey.Get(1) == *intf.Name { domainid, _ := strconv.ParseUint(intfKey.Get(0), 10, 32) mclagdomainId = int(domainid) } } } } mclagIntfKey := strconv.Itoa(mclagdomainId) + "|" + *intf.Name log.Infof("YangToDb_mclag_interface_subtree_xfmr --> key: %v", mclagIntfKey) _, ok := mclagIntfTblMap[mclagIntfKey] if !ok { mclagIntfTblMap[mclagIntfKey] = db.Value{Field: make(map[string]string)} } mclagIntfTblMap[mclagIntfKey].Field["if_type"] = "PortChannel" } } res_map["MCLAG_INTERFACE"] = mclagIntfTblMap return res_map, err }
var YangToDb_napt_mapping_subtree_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error naptMap := make(map[string]map[string]db.Value) tblName := STATIC_NAPT naptTblObj := getNaptTblRoot(inParams.ygRoot, false) if inParams.oper != DELETE && (naptTblObj == nil || naptTblObj.NaptMappingEntry == nil || len(naptTblObj.NaptMappingEntry) < 1) { errStr := "NAPT [container/list] not populated." log.Info("YangToDb_napt_mapping_subtree_xfmr: " + errStr) return naptMap, errors.New(errStr) } if inParams.oper == DELETE { if naptTblObj == nil || naptTblObj.NaptMappingEntry == nil || len(naptTblObj.NaptMappingEntry) < 1 { allKeys, keyErr := getAllTableKeys(inParams.d, &db.TableSpec{Name: tblName}) if keyErr != nil { log.Info("YangToDb_napt_mapping_subtree_xfmr - GetallKeys failed for table : ", tblName) return naptMap, errors.New("GetallKeys failed for table " + tblName) } for _, entKey := range allKeys { if len(entKey.Comp) < 3 { continue } if _, ok := naptMap[tblName]; !ok { naptMap[tblName] = make(map[string]db.Value) } entKeyStr := strings.Join(entKey.Comp, "|") var emtData db.Value naptMap[tblName][entKeyStr] = emtData } } } for key, data := range naptTblObj.NaptMappingEntry { if data.Config == nil && inParams.oper != DELETE { errStr := "NAPT [Config DATA] invalid." log.Info("YangToDb_napt_mapping_subtree_xfmr : " + errStr) return naptMap, errors.New(errStr) } if _, ok := protocol_map[key.Protocol]; !ok { log.Info("YangToDb_napt_mapping_subtree_xfmr : Invalid protocol key for NAPT config entry.") errStr := "NAPT [keys] not valid." return naptMap, errors.New(errStr) } dbkey := key.ExternalAddress + "|" + protocol_map[key.Protocol] + "|" + strconv.FormatInt(int64(key.ExternalPort), 10) if _, ok := naptMap[tblName]; !ok { naptMap[tblName] = make(map[string]db.Value) } dbData := make(map[string]string) entry := db.Value{Field: dbData} if data.Config != nil { if data.Config.InternalAddress != nil { entry.Set("local_ip", *data.Config.InternalAddress) } if data.Config.InternalPort != nil { entry.SetInt("local_port", int(*data.Config.InternalPort)) } if data.Config.Type != 0 { natType := findInMap(NAT_TYPE_MAP, strconv.FormatInt(int64(data.Config.Type), 10)) entry.Set(NAT_TYPE, natType) } if data.Config.TwiceNatId != nil { entry.SetInt("twice_nat_id", int(*data.Config.TwiceNatId)) } } log.Info("YangToDb_napt_mapping_subtree_xfmr : dbkey - ", dbkey, " data - ", entry) naptMap[tblName][dbkey] = entry } log.Info("YangToDb_napt_mapping_subtree_xfmr : Map -: ", naptMap) return naptMap, err }
var YangToDb_nat_mapping_subtree_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error natMap := make(map[string]map[string]db.Value) tblName := STATIC_NAT natTblObj := getNatTblRoot(inParams.ygRoot, false) if inParams.oper != DELETE && (natTblObj == nil || natTblObj.NatMappingEntry == nil || len(natTblObj.NatMappingEntry) < 1) { errStr := "NAT [container/list] not populated." log.Info("YangToDb_nat_mapping_subtree_xfmr: " + errStr) return natMap, errors.New(errStr) } if inParams.oper == DELETE { if natTblObj == nil || natTblObj.NatMappingEntry == nil || len(natTblObj.NatMappingEntry) < 1 { allKeys, keyErr := getAllTableKeys(inParams.d, &db.TableSpec{Name: tblName}) if keyErr != nil { log.Info("YangToDb_nat_mapping_subtree_xfmr - GetallKeys failed for table : ", tblName) return natMap, errors.New("GetallKeys failed for table " + tblName) } for _, entKey := range allKeys { if len(entKey.Comp) < 1 { continue } if _, ok := natMap[tblName]; !ok { natMap[tblName] = make(map[string]db.Value) } entKeyStr := entKey.Comp[0] var emtData db.Value natMap[tblName][entKeyStr] = emtData } } } for key, data := range natTblObj.NatMappingEntry { if data.Config == nil && inParams.oper != DELETE { errStr := "NAT [Config DATA] invalid." log.Info("YangToDb_nat_mapping_subtree_xfmr : " + errStr) return natMap, errors.New(errStr) } dbkey := key if _, ok := natMap[tblName]; !ok { natMap[tblName] = make(map[string]db.Value) } dbData := make(map[string]string) entry := db.Value{Field: dbData} if data.Config != nil { if data.Config.InternalAddress != nil { entry.Set("local_ip", *data.Config.InternalAddress) } if data.Config.Type != 0 { natType := findInMap(NAT_TYPE_MAP, strconv.FormatInt(int64(data.Config.Type), 10)) entry.Set(NAT_TYPE, natType) } if data.Config.TwiceNatId != nil { entry.SetInt("twice_nat_id", int(*data.Config.TwiceNatId)) } } log.Info("YangToDb_nat_mapping_subtree_xfmr : dbkey - ", dbkey, " data - ", entry) natMap[tblName][dbkey] = entry } log.Info("YangToDb_nat_mapping_subtree_xfmr : Map -: ", natMap) return natMap, err }
var YangToDb_network_instance_interface_binding_subtree_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error res_map := make(map[string]map[string]db.Value) log.Infof("YangToDb_network_instance_interface_binding_subtree_xfmr: ygRoot %v uri %v", inParams.ygRoot, inParams.uri) pathInfo := NewPathInfo(inParams.uri) targetUriPath, err := getYangPathFromUri(pathInfo.Path) log.Info("YangToDb_network_instance_interface_binding_subtree_xfmr: targetUri ", targetUriPath) keyName := pathInfo.Var("name") intfId := pathInfo.Var("id") if (keyName == "") || (keyName == "mgmt") { log.Info("YangToDb_network_instance_interface_binding_subtree_xfmr: no intf binding for VRF ", keyName) return res_map, err } if intfId == "" { log.Info("YangToDb_network_instance_interface_binding_subtree_xfmr: empty interface id for VRF ", keyName) return res_map, err } vrfObj := getNwInstRoot(inParams.ygRoot) if vrfObj.NetworkInstance[keyName].Interfaces == nil { return res_map, err } intf_type, _, err := getIntfTypeByName(intfId) if err != nil { log.Info("YangToDb_network_instance_interface_binding_subtree_xfmr: unknown intf type for ", intfId) } intTbl := IntfTypeTblMap[intf_type] intf_tbl_name, _ := getIntfTableNameByDBId(intTbl, inParams.curDb) intfVrfBind, vrf_name := isIntfBindToOtherVrf(intf_tbl_name, intfId, keyName, inParams) if intfVrfBind == true { var errStr string if inParams.oper == DELETE { errStr = "Interface is associated with VRF " + vrf_name } else { errStr = "Interface is already associated with VRF " + vrf_name } log.Info("YangToDb_network_instance_interface_binding_subtree_xfmr: ", errStr) err = tlerr.InvalidArgsError{Format: errStr} return res_map, err } if keyName == "default" { log.Infof("YangToDb_network_instance_interface_binding_subtree_xfmr vrf intf binding for default intf %v", intfId) return res_map, err } if (inParams.oper == CREATE) || (inParams.oper == REPLACE) || (inParams.oper == UPDATE) { if intf_type == IntfTypeEthernet { err = validateIntfAssociatedWithPortChannel(inParams.d, &intfId) if err != nil { return res_map, err } } if intf_type == IntfTypeEthernet || intf_type == IntfTypePortChannel { err = validateIntfAssociatedWithVlan(inParams.d, &intfId) if err != nil { return res_map, err } } if intf_type == IntfTypeLoopback { ipKeys, err1 := doGetIntfIpKeys(inParams.d, LOOPBACK_INTERFACE_TN, intfId) if err1 == nil && len(ipKeys) > 0 { errStr := "Interface: " + intfId + " configured with IP address" log.Info("YangToDb_network_instance_interface_binding_subtree_xfmr: ", errStr) err = tlerr.InvalidArgsError{Format: errStr} } } else { err = validateL3ConfigExists(inParams.d, &intfId) } if err != nil { return res_map, err } } res_map[intf_tbl_name] = make(map[string]db.Value) res_map[intf_tbl_name][intfId] = db.Value{Field: map[string]string{}} dbVal := res_map[intf_tbl_name][intfId] (&dbVal).Set("vrf_name", keyName) log.Infof("YangToDb_network_instance_interface_binding_subtree_xfmr: set vrf_name %v for %v in %v", keyName, intfId, intf_tbl_name) log.Infof("YangToDb_network_instance_interface_binding_subtree_xfmr: %v", res_map) return res_map, err }
YangToDb subtree transformer for network instance interface binding
var YangToDb_route_map_bgp_action_set_community SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error res_map := make(map[string]map[string]db.Value) stmtmap := make(map[string]db.Value) log.Info("YangToDb_route_map_bgp_action_set_community: ", inParams.ygRoot, inParams.uri) rtPolDefsObj := getRoutingPolicyRoot(inParams.ygRoot) if rtPolDefsObj == nil || rtPolDefsObj.PolicyDefinitions == nil || len(rtPolDefsObj.PolicyDefinitions.PolicyDefinition) < 1 { log.Info("YangToDb_route_map_bgp_action_set_community : Routing policy definitions list is empty.") return res_map, errors.New("Routing policy definitions list is empty") } pathInfo := NewPathInfo(inParams.uri) rtPolicyName := pathInfo.Var("name") rtStmtName := pathInfo.Var("name#2") if rtPolicyName == "" || rtStmtName == "" { return res_map, errors.New("Routing policy keys are not present") } rtPolDefObj := rtPolDefsObj.PolicyDefinitions.PolicyDefinition[rtPolicyName] rtStmtObj := rtPolDefObj.Statements.Statement[rtStmtName] if rtStmtObj.Actions == nil || rtStmtObj.Actions.BgpActions == nil || rtStmtObj.Actions.BgpActions.SetCommunity == nil { return res_map, errors.New("Routing policy invalid action parameters") } rtStmtActionCommObj := rtStmtObj.Actions.BgpActions.SetCommunity if rtStmtActionCommObj == nil || (inParams.oper != DELETE && rtStmtActionCommObj.Config == nil) { return res_map, errors.New("Routing policy invalid action parameters") } entry_key := rtPolicyName + "|" + rtStmtName stmtmap[entry_key] = db.Value{Field: make(map[string]string)} final_std_community := "" if rtStmtActionCommObj.Config != nil && rtStmtActionCommObj.Config.Method == ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Config_Method_INLINE { if rtStmtActionCommObj.Inline == nil || rtStmtActionCommObj.Inline.Config == nil || len(rtStmtActionCommObj.Inline.Config.Communities) == 0 { return res_map, errors.New("Routing policy invalid action parameters") } log.Info("YangToDb_route_map_bgp_action_set_community: ", rtStmtActionCommObj.Inline.Config.Communities) for _, commUnion := range rtStmtActionCommObj.Inline.Config.Communities { log.Info("YangToDb_route_map_bgp_action_set_community individual community value: ", commUnion) var b bytes.Buffer commType := reflect.TypeOf(commUnion).Elem() std_community := "" switch commType { case reflect.TypeOf(ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_Config_Communities_Union_E_OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY{}): v := (commUnion).(*ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_Config_Communities_Union_E_OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY) switch v.E_OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY { case ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NOPEER: std_community = "no-peer" break case ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_ADVERTISE: std_community = "no-advertise" break case ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT: std_community = "no-export" break case ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT_SUBCONFED: std_community = "local-AS" break } break case reflect.TypeOf(ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_Config_Communities_Union_Uint32{}): v := (commUnion).(*ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_Config_Communities_Union_Uint32) fmt.Fprintf(&b, "0x%x", v.Uint32) std_community = b.String() break case reflect.TypeOf(ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_Config_Communities_Union_String{}): v := (commUnion).(*ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Inline_Config_Communities_Union_String) std_community = v.String break } if final_std_community == "" { final_std_community = std_community } else { final_std_community = final_std_community + "," + std_community } } if rtStmtActionCommObj.Config.Options == ocbinds.OpenconfigBgpPolicy_BgpSetCommunityOptionType_REMOVE { subOpMap := make(map[db.DBNum]map[string]map[string]db.Value) if _, ok := subOpMap[db.ConfigDB]; !ok { subOpMap[db.ConfigDB] = make(map[string]map[string]db.Value) } if _, ok := subOpMap[db.ConfigDB]["ROUTE_MAP"]; !ok { subOpMap[db.ConfigDB]["ROUTE_MAP"] = make(map[string]db.Value) } subOpMap[db.ConfigDB]["ROUTE_MAP"][entry_key] = db.Value{Field: make(map[string]string)} subOpMap[db.ConfigDB]["ROUTE_MAP"][entry_key].Field["set_community_inline@"] = final_std_community inParams.subOpDataMap[DELETE] = &subOpMap return res_map, nil } stmtmap[entry_key].Field["set_community_inline@"] = final_std_community } else if rtStmtActionCommObj.Config != nil && rtStmtActionCommObj.Config.Method == ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Config_Method_REFERENCE { if rtStmtActionCommObj.Reference == nil { return res_map, errors.New("Routing policy invalid action parameters") } if rtStmtActionCommObj.Config.Options == ocbinds.OpenconfigBgpPolicy_BgpSetCommunityOptionType_REMOVE { subOpMap := make(map[db.DBNum]map[string]map[string]db.Value) if _, ok := subOpMap[db.ConfigDB]; !ok { subOpMap[db.ConfigDB] = make(map[string]map[string]db.Value) } if _, ok := subOpMap[db.ConfigDB]["ROUTE_MAP"]; !ok { subOpMap[db.ConfigDB]["ROUTE_MAP"] = make(map[string]db.Value) } subOpMap[db.ConfigDB]["ROUTE_MAP"][entry_key] = db.Value{Field: make(map[string]string)} subOpMap[db.ConfigDB]["ROUTE_MAP"][entry_key].Field["set_community_ref"] = *rtStmtActionCommObj.Reference.Config.CommunitySetRef inParams.subOpDataMap[DELETE] = &subOpMap return res_map, nil } else { stmtmap[entry_key].Field["set_community_ref"] = *rtStmtActionCommObj.Reference.Config.CommunitySetRef } } else if (rtStmtActionCommObj.Config == nil) && (inParams.oper == DELETE) { stmtmap[entry_key].Field["set_community_inline@"] = "" stmtmap[entry_key].Field["set_community_ref"] = "" } res_map["ROUTE_MAP"] = stmtmap return res_map, err }
var YangToDb_route_map_bgp_action_set_ext_community SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error res_map := make(map[string]map[string]db.Value) stmtmap := make(map[string]db.Value) log.Info("YangToDb_route_map_bgp_action_set_community: ", inParams.ygRoot, inParams.uri) rtPolDefsObj := getRoutingPolicyRoot(inParams.ygRoot) if rtPolDefsObj == nil || rtPolDefsObj.PolicyDefinitions == nil || len(rtPolDefsObj.PolicyDefinitions.PolicyDefinition) < 1 { log.Info("YangToDb_route_map_bgp_action_set_community : Routing policy definitions list is empty.") return res_map, errors.New("Routing policy definitions list is empty") } pathInfo := NewPathInfo(inParams.uri) rtPolicyName := pathInfo.Var("name") rtStmtName := pathInfo.Var("name#2") if rtPolicyName == "" || rtStmtName == "" { return res_map, errors.New("Routing policy keys are not present") } rtPolDefObj := rtPolDefsObj.PolicyDefinitions.PolicyDefinition[rtPolicyName] rtStmtObj := rtPolDefObj.Statements.Statement[rtStmtName] if rtStmtObj.Actions == nil || rtStmtObj.Actions.BgpActions == nil || rtStmtObj.Actions.BgpActions.SetExtCommunity == nil { return res_map, errors.New("Routing policy invalid action parameters") } rtStmtActionCommObj := rtStmtObj.Actions.BgpActions.SetExtCommunity if rtStmtActionCommObj == nil || (inParams.oper != DELETE && rtStmtActionCommObj.Config == nil) { return res_map, errors.New("Routing policy invalid action parameters") } entry_key := rtPolicyName + "|" + rtStmtName stmtmap[entry_key] = db.Value{Field: make(map[string]string)} final_std_community := "" if rtStmtActionCommObj.Config != nil && (rtStmtActionCommObj.Config.Method == ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Config_Method_INLINE) { if rtStmtActionCommObj.Inline == nil || rtStmtActionCommObj.Inline.Config == nil || len(rtStmtActionCommObj.Inline.Config.Communities) == 0 { return res_map, errors.New("Routing policy invalid action parameters") } for _, commUnion := range rtStmtActionCommObj.Inline.Config.Communities { log.Info("YangToDb_route_map_bgp_action_set_ext_community individual community: ", commUnion) commType := reflect.TypeOf(commUnion).Elem() std_community := "" switch commType { case reflect.TypeOf(ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_Config_Communities_Union_E_OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY{}): v := (commUnion).(*ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_Config_Communities_Union_E_OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY) switch v.E_OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY { case ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NOPEER: std_community = "no-peer" break case ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_ADVERTISE: std_community = "no-advertise" break case ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT: std_community = "no-export" break case ocbinds.OpenconfigBgpTypes_BGP_WELL_KNOWN_STD_COMMUNITY_NO_EXPORT_SUBCONFED: std_community = "local-AS" break } break case reflect.TypeOf(ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_Config_Communities_Union_String{}): v := (commUnion).(*ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetExtCommunity_Inline_Config_Communities_Union_String) std_community = v.String break } if final_std_community == "" { final_std_community = std_community } else { final_std_community = final_std_community + "," + std_community } } if rtStmtActionCommObj.Config.Options == ocbinds.OpenconfigBgpPolicy_BgpSetCommunityOptionType_REMOVE { subOpMap := make(map[db.DBNum]map[string]map[string]db.Value) if _, ok := subOpMap[db.ConfigDB]; !ok { subOpMap[db.ConfigDB] = make(map[string]map[string]db.Value) } if _, ok := subOpMap[db.ConfigDB]["ROUTE_MAP"]; !ok { subOpMap[db.ConfigDB]["ROUTE_MAP"] = make(map[string]db.Value) } subOpMap[db.ConfigDB]["ROUTE_MAP"][entry_key] = db.Value{Field: make(map[string]string)} subOpMap[db.ConfigDB]["ROUTE_MAP"][entry_key].Field["set_ext_community_inline@"] = final_std_community inParams.subOpDataMap[DELETE] = &subOpMap return res_map, nil } stmtmap[entry_key].Field["set_ext_community_inline@"] = final_std_community } else if rtStmtActionCommObj.Config != nil && rtStmtActionCommObj.Config.Method == ocbinds.OpenconfigRoutingPolicy_RoutingPolicy_PolicyDefinitions_PolicyDefinition_Statements_Statement_Actions_BgpActions_SetCommunity_Config_Method_REFERENCE { if rtStmtActionCommObj.Reference == nil { return res_map, errors.New("Routing policy invalid action parameters") } if rtStmtActionCommObj.Config.Options == ocbinds.OpenconfigBgpPolicy_BgpSetCommunityOptionType_REMOVE { subOpMap := make(map[db.DBNum]map[string]map[string]db.Value) if _, ok := subOpMap[db.ConfigDB]; !ok { subOpMap[db.ConfigDB] = make(map[string]map[string]db.Value) } if _, ok := subOpMap[db.ConfigDB]["ROUTE_MAP"]; !ok { subOpMap[db.ConfigDB]["ROUTE_MAP"] = make(map[string]db.Value) } subOpMap[db.ConfigDB]["ROUTE_MAP"][entry_key] = db.Value{Field: make(map[string]string)} subOpMap[db.ConfigDB]["ROUTE_MAP"][entry_key].Field["set_ext_community_ref"] = *rtStmtActionCommObj.Reference.Config.ExtCommunitySetRef inParams.subOpDataMap[DELETE] = &subOpMap return res_map, nil } else { stmtmap[entry_key].Field["set_ext_community_ref"] = *rtStmtActionCommObj.Reference.Config.ExtCommunitySetRef } } else if (rtStmtActionCommObj.Config == nil) && (inParams.oper == DELETE) { stmtmap[entry_key].Field["set_ext_community_inline@"] = "" stmtmap[entry_key].Field["set_ext_community_ref"] = "" } res_map["ROUTE_MAP"] = stmtmap return res_map, err }
var YangToDb_sw_vlans_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error res_map := make(map[string]map[string]db.Value) vlanMap := make(map[string]db.Value) vlanMemberMap := make(map[string]db.Value) stpVlanPortMap := make(map[string]db.Value) stpPortMap := make(map[string]db.Value) log.Info("YangToDb_sw_vlans_xfmr: ", inParams.uri) var swVlanConfig swVlanMemberPort_t pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") deviceObj := (*inParams.ygRoot).(*ocbinds.Device) intfObj := deviceObj.Interfaces log.Info("Switched vlans request for ", ifName) intf := intfObj.Interface[ifName] if intf.Ethernet == nil && intf.Aggregation == nil { return nil, errors.New("Wrong Config Request") } if intf.Ethernet != nil { if intf.Ethernet.SwitchedVlan == nil || intf.Ethernet.SwitchedVlan.Config == nil { return nil, errors.New("Wrong config request for Ethernet!") } swVlanConfig.swEthMember = intf.Ethernet.SwitchedVlan } if intf.Aggregation != nil { if intf.Aggregation.SwitchedVlan == nil || intf.Aggregation.SwitchedVlan.Config == nil { return nil, errors.New("Wrong Config Request for Port Channel") } swVlanConfig.swPortChannelMember = intf.Aggregation.SwitchedVlan } intfType, _, err := getIntfTypeByName(ifName) if err != nil { errStr := "Extraction of Interface type from Interface: " + ifName + " failed!" return nil, errors.New(errStr) } err = validateL3ConfigExists(inParams.d, &ifName) if err != nil { return nil, err } if intfType == IntfTypeEthernet { err = validateIntfAssociatedWithPortChannel(inParams.d, &ifName) if err != nil { return nil, err } } switch inParams.oper { case CREATE: fallthrough case UPDATE: err = intfVlanMemberAdd(&swVlanConfig, &inParams, &ifName, vlanMap, vlanMemberMap, stpVlanPortMap, stpPortMap, intfType) if err != nil { log.Errorf("Interface VLAN member port addition failed for Interface: %s!", ifName) return nil, err } res_map[VLAN_TN] = vlanMap res_map[VLAN_MEMBER_TN] = vlanMemberMap res_map[STP_VLAN_PORT_TABLE] = stpVlanPortMap res_map[STP_PORT_TABLE] = stpPortMap case DELETE: err = intfVlanMemberRemoval(&swVlanConfig, &inParams, &ifName, vlanMap, vlanMemberMap, stpVlanPortMap, stpPortMap, intfType) if err != nil { log.Errorf("Interface VLAN member port removal failed for Interface: %s!", ifName) return nil, err } res_map[VLAN_MEMBER_TN] = vlanMemberMap res_map[VLAN_TN] = vlanMap res_map[STP_VLAN_PORT_TABLE] = stpVlanPortMap if len(stpPortMap) != 0 { res_map[STP_PORT_TABLE] = stpPortMap } case REPLACE: return nil, tlerr.NotSupported("REPLACE of Vlan members is currently not supported.") } log.Info("YangToDb_sw_vlans_xfmr: vlan res map:", res_map) return res_map, err }
Subtree transformer supports CREATE, UPDATE and DELETE operations
var YangToDb_sys_aaa_auth_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { log.Info("SubtreeXfmrFunc - Uri SYS AUTH: ", inParams.uri) pathInfo := NewPathInfo(inParams.uri) targetUriPath, _ := getYangPathFromUri(pathInfo.Path) log.Info("TARGET URI PATH SYS AUTH:", targetUriPath) sysObj := getAppRootObject(inParams) usersObj := sysObj.Aaa.Authentication.Users userName := pathInfo.Var("username") log.Info("username:", userName) if len(userName) == 0 { return nil, nil } var status bool var err_str string if _, _ok := inParams.txCache.Load(userName); !_ok { inParams.txCache.Store(userName, userName) } else { if val, present := inParams.txCache.Load("tx_err"); present { return nil, fmt.Errorf("%s", val) } return nil, nil } if inParams.oper == DELETE { status, err_str = hostAccountUserDel(userName) } else { if value, present := usersObj.User[userName]; present { log.Info("User:", *(value.Config.Username)) temp := value.Config.Role.(*ocbinds.OpenconfigSystem_System_Aaa_Authentication_Users_User_Config_Role_Union_String) log.Info("Role:", temp.String) status, err_str = hostAccountUserAdd(*(value.Config.Username), temp.String, *(value.Config.PasswordHashed)) } } if !status { if _, present := inParams.txCache.Load("tx_err"); !present { log.Info("Error in operation:", err_str) inParams.txCache.Store("tx_err", err_str) return nil, fmt.Errorf("%s", err_str) } } else { return nil, nil } return nil, nil }
var YangToDb_unnumbered_intf_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error subIntfmap := make(map[string]map[string]db.Value) intfsObj := getIntfsRoot(inParams.ygRoot) if intfsObj == nil || len(intfsObj.Interface) < 1 { log.Info("YangToDb_unnumbered_intf_xfmr: IntfsObj/interface list is empty.") return subIntfmap, errors.New("IntfsObj/Interface is not specified") } pathInfo := NewPathInfo(inParams.uri) ifName := pathInfo.Var("name") if ifName == "" { errStr := "Interface KEY not present" log.Info("YangToDb_unnumbered_intf_xfmr: " + errStr) return subIntfmap, errors.New(errStr) } if _, ok := intfsObj.Interface[ifName]; !ok { errStr := "Interface entry not found in Ygot tree, ifname: " + ifName log.Info("YangToDb_unnumbered_intf_xfmr : " + errStr) return subIntfmap, errors.New(errStr) } intfObj := intfsObj.Interface[ifName] if intfObj.Subinterfaces == nil || len(intfObj.Subinterfaces.Subinterface) < 1 { errStr := "SubInterface node is not set" log.Info("YangToDb_unnumbered_intf_xfmr : " + errStr) return subIntfmap, errors.New(errStr) } if _, ok := intfObj.Subinterfaces.Subinterface[0]; !ok { log.Info("YangToDb_unnumbered_intf_xfmr : No Unnumbered IP interface handling required") return subIntfmap, err } intfType, _, ierr := getIntfTypeByName(ifName) if intfType == IntfTypeUnset || ierr != nil { errStr := "Invalid interface type IntfTypeUnset" log.Info("YangToDb_unnumbered_intf_xfmr : " + errStr) return subIntfmap, errors.New(errStr) } intTbl := IntfTypeTblMap[intfType] tblName, _ := getIntfTableNameByDBId(intTbl, inParams.curDb) subIntfObj := intfObj.Subinterfaces.Subinterface[0] log.Info("subIntfObj:=", subIntfObj) if subIntfObj.Ipv4 != nil && subIntfObj.Ipv4.Unnumbered.InterfaceRef != nil { if _, ok := subIntfmap[tblName]; !ok { subIntfmap[tblName] = make(map[string]db.Value) } ifdb := make(map[string]string) var value db.Value if inParams.oper == DELETE { log.Info("DELETE Unnum Intf:=", tblName, ifName) intfIPKeys, _ := inParams.d.GetKeys(&db.TableSpec{Name: tblName}) if len(intfIPKeys) > 0 { for i := range intfIPKeys { if len(intfIPKeys[i].Comp) > 1 { ifdb[UNNUMBERED] = "NULL" break } } } } else { unnumberedObj := subIntfObj.Ipv4.Unnumbered.InterfaceRef if unnumberedObj.Config != nil { log.Info("Unnum Intf:=", *unnumberedObj.Config.Interface) ifdb[UNNUMBERED] = *unnumberedObj.Config.Interface } } value = db.Value{Field: ifdb} subIntfmap[tblName][ifName] = value } log.Info("YangToDb_unnumbered_intf_xfmr : subIntfmap : ", subIntfmap) return subIntfmap, err }
var YangToDb_vxlan_vni_instance_subtree_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error var tblName string res_map := make(map[string]map[string]db.Value) valueMap := make(map[string]db.Value) pathInfo := NewPathInfo(inParams.uri) if log.V(3) { log.Info("YangToDb_vxlan_vni_instance_subtree_xfmr: ", inParams.ygRoot, inParams.uri) } path, err := getVxlanNiUriPath(inParams.uri) if err != nil { return res_map, err } reqP := &vxlanReqProcessor{&inParams.requestUri, &inParams.uri, path, inParams.oper, (*inParams.ygRoot).(*ocbinds.Device), inParams.param, inParams.d, inParams.dbs, nil, nil, nil, nil, &inParams} if err := reqP.setVxlanNetInstObjFromReq(); err != nil { return nil, err } if reqP.opcode != DELETE && (reqP.vxlanNetInstObj.VxlanVniInstances == nil || len(reqP.vxlanNetInstObj.VxlanVniInstances.VniInstance) == 0) { return res_map, tlerr.NotFound("Resource Not Found") } niName := *(reqP.vxlanNetInstObj.Name) if strings.HasPrefix(niName, "Vlan") { tblName = "VXLAN_TUNNEL_MAP" } else if strings.HasPrefix(niName, "Vrf") { tblName = "VRF" } else { return res_map, tlerr.InvalidArgs("Invalid Network Instance name: %s", niName) } pathInfoOrig := NewPathInfo(inParams.requestUri) if log.V(3) { log.Info("YangToDb_vxlan_vni_instance_subtree_xfmr: pathInfoOrig => ", pathInfoOrig) } vniIdKeyStr := pathInfoOrig.Var("vni-id") srcNveKeyStr := pathInfoOrig.Var("source-nve") if log.V(3) { log.Info("YangToDb_vxlan_vni_instance_subtree_xfmr: vniIdKeyStr in URI => ", vniIdKeyStr) log.Info("YangToDb_vxlan_vni_instance_subtree_xfmr: srcNveKeyStr in URI => ", srcNveKeyStr) } if tblName == "VXLAN_TUNNEL_MAP" { var VXLAN_TUNNEL_MAP_TS *db.TableSpec = &db.TableSpec{Name: tblName} var isKeysInPaylod bool isKeysInPaylod = false if vniIdKeyStr == "" && srcNveKeyStr == "" { if reqP.vxlanNetInstObj.VxlanVniInstances != nil && len(reqP.vxlanNetInstObj.VxlanVniInstances.VniInstance) > 0 { for vniKeyObj, _ := range reqP.vxlanNetInstObj.VxlanVniInstances.VniInstance { vniIdKeyStr = strconv.Itoa(int(vniKeyObj.VniId)) srcNveKeyStr = vniKeyObj.SourceNve log.Info("YangToDb_vxlan_vni_instance_subtree_xfmr: vniIdKeyStr in payload => ", vniIdKeyStr) log.Info("YangToDb_vxlan_vni_instance_subtree_xfmr: srcNveKeyStr in payload => ", srcNveKeyStr) isKeysInPaylod = true break } if inParams.oper == 3 { tunnelMapKeys, err := reqP.db.GetKeys(VXLAN_TUNNEL_MAP_TS) if err == nil && len(tunnelMapKeys) > 0 { log.Error("YangToDb_vxlan_vni_instance_subtree_xfmr ==> returning ERROR, since Operation not allowed to modify the existing vxlan tunnel map") return res_map, tlerr.New("Operation not allowed to modify/replace the existing vxlan tunnel map") } } } } if vniIdKeyStr != "" && srcNveKeyStr != "" { tunnelMapKeyStr := "map_" + vniIdKeyStr + "_" + niName if log.V(3) { log.Info("YangToDb_vxlan_vni_instance_subtree_xfmr: tunnelMapKeyStr => ", tunnelMapKeyStr) } _, err := reqP.db.GetEntry(VXLAN_TUNNEL_MAP_TS, db.Key{Comp: []string{srcNveKeyStr, tunnelMapKeyStr}}) if log.V(3) { log.Info("YangToDb_vxlan_vni_instance_subtree_xfmr: tblVxlanMapKeys => err => ", err) } if err != nil && inParams.oper != 3 && isKeysInPaylod == false { log.Error("YangToDb_vxlan_vni_instance_subtree_xfmr ==> returning ERROR, since the key doesn't exist") return res_map, tlerr.NotFound("Resource Not Found") } else if err == nil && (inParams.oper == 3 || inParams.oper == 4) { log.Error("YangToDb_vxlan_vni_instance_subtree_xfmr ==> returning ERROR, since Operation not allowed to modify the existing vxlan tunnel map") return res_map, tlerr.New("Operation not allowed to modify the existing vxlan tunnel map") } } } var vniId uint32 var vtepName string var tblKeyStr string if reqP.opcode == DELETE && (pathInfo.Template == "/openconfig-network-instance:network-instances/network-instance{name}/openconfig-vxlan:vxlan-vni-instances/vni-instance" || pathInfo.Template == "/openconfig-network-instance:network-instances/network-instance{name}/openconfig-vxlan:vxlan-vni-instances") { dbKeys, err := inParams.d.GetKeys(&db.TableSpec{Name: tblName}) if err != nil { return res_map, err } if len(dbKeys) > 0 { for _, dbkey := range dbKeys { if strings.HasPrefix(niName, "Vlan") { vtepName = dbkey.Get(0) mapNameList := strings.Split(dbkey.Get(1), "_") vniNum, _ := strconv.ParseUint(mapNameList[1], 10, 32) vniId = uint32(vniNum) log.Info("mapNameList ==> ", mapNameList) log.Info("niName ==> ", niName) log.Info("vniId ==> ", vniId) if mapNameList[2] == niName { tblKeyStr = vtepName + "|" + "map_" + strconv.Itoa(int(vniId)) + "_" + niName log.Info("tblKeyStr ==> ", tblKeyStr) valueMap[tblKeyStr] = db.Value{Field: make(map[string]string)} valueMap[tblKeyStr].Field["vlan"] = niName valueMap[tblKeyStr].Field["vni"] = strconv.Itoa(int(vniId)) } } else if strings.HasPrefix(niName, "Vrf") { vrfEntry, err := inParams.d.GetEntry(&db.TableSpec{Name: tblName}, db.Key{Comp: []string{niName}}) if err != nil { return res_map, err } if vrfEntry.Has("vni") { vniIdStr := vrfEntry.Get("vni") vniNum, _ := strconv.ParseUint(vniIdStr, 10, 32) vniId = uint32(vniNum) } } } } if strings.HasPrefix(niName, "Vlan") { if len(valueMap) > 0 { log.Info("vniId ==> deleting ", vniId) res_map[tblName] = valueMap return res_map, err } else { log.Info("vniId ==> NO delete ", vniId) return nil, err } } } else { for vniKey, _ := range reqP.vxlanNetInstObj.VxlanVniInstances.VniInstance { vniId = vniKey.VniId vtepName = vniKey.SourceNve break } } if strings.HasPrefix(niName, "Vlan") { tblKeyStr = vtepName + "|" + "map_" + strconv.Itoa(int(vniId)) + "_" + niName valueMap[tblKeyStr] = db.Value{Field: make(map[string]string)} valueMap[tblKeyStr].Field["vlan"] = niName valueMap[tblKeyStr].Field["vni"] = strconv.Itoa(int(vniId)) } else if strings.HasPrefix(niName, "Vrf") { tblKeyStr = niName valueMap[tblKeyStr] = db.Value{Field: make(map[string]string)} valueMap[tblKeyStr].Field["vni"] = strconv.Itoa(int(vniId)) } res_map[tblName] = valueMap return res_map, err }
var YangToDb_ztp_config_xfmr SubTreeXfmrYangToDb = func(inParams XfmrParams) (map[string]map[string]db.Value, error) { var err error log.Info("TableXfmrFunc - Uri ZTP: ", inParams.uri) pathInfo := NewPathInfo(inParams.uri) targetUriPath, err := getYangPathFromUri(pathInfo.Path) log.Info("TARGET URI PATH ZTP:", targetUriPath) var act string = "disable" ztpObj := getZtpRoot(inParams.ygRoot) if ztpObj.Config.AdminMode == nil { log.Info("Invalid Input") return nil, err } b := *ztpObj.Config.AdminMode if b { act = "enable" } _, err = ztpAction(act) return nil, err }
type TableXfmrFunc ¶
type TableXfmrFunc func(inParams XfmrParams) ([]string, error)
*
- TableXfmrFunc type is defined to use for table transformer function for dynamic derviation of redis table.
- Param: XfmrParams structure having database pointers, current db, operation, DB data in multidimensional map, YgotRoot, uri
- Return: List of table names, error *
type ValidateCallpoint ¶
type ValidateCallpoint func(inParams XfmrParams) bool
*
- ValidateCallpoint is used to validate a YANG node during data translation back to YANG as a response to GET
- Param : XfmrParams structure having Database pointers, current db, operation, DB data in multidimensional map, output param YgotRoot, uri
- Return : bool *
type XfmrInterface ¶
type XfmrInterface interface {
// contains filtered or unexported methods
}
*
- Xfmr validation interface for validating the callback registration of app modules
- transformer methods. *
type XfmrParams ¶
type XfmrParams struct {
// contains filtered or unexported fields
}
Source Files ¶
- cfg_mgmt_xfmr.go
- host_acct_mgr.go
- host_comm.go
- sw_portchannel.go
- sw_vlan.go
- transformer.go
- xconst.go
- xfmr_acl.go
- xfmr_bfd.go
- xfmr_bgp.go
- xfmr_bgp_evpn_vni.go
- xfmr_bgp_nbr.go
- xfmr_bgp_pgrp.go
- xfmr_bgp_pgrp_af.go
- xfmr_bgp_rib.go
- xfmr_fdb.go
- xfmr_igmp_snooping.go
- xfmr_image_mgmt.go
- xfmr_interface.go
- xfmr_intf.go
- xfmr_intf_nat_zone.go
- xfmr_ip_rib.go
- xfmr_lacp.go
- xfmr_mclag.go
- xfmr_nat.go
- xfmr_neighbors.go
- xfmr_nw_inst.go
- xfmr_path_utils.go
- xfmr_protocols.go
- xfmr_ptp.go
- xfmr_route_cmn.go
- xfmr_route_map.go
- xfmr_route_policy_sets.go
- xfmr_sag_global.go
- xfmr_sag_if.go
- xfmr_showtech.go
- xfmr_snmp.go
- xfmr_sonic_kdump.go
- xfmr_sonic_tests.go
- xfmr_system.go
- xfmr_system_aaa.go
- xfmr_udld.go
- xfmr_vlan.go
- xfmr_vrf.go
- xfmr_vxlan_intf.go
- xfmr_ztp.go
- xlate.go
- xlate_from_db.go
- xlate_tbl_info.go
- xlate_to_db.go
- xlate_utils.go
- xspec.go