Esempio n. 1
0
    def test_flow_stats(self):
        """Check the update method in the GaugeFlowStatsLogger class"""

        # add an ofproto attribute to the datapath
        datapath = create_mock_datapath(0)
        ofp_attr = {'ofproto': ofproto}
        datapath.configure_mock(**ofp_attr)

        # add the datapath as an attribute to the config
        dp_attr = {'dp': datapath}
        self.conf.configure_mock(**dp_attr)

        logger = watcher.GaugeFlowTableLogger(self.conf, '__name__',
                                              mock.Mock())
        logger._running = True
        instructions = [parser.OFPInstructionGotoTable(1)]

        msg = flow_stats_msg(datapath, instructions)
        rcv_time = time.time()
        rcv_time_str = logger._rcv_time(rcv_time)
        logger.update(rcv_time, msg)
        log_str = self.get_file_contents("{}--flowtable--{}.json".format(
            datapath.name, rcv_time_str))

        yaml_dict = yaml_load(
            log_str)['OFPFlowStatsReply']['body'][0]['OFPFlowStats']

        compare_flow_msg(msg, yaml_dict, self)
Esempio n. 2
0
    def verify_vlan_change(self):
        """Change host VLAN, check restart of rules consistent"""
        _, host_port_maps, _ = self.topo.create_port_maps()
        yaml_config = yaml_load(self.CONFIG)
        intf_config = yaml_config['dps'][
            self.topo.switches_by_id[1]]['interfaces']

        for host_i in host_port_maps:
            # Find a host on the second switch
            if 1 in host_port_maps[host_i]:
                port = host_port_maps[host_i][1][0]
                if 'native_vlan' in intf_config[port]:
                    prev_name = intf_config[port]['native_vlan']
                    for v_i in range(self.NUM_VLANS):
                        # Make sure that the new VLAN will be different
                        new_name = self.topo.vlan_name(v_i)
                        if new_name != prev_name:
                            intf_config[port]['native_vlan'] = new_name
                            break
                    else:
                        # Keep on searching for a host VLAN to change
                        continue
                    # Created a different VLAN so now stop searching
                    break

        new_config = yaml_dump(yaml_config)
        self.update_and_revert_config(self.CONFIG, new_config, None)
 def _yaml_parse(config_yaml_str):
     try:
         return yaml_load(config_yaml_str)
     except (TypeError, UnicodeDecodeError, ValueError, ScannerError,
             DuplicateKeyError, ComposerError, ConstructorError,
             ParserError) as err:  # pytype: disable=name-error
         raise _ServerError(f'YAML error: {err}')  # pylint: disable=raise-missing-from
Esempio n. 4
0
 def test_unmirror(self):
     config = yaml_load(self.CONFIG)
     del config['dps']['s1']['interfaces']['p5']['mirror']
     self.update_config(yaml_dump(config), reload_type='warm')
Esempio n. 5
0
 def test_hard(self):
     config = yaml_load(self.CONFIG)
     config['dps']['s1']['interfaces']['p1']['acls_in'] = ['acl2']
     # Changed match conditions require restart.
     self.update_config(yaml_dump(config), reload_type='cold')
Esempio n. 6
0
 def test_soft(self):
     config = yaml_load(self.CONFIG)
     config['dps']['s1']['interfaces']['p1']['acls_in'] = ['acl2']
     # We changed match conditions only, so this can be a warm start.
     self.update_config(yaml_dump(config), reload_type='warm')