Skip to content

Commit

Permalink
Merge 9024a67 into d93c0dc
Browse files Browse the repository at this point in the history
  • Loading branch information
robshakir committed Aug 2, 2019
2 parents d93c0dc + 9024a67 commit ad41d27
Show file tree
Hide file tree
Showing 10 changed files with 9,238 additions and 13,071 deletions.
18 changes: 11 additions & 7 deletions lsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type rawTLV struct {
// unparsed copies of the LSP that is being processed.
type isisLSP struct {
// LSP is the parsed LSP represented as per the OpenConfig model.
LSP *oc.NetworkInstance_Protocol_Isis_Level_Lsp
LSP *oc.Lsp
// rawTLVs is the set of the TLVs that are included within the
// LSP as raw bytes.
rawTLVs []*rawTLV
Expand All @@ -50,8 +50,8 @@ type isisLSP struct {
// struct to be used to store a parsed LSP.
func newISISLSP() *isisLSP {
return &isisLSP{
LSP: &oc.NetworkInstance_Protocol_Isis_Level_Lsp{
Tlv: map[oc.E_OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE]*oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv{},
LSP: &oc.Lsp{
Tlv: map[oc.E_OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE]*oc.Lsp_Tlv{},
},
rawTLVs: []*rawTLV{},
}
Expand All @@ -68,7 +68,7 @@ func newISISLSP() *isisLSP {
// populated indicating that the LSP's contents were not completely succesfully parsed.
// This function is specifically for Cisco IOS XR devices, since it handles the case
// where a number of fields of the LSP are not included within the byte slice.
func ISISBytesToLSP(lspBytes []byte, offset int) (*oc.NetworkInstance_Protocol_Isis_Level_Lsp, bool, error) {
func ISISBytesToLSP(lspBytes []byte, offset int) (*oc.Lsp, bool, error) {
lspBytes = lspBytes[offset:]

if len(lspBytes) < 16 {
Expand Down Expand Up @@ -134,7 +134,7 @@ type ISISRenderArgs struct {
// RenderNotifications takes an input IS-IS LSP and outputs the gNMI Notifications that
// represent the contents of the supplied LSP. The ISISRenderArgs struct provided gives
// the context for the generation. Returns a set of gNMI notifications, or an error.
func RenderNotifications(lsp *oc.NetworkInstance_Protocol_Isis_Level_Lsp, args ISISRenderArgs) ([]*gnmipb.Notification, error) {
func RenderNotifications(lsp *oc.Lsp, args ISISRenderArgs) ([]*gnmipb.Notification, error) {
if lsp == nil {
return nil, fmt.Errorf("cannot handle nil LSP")
}
Expand All @@ -145,7 +145,10 @@ func RenderNotifications(lsp *oc.NetworkInstance_Protocol_Isis_Level_Lsp, args I

rArgs := ygot.GNMINotificationsConfig{
UsePathElem: args.UsePathElem,
StringSlicePrefix: []string{
}

prefix := &gnmipb.Path{
Element: []string{
"network-instances", "network-instance", args.NetworkInstance,
"protocols", "protocol", "ISIS", args.ProtocolInstance,
"isis", "levels", "level", fmt.Sprintf("%d", args.Level),
Expand All @@ -158,7 +161,7 @@ func RenderNotifications(lsp *oc.NetworkInstance_Protocol_Isis_Level_Lsp, args I
if err != nil {
return nil, fmt.Errorf("cannot create prefix path, %v", err)
}
rArgs.PathElemPrefix = p.Elem
prefix = p
rArgs.StringSlicePrefix = nil
}

Expand All @@ -168,6 +171,7 @@ func RenderNotifications(lsp *oc.NetworkInstance_Protocol_Isis_Level_Lsp, args I
}
// IS-IS LSPs are atomically updated.
for _, n := range notifications {
n.Prefix = prefix
n.Atomic = true
}
return notifications, nil
Expand Down
244 changes: 122 additions & 122 deletions lsdb_test.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions parse_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func ip6BytesToString(ip []byte) (string, error) {
// getTLV retrieves a TLV from an isisLSP, creating it if it does not exist. Returns
// the TLV, a boolean indicating whether the TLV was created, or an error if one is
// experienced.
func (i *isisLSP) getTLV(t oc.E_OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE) (*oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv, bool, error) {
func (i *isisLSP) getTLV(t oc.E_OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE) (*oc.Lsp_Tlv, bool, error) {
tlv, ok := i.LSP.Tlv[t]
var created bool
if !ok {
Expand All @@ -94,7 +94,7 @@ func (i *isisLSP) getTLV(t oc.E_OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE) (*oc.Netw
// does not exist within the LSP, it is created. The container within
// the TLV corresponding to the element containerName is initialised
// in the returned TLV.
func (i *isisLSP) getTLVAndInit(t oc.E_OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE, containerName string) (*oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv, error) {
func (i *isisLSP) getTLVAndInit(t oc.E_OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE, containerName string) (*oc.Lsp_Tlv, error) {
tlv, created, err := i.getTLV(t)
if err != nil {
return nil, err
Expand All @@ -112,8 +112,8 @@ func (i *isisLSP) getTLVAndInit(t oc.E_OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE, co
// getCapabilitySubTLV retrieves the specified sub-TLV from the
// OpenConfig Router Capabilities TLV struct. If the sub-TLV does
// not exist, it is created.
func getCapabilitySubTLV(c *oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Capability, t oc.E_OpenconfigIsisLsdbTypes_ISIS_SUBTLV_TYPE) (*oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Capability_Subtlv, error) {
var stlv *oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Capability_Subtlv
func getCapabilitySubTLV(c *oc.Lsp_Tlv_Capability, t oc.E_OpenconfigIsisLsdbTypes_ISIS_SUBTLV_TYPE) (*oc.Lsp_Tlv_Capability_Subtlv, error) {
var stlv *oc.Lsp_Tlv_Capability_Subtlv
stlv, ok := c.Subtlv[t]
if !ok {
var err error
Expand All @@ -129,8 +129,8 @@ func getCapabilitySubTLV(c *oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Capab
// OpenConfig Extended IS Reachability TLV neighbour struct. If the
// sub-TLV does not exist, it is created, and the specified container
// initialised within it.
func getExtendedISReachSubTLV(n *oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance, t oc.E_OpenconfigIsisLsdbTypes_ISIS_SUBTLV_TYPE, c string) (*oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv, error) {
var stlv *oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv
func getExtendedISReachSubTLV(n *oc.Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance, t oc.E_OpenconfigIsisLsdbTypes_ISIS_SUBTLV_TYPE, c string) (*oc.Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv, error) {
var stlv *oc.Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv
stlv, ok := n.Subtlv[t]
if !ok {
var err error
Expand Down
16 changes: 8 additions & 8 deletions parse_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,34 +204,34 @@ func TestGetTLV(t *testing.T) {
inTLVName oc.E_OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE
inTLVContainerName string
inLSP *isisLSP
wantTLV *oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv
wantTLV *oc.Lsp_Tlv
}{{
name: "new tlv",
inTLVName: oc.OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE_DYNAMIC_NAME,
inTLVContainerName: "Hostname",
wantTLV: &oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv{
wantTLV: &oc.Lsp_Tlv{
Type: oc.OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE_DYNAMIC_NAME,
Hostname: &oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Hostname{},
Hostname: &oc.Lsp_Tlv_Hostname{},
},
}, {
name: "existing TLV",
inTLVName: oc.OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE_DYNAMIC_NAME,
inTLVContainerName: "Hostname",
inLSP: &isisLSP{
LSP: &oc.NetworkInstance_Protocol_Isis_Level_Lsp{
Tlv: map[oc.E_OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE]*oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv{
LSP: &oc.Lsp{
Tlv: map[oc.E_OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE]*oc.Lsp_Tlv{
oc.OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE_DYNAMIC_NAME: {
Type: oc.OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE_DYNAMIC_NAME,
Hostname: &oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Hostname{
Hostname: &oc.Lsp_Tlv_Hostname{
Hostname: []string{"fish"},
},
},
},
},
},
wantTLV: &oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv{
wantTLV: &oc.Lsp_Tlv{
Type: oc.OpenconfigIsisLsdbTypes_ISIS_TLV_TYPE_DYNAMIC_NAME,
Hostname: &oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Hostname{
Hostname: &oc.Lsp_Tlv_Hostname{
Hostname: []string{"fish"},
},
},
Expand Down
36 changes: 18 additions & 18 deletions parse_lsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,13 @@ func (i *isisLSP) processCapabilityTLV(r *rawTLV) error {
// processSRAlgorithmCapabilitySubTLV parses the Segment Routing algorithm
// sub-TLV, sub-TLV type 19 of TLV 242. Defined in draft-ietf-isis-segment-routing-extensions.
// The sub-TLV is appended to the Capability TLV provided.
func processSRAlgorithmCapabilitySubTLV(c *oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Capability, r *rawTLV) error {
func processSRAlgorithmCapabilitySubTLV(c *oc.Lsp_Tlv_Capability, r *rawTLV) error {
stlv, err := getCapabilitySubTLV(c, oc.OpenconfigIsisLsdbTypes_ISIS_SUBTLV_TYPE_ROUTER_CAPABILITY_SR_ALGORITHM)
if err != nil {
return err
}

stlv.SegmentRoutingAlgorithms = &oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Capability_Subtlv_SegmentRoutingAlgorithms{}
stlv.SegmentRoutingAlgorithms = &oc.Lsp_Tlv_Capability_Subtlv_SegmentRoutingAlgorithms{}
var pErr errlist.List
// The encoding of the algorithm TLV is 1-byte values per algorithm.
for _, i := range r.Value {
Expand All @@ -322,13 +322,13 @@ func processSRAlgorithmCapabilitySubTLV(c *oc.NetworkInstance_Protocol_Isis_Leve

// processSRCapabilitySubTLV processes the Segment Routing capability
// sub-TLV, sub-TLV type 2, of TLV 242. Defined in draft-ietf-isis-segment-routing-extensions.
func processSRCapabilitySubTLV(c *oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Capability, r *rawTLV) error {
func processSRCapabilitySubTLV(c *oc.Lsp_Tlv_Capability, r *rawTLV) error {
stlv, err := getCapabilitySubTLV(c, oc.OpenconfigIsisLsdbTypes_ISIS_SUBTLV_TYPE_ROUTER_CAPABILITY_SR_CAPABILITY)
if err != nil {
return err
}

srcap := &oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Capability_Subtlv_SegmentRoutingCapability{}
srcap := &oc.Lsp_Tlv_Capability_Subtlv_SegmentRoutingCapability{}
// The encoding of the SR capabilities sub-TLV is as follows.
// 1-byte of flags:
// bit 0: MPLS-IPv4 capability bit
Expand Down Expand Up @@ -400,7 +400,7 @@ func processSRCapabilitySubTLV(c *oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv
// Increment the entry number for subsequent SRGB descriptors.
descrNo++

descr.Label = &oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Capability_Subtlv_SegmentRoutingCapability_SrgbDescriptor_Label_Union_Uint32{lbl}
descr.Label = &oc.Lsp_Tlv_Capability_Subtlv_SegmentRoutingCapability_SrgbDescriptor_Label_Union_Uint32{lbl}
descr.Range = ygot.Uint32(srgbRange)
}
stlv.SegmentRoutingCapability = srcap
Expand Down Expand Up @@ -484,7 +484,7 @@ func (i *isisLSP) processIPv6ReachabilityTLV(r *rawTLV) error {
return err
}

pfxTLV := &oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Ipv6Reachability_Prefix{
pfxTLV := &oc.Lsp_Tlv_Ipv6Reachability_Prefix{
Prefix: ygot.String(pfx),
UpDown: ygot.Bool(upDown),
SBit: ygot.Bool(subTLVPresent),
Expand Down Expand Up @@ -618,7 +618,7 @@ func parsePrefixSIDSubTLV(r *rawTLV) (*prefixSIDSubTLV, error) {

// addIPv6ReachabilityPrefixSID adds the contents of a prefixSIDSubTLV to the supplied
// IPv6 Reachability prefix TLV. Return an error if adding the contents is not possible.
func addIPv6ReachabilityPrefixSID(c *oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_Ipv6Reachability_Prefix, p *prefixSIDSubTLV) error {
func addIPv6ReachabilityPrefixSID(c *oc.Lsp_Tlv_Ipv6Reachability_Prefix, p *prefixSIDSubTLV) error {
subtlv, err := c.NewSubtlv(oc.OpenconfigIsisLsdbTypes_ISIS_SUBTLV_TYPE_IP_REACHABILITY_PREFIX_SID)
if err != nil {
return err
Expand Down Expand Up @@ -707,7 +707,7 @@ func (i *isisLSP) processExtendedISReachabilityTLV(r *rawTLV) error {
}

nid := canonicalHexString(r.Value[x : x+7])
var n *oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIsReachability_Neighbor
var n *oc.Lsp_Tlv_ExtendedIsReachability_Neighbor

if t, ok := tlv.ExtendedIsReachability.Neighbor[nid]; ok {
n = t
Expand Down Expand Up @@ -742,7 +742,7 @@ func (i *isisLSP) processExtendedISReachabilityTLV(r *rawTLV) error {
// parseExtendedISReachSubTLVs parses the subTLVs of the extended IS reachability
// TLV, appending them to the instance provided. Returns an error if parsing is
// unsuccesful.
func parseExtendedISReachSubTLVs(n *oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance, subTLVs []*rawTLV) error {
func parseExtendedISReachSubTLVs(n *oc.Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance, subTLVs []*rawTLV) error {
var pErr errlist.List
for _, s := range subTLVs {
switch s.Type {
Expand All @@ -765,7 +765,7 @@ func parseExtendedISReachSubTLVs(n *oc.NetworkInstance_Protocol_Isis_Level_Lsp_T
pErr.Add(err)
continue
}
n.GetOrCreateSubtlv(oc.OpenconfigIsisLsdbTypes_ISIS_SUBTLV_TYPE_IS_REACHABILITY_LINK_ID).LinkId = &oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv_LinkId{
n.GetOrCreateSubtlv(oc.OpenconfigIsisLsdbTypes_ISIS_SUBTLV_TYPE_IS_REACHABILITY_LINK_ID).LinkId = &oc.Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv_LinkId{
Local: ygot.Uint32(local),
Remote: ygot.Uint32(remote),
}
Expand Down Expand Up @@ -839,7 +839,7 @@ func parseExtendedISReachSubTLVs(n *oc.NetworkInstance_Protocol_Isis_Level_Lsp_T
}

for pri, bw := range ubw {
if err := st.AppendSetupPriority(&oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv_SetupPriority{
if err := st.AppendSetupPriority(&oc.Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv_SetupPriority{
Priority: ygot.Uint8(pri),
Bandwidth: bw,
}); err != nil {
Expand Down Expand Up @@ -999,7 +999,7 @@ func parseLocalRemoteLinkIDSubTLV(r *rawTLV) (uint32, uint32, error) {
// parseAdjSIDSubTLV parses sub-TLV 31 of the IS adjacency TLVs 22, 23,
// 141, 222, and 223. It returns the populated OpenConfig struct for the Adj-SID
// subTLV.
func parseAdjSIDSubTLV(r *rawTLV) (*oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv_AdjacencySid, error) {
func parseAdjSIDSubTLV(r *rawTLV) (*oc.Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv_AdjacencySid, error) {
if len(r.Value) < 5 {
// Length must be a minimum of:
// - 1 byte flagByte
Expand All @@ -1020,7 +1020,7 @@ func parseAdjSIDSubTLV(r *rawTLV) (*oc.NetworkInstance_Protocol_Isis_Level_Lsp_T
return nil, err
}

return &oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv_AdjacencySid{
return &oc.Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv_AdjacencySid{
Value: ygot.Uint32(value),
Flags: flags,
Weight: ygot.Uint8(uint8(weight)),
Expand All @@ -1030,7 +1030,7 @@ func parseAdjSIDSubTLV(r *rawTLV) (*oc.NetworkInstance_Protocol_Isis_Level_Lsp_T
// parseLANAdjSIDSubTLV parses the LAN Adjacency Segment Identifier (TLV ID 32) subTLV of the
// Extended IS Reachability TLVs (22, 23, 222, 223). It returns the populated OpenConfig
// struct for the LAN Adjacency SID sub-TLV.
func parseLANAdjSIDSubTLV(r *rawTLV) (*oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv_LanAdjacencySid, error) {
func parseLANAdjSIDSubTLV(r *rawTLV) (*oc.Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv_LanAdjacencySid, error) {
if len(r.Value) < 8 {
// Length must be a minimum of
// - 1 byte flags
Expand All @@ -1053,7 +1053,7 @@ func parseLANAdjSIDSubTLV(r *rawTLV) (*oc.NetworkInstance_Protocol_Isis_Level_Ls
return nil, err
}

return &oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv_LanAdjacencySid{
return &oc.Lsp_Tlv_ExtendedIsReachability_Neighbor_Instance_Subtlv_LanAdjacencySid{
Value: ygot.Uint32(value),
Flags: flags,
Weight: ygot.Uint8(uint8(weight)),
Expand Down Expand Up @@ -1236,7 +1236,7 @@ func (i *isisLSP) processExtendedIPReachTLV(r *rawTLV) error {
return err
}

pfxTLV := &oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIpv4Reachability_Prefix{
pfxTLV := &oc.Lsp_Tlv_ExtendedIpv4Reachability_Prefix{
Prefix: ygot.String(v4Pfx),
Metric: ygot.Uint32(metric),
SBit: ygot.Bool(subTLVPresent),
Expand Down Expand Up @@ -1280,7 +1280,7 @@ func (i *isisLSP) processExtendedIPReachTLV(r *rawTLV) error {
}

if tlv.ExtendedIpv4Reachability.Prefix == nil {
tlv.ExtendedIpv4Reachability.Prefix = make(map[string]*oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIpv4Reachability_Prefix)
tlv.ExtendedIpv4Reachability.Prefix = make(map[string]*oc.Lsp_Tlv_ExtendedIpv4Reachability_Prefix)
}
tlv.ExtendedIpv4Reachability.Prefix[v4Pfx] = pfxTLV
}
Expand All @@ -1291,7 +1291,7 @@ func (i *isisLSP) processExtendedIPReachTLV(r *rawTLV) error {
// addExtendedIPReachabilityPrefixSID adds the content of a prefixSIDSubTLV to the supplied
// Extended IPv4 Reachability prefix TLV. Returns an error if adding the contents is not
// possible.
func addExtendedIPReachabilityPrefixSID(c *oc.NetworkInstance_Protocol_Isis_Level_Lsp_Tlv_ExtendedIpv4Reachability_Prefix, p *prefixSIDSubTLV) error {
func addExtendedIPReachabilityPrefixSID(c *oc.Lsp_Tlv_ExtendedIpv4Reachability_Prefix, p *prefixSIDSubTLV) error {
subtlv, err := c.NewSubtlv(oc.OpenconfigIsisLsdbTypes_ISIS_SUBTLV_TYPE_IP_REACHABILITY_PREFIX_SID)
if err != nil {
return err
Expand Down
Loading

0 comments on commit ad41d27

Please sign in to comment.