Exemplo n.º 1
0
    def initialize_dataplane(self):
        "Read the config file and update the queued policy variable"

        self.logger.info("Initializing inbound rules")

        final_switch = "main-in"
        if self.cfg.isMultiTableMode():
            final_switch = "main-out"

        self.init_vnh_assignment()

        rule_msgs = init_inbound_rules(self.id, self.policies, self.supersets,
                                       final_switch)
        self.logger.debug("Rule Messages INBOUND:: " + json.dumps(rule_msgs))

        rule_msgs2 = init_outbound_rules(self, self.id, self.policies,
                                         self.supersets, final_switch)
        self.logger.debug("Rule Messages OUTBOUND:: " + json.dumps(rule_msgs2))

        if 'changes' in rule_msgs2:
            if 'changes' not in rule_msgs:
                rule_msgs['changes'] = []
            rule_msgs['changes'] += rule_msgs2['changes']

        #TODO: Initialize Outbound Policies from RIB
        self.logger.debug("Rule Messages:: " + json.dumps(rule_msgs))
        if 'changes' in rule_msgs:
            self.dp_queued.extend(rule_msgs["changes"])
Exemplo n.º 2
0
    def initialize_dataplane(self):
        "Read the config file and update the queued policy variable"

        self.logger.info("Initializing inbound rules")

        final_switch = "main-in"
        if self.cfg.isMultiTableMode():
            final_switch = "main-out"

        self.init_vnh_assignment()

        rule_msgs = init_inbound_rules(self.id, self.policies,
                                        self.supersets, final_switch)
        self.logger.debug("Rule Messages INBOUND:: "+str(rule_msgs))

        rule_msgs2 = init_outbound_rules(self, self.id, self.policies,
                                        self.supersets, final_switch)
        self.logger.debug("Rule Messages OUTBOUND:: "+str(rule_msgs2))

        if 'changes' in rule_msgs2:
            if 'changes' not in rule_msgs:
                rule_msgs['changes'] = []
            rule_msgs['changes'] += rule_msgs2['changes']

        #TODO: Initialize Outbound Policies from RIB
        self.logger.debug("Rule Messages:: "+str(rule_msgs))
        if 'changes' in rule_msgs:
            self.dp_queued.extend(rule_msgs["changes"])
Exemplo n.º 3
0
    def process_policy_changes(self, change_info, mod_type):
        # idea to remove flow rules for the old policies with cookies
        '''
        removal_msgs = []
        for element in change_info:

            if 'removal_cookies' in element:
        
                for cookie in element['removal_cookies']:
                    cookie_id = (cookie['cookie'],65535)
                    match_args = cookie['match']
                    mod =  {"rule_type":"inbound", "priority":4,"match":{} , "action":{}, "cookie":cookie_id, "mod_type":"remove"}
                    removal_msgs.append(mod)
        
        self.dp_queued.extend(removal_msgs)
        '''

        # json file format for change_info - mod_type = remove or insert
        '''
        {
            "policy": [
            {
                mod_type: [ 
        
        # change_info begin

                    {
                        "inbound": [
                            { cookie1 ... match ... action }
                            { cookie2 ... match ... action }
                        ]
                    }

                    {
                        "outbound": [
                            { cookie1 ... match ... action }
                            { cookie2 ... match ... action }
                        ]
                    }

        # change_info end
                
                ]           // end mod_type-array
            }, 
            
            {
                mod_type: ...

            }

            ]               // end policy-array
        }
        '''

        policies = self.sanitize_policies(change_info)

        final_switch = "main-in"
        if self.cfg.isMultiTableMode():
            final_switch = "main-out"

        #self.init_vnh_assignment() // not used
        inbound_policies = {}
        outbound_policies = {}

        for element in policies:
            if 'inbound' in element:
                inbound_policies = element
            if 'outbound' in element:
                outbound_policies = element

        #self.logger.debug("PART_Test: INBOUND: %s" % inbound_policies)
        #self.logger.debug("PART_Test: OUTBOUND: %s" % outbound_policies)

        rule_msgs = init_inbound_rules(self.id, inbound_policies,
                                       self.supersets, final_switch)

        rule_msgs2 = init_outbound_rules(self, self.id, outbound_policies,
                                         self.supersets, final_switch)

        if 'changes' in rule_msgs2:
            if 'changes' not in rule_msgs:
                rule_msgs['changes'] = []
            rule_msgs['changes'] += rule_msgs2['changes']

        for rule in rule_msgs['changes']:
            rule['mod_type'] = mod_type

        #self.logger.debug("PART_Test: Rule Msgs: %s" % rule_msgs)

        if 'changes' in rule_msgs:
            self.dp_queued.extend(rule_msgs["changes"])

        self.push_dp()
    def process_policy_changes(self, change_info, mod_type):
        # idea to remove flow rules for the old policies with cookies
        '''
        removal_msgs = []
        for element in change_info:

            if 'removal_cookies' in element:
        
                for cookie in element['removal_cookies']:
                    cookie_id = (cookie['cookie'],65535)
                    match_args = cookie['match']
                    mod =  {"rule_type":"inbound", "priority":4,"match":{} , "action":{}, "cookie":cookie_id, "mod_type":"remove"}
                    removal_msgs.append(mod)
        
        self.dp_queued.extend(removal_msgs)
        '''

        # json file format for change_info - mod_type = remove or insert
        '''
        {
            "policy": [
            {
                mod_type: [ 
        
        # change_info begin

                    {
                        "inbound": [
                            { cookie1 ... match ... action }
                            { cookie2 ... match ... action }
                        ]
                    }

                    {
                        "outbound": [
                            { cookie1 ... match ... action }
                            { cookie2 ... match ... action }
                        ]
                    }

        # change_info end
                
                ]           // end mod_type-array
            }, 
            
            {
                mod_type: ...

            }

            ]               // end policy-array
        }
        '''

        policies = self.sanitize_policies(change_info)

        final_switch = "main-in"
        if self.cfg.isMultiTableMode():
            final_switch = "main-out"

        #self.init_vnh_assignment() // not used
        inbound_policies = {}
        outbound_policies = {}
        
        for element in policies:
            if 'inbound' in element:
                inbound_policies = element
            if 'outbound' in element:
                outbound_policies = element

        #self.logger.debug("PART_Test: INBOUND: %s" % inbound_policies)
        #self.logger.debug("PART_Test: OUTBOUND: %s" % outbound_policies)

        rule_msgs = init_inbound_rules(self.id, inbound_policies,
                                        self.supersets, final_switch)

        rule_msgs2 = init_outbound_rules(self, self.id, outbound_policies,
                                        self.supersets, final_switch)

        if 'changes' in rule_msgs2:
            if 'changes' not in rule_msgs:
                rule_msgs['changes'] = []
            rule_msgs['changes'] += rule_msgs2['changes']


        for rule in rule_msgs['changes']:
            rule['mod_type'] = mod_type


        #self.logger.debug("PART_Test: Rule Msgs: %s" % rule_msgs)

        if 'changes' in rule_msgs:
            self.dp_queued.extend(rule_msgs["changes"])

        self.push_dp()