• ovs 实战


    [root@kunpeng82 ovs]# ovs-vsctl add-br ovs-switch
    [root@kunpeng82 ovs]#  ovs-vsctl add-port ovs-switch p0 -- set Interface p0 ofport_request=100
    ovs-vsctl: Error detected while setting up 'p0': could not open network device p0 (No such device).  See ovs-vswitchd log for details.
    ovs-vsctl: The default log directory is "/var/log/openvswitch".

     

     

    添加ovs网桥

    ovs-vsctl add-br ovs-switch

     添加三个port

    #ovs-vsctl add-port ovs-switch p0 -- set Interface p1 ofport_request=100
    #ovs-vsctl add-port ovs-switch p1 -- set Interface p1 ofport_request=100
    #ovs-vsctl add-port ovs-switch p2 -- set Interface p2 ofport_request=100
    #ovs-vsctl set Interface p0 type=internal
    #ovs-vsctl set Interface p1 type=internal
    #ovs-vsctl set Interface p2 type=internal
    

      

    添加三个namepsace,将port添加到namesapce

    #ip netns add ns0
    #ip link set p0 netns ns0
    #ip netns exec ns0 ip addr add 192.168.1.100/24 dev p0
    #ip netns exec ns0 ifconfig p0 promisc up
    
    ip netns add ns1
    ip link set p1 netns ns1
    ip netns exec ns1 ip addr add 192.168.1.101/24 dev p1
    ip netns exec ns1 ifconfig p1 promisc up
    
    ip netns add ns2
    ip link set p2 netns ns2
    ip netns exec ns2 ip addr add 192.168.1.102/24 dev p2
    ip netns exec ns2 ifconfig p2 promisc up
    [root@kunpeng82 ovs]# ovs-vsctl show
    2be9582b-aee2-4bc5-8856-2adaabcef19b
        Bridge ovs-switch
            Port ovs-switch
                Interface ovs-switch
                    type: internal
            Port "p0"
                Interface "p0"
                    type: internal
            Port "p1"
                Interface "p1"
                    type: internal
            Port "p2"
                Interface "p2"
                    type: internal
        ovs_version: "2.12.0"
    

      

    [root@kunpeng82 ovs]# ovs-ofctl show ovs-switch
    OFPT_FEATURES_REPLY (xid=0x2): dpid:000032eb99f23a41
    n_tables:254, n_buffers:0
    capabilities: FLOW_STATS TABLE_STATS PORT_STATS QUEUE_STATS ARP_MATCH_IP
    actions: output enqueue set_vlan_vid set_vlan_pcp strip_vlan mod_dl_src mod_dl_dst mod_nw_src mod_nw_dst mod_nw_tos mod_tp_src mod_tp_dst
     1(p1): addr:00:00:00:00:00:00
         config:     PORT_DOWN
         state:      LINK_DOWN
         speed: 0 Mbps now, 0 Mbps max
     2(p2): addr:00:00:00:00:00:00
         config:     PORT_DOWN
         state:      LINK_DOWN
         speed: 0 Mbps now, 0 Mbps max
     100(p0): addr:00:00:00:00:00:00
         config:     PORT_DOWN
         state:      LINK_DOWN
         speed: 0 Mbps now, 0 Mbps max
     LOCAL(ovs-switch): addr:32:eb:99:f2:3a:41
         config:     PORT_DOWN
         state:      LINK_DOWN
         speed: 0 Mbps now, 0 Mbps max
    OFPT_GET_CONFIG_REPLY (xid=0x4): frags=normal miss_send_len=0
    

      

    [root@kunpeng82 ovs]# ovs-vsctl get Interface p0 ofport
    100
    [root@kunpeng82 ovs]# ovs-dpctl show
    2020-02-12T08:46:37Z|00001|dpif_netlink|INFO|The kernel module does not support meters.
    2020-02-12T08:46:37Z|00002|netdev_linux|INFO|ioctl(SIOCGIFINDEX) on p0 device failed: No such device
    2020-02-12T08:46:37Z|00003|netdev_linux|INFO|ioctl(SIOCGIFINDEX) on p1 device failed: No such device
    2020-02-12T08:46:37Z|00004|netdev_linux|INFO|ioctl(SIOCGIFINDEX) on p2 device failed: No such device
    system@ovs-system:
      lookups: hit:15 missed:20 lost:0
      flows: 0
      masks: hit:25 total:0 hit/pkt:0.71
      port 0: ovs-system (internal)
      port 1: ovs-switch (internal)
      port 2: p0 (internal)
      port 3: p1 (internal)
      port 4: p2 (internal)
    

      

     添加新的 OpenFlow 条目,从端口 p1 发出的数据包的源地址更改为 9.181.137.1

    ovs-ofctl add-flow ovs-switch "priority=1 idle_timeout=0,in_port=1,actions=mod_nw_src:9.181.137.1,normal"
    [root@kunpeng82 ovs]# ip netns exec ns1 ping 192.168.1.100
    PING 192.168.1.100 (192.168.1.100) 56(84) bytes of data.
    ^C
    --- 192.168.1.100 ping statistics ---
    11 packets transmitted, 0 received, 100% packet loss, time 10386ms

    [root@kunpeng82 devuser]# ip netns exec ns0 tcpdump -i p0 icmp -nnv
    tcpdump: listening on p0, link-type EN10MB (Ethernet), capture size 262144 bytes
    08:59:11.577219 IP (tos 0x0, ttl 64, id 31818, offset 0, flags [DF], proto ICMP (1), length 84)
        9.181.137.1 > 192.168.1.100: ICMP echo request, id 7234, seq 1, length 64
    08:59:12.603383 IP (tos 0x0, ttl 64, id 31862, offset 0, flags [DF], proto ICMP (1), length 84)
        9.181.137.1 > 192.168.1.100: ICMP echo request, id 7234, seq 2, length 64
    08:59:13.643378 IP (tos 0x0, ttl 64, id 31926, offset 0, flags [DF], proto ICMP (1), length 84)
        9.181.137.1 > 192.168.1.100: ICMP echo request, id 7234, seq 3, length 64
    08:59:14.683378 IP (tos 0x0, ttl 64, id 31947, offset 0, flags [DF], proto ICMP (1), length 84)
        9.181.137.1 > 192.168.1.100: ICMP echo request, id 7234, seq 4, length 64
    08:59:15.723395 IP (tos 0x0, ttl 64, id 31951, offset 0, flags [DF], proto ICMP (1), length 84)
        9.181.137.1 > 192.168.1.100: ICMP echo request, id 7234, seq 5, length 64
    08:59:16.763380 IP (tos 0x0, ttl 64, id 31957, offset 0, flags [DF], proto ICMP (1), length 84)
        9.181.137.1 > 192.168.1.100: ICMP echo request, id 7234, seq 6, length 64
    08:59:17.803380 IP (tos 0x0, ttl 64, id 31977, offset 0, flags [DF], proto ICMP (1), length 84)
        9.181.137.1 > 192.168.1.100: ICMP echo request, id 7234, seq 7, length 64
    08:59:18.843379 IP (tos 0x0, ttl 64, id 32064, offset 0, flags [DF], proto ICMP (1), length 84)
        9.181.137.1 > 192.168.1.100: ICMP echo request, id 7234, seq 8, length 64
    08:59:19.883387 IP (tos 0x0, ttl 64, id 32155, offset 0, flags [DF], proto ICMP (1), length 84)
        9.181.137.1 > 192.168.1.100: ICMP echo request, id 7234, seq 9, length 64
    08:59:20.923384 IP (tos 0x0, ttl 64, id 32210, offset 0, flags [DF], proto ICMP (1), length 84)
        9.181.137.1 > 192.168.1.100: ICMP echo request, id 7234, seq 10, length 64
    08:59:21.963386 IP (tos 0x0, ttl 64, id 32264, offset 0, flags [DF], proto ICMP (1), length 84)
        9.181.137.1 > 192.168.1.100: ICMP echo request, id 7234, seq 11, length 64
    

      

  • 相关阅读:
    Direct2D 几何计算和几何变幻
    ORACLE触发器具体解释
    HI3518E用J-link烧写裸板fastboot u-boot流程
    NYOJ
    使用ServletFileUpload实现上传
    再看数据库——(2)视图
    cookie登录功能实现
    耗时输入框
    Android开发 ----------怎样真机调试?
    Windows搭建Eclipse+JDK+SDK的Android --安卓开发入门级
  • 原文地址:https://www.cnblogs.com/dream397/p/12299632.html
Copyright © 2020-2023  润新知