This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/TDA2EX17EVM: Adding VLAN Tag in Socket communication through TDA2ex

Part Number: TDA2EX17EVM

Tool/software: TI-RTOS

Hello All,

I am using TDA2ex and i am doing socket communication from TDA2ex (Which is client)to server using IPv6. What i want to do is configure VLAN on TDA2ex and i want to use VLAN ID as 2 on TDA2ex in all outgoing packet from TDA2ex. 

So basically i want to configure VLAN , so i can put relevant VLAN header i.e. VLAN ID and Priority etc..

Thanks for any insights.

Thanks,

Kapil Mehta  

  • Kapil,

    I need some more information to help me answer your question.

    Which software release you are using (SDK name and release version)?

    Which network stack you are using?

    Also, which processor is running the network stack and what operating system is it using?

    Thanks,
    ~Ramsey

  • Hello Ramsey,

    Which software release you are using (SDK name and release version)?
    -- Vision SDK 3.1

    Which network stack you are using?
    --NDK_2_24_02_31

    Also, which processor is running the network stack and what operating system is it using?
    It is running on A15 with sysbios.

    I was going through convlan.c file in NDK and found VLANAddDevice function. It seems i should be able to add VLAN interface by this function. But after this do i need to set socket option using setsockopt for setting VLAN ID as 2 in network packets ?

    Thanks in advance.
  • Kapil,

    Using VLANAddDevice() is the correct place to start. Use this API to create a VLAN device on top of EMAC. See NDK API Section A.16.

    When calling VLANAddDevice(), you will need to provide the existing interface ID, the VLAN ID (2 in your case), the index of the default priority (in case setsockopt() is not used) and the priority mapping array. This call will create a new VLAN NIMU object with an IP address for a unique subnet. For example:

    VLAN NIMU Object 1: 192.168.2.1 Network Mask: 255.255.255.0 VLAN ID: 2

    The NDK will also create a new entry in the routing table for the VLAN subnet. This way, all inbound packets for your client IP will be routed to the VLAN module.

    When creating a new socket, specify the protocol as VLAN (0x8100).  All packets sent with this socket will have the VLAN ID and user priority encoded in the VLAN Tag of the packet header. See NDK API Section 3.5.2.

    If you also want to control the user priority, use the prio_mapping parameter of the VLANAddDevice() API to specify a mapping from socket priority to VLAN user priority. This is an array of 8 priorities where the socket priority is used as an index into this array to compute the VLAN user priority. Use the setsocketopt() API to specify the SO_PRIORITY of your socket. Once this is done, all outbound packets will have the VLAN user priority encoded as specified by your prio_mapping array.

    Unfortunately, we don't have an example to illustrate this. Please let me know if you have additional questions.

    ~Ramsey

  • Hello Ramsey,

    One point i want to clarify regarding adding VLAN as protocol in socket creation. I have following code :

    #define SERVER ff14::1:a

    #define SERVER_PORT 50001

    ret = getaddrinfo(SERVER, SERVER_PORT, &hints, &servinfo)) != 0)
    return ret;


    // loop through all the results and make a socket
    for(ptrservinfo = servinfo; ptrservinfo != NULL; ptrservinfo = ptrservinfo->ai_next) {
    if ((Obj->sockfd = socket(ptrservinfo->ai_family, ptrservinfo->ai_socktype, 0x8100)) < 0) {
    continue;
    }
    break;
    }

    How should we mention protocol as VLAN ? Above method is correct ?

    I am using UDP sockets..When i test above code it gives XDC ASSERT - ERROR CALLBACK START  in creating socket. I also tried by converting 0x8100 address using htons but still it gives asserton.

    Thanks in advance..

  • Hello Ramsey,

    One more thing i want to clarify is : with telnet server following output is from ipv6 route command :

    ipv6 route
    -------------------------------------------------
    Interface Name : eth0
    Network Address : fe80::
    Next Hop Address : ::
    Route Type : CLONING
    Timeout : Infinite
    -------------------------------------------------
    Interface Name : eth0
    Network Address : fe80::c6f3:12ff:feb6:566c
    Next Hop Address : fe80::c6f3:12ff:feb6:566c
    Route Type : LOCAL
    Timeout : Infinite
    -------------------------------------------------
    Interface Name : eth0
    Network Address : ::1
    Next Hop Address : ::1
    Route Type : LOCAL
    Timeout : Infinite
    -------------------------------------------------
    Interface Name : eth0
    Network Address : fd53:7cb8:383:2::
    Next Hop Address : ::
    Route Type : CLONING
    Timeout : Infinite
    -------------------------------------------------
    Interface Name : eth0
    Network Address : fd53:7cb8:383:2::1:50
    Next Hop Address : fd53:7cb8:383:2::1:50
    Route Type : LOCAL
    Timeout : Infinite
    -------------------------------------------------
    Interface Name : eth0
    Network Address : fd53:7cb8:383:2::1:16a
    Next Hop Address : fd53:7cb8:383:2::1:16a
    Route Type : HOST
    Timeout : Infinite
    -------------------------------------------------
    Interface Name : eth0
    Network Address : fd53:7cb8:383:2::1:16b
    Next Hop Address : fd53:7cb8:383:2::1:16b
    Route Type : HOST
    Timeout : Infinite
    -------------------------------------------------
    Interface Name : eth0
    Network Address : fd53:7cb8:383:2::1:16c
    Next Hop Address : fd53:7cb8:383:2::1:16c
    Route Type : HOST
    Timeout : Infinite
    -------------------------------------------------
    Interface Name : eth0
    Network Address : fd53:7cb8:383:2::1:16d
    Next Hop Address : fd53:7cb8:383:2::1:16d
    Route Type : HOST
    Timeout : Infinite
    -------------------------------------------------


    In my case TDA2ex has IPv4 as well as IPv6 address and i want to use VLAN ID 2 with fd53:7cb8:383:2::1:50 IPv6 address and not with IPv4 address.

    To add VLAN device i am calling

    vlan_dev_index = VLANAddDevice(1,2,3,prio_mapping); // VLAN ID 2 and priority 3, prio_mapping has mapping of 1-->1 , 2-->2 ans so on..

    Function in IPv6DADStatus function which is passed as an argument to

    status = IPv6InterfaceInit(dev_index, IPv6DADStatus); // IPv6 init function.

    With these changes , VLAN device will be added to IPv4 or IPv6 interfaces ?

    P.S. I have verified vlan_dev_index is 2 returned from VLANAddDevice..

    Thanks in advance..
  • Kapil,

    I was incorrect about calling socket() with a protocol of VLAN. This is not the correct way to access the VLAN feature. Sorry about this.

    I've been working to setup a test bench to validate your use-case. I'll share my results when I have something working.

    Have you see the console sample in convlan.c? This might give you some insights.

    <ndk>/ti/ndk/tools/console/convlan.c

    Re: which interface (IPv4 or IPv6) VLAN will be added

    I will have to study the code and get back to you on this.

    ~Ramsey

  • Hello Ramsey,

    Thanks for your response..

    I was incorrect about calling socket() with a protocol of VLAN. This is not the correct way to access the VLAN feature. Sorry about this.

    Re: Ok , i was trying to set 0x8100 as protocol field , but it didn´t work out, i saw the NDK_socket function and found SOCK_DGRAM socket type , protocol should be IPPROTO_UDP only.

    Yes , i am looking into console application , i could add VLAN using command vlan add, but i am not sure how to validate whether it is added or not ? If i use command ipv6 route i can´t see vlan in the list.

    I will investigate more and update you ..

    Thanks,
    Kapil Mehta
  • Hello Ramsey,

    I was trying with Console application and followed following commands to add IPv6 address to VLAN.

    1) When i started console application,

    **** Vision SDK ****

    Welcome connection : 192.168.1.17:64153


    Welcome to the console program.
    Enter '?' or 'help' for a list of commands.

    >ipaddr all
    Interface Name: eth0
    Interface Id : 1
    IP Address : 192.168.1.100
    IP Mask : 255.255.255.0
    MTU : 1500 bytes
    MAC Address : 0xc4-0xf3-0x12-0xb6-0x56-0x6c


    2) I added VLAN on interface id 1 with VLAN ID 2 and priority 3

    >vlan add 1 2 4
    Successfully created new VLAN Device 2

    3) Again i executed ipaddr all command to see VLAN entry

    >ipaddr all
    Interface Name: eth0:2
    Interface Id : 2
    MTU : 1496 bytes
    MAC Address : 0xc4-0xf3-0x12-0xb6-0x56-0x6c


    Interface Name: eth0
    Interface Id : 1
    IP Address : 192.168.1.100
    IP Mask : 255.255.255.0
    MTU : 1500 bytes
    MAC Address : 0xc4-0xf3-0x12-0xb6-0x56-0x6c


    4) Now i initialized IPv6 stack on VLAN interface which is 2

    >ipv6 init 2
    IPv6 stack has been initialized on 2


    5) Now if i try to add IPv6 address on interface 2: I get following exeception..

    >ipv6 add 2 fd53:7cb8:383:2::1:50 64 0xFFFFFFFF 0xFFFFFFFF UNICAST
    IPv6 Address has been configured.


    [HOST ] 195.404410 s: Unhandled Exception:
    [HOST ] 195.404410 s: Exception occurred in ThreadType_Task
    [HOST ] 195.404410 s: Exception occured in A15 with exception type 18
    [HOST ] 195.404410 s: handle: 0x8f3a61f8.
    [HOST ] 195.404440 s: stack base: 0x8f3e9480.
    [HOST ] 195.404440 s: stack size: 0x2000.
    [HOST ] 195.404440 s: R0 = 0x00000000 R8 = 0xaffffe00
    [HOST ] 195.404440 s: R1 = 0x8004eee4 R9 = 0x8004ec44
    [HOST ] 195.404471 s: R2 = 0x00000000 R10 = 0xff12f3c6
    [HOST ] 195.404471 s: R3 = 0x00000000 R11 = 0x6c56b6fe
    [HOST ] 195.404471 s: R4 = 0x8f3eb318 R12 = 0x00000002
    [HOST ] 195.404471 s: R5 = 0x00000001 SP(R13) = 0x8f313bac
    [HOST ] 195.404501 s: R6 = 0x8004eee4 LR(R14) = 0x8f42f9d4
    [HOST ] 195.404501 s: R7 = 0x50000100 PC(R15) = 0x8f313bac
    [HOST ] 195.404501 s: PSR = 0x8004ec44
    [HOST ] 195.404501 s: DFSR = 0x00000a05
    [HOST ] 195.404501 s: IFSR = 0x00000000
    [HOST ] 195.404532 s: DFAR = 0x00000000
    [HOST ] 195.404532 s: IFAR = 0x00000000
    [HOST ] 195.404532 s: Terminating Execution...
    [HOST ] 195.404532 s:
    [HOST ] 195.404562 s: ### XDC ASSERT - ERROR CALLBACK START ###
    [HOST ] 195.404562 s:
    [HOST ] 195.404562 s: E_dataAbort: pc = 0x8f313bac, lr = 0x8f42f9d4.
    [HOST ] 195.404593 s:
    [HOST ] 195.404593 s: ### XDC ASSERT - ERROR CALLBACK END ###
    [HOST ] 195.404593 s:

    P.S. I have disabled initializing IPv6 from TDA2ex , all commands i have executed from telnet console from PC from putty after taking session on TDA2ex i.e. 192.168.1.100.

    Please suggest if i am doing anything wrong..

    Thanks in advance..

  • Hello Ramsey,

    I got it working with following changes :

    First i created VLAN with vlan id 2

    vlan_dev_index = VLANAddDevice(1,2,4,prio_mapping);

    and it will create new interface ID as 2 that can be verified from IPv6 route command

    and then i initialized IPv6 stack on interface 2 and after this i could see the VLAN ID tagged for all packets i would send.

    Thanks for your guidance..

  • Kapil,

    This is good news. I'm glad you have it working. Sorry I was not much help. Thanks for letting us now.

    If you don't mind, would you describe the network setup between the TDA2EX EVM and your PC. Are you using a smart switch configured for VLAN ID = 2? Did you use static or dynamic VLAN configuration? I'm still trying to setup my test bench.

    Thanks,
    ~Ramsey

  • Hello Ramsey,

    Sorry for the late reply..

    Yes i have switch configured for VLAN ID 2.

    And it's static VLAN configuraiton.

    Thanks,
    Kapil Mehta
  • Kapil,

    No worries. Thanks for the information.

    ~Ramsey