def action_set(dp, conf): for key in conf.keys(): val = conf[key] # print "key->: %s" % key print "val->: %s" % val # if (key == "vlan_vid"): return dp.ofproto_parser.OFPActionSetField( vlan_vid=Utils.to_int(val)) elif (key == "eth_src"): return dp.ofproto_parser.OFPActionSetField(eth_src=val) elif (key == "eth_dst"): return dp.ofproto_parser.OFPActionSetField(eth_dst=val) elif (key == "vlan_pcp"): return dp.ofproto_parser.OFPActionSetField( vlan_pcp=Utils.to_int(val)) elif (key == "group_id"): return dp.ofproto_parser.OFPActionSetField( vlan_vid=Utils.to_int(val)) else: raise Exception("Wrong filed name:", key)
def create_buckets(dp, config): # buckets = [] # # print "@@@@@@@@@@@@@@@@@@@@@@" # print "buckets config: %s" % config # print "@@@@@@@@@@@@@@@@@@@@@@" # for entry in config: # print "entry: %s " % entry actions = Actions.create_actions(dp, entry["actions"]) bucket = dp.ofproto_parser.OFPBucket( weight=Utils.to_int(entry["weight"]), watch_port=Utils.get_mod_port(dp, entry["watch_port"]), watch_group=Utils.get_mod_group(dp, entry["watch_group"]), actions=actions #entry[] ) print "bucket: %s" % bucket buckets.append(bucket) print "buckets: %s" % buckets return buckets
def action_set(dp,conf): for key in conf.keys(): val = conf[key] # print "key: %s" % key print "val: %s" % val # if(key == "vlan_vid"): return dp.ofproto_parser.OFPActionSetField(vlan_vid=Utils.to_int(val)) elif(key == "eth_src"): return dp.ofproto_parser.OFPActionSetField(eth_src=val) elif(key == "eth_dst"): return dp.ofproto_parser.OFPActionSetField(eth_dst=val) elif(key == "group_id"): return dp.ofproto_parser.OFPActionSetField(vlan_vid=Utils.to_int(val)) else: raise Exception("Wrong filed name:", key)
def create_buckets(dp, config): # buckets = [] # print "buckets config: %s" % config # for entry in config: # print "entry: %s " % entry actions = Actions.create_actions(dp, entry["actions"]) bucket = dp.ofproto_parser.OFPBucket( weight=Utils.to_int(entry["weight"]), watch_port=Utils.get_mod_port(dp, entry["watch_port"]), watch_group=Utils.get_mod_group(dp, entry["watch_group"]), actions=actions # entry[] ) print "bucket: %s" % bucket buckets.append(bucket) print "buckets: %s" % buckets return buckets
def create_matches(dp, config): # #TODO: vlan mask matches = dp.ofproto_parser.OFPMatch() # # matches config is a list print "matches config: %s" % config # for key in config.keys(): # #print "key: %s" % key #print "val: %s" % config[key] # if key[0] == '#': continue val = config[key] # if (key == "in_port"): matches.set_in_port(int(val)) elif (key == "in_phy_port"): matches.set_in_phy_port(int(val)) elif (key == "metadata"): matches.set_metadata(int(val)) elif (key == "eth_dst"): matches.set_dl_dst(mac.haddr_to_bin(val)) elif (key == "eth_dst_mask"): haddr = mac.haddr_to_bin(config["eth_dst"]) mask = mac.haddr_to_bin(val) matches.set_dl_dst_masked(haddr,mask) elif (key == "eth_src"): matches.set_dl_src(mac.haddr_to_bin(val)) elif (key == "eth_src_mask"): haddr = mac.haddr_to_bin(config["eth_src"]) mask = mac.haddr_to_bin(val) matches.set_dl_src_masked(mac,mask) elif (key == "eth_type"): matches.set_dl_type(int(val,16)) elif (key == "vlan_vid"): lst = val.split(',') if(len(lst) == 1): vlan_vid = Utils.to_int(lst[0]) matches.set_vlan_vid(vlan_vid) elif(len(lst) == 2): vlan_vid = Utils.to_int(lst[0]) vlan_vid_mask = Utils.to_int(lst[1]) matches.set_vlan_vid_masked(vlan_vid, vlan_vid_mask) else: print key, ": only two values allowed, key ignored" elif (key == "vlan_pcp"): matches.set_vlan_pcp(int(val)) elif (key == "ip_dscp"): matches.set_ip_dscp(int(val)) elif (key == "ip_ecn"): raise Exception("Wrong match name:", key) elif (key == "ip_proto"): matches.set_ip_proto(int(val)) elif (key == "ipv4_src"): matches.set_ipv4_src(Matches.ipv4_to_int(val)) elif (key == "ipv4_src_mask"): addr = Matches.ipv4_to_int(config["ipv4_src"]) mask = Matches.mask_ntob(int(val)) matches.set_ipv4_src_masked(addr, mask) elif (key == "ipv4_dst"): matches.set_ipv4_dst(Matches.ipv4_to_int(val)) elif (key == "ipv4_dst_mask"): addr = Matches.ipv4_to_int(config["ipv4_dst"]) mask = Matches.mask_ntob(int(val)) matches.set_ipv4_dst_masked(addr, mask) elif (key == "tcp_src"): matches.set_tcp_src(int(val)) elif (key == "tcp_dst"): matches.set_tcp_dst(int(val)) elif (key == "udp_src"): matches.set_udp_src(int(val)) elif (key == "udp_dst"): matches.set_udp_dst(int(val)) elif (key == "sctp_src"): matches.set_sctp_src(int(val)) elif (key == "sctp_dst"): matches.set_sctp_dst(int(val)) elif (key == "icmpv4_type"): matches.set_icmpv4_type(int(val)) elif (key == "icmpv4_code"): matches.set_icmpv4_code(int(val)) elif (key == "arp_op"): raise Exception("Wrong match name:", key) elif (key == "arp_spa"): raise Exception("Wrong match name:", key) elif (key == "arp_tpa"): raise Exception("Wrong match name:", key) elif (key == "arp_sha"): raise Exception("Wrong match name:", key) elif (key == "arp_tha"): raise Exception("Wrong match name:", key) elif (key == "ipv6_src"): matches.set_ipv6_src(Matches.ipv6_to_int(val)) elif (key == "ipv6_src_mask"): ipv6_src_int = Matches.ipv6_to_int(config["ipv6_src"]) mask_int = Matches.ipv6_to_int(mask) match.set_ipv6_src_masked(ipv6_src_int, mask_int) elif (key == "ipv6_dst"): matches.set_ipv6_dst(Matches.ipv6_to_int(val)) elif (key == "ipv6_dst_mask"): ipv6_dst_int = Matches.ipv6_to_int(config["ipv6_dst"]) mask_int = Matches.ipv6_to_int(mask) match.set_ipv6_dst_masked(ipv6_dst_int, mask_int) elif (key == "ipv6_flabel"): lst = val.split(',') flabel_int = Utils.to_int(lst[0]) if(len(lst) == 1): matches.set_ipv6_flabel(flabel_int) elif(len(lst) == 2): flabel_mask_int = Utils.to_int(lst[1]) matches.set_ipv6_flabel_masked(flabel_int, flabel_mask_int) else: print key, ": only two values allowed, key ignored" elif (key == "icmpv6_type"): matches.set_icmpv6_type(int(val)) elif (key == "icmpv6_code"): matches.set_icmpv6_code(int(val)) elif (key == "ipv6_nd_target"): raise Exception("Wrong match name:", key) elif (key == "ipv6_nd_sll"): raise Exception("Wrong match name:", key) elif (key == "ipv6_nd_tll"): raise Exception("Wrong match name:", key) elif (key == "mpls_label"): raise Exception("Wrong match name:", key) elif (key == "mpls_tc"): raise Exception("Wrong match name:", key) elif (key == "mpls_bos"): raise Exception("Wrong match name:", key) elif (key == "pbb_isid"): raise Exception("Wrong match name:", key) elif (key == "tunnel_id"): matches.set_tunnel_id(int(val)) elif (key == "ipv6_exthdr"): raise Exception("Wrong match name:", key) else: raise Exception("Wrong match name:", key) #print "matches: %s" % matches return matches
def add_ofdpa_flow(self, datapath, priority, vlan_vid, dst, out_port): #prerequisite ofproto = datapath.ofproto parser = datapath.ofproto_parser #the group id will be generated by increment group_id = generate_group_id() #vlan table match = parser.OFPMatch(in_port=in_port, vlan_vid=vlan_vid) type = ofproto.OFPIT_GOTO_TABLE inst = [parser.OFPInstructionGotoTable(type, Utils.get_table("TABLE_MAC"))] mod = parser.OFPFlowMod(datapath=datapath, cookie = 0, cookie_mask = 0, table_id=Utils.get_table("TABLE_VLAN"), command = Utils.get_mod_command(datapath, "add"), idle_timeout = 0, hard_timeout = 0, priority=priority, buffer_id = 0, match=match, out_port = Utils.get_mod_port(datapath, "any"), out_group = Utils.get_mod_group(datapath, "any"), flags=0, instructions=inst ) datapath.send_msg(mod) #bridging table match = parser.OFPMatch(eth_dst=dst, vlan_vid=vlan_vid) mask = mac.haddr_to_bin("ff:ff:ff:ff:ff:ff") match.set_dl_dst_masked(dst,mask) actions = [parser.OFPActionGroup(Utils.to_int(group_id))] type = ofproto.OFPIT_WRITE_ACTIONS inst = [parser.OFPInstructionActions(type, actions)] mod = parser.OFPFlowMod(datapath=datapath, cookie = 0, cookie_mask = 0, table_id=Utils.get_table("TABLE_BRIDGING"), command = Utils.get_mod_command(datapath, "add"), idle_timeout = 0, hard_timeout = 0, priority=priority, buffer_id = 0, match=match, out_port = Utils.get_mod_port(datapath, "any"), out_group = Utils.get_mod_group(datapath, "any"), flags=0, instructions=inst ) datapath.send_msg(mod) #L2 Group table actions = [parser.OFPActionOutput(out_port)] buckets = [] bucket = datapath.ofproto_parser.OFPBucket( weight = Utils.to_int("0"), watch_port = Utils.get_mod_port("any"), watch_group = Utils.get_mod_group("any"), actions = actions ) buckets.append(bucket) print "buckets: %s" % buckets mod = datapath.ofproto_parser.OFPGroupMod( datapath, Utils.get_mod_command(datapath, "add"), Utils.get_mod_type(datapath, "indirect"), Utils.get_mod_group(datapath, group_id), buckets ) datapath.send_msg(mod)
def action_queue(dp, conf): return dp.ofproto_parser.OFPActionSetQueue( Utils.to_int(conf["queue_id"]))
def action_group(dp, conf): return dp.ofproto_parser.OFPActionGroup(Utils.to_int(conf["group_id"]))
def action_group(dp,conf): return dp.ofproto_parser.OFPActionGroup(Utils.to_int(conf["group_id"]))