Skip to content

Commit 2f0ae37

Browse files
committed
Fix coding style according to flake8
1 parent 49a9b58 commit 2f0ae37

7 files changed

+282
-214
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.egg-info/
44
build/
55
dist/
6+
.settings
67

78
GTAGS
89
GRTAGS

ryu/app/inception.py

+129-131
Large diffs are not rendered by default.

ryu/app/inception_arp.py

+49-48
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,68 @@
1-
"""
2-
Inception Cloud ARP module
3-
"""
1+
# -*- coding: utf-8 -*-
2+
3+
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4+
5+
# Copyright (C) 2014 AT&T Labs All Rights Reserved.
6+
# Copyright (C) 2014 University of Pennsylvania All Rights Reserved.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
9+
# not use this file except in compliance with the License. You may obtain
10+
# a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17+
# License for the specific language governing permissions and limitations
18+
# under the License.
419

520
import logging
621
import os
722

23+
from ryu.app import inception_conf as i_conf
24+
from ryu.app import inception_util as i_util
825
from ryu.lib.dpid import dpid_to_str
926
from ryu.lib.dpid import str_to_dpid
10-
from ryu.ofproto import ether
1127
from ryu.lib.packet import arp
1228
from ryu.lib.packet import ethernet
1329
from ryu.lib.packet import packet
14-
from ryu.app.inception_util import zk_data_to_tuple
15-
from ryu.app.inception_conf import IP_TO_MAC
16-
from ryu.app.inception_conf import DPID_TO_CONNS
17-
from ryu.app.inception_conf import MAC_TO_DPID_PORT
30+
from ryu.ofproto import ether
1831

1932
LOGGER = logging.getLogger(__name__)
2033

2134

2235
class InceptionArp(object):
23-
"""
24-
Inception Cloud ARP module for handling ARP packets
25-
"""
36+
"""Inception Cloud ARP module for handling ARP packets."""
2637

2738
def __init__(self, inception):
2839
self.inception = inception
2940

30-
def handle(self, dpid, in_port, arp_header, transaction):
41+
def handle(self, dpid, in_port, arp_header, txn):
3142
LOGGER.info("Handle ARP packet")
3243

3344
# Do {ip => mac} learning
34-
self._do_arp_learning(arp_header, transaction)
45+
self._do_arp_learning(arp_header, txn)
3546
# Process arp request
3647
if arp_header.opcode == arp.ARP_REQUEST:
37-
self._handle_arp_request(dpid, in_port, arp_header, transaction)
48+
self._handle_arp_request(dpid, in_port, arp_header, txn)
3849
# Process arp reply
3950
elif arp_header.opcode == arp.ARP_REPLY:
40-
self._handle_arp_reply(dpid, arp_header, transaction)
51+
self._handle_arp_reply(dpid, arp_header, txn)
4152

42-
def _do_arp_learning(self, arp_header, transaction):
43-
"""
44-
Learn IP => MAC mapping from a received ARP packet, update
45-
ip_to_mac table
53+
def _do_arp_learning(self, arp_header, txn):
54+
"""Learn IP => MAC mapping from a received ARP packet, update
55+
ip_to_mac table.
4656
"""
4757
src_ip = arp_header.src_ip
4858
src_mac = arp_header.src_mac
4959

50-
if src_ip not in self.inception.zk.get_children(IP_TO_MAC):
51-
transaction.create(os.path.join(IP_TO_MAC, src_ip), src_mac)
60+
if src_ip not in self.inception.zk.get_children(i_conf.IP_TO_MAC):
61+
txn.create(os.path.join(i_conf.IP_TO_MAC, src_ip), src_mac)
5262
LOGGER.info("Learn: (ip=%s) => (mac=%s)", src_ip, src_mac)
5363

54-
def _handle_arp_request(self, dpid, in_port, arp_header, transaction):
55-
"""
56-
Process ARP request packet
57-
"""
64+
def _handle_arp_request(self, dpid, in_port, arp_header, txn):
65+
"""Process ARP request packet."""
5866
src_ip = arp_header.src_ip
5967
src_mac = arp_header.src_mac
6068
dst_ip = arp_header.dst_ip
@@ -66,18 +74,18 @@ def _handle_arp_request(self, dpid, in_port, arp_header, transaction):
6674
LOGGER.info("ARP request: (ip=%s) query (ip=%s)", src_ip, dst_ip)
6775
# If entry not found, broadcast request
6876
# TODO(Chen): Buffering request? Not needed in a friendly environment
69-
if dst_ip not in self.inception.zk.get_children(IP_TO_MAC):
77+
if dst_ip not in self.inception.zk.get_children(i_conf.IP_TO_MAC):
7078
LOGGER.info("Entry for (ip=%s) not found, broadcast ARP request",
7179
dst_ip)
7280

7381
arp_request = arp.arp(opcode=arp.ARP_REQUEST,
74-
dst_mac='ff:ff:ff:ff:ff:ff',
75-
src_mac=src_mac,
76-
dst_ip=dst_ip,
77-
src_ip=src_ip)
82+
dst_mac='ff:ff:ff:ff:ff:ff',
83+
src_mac=src_mac,
84+
dst_ip=dst_ip,
85+
src_ip=src_ip)
7886
eth_request = ethernet.ethernet(ethertype=ether.ETH_TYPE_ARP,
79-
src=arp_header.src_mac,
80-
dst='ff:ff:ff:ff:ff:ff')
87+
src=arp_header.src_mac,
88+
dst='ff:ff:ff:ff:ff:ff')
8189
packet_request = packet.Packet()
8290
packet_request.add_protocol(eth_request)
8391
packet_request.add_protocol(arp_request)
@@ -90,7 +98,7 @@ def _handle_arp_request(self, dpid, in_port, arp_header, transaction):
9098
ports = self.inception.dpset.get_ports(str_to_dpid(dpid))
9199
# Sift out ports connecting to hosts but vxlan peers
92100
vxlan_ports = []
93-
zk_path = os.path.join(DPID_TO_CONNS, dpid)
101+
zk_path = os.path.join(i_conf.DPID_TO_CONNS, dpid)
94102
for child in self.inception.zk.get_children(zk_path):
95103
zk_path_child = os.path.join(zk_path, child)
96104
port_no, _ = self.inception.zk.get(zk_path_child)
@@ -110,11 +118,9 @@ def _handle_arp_request(self, dpid, in_port, arp_header, transaction):
110118
else:
111119
# Setup data forwarding flows
112120
result_dst_mac, _ = self.inception.zk.get(
113-
os.path.join(IP_TO_MAC, dst_ip))
114-
self.inception.setup_switch_fwd_flows(src_mac,
115-
dpid,
116-
result_dst_mac,
117-
transaction)
121+
os.path.join(i_conf.IP_TO_MAC, dst_ip))
122+
self.inception.setup_switch_fwd_flows(src_mac, dpid,
123+
result_dst_mac, txn)
118124
# Construct ARP reply packet and send it to the host
119125
LOGGER.info("Hit: (dst_ip=%s) <=> (dst_mac=%s)",
120126
dst_ip, result_dst_mac)
@@ -144,26 +150,21 @@ def _handle_arp_request(self, dpid, in_port, arp_header, transaction):
144150
arp_reply.dst_ip, arp_reply.dst_mac, in_port,
145151
arp_reply.src_ip, arp_reply.src_mac)
146152

147-
def _handle_arp_reply(self, dpid, arp_header, transaction):
148-
"""
149-
Process ARP reply packet
150-
"""
153+
def _handle_arp_reply(self, dpid, arp_header, txn):
154+
"""Process ARP reply packet."""
151155
src_ip = arp_header.src_ip
152156
src_mac = arp_header.src_mac
153157
dst_ip = arp_header.dst_ip
154158
dst_mac = arp_header.dst_mac
155159

156160
LOGGER.info("ARP reply: (ip=%s) answer (ip=%s)", src_ip, dst_ip)
157-
zk_path = os.path.join(MAC_TO_DPID_PORT, dst_mac)
161+
zk_path = os.path.join(i_conf.MAC_TO_DPID_PORT, dst_mac)
158162
if self.inception.zk.exists(zk_path):
159163
# If I know to whom to forward back this ARP reply
160164
dst_dpid_port, _ = self.inception.zk.get(zk_path)
161-
dst_dpid, dst_port = zk_data_to_tuple(dst_dpid_port)
165+
dst_dpid, dst_port = i_util.str_to_tuple(dst_dpid_port)
162166
# Setup data forwarding flows
163-
self.inception.setup_switch_fwd_flows(src_mac,
164-
dpid,
165-
dst_mac,
166-
transaction)
167+
self.inception.setup_switch_fwd_flows(src_mac, dpid, dst_mac, txn)
167168
# Forward ARP reply
168169
arp_reply = arp.arp(opcode=arp.ARP_REPLY,
169170
dst_mac=dst_mac,

ryu/app/inception_conf.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1-
"""
2-
A global view of Inception configurations, to ease management.
3-
"""
1+
# -*- coding: utf-8 -*-
2+
3+
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4+
5+
# Copyright (C) 2014 AT&T Labs All Rights Reserved.
6+
# Copyright (C) 2014 University of Pennsylvania All Rights Reserved.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
9+
# not use this file except in compliance with the License. You may obtain
10+
# a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17+
# License for the specific language governing permissions and limitations
18+
# under the License.
19+
20+
"""A global view of Inception configurations, to ease management"""
421

522
import os
623

ryu/app/inception_dhcp.py

+32-21
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
1-
"""
2-
Inception Cloud DHCP module
3-
"""
1+
# -*- coding: utf-8 -*-
2+
3+
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4+
5+
# Copyright (C) 2014 AT&T Labs All Rights Reserved.
6+
# Copyright (C) 2014 University of Pennsylvania All Rights Reserved.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
9+
# not use this file except in compliance with the License. You may obtain
10+
# a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17+
# License for the specific language governing permissions and limitations
18+
# under the License.
419

520
import logging
621
import os
722

8-
from ryu.ofproto import ether
9-
from ryu.ofproto import inet
23+
from ryu.app import inception_conf as i_conf
24+
from ryu.app import inception_util as i_util
1025
from ryu.lib.dpid import str_to_dpid
11-
from ryu.lib.packet import packet
1226
from ryu.lib.packet import ethernet
1327
from ryu.lib.packet import ipv4
28+
from ryu.lib.packet import packet
1429
from ryu.lib.packet import udp
15-
from ryu.app.inception_util import zk_data_to_tuple
16-
from ryu.app.inception_conf import MAC_TO_DPID_PORT
17-
from ryu.app.inception_conf import DHCP_SWITCH_DPID
18-
from ryu.app.inception_conf import DHCP_SWITCH_PORT
30+
from ryu.ofproto import ether
31+
from ryu.ofproto import inet
1932

2033
LOGGER = logging.getLogger(__name__)
2134

@@ -24,20 +37,18 @@
2437

2538

2639
class InceptionDhcp(object):
27-
"""
28-
Inception Cloud DHCP module for handling DHCP packets
29-
"""
40+
"""Inception Cloud DHCP module for handling DHCP packets."""
3041

3142
def __init__(self, inception):
3243
self.inception = inception
3344

3445
def update_server(self, dpid, port):
35-
dhcp_switch_dpid, _ = self.inception.zk.get(DHCP_SWITCH_DPID)
36-
dhcp_switch_port, _ = self.inception.zk.get(DHCP_SWITCH_PORT)
46+
dhcp_switch_dpid, _ = self.inception.zk.get(i_conf.DHCP_SWITCH_DPID)
47+
dhcp_switch_port, _ = self.inception.zk.get(i_conf.DHCP_SWITCH_PORT)
3748
if dhcp_switch_port and dhcp_switch_dpid:
3849
LOGGER.warning("DHCP-server-connected switch registered before!")
39-
self.inception.zk.set(DHCP_SWITCH_DPID, dpid)
40-
self.inception.zk.set(DHCP_SWITCH_PORT, port)
50+
self.inception.zk.set(i_conf.DHCP_SWITCH_DPID, dpid)
51+
self.inception.zk.set(i_conf.DHCP_SWITCH_PORT, port)
4152

4253
def handle(self, event):
4354
# process only if it is DHCP packet
@@ -58,8 +69,8 @@ def handle(self, event):
5869
DHCP_SERVER_PORT)
5970
return
6071

61-
dhcp_switch_dpid, _ = self.inception.zk.get(DHCP_SWITCH_DPID)
62-
dhcp_switch_port, _ = self.inception.zk.get(DHCP_SWITCH_PORT)
72+
dhcp_switch_dpid, _ = self.inception.zk.get(i_conf.DHCP_SWITCH_DPID)
73+
dhcp_switch_port, _ = self.inception.zk.get(i_conf.DHCP_SWITCH_PORT)
6374

6475
LOGGER.info("Handle DHCP packet")
6576
if not dhcp_switch_dpid or not dhcp_switch_port:
@@ -86,8 +97,8 @@ def handle(self, event):
8697
# the client and forward the packet to it.
8798
elif udp_header.src_port == DHCP_SERVER_PORT:
8899
dpid_port, _ = self.inception.zk.get(os.path.join(
89-
MAC_TO_DPID_PORT, ethernet_header.dst))
90-
dpid, port = zk_data_to_tuple(dpid_port)
100+
i_conf.MAC_TO_DPID_PORT, ethernet_header.dst))
101+
dpid, port = i_util.str_to_tuple(dpid_port)
91102
LOGGER.info("Forward DHCP message to client (mac=%s) at "
92103
"(switch=%s) (port=%s)", ethernet_header.dst,
93104
dpid, port)

ryu/app/inception_priority.py

+25
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,36 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4+
5+
# Copyright (C) 2014 AT&T Labs All Rights Reserved.
6+
# Copyright (C) 2014 University of Pennsylvania All Rights Reserved.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
9+
# not use this file except in compliance with the License. You may obtain
10+
# a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17+
# License for the specific language governing permissions and limitations
18+
# under the License.
19+
120
"""A global view of priorities for each type of traffic/flow, to ease
221
management.
322
"""
423

524
# The priorities are sorted in a descending order, which is by design
25+
626
ARP = 2000
27+
728
DHCP = 1900
29+
830
HOST_BCAST = 1800
31+
932
SWITCH_BCAST = 1700
33+
1034
DATA_FWD = 1500
35+
1136
NORMAL = 1000

ryu/app/inception_util.py

+26-11
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1-
"""
2-
Inception utilities
3-
"""
1+
# -*- coding: utf-8 -*-
42

3+
# vim: tabstop=4 shiftwidth=4 softtabstop=4
4+
5+
# Copyright (C) 2014 AT&T Labs All Rights Reserved.
6+
# Copyright (C) 2014 University of Pennsylvania All Rights Reserved.
7+
#
8+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
9+
# not use this file except in compliance with the License. You may obtain
10+
# a copy of the License at
11+
#
12+
# http://www.apache.org/licenses/LICENSE-2.0
13+
#
14+
# Unless required by applicable law or agreed to in writing, software
15+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17+
# License for the specific language governing permissions and limitations
18+
# under the License.
19+
20+
"""Inception utilities"""
21+
22+
23+
def tuple_to_str(data_tuple, sep=','):
24+
"""Convert tuple to string."""
525

6-
def tuple_to_zk_data(data_tuple, sep=','):
7-
"""
8-
Convert tuple to string
9-
"""
1026
zk_data = sep.join(data_tuple)
1127
return zk_data
1228

1329

14-
def zk_data_to_tuple(zk_data, sep=','):
15-
"""
16-
Convert string to tuple
17-
"""
30+
def str_to_tuple(zk_data, sep=','):
31+
"""Convert string to tuple."""
32+
1833
data_tuple = tuple(zk_data.split(sep))
1934
return data_tuple

0 commit comments

Comments
 (0)