Ejemplo n.º 1
0
  /**
   * Gets LS request packet body as byte array.
   *
   * @return LS request packet body as byte array
   */
  public byte[] getLsrBodyAsByteArray() {
    List<Byte> bodyLst = new ArrayList<>();

    try {
      for (LsRequestPacket lsrPacket : linkStateRequests) {
        bodyLst.addAll(Bytes.asList(OspfUtil.convertToFourBytes(lsrPacket.lsType())));
        bodyLst.addAll(Bytes.asList(InetAddress.getByName(lsrPacket.linkStateId()).getAddress()));
        bodyLst.addAll(Bytes.asList(InetAddress.getByName(lsrPacket.ownRouterId()).getAddress()));
      }
    } catch (Exception e) {
      log.debug("Error::getLsrBodyAsByteArray {}", e.getMessage());
      return Bytes.toArray(bodyLst);
    }

    return Bytes.toArray(bodyLst);
  }
Ejemplo n.º 2
0
  @Override
  public void readFrom(ChannelBuffer channelBuffer) throws OspfParseException {

    while (channelBuffer.readableBytes() >= OspfUtil.LSREQUEST_LENGTH) {
      LsRequestPacket lsRequestPacket = new LsRequestPacket();
      lsRequestPacket.setLsType(channelBuffer.readInt());
      byte[] tempByteArray = new byte[OspfUtil.FOUR_BYTES];
      channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
      lsRequestPacket.setLinkStateId(Ip4Address.valueOf(tempByteArray).toString());
      tempByteArray = new byte[OspfUtil.FOUR_BYTES];
      channelBuffer.readBytes(tempByteArray, 0, OspfUtil.FOUR_BYTES);
      lsRequestPacket.setOwnRouterId(Ip4Address.valueOf(tempByteArray).toString());

      this.addLinkStateRequests(lsRequestPacket);
    }
  }