@Test public void testConvertToThreeBytes() throws Exception { input2 = 1000000; result1 = OspfUtil.convertToThreeBytes(input2); assertThat(result1.length, is(3)); input2 = 1000; result1 = OspfUtil.convertToThreeBytes(input2); assertThat(result1.length, is(3)); input2 = 1; result1 = OspfUtil.convertToThreeBytes(input2); assertThat(result1.length, is(3)); }
public static byte[] convertToThreeBytes(int numberToConvert) { byte[] numInBytes = new byte[3]; String s1 = Integer.toHexString(numberToConvert); if (s1.length() % 2 != 0) { s1 = "0" + s1; } byte[] hexas = DatatypeConverter.parseHexBinary(s1); if (hexas.length == 1) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = hexas[0]; } else if (hexas.length == 2) { numInBytes[0] = 0; numInBytes[1] = hexas[0]; numInBytes[2] = hexas[1]; } else { numInBytes[0] = hexas[0]; numInBytes[1] = hexas[1]; numInBytes[2] = hexas[2]; } return numInBytes; }
OspfUtil { public static byte[] convertToThreeBytes(int numberToConvert) { byte[] numInBytes = new byte[3]; String s1 = Integer.toHexString(numberToConvert); if (s1.length() % 2 != 0) { s1 = "0" + s1; } byte[] hexas = DatatypeConverter.parseHexBinary(s1); if (hexas.length == 1) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = hexas[0]; } else if (hexas.length == 2) { numInBytes[0] = 0; numInBytes[1] = hexas[0]; numInBytes[2] = hexas[1]; } else { numInBytes[0] = hexas[0]; numInBytes[1] = hexas[1]; numInBytes[2] = hexas[2]; } return numInBytes; } }
OspfUtil { public static byte[] convertToThreeBytes(int numberToConvert) { byte[] numInBytes = new byte[3]; String s1 = Integer.toHexString(numberToConvert); if (s1.length() % 2 != 0) { s1 = "0" + s1; } byte[] hexas = DatatypeConverter.parseHexBinary(s1); if (hexas.length == 1) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = hexas[0]; } else if (hexas.length == 2) { numInBytes[0] = 0; numInBytes[1] = hexas[0]; numInBytes[2] = hexas[1]; } else { numInBytes[0] = hexas[0]; numInBytes[1] = hexas[1]; numInBytes[2] = hexas[2]; } return numInBytes; } private  OspfUtil(); }
OspfUtil { public static byte[] convertToThreeBytes(int numberToConvert) { byte[] numInBytes = new byte[3]; String s1 = Integer.toHexString(numberToConvert); if (s1.length() % 2 != 0) { s1 = "0" + s1; } byte[] hexas = DatatypeConverter.parseHexBinary(s1); if (hexas.length == 1) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = hexas[0]; } else if (hexas.length == 2) { numInBytes[0] = 0; numInBytes[1] = hexas[0]; numInBytes[2] = hexas[1]; } else { numInBytes[0] = hexas[0]; numInBytes[1] = hexas[1]; numInBytes[2] = hexas[2]; } return numInBytes; } private  OspfUtil(); static boolean sameNetwork(Ip4Address ip1, Ip4Address ip2, Ip4Address mask); static long ipAddressToLong(String ipAddress); static boolean isOpaqueEnabled(int options); static int byteToInteger(byte[] bytesToConvert); static long byteToLong(byte[] bytesToConvert); static int createRandomNumber(); static LsaHeader readLsaHeader(ChannelBuffer channelBuffer); static byte[] convertToTwoBytes(int numberToConvert); static byte[] convertToThreeBytes(int numberToConvert); static byte[] convertToFourBytes(int numberToConvert); static byte[] convertToFourBytes(long numberToConvert); static byte[] addLengthAndCheckSum(byte[] ospfPacket, int lengthBytePos1, int lengthBytePos2,
                                              int checksumBytePos1, int checksumBytePos2); static byte[] addMetadata(int interfaceIndex, byte[] ospfPacket, int allDroutersValue,
                                     Ip4Address destinationIp); }
OspfUtil { public static byte[] convertToThreeBytes(int numberToConvert) { byte[] numInBytes = new byte[3]; String s1 = Integer.toHexString(numberToConvert); if (s1.length() % 2 != 0) { s1 = "0" + s1; } byte[] hexas = DatatypeConverter.parseHexBinary(s1); if (hexas.length == 1) { numInBytes[0] = 0; numInBytes[1] = 0; numInBytes[2] = hexas[0]; } else if (hexas.length == 2) { numInBytes[0] = 0; numInBytes[1] = hexas[0]; numInBytes[2] = hexas[1]; } else { numInBytes[0] = hexas[0]; numInBytes[1] = hexas[1]; numInBytes[2] = hexas[2]; } return numInBytes; } private  OspfUtil(); static boolean sameNetwork(Ip4Address ip1, Ip4Address ip2, Ip4Address mask); static long ipAddressToLong(String ipAddress); static boolean isOpaqueEnabled(int options); static int byteToInteger(byte[] bytesToConvert); static long byteToLong(byte[] bytesToConvert); static int createRandomNumber(); static LsaHeader readLsaHeader(ChannelBuffer channelBuffer); static byte[] convertToTwoBytes(int numberToConvert); static byte[] convertToThreeBytes(int numberToConvert); static byte[] convertToFourBytes(int numberToConvert); static byte[] convertToFourBytes(long numberToConvert); static byte[] addLengthAndCheckSum(byte[] ospfPacket, int lengthBytePos1, int lengthBytePos2,
                                              int checksumBytePos1, int checksumBytePos2); static byte[] addMetadata(int interfaceIndex, byte[] ospfPacket, int allDroutersValue,
                                     Ip4Address destinationIp); static final int OSPF_VERSION_2; static final int OSPF_VERSION; static final int PACKET_MINIMUM_LENGTH; static final int METADATA_LEN; static final int MINIMUM_FRAME_LEN; static final int OSPF_HEADER_LENGTH; static final int LSA_HEADER_LENGTH; static final int DD_HEADER_LENGTH; static final int LSREQUEST_LENGTH; static final int OSPFPACKET_LENGTH_POS1; static final int OSPFPACKET_LENGTH_POS2; static final int OSPFPACKET_CHECKSUM_POS1; static final int OSPFPACKET_CHECKSUM_POS2; static final int LSAPACKET_CHECKSUM_POS1; static final int LSAPACKET_CHECKSUM_POS2; static final Ip4Address ALL_SPF_ROUTERS; static final Ip4Address ALL_DROUTERS; static final Ip4Address DEFAULTIP; static final int RETRANSMITINTERVAL; static final int ONLY_ALL_SPF_ROUTERS; static final int JOIN_ALL_DROUTERS; static final int INITIALIZE_SET; static final int INITIALIZE_NOTSET; static final int MORE_SET; static final int MORE_NOTSET; static final int IS_MASTER; static final int NOT_MASTER; static final int NOT_ASSIGNED; static final int FOUR_BYTES; static final int FIVE_BYTES; static final int EIGHT_BYTES; static final int TWELVE_BYTES; static final int EXTERNAL_DESTINATION_LENGTH; static final String SHOST; static final int SPORT; static final int MTU; static final char CONFIG_LENGTH; static final char ROUTER_PRIORITY; static final int HELLO_PACKET_OPTIONS; }