コード例 #1
0
ファイル: pcb_ext.py プロジェクト: Oncilla/scion-detached
class SibraPCBExt(Cerealizable):  # pragma: no cover
    """
    SIBRA PCB extension. Used to attach reservation info to a PathSegment when
    registering a SIBRA steady path.
    """
    NAME = "SibraPCBExt"
    P_CLS = P.SibraPCBExt

    def __init__(self, p):
        super().__init__(p)
        self.info = ResvInfoSteady(p.info)

    @classmethod
    def from_values(cls, id_, info, sofs, up=True):
        p = cls.P_CLS.new_message(id=id_, info=info.pack(), up=up)
        p.init("sofs", len(sofs))
        for i, sof in enumerate(sofs):
            p.sofs[i] = sof.pack()
        return cls(p)

    def isd_as(self):
        return ISD_AS(self.p.id[:ISD_AS.LEN])

    def sof(self, idx):
        return SibraOpaqueField(self.p.sofs[idx])

    def iter_sofs(self, start=0):
        for i in range(start, len(self.p.sofs)):
            yield self.sof(i)

    def exp_ts(self):
        return self.info.exp_ts()

    def sig_pack(self, ver):
        b = []
        if ver >= 2:
            b.append(self.p.info)
            b.append(self.p.up.to_bytes(1, 'big'))
            for sof in self.p.sofs:
                b.append(sof)
        return b"".join(b)

    def __str__(self):
        a = []
        a.append(self.short_desc())
        for sof in self.iter_sofs():
            a.append("  %s" % sof)
        return "\n".join(a)

    def short_desc(self):
        a = []
        a.append("%s: id: %s (owner: %s) Up? %s" %
                 (self.NAME, hex_str(self.p.id), self.isd_as(), self.p.up))
        for line in str(self.info).splitlines():
            a.append("  %s" % line)
        return "\n".join(a)
コード例 #2
0
ファイル: steady.py プロジェクト: forstern/scion
 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)
コード例 #3
0
ファイル: pcb_ext.py プロジェクト: stschwar/scion
 def __init__(self, p):
     super().__init__(p)
     self.info = ResvInfoSteady(p.info)
コード例 #4
0
class SibraPCBExt(Cerealizable):  # pragma: no cover
    """
    SIBRA PCB extension. Used to attach reservation info to a PathSegment when
    registering a SIBRA steady path.
    """
    NAME = "SibraPCBExt"
    P_CLS = P.SibraPCBExt
    VER = len(P_CLS.schema.fields) - 1

    def __init__(self, p):
        super().__init__(p)
        self.info = ResvInfoSteady(p.info)

    @classmethod
    def from_values(cls, id_, info, sofs, cons_dir=False):
        p = cls.P_CLS.new_message(id=id_, info=info.pack(), cons_dir=cons_dir)
        p.init("sofs", len(sofs))
        for i, sof in enumerate(sofs):
            p.sofs[i] = sof.pack()
        return cls(p)

    def isd_as(self):
        return ISD_AS(self.p.id[:ISD_AS.LEN])

    def sof(self, idx):
        return SibraOpaqueField(self.p.sofs[idx])

    def iter_sofs(self, start=0):
        for i in range(start, len(self.p.sofs)):
            yield self.sof(i)

    def exp_ts(self):
        return self.info.exp_ts()

    def sig_pack3(self):
        """
        Pack for signing version 3 (defined by highest field number).
        """
        if self.VER != 3:
            raise SCIONSigVerError(
                "SibraPCBExt.sig_pack3 cannot support version %s", self.VER)
        b = []
        b.append(self.p.id)
        b.append(self.p.info)
        b.append(self.p.cons_dir.to_bytes(1, 'big'))
        for sof in self.p.sofs:
            b.append(sof)
        return b"".join(b)

    def __str__(self):
        a = []
        a.append(self.short_desc())
        for sof in self.iter_sofs():
            a.append("  %s" % sof)
        return "\n".join(a)

    def short_desc(self):
        a = []
        a.append("%s: id: %s (owner: %s) ConsDir? %s" %
                 (self.NAME, hex_str(self.p.id), self.isd_as(), self.p.cons_dir))
        for line in str(self.info).splitlines():
            a.append("  %s" % line)
        return "\n".join(a)
コード例 #5
0
 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()