Skip to content

Commit

Permalink
[WIP] Refactor RateMon for RWND project
Browse files Browse the repository at this point in the history
  • Loading branch information
ccanel committed Mar 10, 2024
1 parent fd8ac8e commit fe1152a
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 278 deletions.
2 changes: 1 addition & 1 deletion ratemon/model/loss_event_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class LossTracker:
def __init__(self, flow, window_sizes=[8]):
assert window_sizes, "Must specific window_sizes."
assert window_sizes, "Must specify window_sizes."
self.flow = flow
self.window_sizes = window_sizes
self.largest_window = max(self.window_sizes)
Expand Down
12 changes: 12 additions & 0 deletions ratemon/model/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,18 @@ def predict(self, dat_in):
raise NotImplementedError("ServicePolicyModel does not support prediction.")


class VoidModel:
"""An empty model. Used to maintain API compatibility."""

# win_size = 8

in_spc = ()

def predict(self, dat_in):
"""Predicts the fairness of a flow."""
raise NotImplementedError("VoidModel does not support prediction.")


#################################################################
# Old models. Present for archival purposes only. These are not #
# guaranteed to function. #
Expand Down
5 changes: 4 additions & 1 deletion ratemon/runtime/flow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def __init__(self, fourtuple, loss_event_windows, start_time_us):
self.latest_time_sec = time.time()
self.label = defaults.Class.NEAR_TARGET
self.decision = (defaults.Decision.NOT_PACED, None)
self.loss_tracker = loss_event_rate.LossTracker(self, loss_event_windows)
if loss_event_windows:
self.loss_tracker = loss_event_rate.LossTracker(self, loss_event_windows)
else:
self.loss_tracker = None

def __str__(self):
"""Create a string representation of this flow."""
Expand Down
21 changes: 19 additions & 2 deletions ratemon/runtime/policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enum import IntEnum
import logging

from ratemon.model import features, utils, defaults
from ratemon.model import defaults, models, features, utils
from ratemon.runtime import reaction_strategy


Expand Down Expand Up @@ -55,6 +55,23 @@ def choices():
return [to_str(policy) for policy in POLICIES]


def get_model_for_policy(policy, model_file):
if policy == Policy.NOPOLICY:
model = models.VoidModel()
elif policy == Policy.SERVICEPOLICY:
model = models.ServicePolicyModel()
elif policy == Policy.FLOWPOLICY:
assert model_file is not None
model = models.load_model(model_file)
elif policy == Policy.STATIC_RWND:
model = models.VoidModel()
elif policy == Policy.SCHEDULED_RWND:
model = models.VoidModel()
else:
raise RuntimeError(f"Unknown policy: {to_str(policy)}")
return model


def make_decision(
policy,
flowkeys,
Expand Down Expand Up @@ -296,5 +313,5 @@ def make_decision_staticrwnd(schedule):
return (
defaults.Decision.PACED,
None,
reaction_strategy.get_scheduled_pacing(schedule),
reaction_strategy.get_static_rwnd(schedule),
)
8 changes: 2 additions & 6 deletions ratemon/runtime/policy_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ def signal_handler(sig, frame):
def main_loop(args, flow_to_rwnd, que, flags, done):
"""Receive packets and run evaluate the policy on them."""
logging.info("Loading model: %s", args.model_file)
net = (
models.ServicePolicyModel()
if args.policy == Policy.SERVICEPOLICY
else models.load_model(args.model_file)
)
net = policies.get_model_for_policy(args.policy, args.model_file)
logging.info("Model features:\n\t%s", "\n\t".join(net.in_spc))
flow_to_prev_features = {}
# Maps flowkey to (decision, desired throughput, corresponding RWND)
Expand Down Expand Up @@ -378,8 +374,8 @@ def batch_eval(
all_fets,
smooth(flw_labels),
flow_to_decisions,
args.schedule,
args.reaction_strategy,
args.schedule,
)
if new_decision is not None:
for flowkey in flowkeys:
Expand Down
Loading

0 comments on commit fe1152a

Please sign in to comment.