Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get DHCP lease with double tagged vlan. #1148

Open
pd1drone opened this issue Sep 20, 2024 · 0 comments
Open

How to get DHCP lease with double tagged vlan. #1148

pd1drone opened this issue Sep 20, 2024 · 0 comments

Comments

@pd1drone
Copy link

pd1drone commented Sep 20, 2024

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

[root@testcloak v3.04]# cat /etc/trex_cfg.yaml
### Config file generated by dpdk_setup_ports.py ###

- version: 2
  interfaces: ['41:00.0', '41:00.1']
  port_info:
      - ip: 20.0.0.2
        default_gw: 20.0.0.1
      - ip: 192.168.0.2
        default_gw: 192.168.0.1

  platform:
      master_thread_id: 0
      latency_thread_id: 2
      dual_if:
        - socket: 1
          threads: [1,3,5,7]

This is my python code:

import stl_path
from trex.stl.api import *
from functools import partial
from trex.common.services.trex_service_dhcp import ServiceDHCP
import random
from trex.common.trex_vlan import VLAN  # Import VLAN class for proper tagging

# Function to generate a random MAC address
def random_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 server
    client = STLClient()
    client.connect()
    ctx = client.create_service_ctx(port=0)
    port = client.get_port(0)

    # Acquire port 0 for use
    client.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 configuration
    print(f"VLAN configuration for port 0: {vlan_cfg}")

    # Create a service context for port 0
    client.set_service_mode(ports=0)

    # Generate DHCP clients with random MAC addresses
    dhcps = [ServiceDHCP(mac=random_mac()) for _ in range(10)]

    # Send DHCP lease requests for each client (one per VLAN)
    for dhcp_client in dhcps:
        ctx.run(dhcp_client)

    # Now generate traffic streams for each bounded DHCP client
    bounded_dhcps = [dhcp for dhcp in dhcps if dhcp.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 configuration
    print(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

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

No branches or pull requests

1 participant