ecklm / adaptive-network-slicing

Project holding the implementation and results of my thesis project at University of Trento, Italy
20 stars 5 forks source link

Controller: Integrate some configuration parser #4

Closed ecklm closed 4 years ago

ecklm commented 4 years ago

A config file format should be selected and its parsing implemented in the controller. Preferably YAML or INI.

As a first step, extract parameters such as time_step, QoSManager.LIMIT_STEP and others which do not require touching the internals of classes.

ecklm commented 4 years ago

Check out config file formats support for python3

ecklm commented 4 years ago
ecklm commented 4 years ago

PyYaml object creation should not be used as it can create non-conforming objects with the same class name enabling mistyped names in the config. See how the mix of udp_dst and upd_dst in the output gets parsed without any error.

util.py

@dataclass(frozen=True)
class FlowId:
    ipv4_dst: str
    udp_dst: int

    def __repr__(self):
        return self.__str__()

    def __str__(self):
        return str(self.__dict__)

config.yml

---
flows:
  - !!python/object:util.FlowId
    ipv4_dst: 192.0.2.1
    upd_dst: 5001
  - !!python/object:util.FlowId
    ipv4_dst: 192.0.2.2
    udp_dst: 5002
  - !!python/object:util.FlowId
    ipv4_dst: 192.0.2.3
    udp_dst: 5003
  - !!python/object:util.FlowId
    ipv4_dst: 192.0.2.4
    udp_dst: 5004
  - ipv4_dst: 192.0.2.5
    udp_dst: 5005

Python console

>>> import yaml
>>> from yaml import Loader, Dumper
>>> with open('config.yml', 'r') as f:
...     o = yaml.load(f, Loader=Loader)
...     
>>> print(o)
{'flows': [{'ipv4_dst': '192.0.2.1', 'upd_dst': 5001}, {'ipv4_dst': '192.0.2.2', 'udp_dst': 5002}, {'ipv4_dst': '192.0.2.3', 'udp_dst': 5003}, {'ipv4_dst': '192.0.2.4', 'udp_dst': 5004}, {'ipv4_dst': '192.0.2.5', 'udp_dst': 5005}]}