Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    def create_flow_mod(dp, config):
        #
        matches_config = ConfigParser.get_matches(config)
        matches = Matches.create_matches(dp, matches_config)
        #
        instr_config = ConfigParser.get_instr_config(config)
        instructions = Instructions.create_instructions(dp, instr_config)
        #

        mod = dp.ofproto_parser.OFPFlowMod(
            dp,
            cookie=0,
            cookie_mask=0,
            table_id=Utils.get_table(config["table"]),
            command=Utils.get_mod_command(dp, config["cmd"]),
            idle_timeout=0,
            hard_timeout=0,
            priority=0,
            buffer_id=0,
            out_port=Utils.get_mod_port(dp, config["port"]),
            out_group=Utils.get_mod_group(dp, config["group"]),
            flags=0,
            match=matches,
            instructions=instructions)
        return mod
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    def create_flow_mod(dp, config):
        #
        matches_config = ConfigParser.get_matches(config)
        matches = Matches.create_matches(dp, matches_config)
        #
        instr_config = ConfigParser.get_instr_config(config)
        instructions = Instructions.create_instructions(dp, instr_config)
        #

        mod = dp.ofproto_parser.OFPFlowMod (
            dp,
            cookie = 0,
            cookie_mask = 0,
            table_id = Utils.get_table(config["table"]),
            command = Utils.get_mod_command(dp, config["cmd"]),
            idle_timeout = 0,
            hard_timeout = 0,
            priority = 0,
            buffer_id = 0,
            out_port = Utils.get_mod_port(dp, config["port"]),
            out_group = Utils.get_mod_group(dp, config["group"]),
            flags=0,
            match=matches,
            instructions=instructions
        )
        return mod
Exemplo n.º 5
0
 def delete_group_mod(dp, config):
     #
     mod = dp.ofproto_parser.OFPGroupMod(
         dp,
         Utils.get_group_mod_command(dp, config["cmd"]),
         Utils.get_mod_type(dp, config["type"]),
         Utils.get_mod_group(dp, config["group_id"])
         )
     return mod
Exemplo n.º 6
0
    def create_group_mod(dp, config):
        #
        buckets_config = ConfigParser.get_buckets_config(config)
        buckets = Buckets.create_buckets(dp, buckets_config)
        #

        mod = dp.ofproto_parser.OFPGroupMod(
            dp, Utils.get_mod_command(dp, config["cmd"]),
            Utils.get_mod_type(dp, config["type"]),
            Utils.get_mod_group(dp, config["group_id"]), buckets)
        return mod
Exemplo n.º 7
0
    def create_group_mod(dp, config):
        #
        buckets_config= ConfigParser.get_buckets_config(config)
        buckets = Buckets.create_buckets(dp, buckets_config)
        #

        mod = dp.ofproto_parser.OFPGroupMod(
            dp,
            Utils.get_mod_command(dp, config["cmd"]),
            Utils.get_mod_type(dp, config["type"]),
            Utils.get_mod_group(dp, config["group_id"]),
            buckets
            )
        return mod
Exemplo n.º 8
0
 def delete_flow_mod(dp, config):
     #
     mod = dp.ofproto_parser.OFPFlowMod (
         dp,
         cookie = 0,
         cookie_mask = 0,
         table_id = Utils.get_table(config["table"]),
         command = Utils.get_mod_command(dp, config["cmd"]),
         idle_timeout = 0,
         hard_timeout = 0,
         priority = 0,
         buffer_id = 0,
         out_port = Utils.get_mod_port(dp, config["port"]),
         out_group = Utils.get_mod_group(dp, config["group"]),
         flags=0
     )
     return mod
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    def switch_features_handler(self, ev):
        datapath = ev.msg.datapath
        ofproto = datapath.ofproto
        parser = datapath.ofproto_parser

        match = parser.OFPMatch()
        actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
                                          ofproto.OFPCML_NO_BUFFER)]
        
        #FIXME: Sending packet-in message to controller is probably not by this way. 
        # Based on the documenet about Source MAC Learning Feature, we need to use 
        # client_srcmac_learn program or others to this. Indigo doesn't provide this.
        self.add_flow(datapath, 0, match, actions, 
                      Utils.get_table("TABLE_ACL"))
Exemplo n.º 12
0
 def process_goto(dp,config):
     table = Utils.get_table(config["table"])
     return dp.ofproto_parser.OFPInstructionGotoTable(table)
Exemplo n.º 13
0
    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
Exemplo n.º 14
0
    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)
Exemplo n.º 15
0
 def action_group(dp, conf):
     return dp.ofproto_parser.OFPActionGroup(Utils.to_int(conf["group_id"]))
Exemplo n.º 16
0
 def action_group(dp,conf):
     return dp.ofproto_parser.OFPActionGroup(Utils.to_int(conf["group_id"]))
Exemplo n.º 17
0
 def process_goto(dp, config):
     table = Utils.get_table(config["table"])
     return dp.ofproto_parser.OFPInstructionGotoTable(table)
Exemplo n.º 18
0
 def action_output(dp, conf):
     # Xiaoye
     # return dp.ofproto_parser.OFPActionOutput(int(conf["port"]))
     return dp.ofproto_parser.OFPActionOutput(
         Utils.get_mod_port(dp, conf["port"]))
Exemplo n.º 19
0
 def action_queue(dp, conf):
     return dp.ofproto_parser.OFPActionSetQueue(
         Utils.to_int(conf["queue_id"]))