install vms
install two vms
rhel_version=rhel$(rpm -E %rhel)
# libvirt && kvm
yum -y install virt-install
yum -y install libvirt
yum install -y python3-lxml.x86_64
rpm -qa | grep qemu-kvm >/dev/null || yum -y install qemu-kvm
if (($rhel_version < 7)); then
service libvirtd restart
else
systemctl restart libvirtd
systemctl start virtlogd.socket
fi
# work around for failure of virt-install
chmod 666 /dev/kvm
# define default vnet
virsh net-define /usr/share/libvirt/networks/default.xml
virsh net-start default
virsh net-autostart default
# define vm name and mac
vm_name=v0
mac4vm=a4:a4:a4:a4:a4:a0
# download image
wget http://netqe-bj.usersys.redhat.com/share/vms/rhel8.4.qcow2 -O /var/lib/libvirt/images/$vm_name.qcow2
# install vm
virt-install \
--name $vm_name \
--vcpus=2 \
--ram=2048 \
--disk path=/var/lib/libvirt/images/$vm_name.qcow2,device=disk,bus=virtio,format=qcow2 \
--network bridge=virbr0,model=virtio,mac=$mac4vm \
--boot hd \
--accelerate \
--graphics vnc,listen=0.0.0.0 \
--force \
--os-type=linux \
--noautoconsol
setup vm
systemctl start openvswitch
systemctl start ovn-northd
ovn-sbctl set-connection ptcp:6642
ovn-nbctl set-connection ptcp:6641
ovs-vsctl set Open_vSwitch . external-ids:ovn-remote=tcp:177.1.1.1:6642
ovs-vsctl set Open_vSwitch . external-ids:ovn-encap-type=geneve
ovs-vsctl set Open_vSwitch . external-ids:ovn-encap-ip=177.1.1.1
systemctl restart ovn-controller
mac_v0_vnet1=04:ac:10:ff:01:94
mac_v0_vnet2=04:ac:10:ff:01:95
mac_v1_vnet1=04:ac:10:ff:01:96
mac_v1_vnet2=04:ac:10:ff:01:97
cat <<-EOF > v0-vnet1.xml
<interface type='bridge'>
<target dev='h0_v0_vnet1'/>
<mac address='${mac_v0_vnet1}'/>
<source bridge='br-int'/>
<virtualport type='openvswitch'/>
<model type='virtio'/>
</interface>
EOF
cat <<-EOF > v0-vnet2.xml
<interface type='bridge'>
<target dev='h0_v0_vnet2'/>
<mac address='${mac_v0_vnet2}'/>
<source bridge='br-int'/>
<virtualport type='openvswitch'/>
<model type='virtio'/>
</interface>
EOF
cat <<-EOF > v1-vnet1.xml
<interface type='bridge'>
<target dev='h0_v1_vnet1'/>
<mac address='${mac_v1_vnet1}'/>
<source bridge='br-int'/>
<virtualport type='openvswitch'/>
<model type='virtio'/>
</interface>
EOF
cat <<-EOF > v1-vnet2.xml
<interface type='bridge'>
<target dev='h0_v1_vnet2'/>
<mac address='${mac_v1_vnet2}'/>
<source bridge='br-int'/>
<virtualport type='openvswitch'/>
<model type='virtio'/>
</interface>
EOF
virsh attach-device v0 v0-vnet1.xml
virsh attach-device v0 v0-vnet2.xml
virsh attach-device v1 v1-vnet1.xml
virsh attach-device v1 v1-vnet2.xml
ovs-vsctl set interface h0_v0_vnet1 external-ids:iface-id=h0_v0_vnet1
ovs-vsctl set interface h0_v0_vnet2 external-ids:iface-id=h0_v0_vnet2
ovs-vsctl set interface h0_v1_vnet1 external-ids:iface-id=h0_v1_vnet1
ovs-vsctl set interface h0_v1_vnet2 external-ids:iface-id=h0_v1_vnet2
create topo
mac_h0_v0_vnet1=04:ac:10:ff:01:94
mac_h0_v0_vnet2=04:ac:10:ff:01:95
mac_h0_v1_vnet1=04:ac:10:ff:01:96
mac_h0_v1_vnet2=04:ac:10:ff:01:97
mac_h1_v0_vnet1=02:ac:10:ff:01:94
mac_h1_v0_vnet2=02:ac:10:ff:01:95
mac_h1_v1_vnet1=02:ac:10:ff:01:96
mac_h1_v1_vnet2=02:ac:10:ff:01:97
# add logical switch
ovn-nbctl ls-add ls1 -- add Logical_Switch ls1 other_config subnet=172.16.1.0/24
ovn-nbctl ls-add ls2 -- add Logical_Switch ls2 other_config subnet=172.16.2.0/24
# setup ls ipv6_prefix
ovn-nbctl set Logical-switch ls1 other_config:ipv6_prefix=2001:db8:1::0
ovn-nbctl set Logical-switch ls2 other_config:ipv6_prefix=2001:db8:2::0
# create dhcp_options
dhcp_options1=$(ovn-nbctl create DHCP_Options cidr=172.16.1.0/24 \
options="\"server_id\"=\"172.16.1.254\" \"server_mac\"=\"00:00:00:00:01:00\" \
\"lease_time\"=\"$((36000 + RANDOM % 3600))\" \"router\"=\"172.16.1.254\" \"dns_server\"=\"172.16.1.254\"")
dhcp_options2=$(ovn-nbctl create DHCP_Options cidr=172.16.2.0/24 \
options="\"server_id\"=\"172.16.2.254\" \"server_mac\"=\"00:00:00:00:02:00\" \
\"lease_time\"=\"$((36000 + RANDOM % 3600))\" \"router\"=\"172.16.2.254\" \"dns_server\"=\"172.16.2.254\"")
dhcpv6_options1=$(ovn-nbctl create DHCP_Options cidr="2001\:db8\:1\:\:0/64" \
options="\"server_id\"=\"00:00:00:00:01:00\" \"dns_server\"=\"2001:db8:1::254\"")
dhcpv6_options2=$(ovn-nbctl create DHCP_Options cidr="2001\:db8\:2\:\:0/64" \
options="\"server_id\"=\"00:00:00:00:02:00\" \"dns_server\"=\"2001:db8:2::254\"")
# create logical switch port and setup dhcp_option
lsp_name=h0_v0_vnet1
mac=$mac_h0_v0_vnet1
ovn-nbctl lsp-add ls1 $lsp_name
ovn-nbctl lsp-set-addresses $lsp_name "$mac dynamic"
ovn-nbctl lsp-set-dhcpv4-options $lsp_name ${dhcp_options1}
ovn-nbctl add Logical_Switch_Port $lsp_name dhcpv6_options ${dhcpv6_options1}
lsp_name=h0_v0_vnet2
mac=$mac_h0_v0_vnet2
ovn-nbctl lsp-add ls2 $lsp_name
ovn-nbctl lsp-set-addresses $lsp_name "$mac dynamic"
ovn-nbctl lsp-set-dhcpv4-options $lsp_name ${dhcp_options2}
ovn-nbctl add Logical_Switch_Port $lsp_name dhcpv6_options ${dhcpv6_options2}
lsp_name=h0_v1_vnet1
mac=$mac_h0_v1_vnet1
ovn-nbctl lsp-add ls1 $lsp_name
ovn-nbctl lsp-set-addresses $lsp_name "$mac dynamic"
ovn-nbctl lsp-set-dhcpv4-options $lsp_name ${dhcp_options1}
ovn-nbctl add Logical_Switch_Port $lsp_name dhcpv6_options ${dhcpv6_options1}
lsp_name=h0_v1_vnet2
mac=$mac_h0_v1_vnet2
ovn-nbctl lsp-add ls2 $lsp_name
ovn-nbctl lsp-set-addresses $lsp_name "$mac dynamic"
ovn-nbctl lsp-set-dhcpv4-options $lsp_name ${dhcp_options2}
ovn-nbctl add Logical_Switch_Port $lsp_name dhcpv6_options ${dhcpv6_options2}
setup QOS
mac_v0_vnet1=04:ac:10:ff:01:94
mac_v0_vnet2=04:ac:10:ff:01:95
mac_v1_vnet1=04:ac:10:ff:01:96
mac_v1_vnet2=04:ac:10:ff:01:97
ip_v0_vnet1=172.16.1.2
ip_v1_vnet1=172.16.1.3
ofport1=$(ovs-vsctl --bare --columns=ofport find interface external-ids:attached-mac=\"$mac_v0_vnet1\")
ofport2=$(ovs-vsctl --bare --columns=ofport find interface external-ids:attached-mac=\"$mac_v1_vnet1\")
echo "openflow port for h0_v0_vnet1 is $ofport1"
echo "openflow port for h0_v1_vnet1 is $ofport2"
# check above result
#ovs-ofctl show br-int
# list ovn flows
#ovn-sbctl lflow-list ls1
# list OpenFlow flows
#ovn-sbctl --ovs lflow-list ls1
# trace packet through ovn logical flow tables
#ovn-trace --all ls1 'inport == "h0_v0_vnet1" && eth.src == '$mac_v0_vnet1' && eth.dst == '$mac_v1_vnet1' && ip4.src == '$ip_v0_vnet1' && ip4.dst == '$ip_v1_vnet1' '
# trace packet through OpenFlow tables
ovs-appctl ofproto/trace br-int 'in_port='$ofport1',dl_src='$mac_v0_vnet1',dl_dst='$mac_v1_vnet1',dl_type=0x800,nw_src='$ip_v0_vnet1',nw_dst='$ip_v1_vnet1' '
qos_id=`ovn-nbctl --wait=hv -- --id=@lp1-qos create QoS priority=100 action=dscp=48 match="inport\=\=\"h0_v0_vnet1\"\ &&\ is_chassis_resident(\"h0_v0_vnet1\")" direction="from-lport" -- set Logical_Switch ls1 qos_rules=@lp1-qos`
ovs-appctl ofproto/trace br-int 'in_port='$ofport1',dl_src='$mac_v0_vnet1',dl_dst='$mac_v1_vnet1',dl_type=0x800,nw_src='$ip_v0_vnet1',nw_dst='$ip_v1_vnet1' ' | grep "Final flow"| grep "nw_tos=192"
# 500Mbps
ovn-nbctl --wait=hv set QoS $qos_id bandwidth=rate=500000,burst=4294967295
ovs-ofctl dump-meters br-int -O OpenFlow13
ovs-ofctl dump-flows br-int -O OpenFlow13 | grep meter
#change the direction
ovn-nbctl --wait=hv set QoS $qos_id match="outport\=\=\"h0_v0_vnet1\"" direction="to-lport"
#add qos on tunnel interface
#This will not effect now
ovn-nbctl set Logical_Switch_Port h0_v0_vnet1 options:qos_max_rate=50000
ovn-nbctl set Logical_Switch_Port h0_v0_vnet1 options:qos_burst=1000
ovn-nbctl qos-del ls1
ovn-nbctl remove Logical_Switch_Port h0_v0_vnet1 options qos_max_rate
ovn-nbctl remove Logical_Switch_Port h0_v0_vnet1 options qos_burst
#add qos on tunnel interface
#This will effect now
ovn-nbctl set Logical_Switch_Port h0_v0_vnet1 options:qos_max_rate=500000
ovn-nbctl set Logical_Switch_Port h0_v0_vnet1 options:qos_burst=1000