def __init__(self, action=NONE, pkt=None): """Initialize @param action NONE (default), DROP, GET, FLOOD @param packet dpkt parsed packet """ actions.__init__(self) packet.__init__(self, pkt) ##Match self.match = pyof.ofp_match() ##Idle timeout self.idle_timeout = DEFAULT_TIMEOUT ##Hard timeout self.hard_timeout = pyof.OFP_FLOW_PERMANENT ##Priority self.priority = pyof.OFP_DEFAULT_PRIORITY ##Out port self.out_port = pyof.OFPP_NONE ##Flags self.flags = 0 if action == flow_entry.GET: self.add_output(pyof.OFPP_CONTROLLER) elif action == flow_entry.FLOOD: self.add_output(pyof.OFPP_FLOOD)
def get_ofp_match(in_port, packet): """Generate ofp_match from raw packet Note that OpenFlow uses outermost Ethertype, while dokt provides the innermost one. And VLAN tag parsing is manually done. @param in_port input port of packet @param packet raw packet @return (ofp match, dpkt's packet) """ ofm = pyof.ofp_match() pkt = dpkt.ethernet.Ethernet(packet) #In Port ofm.in_port = in_port #Get Ethernet ofm.dl_src = pu.byte_str2array(pkt.src) ofm.dl_dst = pu.byte_str2array(pkt.dst) ofm.dl_type = struct.unpack('>H',packet[12:14])[0] #802.1Q VLAN if (ofm.dl_type == dpkt.ethernet.ETH_TYPE_8021Q): ofm.dl_vlan = pkt.tag & VLAN_ID_MASK ofm.dl_vlan_pcp = (pkt.tag & VLAN_PRIORITY_MASK) >> VLAN_PRIORITY_SHIFT #Get IP if any if (isinstance(pkt.data, dpkt.ip.IP)): __get_ip_ofp_match(ofm, pkt.data) elif (isinstance(pkt.data, dpkt.arp.ARP)): __get_arp_ofp_match(ofm, pkt.data) return (ofm, pkt)