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.

C6657: NDK and NAT

Hi all,

I'm trying the NAT feature of NDK on C6657.

What I have in mind is:

1. add two IP address of two different subnets on the same interface and use NAT to link the subnets each other.

2. associate two VLAN to the two addresses

Analyzing the natsrv.c file I understood that the Virtual IP has not to be added to the configuration; so I've tried to enable NAT without XGCONF modifying the client example with this code:

CI_SERVICE_NAT    nat;

bzero( &nat, sizeof(nat) );
nat.cisargs.Mode = CIS_FLG_IFIDXVALID | CIS_FLG_RESOLVEIP | CIS_FLG_RESTARTIPTERM;
nat.cisargs.IfIdx = 1;
nat.cisargs.pCbSrv = &ServiceReport;

nat.param.IPVirt = inet_addr("192.168.1.254");
nat.param.IPMask = inet_addr("255.255.255.0");
nat.param.MTU = 1492;

CfgAddEntry( hCfg, CFGTAG_SERVICE, CFGITEM_SERVICE_NAT, 0, sizeof(nat), (UINT8 *)&nat, 0 );


rc = 1;
CfgAddEntry( hCfg, CFGTAG_IP, CFGITEM_IP_IPNATENABLE, CFG_ADDMODE_UNIQUE, sizeof(uint), (UINT8 *)&rc, 0 );

The service report routine print on console "NAT Failed". 

Configuring NDK with XGCONF the service seems to work(console shows NAT Enabled) but if I try to ping the virtual IP it doesn't work.

Any idea?

  • Hi all,

    I'm attempting to rebuild NDK with debug information in order to do a debug step-by-step .

    I have followed this guide http://processors.wiki.ti.com/index.php/Rebuilding_The_NDK_Core_Using_Gmake and modified the file ndk.bld to include debug information in the library:

    /* Uncomment the following lines to build libraries for debug mode: */

    c6xOpts += " -g -o0 ";
    armOpts += " -g -o0 ";

    I rebuild my project with new library but what I'm not able to is do a debug step-by-step using CCS5; in a CCS Debug perspective I opened the ndk source file, but if I try to insert a breakpoint, it results disabled (with gray icon).

    Where am I doing wrong?

    Many thanks in advance

    Matteo

  • Hi Matteo,

    My apologies for the lack of response, I see your issue and I'm going to look into that now and get back to you as soon as I can.

    In the meantime, for your CCS break point problem, can you try the following?

    This may mean that your application was not built using the debug versions of the NDK libraries that you rebuilt.  Are you able to set a breakpoint at a function name in the file?  If so then you may not be building against your rebuilt NDK.

    Another possibility ... I've had a similar issue setting break points before when you open a file this way and then try to set one.  It seems that sometimes CCS doesn't "associate the file" with the program that's currently running/loaded.

    So you can enter a break point by first opening the break point manager (In CCS Window menu -> show view -> break points).  Once that is open, find and click the button to add a new break point in the breakpoint manager view.  Type in the name of the function into the text field that appears and it will put a break point at that symbol.

    Run your program and when the break point hits, the source should appear (or a dialogue window asking you to locate the source file).  Once you have the source file opened in this manner, you should be able to set break points within the source window that came up.

    Steve

  • Hi Steve,

    thanks for the reply.

    Unfortunately I'm not able to set a breakpoint at fuction name, Breakpoint appears "gray".

    The second way is more effective: adding a breakpoint from breakpoint manager view, the symbol has been resolved.

    Running my application, a dialogue windows is shown asking me to locate the source file, and it works! After that I can add a breakpoint wherever I need; it means that the library has been compiled correctly with debug information. It's a lack of the CCS the impossibility to understand where a library source file is located, or maybe we are not following the right way :)

    However, please provide me any update regarding the NAT in the NDK.

    Thanks,

    Matteo

  • Hi Steve,

    I've encountered another issue debugging the NDK library.  I've compiled again the library (after cleaning it) with debug informations.

    It seems that the PC cursor doesn't match to the real code! Step-by-step debug seems to work properly, but the variables' values don't match to the written code

    e.g.

    my  instruction is: IPMask = 0;

    before instruction IPMask is 0x12345678 (from watch window)

    after instruction IPMask is still 0x12345678 (from watch window)

    Thanks,

    Matteo

  • Are you compiling with optimization level set to zero? (-o0?)

    Or it could be that you source file you are viewing is not properly matched with the one you build with.  You can check this by (in the CCS debug view) right clicking on your connected target and selecting "edit source view lookup".  This will allow you to see the paths it is using to find the source files in the debug view.

    Steve

  • From "Edit Source view lookup", the source files used by CCS match with the ndk source files. 

    To re-compile the library I've modified the file ndk.bld in ndk root directory, setting these options:

    var c6xOpts = " -mi10 -mo -pdr -pden -pds=238 -pds=880 -pds1110";
    c6xOpts += " -g -o0";

    I've tried to remove the option  -o0 to not optimize the register, but the issue remains.

    Matteo

  • Can you add a space after the optimization?  Change the above line to be:

    c6xOpts += " -g -o0 ";

    (note the space in "-o0 "; ...).

    The -o0 may be getting appended to another option causing it to not have effect.

    Steve

  • Hi Steve,

    I resolved the mismatch between source file and library; as supposed, the optimizazion option is not -o0! 

    Even if in the ndk.mak file the compiler option is -o0 (c6xOpts += -g -o0) , the library mak files automatically generated contains the -o2 option! Please see the mak files in packages\ti\ndk\stack\lib.

    So I need to compile the library without -o2 option, but it seems that changing the file ndk.mak is not enough.
    What do I need to modifying to remove this compiler option?

    Many thanks,

    Matteo

  • Matteo,

    What settings do you have in your project?  Is your project being compiled for the debug profile?  It may be happening there.

    Regarding your original problem, I need to understand more about your set up and the problem you are trying to solve so that I can help you.

    Could you please respond with your network layout/topology?  A diagram would be very helpful.

    And what is the problem you are trying to solve here?  Are you trying to make the NDK into a router?  Connecting multiple hosts over a VLAN?

    Steve

  • Steve,

    the target is make NDK into a router, where processor is the C6657.

    The first step is enable the NAT feature and connect host over LAN to host over WAN, without VLAN utilization. 

    The second step is enable VLAN to separate broadcast domain.

    In the following image is shown the topology:

    Here in after the screenshots of NAT and IP configuration using XGCONF:

    Ping from PC2 to 10.7.9.125 works

    Ping from PC1 to 192.168.1.254 doesn't work (the NDK does not reply to ARP request)

    Pings from PC1 to PC2 doesn't work.

    Let me know if you need further clarification.

    Thanks

    Matteo 

  • Hi Matteo,

    Thank you for the detailed diagram, this helps a lot.  I'm trying to get your problem reproduced but haven't been able to get the set up proper yet.
    How is PC1 getting its IP address?  Is it running as a DHCP client with the NDK acting as the DHCP server?  What about for PC2?

    Are you able to debug the stack successfully now?  Can you put a breakpoint into the file nimu.c to see if it's getting the ARP packet at all?  Or maybe it's dropping it for some reason?  (Or maybe it's getting dropped in the EMAC layer...).

    You should add a break point into the switch statement that passes the packet up the stack based on the type field of the Ethernet frame header.  You'll want to check if the stack is even seeing the ARP packet.  The code looks like this:

        if (Type == 0x8100)
            Type = VLANReceivePacket (hPkt);

        /* Dispatch the Packet to the appropriate protocol layer. */
        switch( Type )
        {
            case 0x800:
            {
                /* Received packet is an IP Packet. */
                IPRxPacket( ptr_pkt );
                break;
            }
            case 0x806:
            {
                /* Received packet is an ARP Packet. */
                LLIRxPacket( ptr_pkt );
                break;
            }
    ...

    Steve

  • Hi Steve,

    Now I'm able to debug the stack and I found a potential bug (with a workaround) in NAT server.

    In order to use NAT server correctly I have done the following steps:

    - added two IP address to the stack (192.168.1.254 and 10.7.9.100)

    - configured the NAT to operate with Virtual Address 192.168.1.0 and not 192.168.1.254!!

    Analysing the file natpkt.c, transmission function  process the packet just if source address is in the same net of virtual subnet and the destination address is outside the virtual subnet; I think that this condition is wrong:

    if( (IPSrc&NatIpMask) != NatIpAddr  || (IPDst&NatIpMask) == NatIpAddr)
    return(0);

    IPsrc is masked with NatIpMask but NatIpAddr no! So the condition is always TRUE and the packets outgoing the router are never processed; configuring the Virtual address masked with Netmask it works properly!

    Thanks

    Matteo

  • Matteo,

    I've filed a bug report to ensure that this problem is tracked and gets fixed.

    SDOCM00097959 NAT server code has incorrect mask logic

    Steve