open-traffic-generator / models

Open Traffic Generator Core Models
https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/open-traffic-generator/models/master/artifacts/openapi.yaml&nocors
MIT License
62 stars 16 forks source link

Traffic over DHCPv4 interface #372

Closed SuryyaKrJana closed 4 months ago

SuryyaKrJana commented 7 months ago

This PR only focuses on traffic for DHCPv4, a similar PR for v6 will be created once we converge on the v4 approach.

To Know about the background: Please visit: https://github.com/open-traffic-generator/models/pull/371

Redocly for this PR. https://redocly.github.io/redoc/?url=https://raw.githubusercontent.com/open-traffic-generator/models/traffic_over_dhcp_interface/artifacts/openapi.yaml&nocors

// This example basically focuses on how flows can be created for dhcp configurations

config := gosnappi.NewConfig()

// skipping configuration of ports, devices, and common protocols like ethernet

// Configure a DHCP Client on device 1
d1Eth1.DhcpV4Interfaces().Add().
  SetName("p1d1dchpv4client").
  SetFirstServer(true).
  ParametersRequestList().
  SetSubnetMask(true).
  SetRenewalTimer(true).
  SetRouter(true)

// configure ipv4 on device 2
d2Eth1.
  Ipv4Addresses().
  Add().
  SetName("p2d1ipv4").
  SetAddress("2.2.2.2").
  SetGateway("2.2.2.1").
  SetPrefix(32)

// Configure a DHCP Server on device 2
d2Dhcpv4Server := d2.DhcpServer().Ipv4Interfaces().Add().SetName("p2d2dhcpv4server")

d2Dhcpv4Server.SetIpv4Name("p2d1ipv4").AddressPools().Add().
  SetName("pool1").
  SetLeaseTime(3600).
  SetStartAddress("1.1.1.2").
  SetStep(1).
  SetCount(5).
  SetPrefixLength(31).Options().
  SetRouterAddress("1.1.1.1")

// configure flow from dhcp client to ipv4 interface on dhcp server side
f1 := config.Flows().Items()[0]
f1.SetName(p1.Name() + " -> " + p2.Name()).
    TxRx().Device().
    SetTxNames([]string{"p1d1dhcpv4client"}).
    SetRxNames([]string{"p2d1ipv4"})

f1Eth := f1.Packet().Add().Ethernet()
f1Eth.Src().SetValue(d1Eth1.Mac())
f1Eth.Dst().Auto()

f1Ip := f1.Packet().Add().Ipv4()
// will be populated automatically with the the dynamically allocated Ip to DHCP client
f1Ip.Src().Auto().Dhcp()
f1Ip.Dst().SetValue("2.2.2.2")

// configure flow from ipv4 interface on the dhcp server side to DHCP client
f2 := config.Flows().Items()[1]
f2.SetName(p2.Name() + " -> " + p1.Name()).
    TxRx().Device().
    SetTxNames([]string{"p2d1ipv4")}).
    SetRxNames([]string{"p1d1dhcpv4client"})

f2Eth := f2.Packet().Add().Ethernet()
f2Eth.Src().SetValue(d2Eth1.Mac())
f2Eth.Dst().Auto()

f2Ip := f2.Packet().Add().Ipv4()
f2Ip.Src().SetValue("2.2.2.2")
// will be populated automatically with the the dynamically allocated Ip to DHCP client
f2Ip.Dst().Auto().Dhcp()