Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3659369
  • 博文数量: 880
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 6155
  • 用 户 组: 普通用户
  • 注册时间: 2016-11-11 09:12
个人简介

To be a better coder

文章分类

全部博文(880)

文章存档

2022年(5)

2021年(60)

2020年(175)

2019年(207)

2018年(210)

2017年(142)

2016年(81)

分类: LINUX

2019-09-21 10:41:49

root@60467818e879:/usr/local/lib/python2.7/dist-packages/ryu/lib# vi ofctl_v1_3.py

def get_arp_stats(dp, waiters, port=None, vlanid=None, mac=None, ip=None, to_user=True):
    print("send arp message arp message arp message arp message arp message arp message")
    datapath = dp
    out_port = str_to_int(port)
    actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]

    ARP_Request = packet.Packet()
    ARP_Request.add_protocol(ethernet.ethernet(
        ethertype=2054,
        dst="ff:ff:ff:ff:ff:ff",
        src=mac))
    utils.may_add_vlan(ARP_Request, str_to_int(vlanid))
    ARP_Request.add_protocol(arp.arp(
        opcode=arp.ARP_REQUEST,
        src_mac=mac,
        src_ip=ip,
        dst_mac="00:00:00:00:00:00",
        dst_ip=ip))

    ARP_Request.serialize()

    out = datapath.ofproto_parser.OFPPacketOut(
        datapath=datapath,
        buffer_id=datapath.ofproto.OFP_NO_BUFFER,
        in_port=datapath.ofproto.OFPP_CONTROLLER,
        actions=actions, data=ARP_Request.data)

    datapath.send_msg(out)

    return wrap_dpid_dict(dp, {}, to_user)

def get_ping_stats(dp, waiters, port=None, srcip=None, dstip=None, count=None, to_user=True):
    print("send ping message ping message ping message ping message ping message ping message")
    datapath = dp
    echo = icmp.echo(id_=66, seq=8)
    type = icmp.ICMP_ECHO_REQUEST
    SRC_MAC = "00:00:00:00:00:01"
    DST_MAC = "00:00:00:00:00:02"
    SRC_IP = int(netaddr.IPAddress(srcip))
    DST_IP = int(netaddr.IPAddress(dstip))
    out_port = str_to_int(port)
    num = str_to_int(count)
    actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]


    e = ethernet.ethernet(DST_MAC, SRC_MAC, ether.ETH_TYPE_IP)
    ip = ipv4.ipv4(version=4, header_length=5, tos=0, total_length=0,
                                   identification=0, flags=0, offset=0, ttl=64,
                                   proto=inet.IPPROTO_ICMP, csum=0,
                                   src=SRC_IP, dst=DST_IP)
    ping = icmp.icmp(type, code=0, csum=0, data=echo)

    p = packet.Packet()
    p.add_protocol(e)
    p.add_protocol(ip)
    p.add_protocol(ping)
    p.serialize()

    out = datapath.ofproto_parser.OFPPacketOut(
                datapath=datapath,
                buffer_id=datapath.ofproto.OFP_NO_BUFFER,
                in_port=datapath.ofproto.OFPP_CONTROLLER,
                actions=actions, data=p.data)
    for a in range(num):
        datapath.send_msg(out)

    return wrap_dpid_dict(dp, {}, to_user)

阅读(1334) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~