Closed ecklm closed 4 years ago
Check out config file formats support for python3
FlowId
objectsPyYaml 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.
@dataclass(frozen=True)
class FlowId:
ipv4_dst: str
udp_dst: int
def __repr__(self):
return self.__str__()
def __str__(self):
return str(self.__dict__)
---
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
>>> 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}]}
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.