Skip to content

Commit a3668ee

Browse files
committed
corrected init delay, defaults, added basic ovn structure
1 parent 2f56eee commit a3668ee

File tree

7 files changed

+111
-9
lines changed

7 files changed

+111
-9
lines changed

deployments/experiments/libp2p/experiment.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,32 +399,38 @@ def parse_args():
399399
parser.add_argument(
400400
"--namespace",
401401
type=str,
402+
default=DEFAULTS["namespace"],
402403
help=f"Kubernetes namespace (default: {DEFAULTS['namespace']})",
403404
)
404405
parser.add_argument(
405406
"--servicename",
406407
type=str,
408+
default=DEFAULTS["servicename"],
407409
help=f"Service name for DNS resolution (default: {DEFAULTS['servicename']})",
408410
)
409411
parser.add_argument(
410412
"--statefulset-name",
411413
type=str,
414+
default=DEFAULTS["statefulset_name"],
412415
help=f"StatefulSet name (default: {DEFAULTS['statefulset_name']})",
413416
)
414417
parser.add_argument(
415418
"--peers",
416419
type=int,
420+
default=DEFAULTS["peers"],
417421
help=f"Number of peers/replicas (default: {DEFAULTS['peers']})",
418422
)
419423
parser.add_argument(
420424
"--muxer",
421425
type=str,
426+
default=DEFAULTS["muxer"],
422427
choices=["mplex", "yamux", "quic"],
423-
help=f"Muxer type (default: {DEFAULTS['muxer']})",
428+
help=f"Muxer type - mplex is only available for nim (default: {DEFAULTS['muxer']})",
424429
)
425430
parser.add_argument(
426431
"--image",
427432
type=str,
433+
default=DEFAULTS["image"],
428434
help=f"Container image for the libp2p test node (default: {DEFAULTS['image']})",
429435
)
430436
parser.add_argument(
@@ -441,11 +447,13 @@ def parse_args():
441447
parser.add_argument(
442448
"--delay-ms",
443449
type=int,
450+
default=DEFAULTS["delay_ms"],
444451
help=f"Average link delay in milliseconds. Applied for --with-delay only (default: {DEFAULTS['delay_ms']})",
445452
)
446453
parser.add_argument(
447454
"--jitter-ms",
448455
type=int,
456+
default=DEFAULTS["jitter_ms"],
449457
help=f"Average jitter in milliseconds. Applied for --with-delay only (default: {DEFAULTS['jitter_ms']})",
450458
)
451459
parser.add_argument(
@@ -456,16 +464,19 @@ def parse_args():
456464
parser.add_argument(
457465
"--num-mix",
458466
type=int,
467+
default=DEFAULTS["num_mix"],
459468
help=f"Number of mix nodes (default: {DEFAULTS['num_mix']})",
460469
)
461470
parser.add_argument(
462471
"--mix-d",
463472
type=int,
473+
default=DEFAULTS["mix_d"],
464474
help=f"Mix tunnel length (default: {DEFAULTS['mix_d']})",
465475
)
466476
parser.add_argument(
467477
"--output-dir",
468478
type=str,
479+
default=DEFAULTS["output_dir"],
469480
help=f"Output directory for YAML files (default: {DEFAULTS['output_dir']})",
470481
)
471482

deployments/libp2p/builders/builders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ class Libp2pStatefulSetBuilder(StatefulSetBuilder):
2121
Usage:
2222
statefulset = (
2323
Libp2pStatefulSetBuilder(StatefulSetConfig())
24-
.with_libp2p_config(name="pod", namespace="refactortesting-libp2p", num_nodes=50)
24+
.with_libp2p_config(name="pod", namespace="zerotesting-nimlibp2p", num_nodes=50)
2525
.with_network_delay(delay_ms=100, jitter_ms=30)
2626
.build()
2727
)
2828
2929
# With mix protocol
3030
statefulset = (
3131
Libp2pStatefulSetBuilder(StatefulSetConfig())
32-
.with_libp2p_config(name="pod", namespace="refactortesting-libp2p", num_nodes=50)
32+
.with_libp2p_config(name="pod", namespace="zerotesting-nimlibp2p", num_nodes=50)
3333
.with_mix(num_mix=50, mix_d=3)
3434
.build()
3535
)
@@ -180,7 +180,7 @@ def with_ovn_config(
180180
return self
181181

182182
def create_mix_pvc(
183-
namespace: str = "refactortesting-libp2p",
183+
namespace: str = "zerotesting-nimlibp2p",
184184
name: str = Mix.DEFAULT_PVC_NAME,
185185
storage_size: str = "1Gi",
186186
storage_class: str = "moosefs-storage",

deployments/libp2p/builders/mix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
def create_mix_pvc(
2525
name: str = DEFAULT_PVC_NAME,
26-
namespace: str = "refactortesting-libp2p",
26+
namespace: str = "zerotesting-nimlibp2p",
2727
storage_size: str = DEFAULT_STORAGE_SIZE,
2828
storage_class: str = DEFAULT_STORAGE_CLASS,
2929
) -> V1PersistentVolumeClaim:

deployments/libp2p/builders/network_delay.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def network_delay_init_container(
1212
:param jitter_ms: Jitter/variation in milliseconds
1313
:param distribution: Distribution types
1414
"""
15-
command = (
15+
tc_command = (
1616
f"tc qdisc add dev eth0 root netem delay {delay_ms}ms {jitter_ms}ms "
1717
f"distribution {distribution}"
1818
)
@@ -26,7 +26,8 @@ def network_delay_init_container(
2626
"add": ["NET_ADMIN"],
2727
},
2828
},
29-
"command": ["sh", "-c", command],
29+
"command": ["sh"],
30+
"args": ["-c", tc_command],
3031
}
3132

3233
def apply_network_delay_pod_spec(

deployments/libp2p/builders/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def get_service_name(self) -> str:
7878
class Nodes:
7979
"""Base configuration for libp2p nodes."""
8080
# Default values
81-
DEFAULT_NAMESPACE = "refactortesting-libp2p"
81+
DEFAULT_NAMESPACE = "zerotesting-nimlibp2p"
8282
DEFAULT_SERVICE_NAME = "nimp2p-service"
8383
DEFAULT_IMAGE = Image(repo="ufarooqstatus/refactored-test-node", tag="v1.0")
8484

deployments/libp2p/builders/ovn.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
from dataclasses import dataclass
2+
from typing import Optional
3+
4+
from core.configs.pod import PodTemplateSpecConfig
5+
from core.configs.statefulset import StatefulSetConfig, StatefulSetSpecConfig
6+
7+
8+
@dataclass
9+
class OvnConfig:
10+
"""OVN configuration for bandwidth shaping and subnet attachment."""
11+
# Bandwidth shaping (in Mbps)
12+
ingress_rate: Optional[int] = None
13+
egress_rate: Optional[int] = None
14+
# Subnet attachment
15+
logical_switch: Optional[str] = None
16+
17+
def to_annotations(self) -> dict:
18+
"""Convert configuration to OVN annotations dict."""
19+
annotations = {}
20+
21+
if self.ingress_rate is not None:
22+
annotations["ovn.kubernetes.io/ingress_rate"] = str(self.ingress_rate)
23+
if self.egress_rate is not None:
24+
annotations["ovn.kubernetes.io/egress_rate"] = str(self.egress_rate)
25+
if self.logical_switch is not None:
26+
annotations["ovn.kubernetes.io/logical_switch"] = self.logical_switch
27+
28+
return annotations
29+
30+
31+
def apply_ovn_pod_template(
32+
config: PodTemplateSpecConfig,
33+
ovn_config: OvnConfig,
34+
):
35+
"""Apply OVN annotations to PodTemplateSpecConfig."""
36+
for key, value in ovn_config.to_annotations().items():
37+
config.with_annotation(key, value, overwrite=True)
38+
39+
40+
def apply_ovn_statefulset_spec(
41+
config: StatefulSetSpecConfig,
42+
ovn_config: OvnConfig,
43+
):
44+
"""Apply OVN annotations to StatefulSetSpecConfig."""
45+
apply_ovn_pod_template(config.pod_template_spec_config, ovn_config)
46+
47+
48+
def apply_ovn_statefulset(
49+
config: StatefulSetConfig,
50+
ovn_config: OvnConfig,
51+
):
52+
"""Apply OVN annotations to StatefulSetConfig."""
53+
apply_ovn_statefulset_spec(config.stateful_set_spec, ovn_config)
54+
55+
56+
#bandwidth configurations
57+
def apply_bandwidth_limit(
58+
config: StatefulSetConfig | StatefulSetSpecConfig | PodTemplateSpecConfig,
59+
ingress_mbps: int,
60+
egress_mbps: Optional[int] = None,
61+
):
62+
if egress_mbps is None:
63+
egress_mbps = ingress_mbps
64+
65+
ovn_config = OvnConfig(ingress_rate=ingress_mbps, egress_rate=egress_mbps)
66+
67+
if isinstance(config, StatefulSetConfig):
68+
apply_ovn_statefulset(config, ovn_config)
69+
elif isinstance(config, StatefulSetSpecConfig):
70+
apply_ovn_statefulset_spec(config, ovn_config)
71+
elif isinstance(config, PodTemplateSpecConfig):
72+
apply_ovn_pod_template(config, ovn_config)
73+
else:
74+
raise TypeError(f"Unsupported config type: {type(config)}")
75+
76+
77+
def apply_logical_switch(
78+
config: StatefulSetConfig | StatefulSetSpecConfig | PodTemplateSpecConfig,
79+
logical_switch: str,
80+
):
81+
ovn_config = OvnConfig(logical_switch=logical_switch)
82+
83+
if isinstance(config, StatefulSetConfig):
84+
apply_ovn_statefulset(config, ovn_config)
85+
elif isinstance(config, StatefulSetSpecConfig):
86+
apply_ovn_statefulset_spec(config, ovn_config)
87+
elif isinstance(config, PodTemplateSpecConfig):
88+
apply_ovn_pod_template(config, ovn_config)
89+
else:
90+
raise TypeError(f"Unsupported config type: {type(config)}")

deployments/libp2p/builders/publisher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def to_args(self) -> List[str]:
4242
class Publisher:
4343

4444
DEFAULT_IMAGE = Image(repo="ufarooqstatus/libp2p-publisher", tag="v1.0")
45-
DEFAULT_NAMESPACE = "refactortesting-libp2p"
45+
DEFAULT_NAMESPACE = "zerotesting-nimlibp2p"
4646
DEFAULT_SERVICE_NAME = "nimp2p-service"
4747

4848
@staticmethod

0 commit comments

Comments
 (0)