def setUp_with_routing_type3(self): self.routing_nxt = 6 self.routing_size = 6 self.routing_type = 3 self.routing_seg = 2 self.routing_cmpi = 0 self.routing_cmpe = 0 self.routing_adrs = ["2001:db8:dead::1", "2001:db8:dead::2", "2001:db8:dead::3"] self.routing = ipv6.routing_type3( self.routing_nxt, self.routing_size, self.routing_type, self.routing_seg, self.routing_cmpi, self.routing_cmpe, self.routing_adrs) self.ext_hdrs = [self.routing] self.payload_length += len(self.routing) self.nxt = ipv6.routing.TYPE self.ip = ipv6.ipv6( self.version, self.traffic_class, self.flow_label, self.payload_length, self.nxt, self.hop_limit, self.src, self.dst, self.ext_hdrs) self.buf = struct.pack( ipv6.ipv6._PACK_STR, self.v_tc_flow, self.payload_length, self.nxt, self.hop_limit, addrconv.ipv6.text_to_bin(self.src), addrconv.ipv6.text_to_bin(self.dst)) self.buf += self.routing.serialize()
def test_serialize_with_compression(self): nxt = 0 size = 3 type_ = 3 seg = 0 cmpi = 8 cmpe = 8 adrs = ["2001:db8:dead::1", "2001:db8:dead::2", "2001:db8:dead::3"] # calculate pad pad = (8 - ((len(adrs) - 1) * (16 - cmpi) + (16 - cmpe) % 8)) % 8 slice_i = slice(cmpi, 16) slice_e = slice(cmpe, 16) routing = ipv6.routing_type3( nxt, size, type_, seg, cmpi, cmpe, adrs) buf = routing.serialize() form = '!BBBBBB2x8s8s8s' res = struct.unpack_from(form, str(buf)) eq_(nxt, res[0]) eq_(size, res[1]) eq_(type_, res[2]) eq_(seg, res[3]) eq_(cmpi, res[4] >> 4) eq_(cmpe, res[4] & 0xf) eq_(pad, res[5]) eq_(addrconv.ipv6.text_to_bin(adrs[0])[slice_i], res[6]) eq_(addrconv.ipv6.text_to_bin(adrs[1])[slice_i], res[7]) eq_(addrconv.ipv6.text_to_bin(adrs[2])[slice_e], res[8])
def setUp(self): self.nxt = 0 self.size = 6 self.type_ = 3 self.seg = 0 self.cmpi = 0 self.cmpe = 0 self.adrs = ["2001:db8:dead::1", "2001:db8:dead::2", "2001:db8:dead::3"] # calculate pad self.pad = (8 - ((len(self.adrs) - 1) * (16 - self.cmpi) + (16 - self.cmpe) % 8)) % 8 self.routing = ipv6.routing_type3( self.nxt, self.size, self.type_, self.seg, self.cmpi, self.cmpe, self.adrs) self.form = '!BBBBBB2x16s16s16s' self.buf = struct.pack(self.form, self.nxt, self.size, self.type_, self.seg, (self.cmpi << 4) | self.cmpe, self.pad << 4, addrconv.ipv6.text_to_bin(self.adrs[0]), addrconv.ipv6.text_to_bin(self.adrs[1]), addrconv.ipv6.text_to_bin(self.adrs[2]))
def test_serialize_with_compression(self): nxt = 0 size = 3 type_ = 3 seg = 0 cmpi = 8 cmpe = 8 adrs = ["2001:db8:dead::1", "2001:db8:dead::2", "2001:db8:dead::3"] # calculate pad pad = (8 - ((len(adrs) - 1) * (16 - cmpi) + (16 - cmpe) % 8)) % 8 slice_i = slice(cmpi, 16) slice_e = slice(cmpe, 16) routing = ipv6.routing_type3(nxt, size, type_, seg, cmpi, cmpe, adrs) buf = routing.serialize() form = '!BBBBBB2x8s8s8s' res = struct.unpack_from(form, six.binary_type(buf)) eq_(nxt, res[0]) eq_(size, res[1]) eq_(type_, res[2]) eq_(seg, res[3]) eq_(cmpi, res[4] >> 4) eq_(cmpe, res[4] & 0xf) eq_(pad, res[5]) eq_(addrconv.ipv6.text_to_bin(adrs[0])[slice_i], res[6]) eq_(addrconv.ipv6.text_to_bin(adrs[1])[slice_i], res[7]) eq_(addrconv.ipv6.text_to_bin(adrs[2])[slice_e], res[8])
def setUp_with_routing_type3(self): self.routing_nxt = 6 self.routing_size = 6 self.routing_type = 3 self.routing_seg = 2 self.routing_cmpi = 0 self.routing_cmpe = 0 self.routing_adrs = [ "2001:db8:dead::1", "2001:db8:dead::2", "2001:db8:dead::3" ] self.routing = ipv6.routing_type3(self.routing_nxt, self.routing_size, self.routing_type, self.routing_seg, self.routing_cmpi, self.routing_cmpe, self.routing_adrs) self.ext_hdrs = [self.routing] self.payload_length += len(self.routing) self.nxt = ipv6.routing.TYPE self.ip = ipv6.ipv6(self.version, self.traffic_class, self.flow_label, self.payload_length, self.nxt, self.hop_limit, self.src, self.dst, self.ext_hdrs) self.buf = struct.pack(ipv6.ipv6._PACK_STR, self.v_tc_flow, self.payload_length, self.nxt, self.hop_limit, addrconv.ipv6.text_to_bin(self.src), addrconv.ipv6.text_to_bin(self.dst)) self.buf += self.routing.serialize()
def test_default_args(self): hdr = ipv6.routing_type3() buf = hdr.serialize() LOG.info(repr(buf)) res = struct.unpack_from(ipv6.routing_type3._PACK_STR, str(buf)) LOG.info(res) eq_(res[0], 6) eq_(res[1], 0) eq_(res[2], 3) eq_(res[3], 0) eq_(res[4], (0 << 4) | 0) eq_(res[5], 0)
def test_default_args(self): hdr = ipv6.routing_type3() buf = hdr.serialize() LOG.info(repr(buf)) res = struct.unpack_from(ipv6.routing_type3._PACK_STR, six.binary_type(buf)) LOG.info(res) eq_(res[0], 6) eq_(res[1], 0) eq_(res[2], 3) eq_(res[3], 0) eq_(res[4], (0 << 4) | 0) eq_(res[5], 0)
def test_serialize_with_adrs_zero(self): nxt = 0 size = 0 type_ = 3 seg = 0 cmpi = 0 cmpe = 0 adrs = [] # calculate pad pad = (8 - ((len(adrs) - 1) * (16 - cmpi) + (16 - cmpe) % 8)) % 8 routing = ipv6.routing_type3(nxt, size, type_, seg, cmpi, cmpe, pad) buf = routing.serialize() form = '!BBBBBB2x' res = struct.unpack_from(form, six.binary_type(buf)) eq_(nxt, res[0]) eq_(size, res[1]) eq_(type_, res[2]) eq_(seg, res[3]) eq_(cmpi, res[4] >> 4) eq_(cmpe, res[4] & 0xf) eq_(pad, res[5])
def test_serialize_with_adrs_zero(self): nxt = 0 size = 0 type_ = 3 seg = 0 cmpi = 0 cmpe = 0 adrs = [] # calculate pad pad = (8 - ((len(adrs) - 1) * (16 - cmpi) + (16 - cmpe) % 8)) % 8 routing = ipv6.routing_type3( nxt, size, type_, seg, cmpi, cmpe, pad) buf = routing.serialize() form = '!BBBBBB2x' res = struct.unpack_from(form, str(buf)) eq_(nxt, res[0]) eq_(size, res[1]) eq_(type_, res[2]) eq_(seg, res[3]) eq_(cmpi, res[4] >> 4) eq_(cmpe, res[4] & 0xf) eq_(pad, res[5])