Skip to content
This repository was archived by the owner on Jun 27, 2018. It is now read-only.

Commit 993f873

Browse files
committed
added comments, removed unused imports, improved get_packet_processor
1 parent ada611a commit 993f873

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

pyretic/core/packet.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
1+
import struct, re
12
import pyretic.vendor
2-
from ryu.lib.packet import *
3-
from ryu.lib.packet import vlan
4-
5-
import struct
6-
import re
73

8-
from bitarray import bitarray
4+
from ryu.lib.packet import *
5+
from ryu.lib import addrconv
96

10-
from pyretic.core.network import IPAddr, EthAddr
117
from pyretic.core import util
12-
13-
from ryu.lib import addrconv
14-
15-
["switch", "inport", "header_len", "payload_len", "srcmac", "dstmac", "ethtype", 'vlan_id', 'vlan_pcp', "ethtype", "srcip", "dstip", "protocol", "tos", "srcport", "dstport", "ethtype", "protocol", "srcip", "dstip", "raw"]
8+
from pyretic.core.network import IPAddr, EthAddr
169

1710
__all__ = ['of_field', 'of_fields', 'get_packet_processor', 'Packet']
1811
_field_list = dict()
@@ -26,6 +19,9 @@
2619
TCP_PROTO = 6
2720
UDP_PROTO = 17
2821

22+
##################################################
23+
# EMPTY TEMPLATE PACKETS FOR DIFFERENT PROTCOLS
24+
##################################################
2925
def arp_packet_gen():
3026
pkt = packet.Packet()
3127
pkt.protocols.append(ethernet.ethernet("ff:ff:ff:ff:ff:ff", "ff:ff:ff:ff:ff:ff", ARP))
@@ -181,6 +177,12 @@ def convert(h, v):
181177
# Build the packet processor pipeline
182178
return self
183179

180+
def get_packet_processor():
181+
try:
182+
return get_packet_processor.processor
183+
except AttributeError:
184+
get_packet_processor.processor = Processor().compile()
185+
return get_packet_processor.processor
184186

185187
################################################################################
186188
# Field Validators
@@ -279,7 +281,7 @@ def vlan_validator(*args, **kwargs):
279281

280282

281283
################################################################################
282-
# Field definition and Decorators
284+
# Field Decorator
283285
################################################################################
284286
def of_field(match="", pyretic_field="", validator=true_validator(), version="1.0"):
285287
matches = match.split(".")
@@ -353,6 +355,9 @@ def is_valid(self, ryu_pkt):
353355

354356
return _of_field
355357

358+
#######################
359+
# OPENFLOW 1.0 FIELDS
360+
#######################
356361
@of_field("udp.dst_port", "dstport", proto_validator(UDP_PROTO), "1.0")
357362
class UdpDstPort(object): pass
358363

@@ -478,9 +483,6 @@ class ArpSrcIp(object): pass
478483
@of_field("arp.dst_ip", "dstip", ether_validator(ARP), version="1.0")
479484
class ArpDstIp(object): pass
480485

481-
def get_packet_processor():
482-
return Processor().compile()
483-
484486
################################################################################
485487
# Packet
486488
################################################################################

0 commit comments

Comments
 (0)