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 _create_info(self, inc=False): """ Create a reservation info block, optionally incrementing the reservation index """ if inc: self._inc_idx() exp_tick = current_tick() + RESV_LEN return ResvInfoSteady.from_values( tick_to_time(exp_tick), bw_cls=self.bw, index=self.idx)
def update_tick(self): """ Perform the tick update steps until the state is updated to the current tick. """ now = current_tick() while self.curr_tick < now: self.curr_tick += 1 self.link.next() self._resv_tick(self.steady) self._resv_tick(self.ephemeral)
def _renew(self): """ Renew the steady path, if needed. """ self._check_timeout() if self._stamp: return self._expire_blocks() latest = self.blocks[-1] if latest.info.exp_tick - current_tick() >= RESV_LEN / 2: # If the latest block covers at least half of RESV_LEN, don't bother # renewing yet. return ext = self._create_ext_use() ext.renew(self._create_info(inc=True)) logging.debug("Sending renewal request:\n%s", ext) pkt = self._create_sibra_pkt(ext) self._stamp = time.time() self.sendq.put(pkt)