Hot!How to implemente VLAN ?

Author
Emcy
Super Member
  • Total Posts : 542
  • Reward points : 0
  • Joined: 2008/01/09 03:37:06
  • Location: 0
  • Status: offline
2017/05/09 02:02:56 (permalink)
0

How to implemente VLAN ?

Hello,
 
Is it possible easily to implemente VLAN (it is a field to add between MAC Address and EtherType) ?
=> I implemented VLAN in the MLA but MLA struct was not very good because I had to change all Ethernet Layers (MAC, IP, TCP, ...) : is there the same problem with Harmony ? Can I implemente VLAN by modifying only the MAC layer (and the configuration section) ?
 
Can you tell me best practices to ensure compatibility with future versions of Harmony ?
 
I need :
- set Harmony Web server with a specific VLAN
- Create an Layer-2 applications which use one and more VLANs (ie: spanning tree protocol).
 
post edited by Emcy - 2017/05/09 02:40:45
#1

6 Replies Related Threads

    rainad
    Moderator
    • Total Posts : 1010
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: online
    Re: How to implemente VLAN ? 2017/05/10 10:13:21 (permalink)
    3.5 (4)
    To add VLAN support in Harmony all that's needed is to modify the MAC driver to support tagged VLAN frames.
    Because of the way the packets are constructed, the packet fields can be easily updated to point to the right fields when a VLAN frame is received. So, no need to touch the stack modules.
    However, you need to have a good understanding of the MAC packets and where/how these fields are set.
    Adding VLAN suport is on our TODO list but I cannot offer any more details for now.
    #2
    Emcy
    Super Member
    • Total Posts : 542
    • Reward points : 0
    • Joined: 2008/01/09 03:37:06
    • Location: 0
    • Status: offline
    Re: How to implemente VLAN ? 2017/05/11 00:10:18 (permalink)
    5 (2)
    After reading Harmony source code, it appears that the code is not so well structured that: I will have to change the code of multiple layers (IP, TCP, UDP, ...).

    1st problem : EtherType is defined in the MAC Ethernet header struct

    typedef struct  __attribute__((aligned(2), packed))
    {
        TCPIP_MAC_ADDR      DestMACAddr;
        TCPIP_MAC_ADDR      SourceMACAddr;
        uint16_t            Type;
    } TCPIP_MAC_ETHERNET_HEADER;


    2nd problem : some functions use a static position which use MAC Layer pointer (MAC layer pointer is using instead of current layer pointer) :

    extern __inline__ const IPV6_ADDR* __attribute__((always_inline)) TCPIP_IPV6_PacketGetDestAddress(TCPIP_MAC_PACKET* pRxPkt)
    {
        return &((IPV6_HEADER*)(pRxPkt->pMacLayer + sizeof(TCPIP_MAC_ETHERNET_HEADER)))->DestAddress;
    }



    static uint16_t _UDPv4IsTxPutReady(UDP_SOCKET_DCPT* pSkt)
    {
        void* pPkt = _TxSktGetLockedV4Pkt(pSkt, true);

        if(pPkt == 0)
        {   // packet is in one of the queues; allocate another tx space
            if(_UDPv4AllocateSktTxBuffer(pSkt, IP_ADDRESS_TYPE_IPV4, true) == 0)
            {   // allocation failed; caller will have to retry later
                return 0;
            }
            // else the new packet data is updated in place
        }

        if(pSkt->flags.txSplitAlloc == 0)
        {
            return pSkt->txEnd - pSkt->txWrite;
        }

        // return max segment possible
        return 1514 - sizeof(TCPIP_MAC_ETHERNET_HEADER) - sizeof(IPV4_HEADER) - sizeof(UDP_HEADER);
    }



    I will have to modify a lot of functions because layers are dependent



    post edited by Emcy - 2017/05/11 00:16:12
    #3
    rainad
    Moderator
    • Total Posts : 1010
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: online
    Re: How to implemente VLAN ? 2017/05/11 09:35:45 (permalink)
    0
    The vlan tag should be part of the Ethernet header. Only the definition should be changed.
    But you're right, the dependency should be broken.
    Most of the cases where the knowledge about the ETH header is used is just a shortcut and could be easily implemented different, using the packet pointers. There was no vlan frames support until now, so that's why didn't really matter. But we'll take care of this. 
     
     
     
    post edited by rainad - 2017/05/11 12:34:12
    #4
    Emcy
    Super Member
    • Total Posts : 542
    • Reward points : 0
    • Joined: 2008/01/09 03:37:06
    • Location: 0
    • Status: offline
    Re: How to implemente VLAN ? 2017/05/12 00:18:25 (permalink)
    5 (2)
    I do not have time to wait for you to develop it, which is why I will do it now. If you want, I will be able to provide you the code once tested and validated so that you integrate it to Harmony.
    Also I plan to add a custom layer between the MAC header and the VLAN tag : the interest is to be able to manage entries inserted by some components (ie : Ethernet switch insert a header to detect port source of a Ethernet packet).
    I will validate it only for PIC32MZ : You will have to add/validate this function for the other devices.
     
    Where should I send the source code ? ... I will make it public only if it is integrated into harmony beacause I do it for my company (the interest for me that it is integrated in the source code of Harmony is that I will have a guarantee that my code will be maintained during the updates of Harmony... It's give-and-take ;) )
    post edited by Emcy - 2017/05/12 00:47:53
    #5
    rainad
    Moderator
    • Total Posts : 1010
    • Reward points : 0
    • Joined: 2009/05/01 13:39:25
    • Location: 0
    • Status: online
    Re: How to implemente VLAN ? 2017/05/12 13:31:57 (permalink)
    0
    Sent you a PM.
    #6
    Skaptor
    n00b member
    • Total Posts : 233
    • Reward points : 0
    • Joined: 2012/07/25 11:18:48
    • Location: Tilted Towers
    • Status: offline
    Re: How to implemente VLAN ? 2018/09/13 12:32:35 (permalink)
    0
    Sorry to bring this old thread up, but is this code available? I need to send some ARP requests on a specific VLAN, the ARP module is working, however I am lost with the VLAN stuff. Regards

    Porsche 718 Cayman GTS
    #7
    Jump to:
    © 2018 APG vNext Commercial Version 4.5