Esempio n. 1
0
 def rate_limit_for_member(self, mac, bandwidth):
     meter_id = 0
     for myid, mybandwidth in qos_config.meter.iteritems():
         if mybandwidth == bandwidth:
             meter_id = myid
     forwarding_config.member_list.get(mac).meter_id = meter_id
     datapath = forwarding_config.member_list.get(mac).datapath
     out_port = forwarding_config.member_list.get(mac).port
     parser = datapath.ofproto_parser
     actions = [parser.OFPActionOutput(out_port)]
     match = parser.OFPMatch(eth_dst=mac)
     ofp_helper.add_flow_rate_limit(datapath=datapath,
                                    table_id=0,
                                    priority=self.member_limit_priority,
                                    match=match,
                                    meter_id=meter_id,
                                    idle_timeout=10)
Esempio n. 2
0
    def flow_meter_add_handler(self, flow):
        app_setting = qos_config.app_list.get(flow.app)
        if app_setting is None:
            return
        for mac, meter in app_setting.iteritems():
            target_host = forwarding_config.member_list.get(mac)
            if (target_host.mac
                    == flow.dst_mac) or (target_host.ip
                                         == flow.dst_ip) or (mac == 'all'):
                meter_id = meter.get('meter_id')
                bandwidth = meter.get('bandwidth')
                datapath = self.MyDATAPATH
                parser = datapath.ofproto_parser
                if flow.ip_proto == inet.IPPROTO_TCP:
                    match = parser.OFPMatch(eth_src=flow.src_mac,
                                            eth_dst=flow.dst_mac,
                                            eth_type=ether.ETH_TYPE_IP,
                                            ipv4_src=flow.src_ip,
                                            ipv4_dst=flow.dst_ip,
                                            ip_proto=flow.ip_proto,
                                            tcp_src=flow.src_port,
                                            tcp_dst=flow.dst_port)
                else:
                    match = parser.OFPMatch(eth_src=flow.src_mac,
                                            eth_dst=flow.dst_mac,
                                            eth_type=ether.ETH_TYPE_IP,
                                            ipv4_src=flow.src_ip,
                                            ipv4_dst=flow.dst_ip,
                                            ip_proto=flow.ip_proto,
                                            udp_src=flow.src_port,
                                            udp_dst=flow.dst_port)

                ofp_helper.add_flow_rate_limit(
                    datapath=self.MyDATAPATH,
                    table_id=0,
                    priority=self.app_limit_priority,
                    match=match,
                    meter_id=meter_id,
                    idle_timeout=10)
Esempio n. 3
0
    def rate_limit_for_app(self, app, mac, bandwidth):
        if qos_config.app_list.get(app) is None:
            new_meter_id = self.get_free_meterid()
            self.add_meter(bandwidth, new_meter_id)
            rate_for_member = {
                mac: {
                    "meter_id": new_meter_id,
                    "bandwidth": bandwidth
                }
            }
            qos_config.app_list.update({app: rate_for_member})
        else:
            if qos_config.app_list.get(app).get(mac) is None:
                new_meter_id = self.get_free_meterid()
                self.add_meter(bandwidth, new_meter_id)
                qos_config.app_list.get(app).update(
                    {mac: {
                        "meter_id": new_meter_id,
                        "bandwidth": bandwidth
                    }})
            else:
                rate_for_member = {mac: {"bandwidth": bandwidth}}
                qos_config.app_list.get(app).get(mac)['bandwidth'] = bandwidth

        # Add rule for all flow which app is this app
        app_setting = qos_config.app_list.get(app).get(mac)
        meter_id = app_setting.get('meter_id')
        bandwidth = app_setting.get('bandwidth')
        datapath = self.MyDATAPATH
        parser = datapath.ofproto_parser
        if mac is not 'all':
            target_host = forwarding_config.member_list.get(mac)
        for key, flow in forwarding_config.flow_list.iteritems():
            if (mac == 'all') or (target_host.mac
                                  == flow.dst_mac) or (target_host.ip
                                                       == flow.dst_ip):
                if flow.ip_proto == inet.IPPROTO_TCP:
                    match = parser.OFPMatch(eth_src=flow.src_mac,
                                            eth_dst=flow.dst_mac,
                                            eth_type=ether.ETH_TYPE_IP,
                                            ipv4_src=flow.src_ip,
                                            ipv4_dst=flow.dst_ip,
                                            ip_proto=flow.ip_proto,
                                            tcp_src=flow.src_port,
                                            tcp_dst=flow.dst_port)
                else:
                    match = parser.OFPMatch(eth_src=flow.src_mac,
                                            eth_dst=flow.dst_mac,
                                            eth_type=ether.ETH_TYPE_IP,
                                            ipv4_src=flow.src_ip,
                                            ipv4_dst=flow.dst_ip,
                                            ip_proto=flow.ip_proto,
                                            udp_src=flow.src_port,
                                            udp_dst=flow.dst_port)
                ofp_helper.add_flow_rate_limit(
                    datapath=self.MyDATAPATH,
                    table_id=0,
                    priority=self.app_limit_priority,
                    match=match,
                    meter_id=meter_id,
                    idle_timeout=10)
        self.bandwidth_update_handler()