You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importstl_pathfromtrex.stl.apiimport*fromfunctoolsimportpartialfromtrex.common.services.trex_service_dhcpimportServiceDHCPimportrandomfromtrex.common.trex_vlanimportVLAN# Import VLAN class for proper tagging# Function to generate a random MAC addressdefrandom_mac():
c=partial(random.randint, 0, 255)
return'%02x:%02x:%02x:%02x:%02x:%02x'% (c(), c(), c(), c(), c(), c())
# DHCP request destination (DHCP server)dhcp_server_ip='20.0.0.1'try:
# Connect to the TRex serverclient=STLClient()
client.connect()
ctx=client.create_service_ctx(port=0)
port=client.get_port(0)
# Acquire port 0 for useclient.acquire(ports=[0],force=True)
vlan_obj=VLAN([100, 1])
port.set_vlan(vlan_obj)
# Verify and print VLAN configuration using get_vlan_cfg()vlan_cfg=client.get_port(0).get_vlan_cfg() # Get the VLAN configurationprint(f"VLAN configuration for port 0: {vlan_cfg}")
# Create a service context for port 0client.set_service_mode(ports=0)
# Generate DHCP clients with random MAC addressesdhcps= [ServiceDHCP(mac=random_mac()) for_inrange(10)]
# Send DHCP lease requests for each client (one per VLAN)fordhcp_clientindhcps:
ctx.run(dhcp_client)
# Now generate traffic streams for each bounded DHCP clientbounded_dhcps= [dhcpfordhcpindhcpsifdhcp.state=='BOUND']
streams= []
The output here is
VLAN configuration for port 0: [100, 1]
DHCP: ed:4a:be:f0:94:4d *** timeout on offers - retries left: 4
DHCP: ed:4a:be:f0:94:4d *** timeout on offers - retries left: 3
DHCP: ed:4a:be:f0:94:4d *** timeout on offers - retries left: 2
DHCP: ed:4a:be:f0:94:4d *** timeout on offers - retries left: 1
DHCP: c8:91:a2:17:ba:59 *** timeout on offers - retries left: 4
DHCP: c8:91:a2:17:ba:59 *** timeout on offers - retries left: 3
DHCP: c8:91:a2:17:ba:59 *** timeout on offers - retries left: 2
DHCP: c8:91:a2:17:ba:59 *** timeout on offers - retries left: 1
DHCP: 1f:bc:18:f3:4f:d3 *** timeout on offers - retries left: 4
Im not sure how to double vlan tag the dhcp request so I set it in the port by doing this:
vlan_obj=VLAN([100, 1])
port.set_vlan(vlan_obj)
# Verify and print VLAN configuration using get_vlan_cfg()vlan_cfg=client.get_port(0).get_vlan_cfg() # Get the VLAN configurationprint(f"VLAN configuration for port 0: {vlan_cfg}")
I also get the port and the vlan cfg to check if its tagged as vlan.
Am I doing it wrong ? or did I miss something ? How do I double tag a vlan to the dhcp request ?
Thank you
The text was updated successfully, but these errors were encountered:
Hi,
Just wanted to get your input. Im having trouble getting DHCP lease because the request needs to have a double tagged vlan. Im using Port 0
This is my trex_cfg.yaml
This is my python code:
The output here is
Im not sure how to double vlan tag the dhcp request so I set it in the port by doing this:
I also get the port and the vlan cfg to check if its tagged as vlan.
Am I doing it wrong ? or did I miss something ? How do I double tag a vlan to the dhcp request ?
Thank you
The text was updated successfully, but these errors were encountered: