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)
阅读(1407) | 评论(0) | 转发(0) |