peter zhang
peter zhang

Reputation: 1385

how to forward packets to OpenDaylight controller

i use Open vSwitch and OpenDaylight.i want to forward packets to controller. what i want to do is build a firewall, so ovs first send all packets to controller, and the controller will judge whether the packet should be blocked or not. i add following code in datapath/datapath.c/ovs_dp_process_packet()

    struct dp_upcall_info upcall;
    int error;
    memset(&upcall, 0, sizeof(upcall));
    upcall.cmd = OVS_PACKET_CMD_MISS;
    upcall.portid = ovs_vport_find_upcall_portid(p, skb);
    upcall.mru = OVS_CB(skb)->mru;
    error = ovs_dp_upcall(dp, skb, key, &upcall, 0);

what i want to do is upcall the packets to controller even if they match the flowtable. but after i complie the code, it doesn't work. so how to upcall packets to controller ?

Upvotes: 0

Views: 374

Answers (1)

Amin
Amin

Reputation: 1013

OVS:

Adding a new action to OVS is a long story that you can follow. here is a list of most important code files that you should change:

  • lib/ofp-actions.c: Defining new action, encoding, decoding and formating
  • include/openvswitch/ofp-actions.h: propagating action
  • datapath/linux/compat/include/linux/openvswitch.h: defining in kernel level
  • lib/odp-util.c: defining action's bytes length
  • ofproto/ofproto-dpif-xlate.c: this file handles comunication between kernel and userspace. specifically when there is no match for a new flow
  • datapath/flow_netlink.c: define action's bytes in kernel
  • datapath/actions.c: execution action

For complete steps, I highly recommend following Custom Open vSwitch Actions

After changing in source files use these commands in the root directory of OVS to stop, make and run it. be careful that your gcc version should be the same as the version that your Linux header files have been compiled.

ovs-ctl stop

ovs-dpctl del-dp ovs-system

rmmod openvswitch

make clean

make modules_install clean

./boot.sh

./configure --with-linux=/lib/modules/`uname -r`/build --enable-Werror

make

make install

make modules_install

config_file="/etc/depmod.d/openvswitch.conf"

for module in datapath/linux/*.ko; do
  modname="$(basename ${module})"
  echo "override ${modname%.ko} * extra" >> "$config_file"
  echo "override ${modname%.ko} * weak-updates" >> "$config_file"
  done

depmod -a

modprobe openvswitch

lsmod | grep openvswitch

mkdir -p /usr/local/etc/openvswitch

ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema

mkdir -p /usr/local/var/run/openvswitch

ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --pidfile --detach --log-file

ovs-vsctl --no-wait init

ovs-vswitchd --pidfile --detach --log-file

export PATH=$PATH:/usr/local/share/openvswitch/scripts

ovs-ctl start

Controller:

In the controller, you should be able to create and push Action to switch. I have no information about the way of defining new Action in OpenDayLight but, I know that in Floodlight it is achieved by using Loxigen.

If you had any problem, feel free to contact me.

Upvotes: 2

Related Questions