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/AM3354: Ethernet gateway configuration

Part Number: AM3354


Tool/software: TI-RTOS

Hello.

I have two ports on my device. For each of them, the address and mask are configured as shown here. Here I set the IP address, mask and gateway for the first Ethernet port. The second port is configured in the same way (only the PHY number changes upon initialization of the IP address and gateway).

    /* Get current IP record 								*/
	if(CfgGetEntry(0, CFGTAG_IPNET, phy_num_to_ip2, 1, &hCfgIpAddr2)==1)
	{
	    /* Remove it from entries                                */
	    CfgRemoveEntry(0, hCfgIpAddr2);
	}

    /* setup record with required values */
	bzero(&NA, sizeof(NA));			/* Clear record                      	*/
	NA.IPAddr  = ip_addr1;			/* Set new address      				*/
	NA.IPMask  = ip_mask1;			/* and new mask             		 	*/

    /* Add record in ip entries table */
	int ret = CfgAddEntry( 0, CFGTAG_IPNET, phy_num_to_ip2, 0, sizeof(CI_IPNET), (UINT8 *)&NA, 0 );

    /* Get current route from table                         */
    if(CfgGetEntry(0, CFGTAG_ROUTE, phy_num_to_ip2, 1, &hCfgRoute2)==1)
    {
        /* Remove it from entries                               */
        CfgRemoveEntry(0, hCfgRoute2);
    }

    /* setup record with required values */
    bzero(&RT, sizeof(RT));
    /* For gateways IP and Mask are always equal 0 */
    RT.IPDestAddr = 0;
    RT.IPDestMask = 0;
    RT.IPGateAddr = ip_rt_addr;

    /* Add entry */
    ret = CfgAddEntry(0, CFGTAG_ROUTE, 0, 0, sizeof(CI_ROUTE), (UINT8 *)&RT, 0);

How do I need to configure an address table to bind a gateway to a specific port?

Respectfully,
Vitali

  • Vitali,

    You may refer to the NIMU dual mac example from PDK AM57x, which shows how to configure each specific port's IP address and bind  a gateway, see nimu_dual_mac_idk.cfg (pdk_am335x_1_0_14\packages\ti\transport\ndk\nimu\example\am572x\armv7\bios) and main_AM57xx.c (pdk_am335x_1_0_14\packages\ti\transport\ndk\nimu\example\src).

    Regards,
    Garrett

  • Hello, Garrett.
    I looked at an example of your links, but we have already implemented the same, though in the code in C, not for XDC. But this does not work, because when the gateway is configured for the second port, it still sends data to the gateway of the first port. Therefore, the question of customization remains open.
    Respectfully,
    Vitali

  • Vitali,

    Do you have the two ports configured to two separate subnets as shown in dual mac example for AM57x? i.e. 192.168.1.x and 192.168.2.x respectively?

    Regards,

    Garrett

  • Hi, Garrett.
    Yes, ports are on different subnets.
    Configuration for the first port
    Address / Mask / Gateway
    172.16.4.50 / 255.255.255.0 / 172.16.4.1
    Second port configuration
    Address / Mask / Gateway
    192.168.1.50 / 255.255.255.0 / 192.168.1.1

    After reading the information about the implementation of the gateway, I came to the conclusion that there is only one gateway for each routing table. Since we have a common routing table for both ports, then, accordingly, we can only have one gateway.

    Therefore, questions about this.
    1. Is it possible to create several routing tables in TIRTOS?
    2. And if it is possible, I would like to know how to do this?
    Respectfully,
    Vitali

  • Vitali,

    Actually a routing table allows multiple gateways, see this example

    Regards,

    Garrett

  • Hi, Garrett.
    Do I understand correctly that if we configure the device as follows:
        /* for first port */
        ip_cfg.IPAddr = inet_addr("172.16.4.50");
        ip_cfg.IPMask = inet_addr("255.255.255.0");
        CfgAddEntry(hCfg, CFGTAG_IPNET, 1, 0, sizeof(CI_IPNET), (uint8_t*)&ip_cfg, 0);

        ip_route.IPDestAddr = inet_addr("172.16.4.0");
        ip_route.IPDestMask = inet_addr("255.255.255.0");
        ip_route.IPGateAddr = inet_addr("172.16.4.1");
        CfgAddEntry(hCfg, CFGTAG_ROUTE, 0, 1, sizeof(CI_ROUTE), (uint8_t*)&ip_route, 0);
        
        /* for second port */
        ip_cfg.IPAddr = inet_addr("192.168.1.50");
        ip_cfg.IPMask = inet_addr("255.255.255.0");
        CfgAddEntry(hCfg, CFGTAG_IPNET, 2, 0, sizeof(CI_IPNET), (uint8_t*)&ip_cfg, 0);

        ip_route.IPDestAddr = inet_addr("192.168.1.0");
        ip_route.IPDestMask = inet_addr("255.255.255.0");
        ip_route.IPGateAddr = inet_addr("192.168.1.1");
        CfgAddEntry(hCfg, CFGTAG_ROUTE, 0, 1, sizeof(CI_ROUTE), (uint8_t*)&ip_route, 0);

    It will work like this: the data to the devices that are not in the subnet of the first port will go to the gateway of the subnet of the first port, and from there they will be transferred further to the corresponding devices? Similar for the second port.
    Respectfully,
    Vitali

  • Vitali,

    With above configuration, if a packet sends to the subnet of 172.16.4.x, it will forward to 172.16.4.1, if sending to the subnet of 192.168.1.x, it will forward to 192.168.1.1. If you have IPDestAddr set to 0.0.0.0, the packet will not be forwarded.

    In general, for each entry in the route table, it computes the logical AND of the packet destination IP and the mask entry (ip_route.IPDestMask), then compare that with the destination entry (ip_route.IPDestAddr), if those match, send the packet out the interface. If not, move on to the next entry in the table.

    Regards,
    Garrett

  • Garrett,

    If I correctly understand you, in my configuration if I want to send IP packet to 10.0.0.30, which located in subnet of 172.16.4.x, I cannot do this, because I have no default gateway. But if I want to send IP packet to any device, located in the subnet of 172.16.4.x, it will be passed through 172.16.4.1, because this is my gateway for this network. Can I have two default gateways for Ethernet: one for port 1 and another one for port 2?

    Respectfully,

    Vitali

  • Vitali,

    Yes, the dual EMAC example for AM572x mentioned above uses default gateways for Ethernet: one for port 1 and another one for port 2.

    Regards,

    Garrett