Skip to content

Commit

Permalink
fixed delay detector error
Browse files Browse the repository at this point in the history
  • Loading branch information
chengli2 committed Aug 27, 2016
1 parent 7380371 commit 7e379ee
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
CHANGES
=======

* add Class docs and comments
* add Class docs and comments
* get echo delay before it was used
* del useless files including scripts
* del dirty files of simple_monitor.py
* fixed showing info error
* enhance performance
Expand Down
27 changes: 15 additions & 12 deletions ryu/app/network_awareness/network_delay_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
class NetworkDelayDetector(app_manager.RyuApp):
"""
NetworkDelayDetector is a Ryu app for collecting link delay.
"""

OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]

def __init__(self, *args, **kwargs):
super(NetworkDelayDetector, self).__init__(*args, **kwargs)
self.name = 'delaydetector'
self.sending_echo_request_interval = 0.05
# Get the active object of swicthes and awareness module.
# So that this module can use their data.
self.sw_module = lookup_service_brick('switches')
Expand Down Expand Up @@ -89,17 +89,24 @@ def _send_echo_request(self):
"""
for datapath in self.datapaths.values():
parser = datapath.ofproto_parser
data = "%.6f" % time.time()
echo_req = parser.OFPEchoRequest(datapath, data=data)
echo_req = parser.OFPEchoRequest(datapath,
data="%.12f" % time.time())
datapath.send_msg(echo_req)
# Important! Don't send echo request together, Because it will
# generate a lot of echo reply almost in the same time.
# which will generate a lot of delay of waiting in queue
# when processing echo reply in echo_reply_handler.

hub.sleep(self.sending_echo_request_interval)

@set_ev_cls(ofp_event.EventOFPEchoReply, MAIN_DISPATCHER)
def echo_reply_handler(self, ev):
"""
Handle the echo reply msg, and get the latency of link.
"""
now_timestamp = time.time()
try:
latency = time.time() - eval(ev.msg.data)
latency = now_timestamp - eval(ev.msg.data)
self.echo_latency[ev.msg.datapath.id] = latency
except:
return
Expand All @@ -122,7 +129,7 @@ def get_delay(self, src, dst):
re_delay = self.awareness.graph[dst][src]['lldpdelay']
src_latency = self.echo_latency[src]
dst_latency = self.echo_latency[dst]

delay = (fwd_delay + re_delay - src_latency - dst_latency)/2
return max(delay, 0)
except:
Expand Down Expand Up @@ -162,18 +169,14 @@ def packet_in_handler(self, ev):
try:
src_dpid, src_port_no = LLDPPacket.lldp_parse(msg.data)
dpid = msg.datapath.id
in_port = msg.match['in_port']
if self.sw_module is None:
self.sw_module = lookup_service_brick('switches')

for port in self.sw_module.ports.keys():
if src_dpid == port.dpid and src_port_no == port.port_no:
port_data = self.sw_module.ports[port]
timestamp = port_data.timestamp
if timestamp:
delay = time.time() - timestamp
self._save_lldp_delay(src=src_dpid, dst=dpid,
lldpdelay=delay)
delay = self.sw_module.ports[port].delay
self._save_lldp_delay(src=src_dpid, dst=dpid,
lldpdelay=delay)
except LLDPPacket.LLDPUnknownFormat as e:
return

Expand Down
4 changes: 2 additions & 2 deletions ryu/app/network_awareness/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

MONITOR_PERIOD = 10 # For monitoring traffic

DELAY_DETECTING_PERIOD = 10 # For detecting link delay.
DELAY_DETECTING_PERIOD = 5 # For detecting link delay.

TOSHOW = False # For showing information in terminal
TOSHOW = True # For showing information in terminal

MAX_CAPACITY = 281474976710655L # Max capacity of link
1 change: 0 additions & 1 deletion ryu/app/simple_switch_13.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def _packet_in_handler(self, ev):
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
in_port = msg.match['in_port']
print ofproto, parser

pkt = packet.Packet(msg.data)
eth = pkt.get_protocols(ethernet.ethernet)[0]
Expand Down
9 changes: 9 additions & 0 deletions ryu/topology/switches.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ def __init__(self, is_down, lldp_data):
self.lldp_data = lldp_data
self.timestamp = None
self.sent = 0
self.delay = 0

def lldp_sent(self):
self.timestamp = time.time()
Expand Down Expand Up @@ -689,6 +690,7 @@ def _drop_packet(msg):

@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def packet_in_handler(self, ev):
recv_timestamp = time.time()
if not self.link_discovery:
return

Expand All @@ -709,6 +711,13 @@ def packet_in_handler(self, ev):
LOG.error('cannot accept LLDP. unsupported version. %x',
msg.datapath.ofproto.OFP_VERSION)

# get the lldp delay
for port in self.ports.keys():
if src_dpid == port.dpid and src_port_no == port.port_no:
send_timestamp = self.ports[port].timestamp
if send_timestamp:
self.ports[port].delay = recv_timestamp - send_timestamp

src = self._get_port(src_dpid, src_port_no)
if not src or src.dpid == dst_dpid:
return
Expand Down

0 comments on commit 7e379ee

Please sign in to comment.