Skip to content

Support for LDP (IPv4) - #497

Open
rudranil-das wants to merge 4 commits into
masterfrom
ldp-model
Open

rudranil-das wants to merge 4 commits into
masterfrom
ldp-model

Conversation

@rudranil-das

@rudranil-das rudranil-das commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Feature Overview

Brief Description:
Adds LDP (Label Distribution Protocol, RFC 5036) emulation for IPv4. A new ldp property on Device configures one emulated Label Switching Router (LSR) per device. It runs Basic (link) discovery on IPv4 interfaces (RFC 5036 Section 2.4.1) and Extended (targeted) discovery to configured peers (RFC 5036 Section 2.4.2), sourced from an IPv4 interface or an IPv4 loopback. The router carries the session parameters: LSR ID and label space ID (the LDP Identifier), label advertisement mode (Downstream Unsolicited or Downstream on Demand) and keepalive timers. It also supports TCP MD5 authentication (RFC 2385) per interface / targeted peer and graceful restart (FT Session TLV, RFC 3478). The LSR advertises ranges of IPv4 Prefix FECs, each bound to an incrementing or fixed label; a fixed 3 (Implicit NULL) or 0 (Explicit NULL) emulates an egress LSR. The PR also adds:

  • LDP FEC ranges as flow endpoints (Flow.Router tx_names / rx_names).
  • FEC withdraw / advertise through the existing route state API (State.Protocol.Route).
  • Router up / down (State.Protocol.Ldp) and initiate graceful restart (Action.Protocol.Ldp).
  • Per-router Get Metrics: session counts, per-FSM-state session counts, label message counters and LSP counts.
  • Get States for the FEC-label bindings each router received from its peers.

Out of scope for this PR (separate features, and the naming leaves room for them): LDPv6 / dual-stack, mLDP, pseudowires / VPLS (FEC 128 / 129), per-session state, and the OTF update API.

Feature Details
Redocly docs for this feature/branch
https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/open-traffic-generator/models/ldp-model/artifacts/openapi.yaml&nocors#tag/Configuration/operation/set_config

New Locations/Nomenclature:
Configuration

  • Device.ldp (Device.LdpRouter) in device/device.yaml, defined in device/ldp/ldp.yaml. It contains lsr_id (required), label_space_id, label_advertisement_mode, keepalive_hold_time, keepalive_interval, graceful_restart (Ldp.GracefulRestart; GR is on when present), and the arrays ipv4_interfaces, ipv4_targeted_peers and ipv4_fec_ranges.
  • Ldp.Ipv4Interface (device/ldp/ipv4interface.yaml): link discovery on a Device.Ipv4, with hello_interval, hello_hold_time and optional authentication.
  • Ldp.Ipv4TargetedPeer (device/ldp/ipv4targetedpeer.yaml): targeted discovery from a Device.Ipv4 or Device.Ipv4Loopback to remote_address, with its own Hello timers and optional authentication.
  • Ldp.Authentication (device/ldp/authentication.yaml): TCP MD5 key. Authentication is on when the object is present.
  • Ldp.Ipv4FecRange, Ldp.FecLabel, Ldp.FecLabel.Increment (device/ldp/ipv4fecrange.yaml): prefixes reuse V4RouteAddress. label is increment (start + n for the n-th prefix, default start 16) or fixed (default 3, Implicit NULL).
  • Ldp.Ipv4FecRange names added to the Flow.Router tx_names / rx_names constraints in flow/endpoint.yaml.

Control

  • State.Protocol.ldp (State.Protocol.Ldp -> routers: router_names, state up | down) in control/state.yaml and control/protocol.yaml.
  • Ldp.Ipv4FecRange names added to the State.Protocol.Route constraint (withdraw | advertise) in control/protocol.yaml.
  • Action.Protocol.ldp (Action.Protocol.Ldp -> initiate_graceful_restart: router_names, restart_delay) in control/action.yaml, defined in the new control/ldp.yaml.

Monitor

  • Get Metrics: Metrics.Request.ldp (Ldp.Metrics.Request) and Metrics.Response.ldp_metrics (Ldp.Metric) in result/metrics.yaml, defined in result/ldp.yaml. The columns are:

    • sessions_up and sessions_flap.
    • Session counts per state of the session initialization state machine: sessions_non_existent, sessions_initialized, sessions_open_received, sessions_open_sent, sessions_operational.
    • Notification, Label Mapping, Label Request, Label Withdraw, Label Release and Label Abort Request messages, each sent and received.
    • ingress_lsps_up and egress_lsps_up.

    Every value is uint64.

  • Get States: States.Request.ldp_bindings (LdpBindings.State.Request) and States.Response.ldp_bindings (LdpBindings.State -> ipv4_bindings[]: LdpIpv4Binding.State with prefix, prefix_length, label, peer_lsr_id, peer_label_space_id) in result/states.yaml, defined in result/ldpbindings.yaml.

Dev-Snappi branch reference
https://github.com/open-traffic-generator/snappi/tree/dev_ldpv4

Example command to fetch the dev-snappi branch:

go get github.com/open-traffic-generator/snappi/gosnappi@dev_ldpv4

Code snippets
Please provide a concise, well-commented code snippet demonstrating how to use the new feature in snappi/gosnappi:

api := gosnappi.NewApi()
api.NewHttpTransport().SetLocation("https://localhost:8443").SetVerify(false)

cfg := gosnappi.NewConfig()

// ---------------------------------------------------------------------
// Ports and devices: d1 (behind p1) is a plain IPv4 traffic source,
// d2 (behind p2) is an emulated LSR running IS-IS and LDP towards the DUT.
// ---------------------------------------------------------------------
p1 := cfg.Ports().Add().SetName("p1")
p2 := cfg.Ports().Add().SetName("p2")

d1 := cfg.Devices().Add().SetName("d1")
d1Eth := d1.Ethernets().Add().SetName("d1.eth").SetMac("00:00:01:01:01:01")
d1Eth.Connection().SetPortName(p1.Name())
d1Ip := d1Eth.Ipv4Addresses().Add().
    SetName("d1.ipv4").
    SetAddress("10.1.1.2").
    SetGateway("10.1.1.1").
    SetPrefix(24)

d2 := cfg.Devices().Add().SetName("d2")
d2Eth := d2.Ethernets().Add().SetName("d2.eth").SetMac("00:00:02:02:02:02")
d2Eth.Connection().SetPortName(p2.Name())
d2Ip := d2Eth.Ipv4Addresses().Add().
    SetName("d2.ipv4").
    SetAddress("10.2.2.2").
    SetGateway("10.2.2.1").
    SetPrefix(24)
d2Lo := d2.Ipv4Loopbacks().Add().
    SetName("d2.lo").
    SetEthName(d2Eth.Name()).
    SetAddress("2.2.2.2")

// IS-IS advertises the loopback and the FEC prefixes, so the DUT has a
// route for every FEC (RFC 5036 Section 2.6.1) and can reach 2.2.2.2.
isis := d2.Isis().SetName("d2.isis").SetSystemId("640000000002")
isis.Interfaces().Add().SetName("d2.isis.if").SetEthName(d2Eth.Name())
isis.V4Routes().Add().SetName("d2.isis.lo").
    Addresses().Add().SetAddress("2.2.2.2").SetPrefix(32)
isis.V4Routes().Add().SetName("d2.isis.pe").
    Addresses().Add().SetAddress("100.1.0.0").SetPrefix(24).SetCount(10).SetStep(1)

// ---------------------------------------------------------------------
// LDP router: LDP Identifier 2.2.2.2:0, Downstream Unsolicited (default),
// keepalive 90 / 30 s, graceful restart on (object present = GR on).
// ---------------------------------------------------------------------
ldp := d2.Ldp().
    SetName("d2.ldp").
    SetLsrId("2.2.2.2").
    SetKeepaliveHoldTime(90).
    SetKeepaliveInterval(30)
ldp.GracefulRestart().SetReconnectTime(120).SetRecoveryTime(120)

// Basic (link) discovery on d2.ipv4 with TCP MD5 (object present = MD5 on)
ldpIf := ldp.Ipv4Interfaces().Add().
    SetName("d2.ldp.if").
    SetIpv4Name(d2Ip.Name()).
    SetHelloInterval(5).
    SetHelloHoldTime(15)
ldpIf.Authentication().SetMd5("ldp-key-1")

// Extended (targeted) discovery from the loopback to the DUT loopback.
// Same peer LSR as the link adjacency -> same session -> same MD5 key.
tp := ldp.Ipv4TargetedPeers().Add().
    SetName("d2.ldp.tp1").
    SetIpv4Name(d2Lo.Name()).
    SetRemoteAddress("1.1.1.1")
tp.Authentication().SetMd5("ldp-key-1")

// 10 Prefix FECs 100.1.0.0/24 ... 100.1.9.0/24 with labels 16000 ... 16009
fec := ldp.Ipv4FecRanges().Add().SetName("d2.ldp.fec.pe")
fec.Addresses().Add().SetAddress("100.1.0.0").SetPrefix(24).SetCount(10).SetStep(1)
fec.Label().Increment().SetStart(16000)

// Egress LSR emulation: Implicit NULL (3) for 200.1.1.0/24 and 200.1.2.0/24
egress := ldp.Ipv4FecRanges().Add().SetName("d2.ldp.fec.egress")
egress.Addresses().Add().SetAddress("200.1.1.0").SetPrefix(24).SetCount(2).SetStep(1)
egress.Label().SetFixed(3)

// ---------------------------------------------------------------------
// Flow d1 -> LDP FEC range: the DUT must push the labels d2 advertised.
// ---------------------------------------------------------------------
f1 := cfg.Flows().Add().SetName("f1")
f1.TxRx().Device().
    SetTxNames([]string{d1Ip.Name()}).
    SetRxNames([]string{fec.Name()})
f1.Packet().Add().Ethernet()
f1.Packet().Add().Ipv4()
f1.Size().SetFixed(512)
f1.Rate().SetPps(1000)
f1.Metrics().SetEnable(true)

if _, err := api.SetConfig(cfg); err != nil {
    log.Fatal(err)
}

// ---------------------------------------------------------------------
// Get Metrics: per-router session and label message counters
// ---------------------------------------------------------------------
mr := gosnappi.NewMetricsRequest()
mr.Ldp().
    SetRouterNames([]string{ldp.Name()}).
    SetColumnNames([]gosnappi.LdpMetricsRequestColumnNamesEnum{
        gosnappi.LdpMetricsRequestColumnNames.SESSIONS_UP,
        gosnappi.LdpMetricsRequestColumnNames.LABEL_MAPPINGS_RECEIVED,
        gosnappi.LdpMetricsRequestColumnNames.INGRESS_LSPS_UP,
    })
mRes, err := api.GetMetrics(mr)
if err != nil {
    log.Fatal(err)
}
for _, m := range mRes.LdpMetrics().Items() {
    fmt.Println(m.Name(), m.SessionsUp(), m.LabelMappingsReceived(), m.IngressLspsUp())
}

// ---------------------------------------------------------------------
// Get States: FEC-label bindings received from the peers
// ---------------------------------------------------------------------
sr := gosnappi.NewStatesRequest()
sr.LdpBindings().SetLdpRouterNames([]string{ldp.Name()})
sRes, err := api.GetStates(sr)
if err != nil {
    log.Fatal(err)
}
for _, r := range sRes.LdpBindings().Items() {
    for _, b := range r.Ipv4Bindings().Items() {
        fmt.Println(r.LdpRouterName(), b.Prefix(), b.PrefixLength(), b.Label(), b.PeerLsrId())
    }
}

// ---------------------------------------------------------------------
// Control: withdraw the FEC range (Label Withdraw), then advertise it again
// ---------------------------------------------------------------------
cs := gosnappi.NewControlState()
route := cs.Protocol().Route().SetNames([]string{fec.Name()})
route.SetState(gosnappi.StateProtocolRouteState.WITHDRAW)
api.SetControlState(cs)
route.SetState(gosnappi.StateProtocolRouteState.ADVERTISE)
api.SetControlState(cs)

// Control: take the LDP router down / up
cs = gosnappi.NewControlState()
routers := cs.Protocol().Ldp().Routers().SetRouterNames([]string{ldp.Name()})
routers.SetState(gosnappi.StateProtocolLdpRoutersState.DOWN)
api.SetControlState(cs)
routers.SetState(gosnappi.StateProtocolLdpRoutersState.UP)
api.SetControlState(cs)

// Control: graceful restart - sessions close without withdrawing labels
// and are re-established after 30 s (FT Session TLV, RFC 3478)
ca := gosnappi.NewControlAction()
ca.Protocol().Ldp().InitiateGracefulRestart().
    SetRouterNames([]string{ldp.Name()}).
    SetRestartDelay(30)
api.SetControlAction(ca)

Test Specification (Optional)
Example test scenario:

  • Configuration details: Test Port - DUT - Test Port
  • Configure the topology in the code snippet. The DUT (loopback 1.1.1.1) runs IS-IS and LDP towards device d2 (behind p2), with MD5 key ldp-key-1 and graceful restart helper enabled. Device d1 (behind p1) is a plain IPv4 traffic source.
  • Verify sessions_up is 1 on d2.ldp. The link and targeted adjacencies lead to the same DUT LSR, so they share one session.
  • Verify the DUT has installed labels 16000 ... 16009 for 100.1.0.0/24 ... 100.1.9.0/24, and that ldp_bindings on d2.ldp shows the bindings received from the DUT (for example Implicit NULL for 1.1.1.1/32).
  • Verify all packets of flow f1 are received on p2 with the advertised labels.
  • Withdraw d2.ldp.fec.pe and verify the DUT removes the labels (label_withdraws_sent increases and f1 is forwarded unlabelled). Advertise it again and verify the labels return.
  • Initiate a graceful restart on d2.ldp and verify f1 sees no loss while the session is re-established.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants