sdnfv / openNetVM

A high performance container-based NFV platform from GW and UCR.
http://sdnfv.github.io/onvm/
Other
261 stars 134 forks source link

Questions about the bridge example #286

Closed strongcourage closed 3 years ago

strongcourage commented 3 years ago

Hi all,

I'm trying to modify the bridge example so that only packets from a given IP address will be sent from port 0 to port 1. Here there are 3 DPDK ports. By running the bridge example, I get the following result:

Screenshot 2021-05-06 at 15 34 22

I don't understand why TX of port 1 and RX of port 2 have those values (not 0). Does meta->destination correspond to the port ID, e.g., 0, 1, 2 ? In case where there are multiple ports, how can I only send packets to port 1 ? Thank you.

JackKuo-tw commented 3 years ago

What's your expectation & your code modification?

strongcourage commented 3 years ago

I'd like to implement a simple Load Balancer NF on VM1 that has 3 DPDK ports. The LB will send only packets from source IP1 to VM2, and only packets from source IP2 to VM3. On VM2 and VM3, there are different NFs that process those incoming packets.

Screenshot 2021-05-07 at 09 57 34

I think I can adapt the bridge NF example to implement the LB, but it seems that it didn't work. Thank you.

        struct rte_ipv4_hdr *ipv4_hdr;
        char ip_string[16];
        if (pkt->port == 0) {
                if (onvm_pkt_is_ipv4(pkt)) {
                    ipv4_hdr = onvm_pkt_ipv4_hdr(pkt);
                    onvm_pkt_parse_char_ip(ip_string, rte_be_to_cpu_32(ipv4_hdr->src_addr));
                    if (strncmp(ip_string, "192.168.", strlen("192.168.")) == 0) {
                        meta->destination = 1;
                        meta->action = ONVM_NF_ACTION_OUT;
                        RTE_LOG(INFO, APP, "Send packet from source IP %s to port %d\n", ip_string, meta->destination);
                    } else {
                        meta->destination = 2;
                        meta->action = ONVM_NF_ACTION_OUT;
                        RTE_LOG(INFO, APP, "Send packet from source IP %s to port %d\n", ip_string, meta->destination);
                    }
                } else {
                    meta->destination = 0;
                    meta->action = ONVM_NF_ACTION_DROP;
                }
        }
        else {
                meta->destination = 0;
                meta->action = ONVM_NF_ACTION_DROP;
        }
twood02 commented 3 years ago

@strongcourage - the logic in your code seems fine to me. Have you double checked that the port numbers are what you expect (i.e. look at the manager output and compare the MAC addresses so you know which port is which)?

Can you describe what happens when you run your code?

strongcourage commented 3 years ago

Thanks, Tim. It seems work when I set 2 different types of network adapter (Internal Network for DPDK-NIC2 and NAT Network for DPDK-NIC3) on VM1. If not, packets will be sent from port 0 to both ports 1 and 2.