Пример #1
0
 def test(self, raw):
     inst = SibraOpaqueField()
     data = create_mock(["pop"])
     data.pop.side_effect = bytes(range(4)), "mac"
     raw.return_value = data
     # Call
     inst._parse("data")
     # Tests
     raw.assert_called_once_with("data", inst.NAME, inst.LEN)
     ntools.eq_(inst.ingress, 0x0001)
     ntools.eq_(inst.egress, 0x0203)
     ntools.eq_(inst.mac, "mac")
Пример #2
0
 def test_steady_no_prev(self, cbcmac):
     inst = SibraOpaqueField()
     inst.ingress = 0x1111
     inst.egress = 0xFFFF
     cbcmac.return_value = "cbcmac"
     info = create_mock(["LEN", "pack"])
     info.LEN = 8
     info.pack.return_value = b"packinfo"
     # Call
     ntools.eq_(inst.calc_mac(info, "key", [b"path id0"]), "cbcm")
     # Tests
     cbcmac.assert_called_once_with("key", b"".join([
         bytes.fromhex("1111 FFFF"), b"packinfo", b"path id0",
         bytes(inst.MAX_PATH_IDS_LEN - 8), bytes(8),
         bytes(inst.MAC_BLOCK_PADDING),
     ]))
Пример #3
0
 def test_ephemeral_prev(self, cbcmac):
     inst = SibraOpaqueField()
     inst.ingress = 0x1111
     inst.egress = 0xFFFF
     cbcmac.return_value = "cbcmac"
     info = create_mock(["LEN", "pack"])
     info.LEN = 8
     info.pack.return_value = b"packinfo"
     path_ids = b"steadyid", b"ephemeralpath id"
     prev_raw = b"deadbeef"
     # Call
     ntools.eq_(inst.calc_mac(info, "key", path_ids, prev_raw), "cbcm")
     # Tests
     cbcmac.assert_called_once_with("key", b"".join([
         bytes.fromhex("1111 FFFF"), b"packinfo",
         b"steadyid", b"ephemeralpath id", bytes(inst.MAX_PATH_IDS_LEN - 24),
         prev_raw, bytes(inst.MAC_BLOCK_PADDING),
     ]))
Пример #4
0
 def add_hop(self, ingress, egress, prev_raw, key, path_ids):
     """
     Add a SIBRA Opaque Field to the reservation block. This happens when a
     request has been accepted by a hop on the path.
     """
     assert len(self.sofs) + 1 <= self.num_hops
     sof = SibraOpaqueField.from_values(ingress, egress)
     sof.mac = sof.calc_mac(self.info, key, path_ids, prev_raw)
     self.sofs.append(sof)
Пример #5
0
 def _parse(self, raw):
     data = Raw(raw, self.NAME, self.MIN_LEN, min_=True)
     self.info = self.RESVINFO(data.pop(self.RESVINFO.LEN))
     self.num_hops = len(data) // SibraOpaqueField.LEN
     while data:
         raw_sof = data.pop(SibraOpaqueField.LEN)
         if raw_sof == bytes(SibraOpaqueField.LEN):
             break
         self.sofs.append(SibraOpaqueField(raw_sof))
Пример #6
0
 def test(self):
     inst = SibraOpaqueField()
     inst.ingress = 0x0001
     inst.egress = 0x0203
     inst.mac = b"mac"
     # Call
     ntools.eq_(inst.pack(), bytes(range(4)) + b"mac")
Пример #7
0
 def sof(self, idx):
     return SibraOpaqueField(self.p.sofs[idx])