@Test
  public void deserialize__Bits() throws Exception {
    Rloc address =
        LispAddressSerializer.getInstance()
            .deserializeRloc(
                hexToByteBuffer(
                    "40 03 00 00 "
                        + //
                        "0A 00 00 10 "
                        + //
                        "00 05 00 01 AA BB CC DD "
                        + // IPv4
                        "00 02 00 01 11 22 33 44")); // IPv4

    assertEquals(ExplicitLocatorPathLcaf.class, address.getAddressType());
    ExplicitLocatorPath elp = (ExplicitLocatorPath) address.getAddress();

    List<Hop> hops = elp.getExplicitLocatorPath().getHop();
    assertEquals(2, hops.size());

    assertEquals("170.187.204.221", String.valueOf(hops.get(0).getAddress().getValue()));
    assertEquals(true, hops.get(0).getLrsBits().isLookup().booleanValue());
    assertEquals(false, hops.get(0).getLrsBits().isRlocProbe().booleanValue());
    assertEquals(true, hops.get(0).getLrsBits().isStrict().booleanValue());
    assertEquals("17.34.51.68", String.valueOf(hops.get(1).getAddress().getValue()));
    assertEquals(false, hops.get(1).getLrsBits().isLookup().booleanValue());
    assertEquals(true, hops.get(1).getLrsBits().isRlocProbe().booleanValue());
    assertEquals(false, hops.get(1).getLrsBits().isStrict().booleanValue());
  }
  @Test
  public void deserialize__NoAddresses() throws Exception {
    Rloc address =
        LispAddressSerializer.getInstance()
            .deserializeRloc(
                hexToByteBuffer(
                    "40 03 00 00 "
                        + //
                        "0A 00 00 00 "));

    assertEquals(ExplicitLocatorPathLcaf.class, address.getAddressType());
    ExplicitLocatorPath elp = (ExplicitLocatorPath) address.getAddress();

    List<Hop> hops = elp.getExplicitLocatorPath().getHop();
    assertEquals(0, hops.size());
  }
Ejemplo n.º 3
0
  private MappingRecord updateServicePathMappingRecord(MappingRecord mapping, Eid eid) {
    // keep properties of original record
    MappingRecordBuilder recordBuilder = new MappingRecordBuilder(mapping);
    recordBuilder.setLocatorRecord(new ArrayList<LocatorRecord>());

    // there should only be one locator record
    if (mapping.getLocatorRecord().size() != 1) {
      LOG.warn("MappingRecord associated to ServicePath EID has more than one locator!");
      return mapping;
    }

    LocatorRecord locatorRecord = mapping.getLocatorRecord().get(0);
    long serviceIndex = ((ServicePath) eid.getAddress()).getServicePath().getServiceIndex();
    int index = LispAddressUtil.STARTING_SERVICE_INDEX - (int) serviceIndex;
    Rloc rloc = locatorRecord.getRloc();
    if (rloc.getAddress() instanceof Ipv4 || rloc.getAddress() instanceof Ipv6) {
      if (index != 0) {
        LOG.warn("Service Index should be 255 for simple IP RLOCs!");
      }
      return mapping;
    } else if (rloc.getAddress() instanceof ExplicitLocatorPath) {
      ExplicitLocatorPath elp = (ExplicitLocatorPath) rloc.getAddress();
      List<Hop> hops = elp.getExplicitLocatorPath().getHop();

      if (index < 0 || index > hops.size()) {
        LOG.warn("Service Index out of bounds!");
        return mapping;
      }

      SimpleAddress nextHop = hops.get(index).getAddress();
      LocatorRecordBuilder lrb = new LocatorRecordBuilder(locatorRecord);
      lrb.setRloc(LispAddressUtil.toRloc(nextHop));
      recordBuilder.getLocatorRecord().add(lrb.build());
      return recordBuilder.build();
    } else {
      LOG.warn("Nothing to do with ServicePath mapping record");
      return mapping;
    }
  }