예제 #1
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)
예제 #2
0
 def del_dp_interfaces():
     config_filename = self.default_config
     config_yaml = self._get_config_file(config_filename)
     for dp_info in request.interfaces_config:
         dp_port_nos = set()
         dp_interfaces = config_yaml['dps'][dp_info.name]['interfaces']
         for interface_info in dp_info.interfaces:
             try:
                 del dp_interfaces[interface_info.port_no]
                 dp_port_nos.add(interface_info.port_no)
             except KeyError:
                 continue
         # second pass to clean up any mirroring
         for interface in dp_interfaces:
             port_mirror = set(dp_interfaces[interface].get(
                 'mirror', []))
             if port_mirror:
                 dp_interfaces[interface]['mirror'] = list(port_mirror -
                                                           dp_port_nos)
     if request.delete_empty_dp:
         for dp_info in request.interfaces_config:
             try:
                 if not dp_interfaces:
                     self._del_dp(dp_info.name, config_yaml)
             except KeyError:
                 continue
     self._set_config_file(config_filename, yaml_dump(config_yaml),
                           False, [])
     return default_reply
예제 #3
0
 def del_dps():
     config_filename = self.default_config
     config_yaml = self._get_config_file(config_filename)
     for dp_request in request.interfaces_config:
         self._del_dp(dp_request.name, config_yaml)
     self._set_config_file(config_filename, yaml_dump(config_yaml),
                           False, [])
     return default_reply
예제 #4
0
 def _set_copro(self, config_filename, request):
     config_yaml = self._get_config_file(config_filename)
     interfaces = config_yaml['dps'][request.dp_name]['interfaces']
     interfaces[request.port_no] = {
         'description': request.description,
         'coprocessor': {
             'strategy': request.strategy
         }
     }
     self._set_config_file(config_filename, yaml_dump(config_yaml), False,
                           [])
예제 #5
0
 def set_dp_interfaces():
     config_filename = self.default_config
     config_yaml = self._get_config_file(config_filename)
     for dp_request in request.interfaces_config:
         interfaces = config_yaml['dps'][
             dp_request.dp_name]['interfaces']
         for interface_request in dp_request.interface_config:
             interfaces[interface_request.port_no] = self._yaml_parse(
                 interface_request.config_yaml)
     self._set_config_file(config_filename, yaml_dump(config_yaml),
                           False, [])
     return default_reply
예제 #6
0
 def _replace_config_file(self,
                          config_filename,
                          config_yaml,
                          config_dir=None):
     if config_dir is None:
         config_dir = self.config_dir
     config_filename = self._validate_filename(config_filename)
     with tempfile.NamedTemporaryFile(mode='wt',
                                      dir=config_dir,
                                      delete=False) as new_file:
         new_file_name = new_file.name
         new_file.write(yaml_dump(config_yaml))
     os.rename(new_file_name, os.path.join(config_dir, config_filename))
예제 #7
0
 def set_dps():
     config_filename = self.default_config
     config_yaml = self._get_config_file(config_filename)
     existing_dp_ids = {
         dp['dp_id']
         for dp in config_yaml['dps'].values()
     }
     for dp_request in request.dp_config:
         dp_config_yaml = self._yaml_parse(dp_request.config_yaml)
         while not 'dp_id' in dp_config_yaml:
             new_dp_id = random.randint(1, 2**64 - 1)
             if new_dp_id not in existing_dp_ids:
                 dp_config_yaml['dp_id'] = new_dp_id
         config_yaml['dps'][dp_request.dp_name] = dp_config_yaml
     self._set_config_file(config_filename, yaml_dump(config_yaml),
                           False, [])
     return default_reply
예제 #8
0
 def set_remote_mirror_port():
     config_filename = self.default_config
     config_yaml = self._get_config_file(config_filename)
     config_yaml.setdefault('acls', {})
     acl_name = f'remote-mirror-{request.tunnel_vid}-{request.remote_dp_name}' \
                f'-{request.remote_port_no}'
     config_yaml['acls'][acl_name] = make_acl([
         {
             'vlan_vid': request.tunnel_vid,
             'actions': {
                 'allow': 0
             }
         },
         {
             'actions': {
                 'allow': 0,
                 'output': {
                     'tunnel': {
                         'dp': request.remote_dp_name,
                         'port': request.remote_port_no,
                         'tunnel_id': request.tunnel_vid,
                         'type': 'vlan'
                     }
                 }
             }
         },
     ])
     dp = config_yaml['dps'][request.dp_name]  # pylint: disable=invalid-name
     dp['interfaces'][request.port_no] = {
         'acls_in': [acl_name],
         'coprocessor': {
             'strategy': 'vlan_vid',
         },
         'description': 'loopback'
     }
     self._set_config_file(config_filename, yaml_dump(config_yaml),
                           False, [])
     return default_reply
예제 #9
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')
예제 #10
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')
예제 #11
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')
예제 #12
0
 def get_config_file():
     config_filename = request.config_filename
     if not config_filename:
         config_filename = self.default_config
     return faucetconfrpc_pb2.GetConfigFileReply(
         config_yaml=yaml_dump(self._get_config_file(config_filename)))