def test(self): inst = LinkBandwidth("owner", BWSnapshot(100, 100)) for i, bw in enumerate([50, 0, -10, -20, 0, 0, -20]): inst.resvs[i] = BWSnapshot(bw, bw) updates = [] for idx, bw in [(0, -10), (1, -10), (2, +10), (6, 10)]: updates.append((idx, BWSnapshot(bw, bw))) # Call inst.update(updates) # Tests for i, bw in enumerate([40, -10, 0, -20, 0, 0, -10]): tick = BWSnapshot(bw, bw) ntools.eq_(inst.resvs[i], tick)
def test(self): inst = SteadyReservation("owner", BWSnapshot(100, 100), "parent") inst.max_bw = BWSnapshot(100, 100) for i, bw in enumerate([50, 0, -10, -20, 0, 0, -20]): inst.child_resvs[i] = BWSnapshot(bw, bw) updates = [] for idx, bw in [(0, -10), (1, -10), (2, +10), (6, 10)]: updates.append((idx, BWSnapshot(bw, bw))) # Call inst.update(updates) # Tests for i, bw in enumerate([40, -10, 0, -20, 0, 0, -10]): tick = BWSnapshot(bw, bw) ntools.eq_(inst.child_resvs[i], tick)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.bw_cls = BWSnapshot(1000 * 1024, 2000 * 1024).to_classes().ceil() self.block = None self.setup_ts = 0 self.setup_tries = 3 self.eph_id = SibraExtEphemeral.mk_path_id(self.addr.isd_as)
def _process_use(self, meta): """ Process a packet using a SIBRA reservation. Update the appropriate usage counters, and determine the next hop. """ bw_used = BWSnapshot(len(meta.spkt) * 8) if not meta.dir_fwd: bw_used.reverse() logging.debug("SIBRA use (Steady? %s)", self.steady) if not meta.state.use(self.path_ids[0], self.active_blocks[self.block_idx].info.index, bw_used, self.steady): return [(RouterFlag.ERROR, "SIBRA packet rejected")] next_ifid = self.get_next_ifid() if next_ifid: return [(RouterFlag.FORWARD, next_ifid)] return [(RouterFlag.DELIVER, )]
def __init__(self, bw, link_name): # pragma: no cover self.curr_tick = current_tick() self.link = LinkBandwidth(link_name, BWSnapshot(bw * 1024, bw * 1024)) self.steady = {} self.pend_steady = {} self.ephemeral = {} self.pend_ephemeral = {} self.pending = {} logging.info("Initialized SibraState: %s", self.link)
def _check(self, old_resvs, resvs, updates, super_init): inst = ReservationBaseTesting("path id", "owner", "parent") inst.parent = create_mock(["update"]) inst.resvs = [] for bw in old_resvs: inst.resvs.append(BWSnapshot(bw * 1024, bw * 1024)) for idx, exp_tick, bw in resvs: inst.order.append(idx) resv = create_mock(["bwsnap", "exp_tick"]) resv.bwsnap = BWSnapshot(bw * 1024, bw * 1024) resv.exp_tick = exp_tick inst.idxes[idx] = resv # Call inst._update(0) # Tests if not updates: ntools.eq_(inst.parent.update.called, False) return parent_updates = [] for idx, bw in updates: parent_updates.append((idx, BWSnapshot(bw * 1024, bw * 1024))) inst.parent.update.assert_called_once_with(parent_updates)
def _steady_add(self, isd_as): seg = self._pick_seg(isd_as) if not seg: del self.dests[isd_as] return ifid = seg.last_hof().ingress_if link_state = self.link_states[ifid] link_type = self.link_types[ifid] # FIXME(kormat): un-hardcode these bandwidths bwsnap = BWSnapshot(500 * 1024, 500 * 1024) steady = SteadyPath(self.addr, self._port, self.sendq, self.signing_key, link_type, link_state, seg, bwsnap) self.dests[isd_as][steady.id] = steady logging.debug("Setting up steady path %s -> %s over %s", self.addr.isd_as, isd_as, seg.short_desc()) steady.setup()
def teardown(self): # pragma: no cover """Shut down the current reservation.""" # FIXME(kormat): not implemented yet in sibra state. req_info = ResvInfoSteady.from_values(0, BWSnapshot(), 0) self.req_block = ResvBlockSteady.from_values(req_info, self.total_hops) self._set_size()