Example #1
0
    def __init__(self,
                 ipv6=False,
                 out_dir=GEN_PATH,
                 topo_file=DEFAULT_TOPOLOGY_FILE,
                 path_policy_file=DEFAULT_PATH_POLICY_FILE,
                 zk_config_file=DEFAULT_ZK_CONFIG,
                 network=None,
                 use_mininet=False,
                 bind_addr=GENERATE_BIND_ADDRESS,
                 pseg_ttl=DEFAULT_SEGMENT_TTL,
                 cs=DEFAULT_CERTIFICATE_SERVER):
        """
        Initialize an instance of the class ConfigGenerator.

        :param string out_dir: path to the topology folder.
        :param string topo_file: path to topology config
        :param string path_policy_file: path to PathPolicy.yml
        :param string zk_config_file: path to Zookeeper.yml
        :param string network:
            Network to create subnets in, of the form x.x.x.x/y
        :param bool use_mininet: Use Mininet
        :param int pseg_ttl: The TTL for path segments (in seconds)
        :param string cs: Use go or python implementation of certificate server
        """
        self.ipv6 = ipv6
        self.out_dir = out_dir
        self.topo_config = load_yaml_file(topo_file)
        self.zk_config = load_yaml_file(zk_config_file)
        self.path_policy_file = path_policy_file
        self.mininet = use_mininet
        self.default_mtu = None
        self.gen_bind_addr = bind_addr
        self.pseg_ttl = pseg_ttl
        self._read_defaults(network)
        self.cs = cs
Example #2
0
    def __init__(self,
                 out_dir=GEN_PATH,
                 topo_file=DEFAULT_TOPOLOGY_FILE,
                 path_policy_file=DEFAULT_PATH_POLICY_FILE,
                 zk_config_file=DEFAULT_ZK_CONFIG,
                 network=None,
                 use_mininet=False,
                 router="py"):
        """
        Initialize an instance of the class ConfigGenerator.

        :param string out_dir: path to the topology folder.
        :param string topo_file: path to topology config
        :param string path_policy_file: path to PathPolicy.yml
        :param string zk_config_file: path to Zookeeper.yml
        :param string network:
            Network to create subnets in, of the form x.x.x.x/y
        :param bool use_mininet: Use Mininet
        """
        self.out_dir = out_dir
        self.topo_config = load_yaml_file(topo_file)
        self.zk_config = load_yaml_file(zk_config_file)
        self.path_policy_file = path_policy_file
        self.mininet = use_mininet
        self.default_zookeepers = {}
        self.default_mtu = None
        self.router = router
        self._read_defaults(network)
Example #3
0
    def __init__(self, args):
        """
        Initialize an instance of the class ConfigGenerator.

        :param ConfigGenArgs args: Contains the passed command line arguments.
        """
        self.args = args
        self.topo_config = load_yaml_file(self.args.topo_config)
        self.zk_config = load_yaml_file(self.args.zk_config)
        if self.args.docker and self.args.mininet:
            logging.critical("Cannot use mininet with docker!")
            sys.exit(1)
        self.default_mtu = None
        self._read_defaults(self.args.network)
        self.port_gen = PortGenerator()
Example #4
0
    def from_file(cls, topology_file):  # pragma: no cover
        """
        Create a Topology instance from the file.

        :param str topology_file: path to the topology file
        """
        return cls.from_dict(load_yaml_file(topology_file))
Example #5
0
    def from_file(policy_file):  # pragma: no cover
        """
        Create a PathPolicy instance from the file.

        :param str policy_file: path to the path policy file
        """
        return PathPolicy.from_dict(load_yaml_file(policy_file))
Example #6
0
    def from_file(cls, config_file):  # pragma: no cover
        """
        Create a Config instance from the configuration file.

        :param str config_file: path to the configuration file
        :returns: the newly created Config instance
        :rtype: :class:`Config`
        """
        return cls.from_dict(load_yaml_file(config_file))
Example #7
0
def _load_as_list():
    as_dict = load_yaml_file(os.path.join(GEN_PATH, AS_LIST_FILE))
    as_list = []
    for as_str in as_dict.get("Non-core", []) + as_dict.get("Core", []):
        as_list.append(ISD_AS(as_str))
    return as_list
Example #8
0
def generate(name: Optional[str], input_file_path: Path, workdir: Path,
             sc: Path, dc: docker.DockerClient) -> Topology:
    """Generate a SCION topology from a topology definition.

    :param name: Optional name for the network. This name is used as a prefix for all Docker
                 objects and OVS bridges.
    :param input_file_path: Path to the topology definition file (YAML format).
    :param workdir: Directory in which the output files are written.
    :param sc: Path to the root of the SCION source tree.
    :param dc: Docker client object connected to the local Docker daemon.
    """
    # Process the topology file.
    topo_file = load_yaml_file(input_file_path)
    topo = extract_topo_info(topo_file, name)
    if topo.coordinator is None:
        # Create a topology file to be read by 'scion.sh topology'.
        processed_topo_file_path = workdir.joinpath(const.PROCESSED_TOPO_FILE)
        with open(processed_topo_file_path, 'w') as f:
            f.write(yaml.dump(topo_file))
        log.info("Wrote processed topology file to '%s'.",
                 processed_topo_file_path)

    # Assign IP addresses in the coordinator network
    if topo.coordinator is not None:
        addr_alloc.assign_coord_ip_addresses(topo)

    # Assign BR interface IP addresses
    addr_alloc.check_subnet_overlap(topo)
    addr_alloc.assign_underlay_addresses(topo)

    # Make sure SCION images exists
    try:
        dc.images.get(const.SCION_BASE_IMG_NAME)
    except docker.errors.ImageNotFound:
        # Make sure the scion user in the container has the same UID and GID as the user on the
        # host, so volumes mounted from the host work properly. Since UID and GID are set when the
        # image is created, mounting volumes on another host requires fixing permissions when
        # containers are created.
        # Assigning the same GID to the 'docker' group as on the host allows the container to access
        # the host's Docker daemon without sudo (by mounting '/var/run/docker.sock').
        build_args = {
            'SCION_UID': str(os.getuid()),
            'SCION_GID': str(os.getgid()),
            'DOCKER_GID': _get_gid(topo.hosts['localhost'], "docker")
        }
        _build_docker_image(const.SCION_BASE_IMG_NAME, "docker/scion_base", dc,
                            build_args)

    build_args = {'BASE_IMAGE': const.SCION_BASE_IMG_NAME}
    _build_docker_image(const.AS_IMG_NAME, "docker/as", dc, build_args)
    if topo.coordinator is None:
        _build_standalone_topology(topo, sc, workdir, dc)
    else:
        if topo.coordinator.debug:
            _build_docker_image(const.COORD_IMG_NAME, "docker/coordinator", dc)
        _generate_coord_ssh_keys(topo, workdir)

    if topo.coordinator is None:
        # Modify topology.json files and create mount folder for all AS containers.
        gen_path = workdir.joinpath(const.MASTER_CNTR_MOUNT, "gen")
        gen_dir.modify_topo_files(gen_path, topo)
        gen_dir.modify_sciond_address(gen_path, topo)
        gen_dir.create_as_mount_dirs(workdir, topo)
    else:
        # Create mount folders for local ASes.
        # The AS configuration is downloaded from the coordinator when the containers are created.
        gen_dir.create_as_mount_dirs_coord(workdir, topo)
    log.info("Created mount folders.")

    return topo