Commit fba7164d authored by Antoine Kaufmann's avatar Antoine Kaufmann Committed by Antoine Kaufmann
Browse files

experiments: use exceptions instead of sys.exit in e2e_components

parent f82b5198
...@@ -27,8 +27,6 @@ import typing as tp ...@@ -27,8 +27,6 @@ import typing as tp
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from enum import Enum from enum import Enum
import sys
class CongestionControl(Enum): class CongestionControl(Enum):
RENO = ("ns3::TcpLinuxReno", "reno") RENO = ("ns3::TcpLinuxReno", "reno")
...@@ -59,8 +57,8 @@ class CongestionControl(Enum): ...@@ -59,8 +57,8 @@ class CongestionControl(Enum):
@property @property
def ns3(self): def ns3(self):
if self.ns3_str == "": if self.ns3_str == "":
print(f"There is no ns3 implementation for {self.name} available") raise AttributeError(f"There is no ns3 implementation for "
sys.exit(1) f"{self.name} available")
return self.ns3_str return self.ns3_str
@property @property
...@@ -118,8 +116,7 @@ class E2EGlobalConfig(E2EBase): ...@@ -118,8 +116,7 @@ class E2EGlobalConfig(E2EBase):
return super().ns3_config() return super().ns3_config()
def add_component(self, component: E2EComponent) -> None: def add_component(self, component: E2EComponent) -> None:
print("Can't add a component to the global config") raise AttributeError("Can't add a component to the global config")
sys.exit(1)
class E2EComponent(E2EBase): class E2EComponent(E2EBase):
...@@ -132,8 +129,7 @@ class E2EComponent(E2EBase): ...@@ -132,8 +129,7 @@ class E2EComponent(E2EBase):
def ns3_config(self) -> str: def ns3_config(self) -> str:
if self.id == "" or self.type == "": if self.id == "" or self.type == "":
print("Id or Type cannot be empty") raise AttributeError("Id or Type cannot be empty")
sys.exit(1)
self.mapping.update({"Id": self.id, "Type": self.type}) self.mapping.update({"Id": self.id, "Type": self.type})
return super().ns3_config() return super().ns3_config()
...@@ -144,13 +140,14 @@ class E2EComponent(E2EBase): ...@@ -144,13 +140,14 @@ class E2EComponent(E2EBase):
def resolve_paths(self) -> None: def resolve_paths(self) -> None:
self.has_path = True self.has_path = True
for component in self.components: for component in self.components:
path = f"{self.id}/{component.id}"
if component.has_path: if component.has_path:
print( raise AttributeError(
f"Component {component.id} was already " + f"Component {component.id} was already "
"added to another component" f"added to another component (while trying "
f"to assign {path})."
) )
sys.exit(1) component.id = path
component.id = f"{self.id}/{component.id}"
component.resolve_paths() component.resolve_paths()
...@@ -196,8 +193,7 @@ class E2ESimpleChannel(E2ETopologyChannel): ...@@ -196,8 +193,7 @@ class E2ESimpleChannel(E2ETopologyChannel):
def ns3_config(self) -> str: def ns3_config(self) -> str:
if self.left_node is None or self.right_node is None: if self.left_node is None or self.right_node is None:
print(f"Not all nodes for channel {self.id} given") raise AttributeError(f"Not all nodes for channel {self.id} given")
sys.exit(1)
self.mapping.update({ self.mapping.update({
"DataRate": self.data_rate, "DataRate": self.data_rate,
"QueueSize": self.queue_size, "QueueSize": self.queue_size,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment