package component; import encoding.*; import org.junit.Test; import java.util.Arrays; import static org.junit.Assert.*; /* * @Author: feng Zhao * @Description: * @Version: 1.0.0 * @Date: 16:09 2021/3/25 * @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室 */ public class HopLimitTest { int MaxPacketSize = 8800; @Test public void TestHopLimit_GetHopLimit() { HopLimit hop = new HopLimit(); System.out.println("interest;"+hop.getHopLimit()); hop.setHopLimit(Long.MAX_VALUE); assertEquals(hop.getHopLimit(),Long.MAX_VALUE); assertTrue(hop.isInitial()); } @Test public void TestHopLimit_WireEncode() throws ComponentException, EncoderException, BlockException { HopLimit hop = new HopLimit(); System.out.println("interest;"+hop.getHopLimit()); hop.setHopLimit(Long.MAX_VALUE); assertEquals(hop.getHopLimit(),Long.MAX_VALUE); assertTrue(hop.isInitial()); Encoder encoder = new Encoder(); encoder.encoderReset(new SizeT(MaxPacketSize), new SizeT(0)); hop.wireEncode(encoder); byte[] buf = encoder.getBuffer(); System.out.println("HopLimit buf:"+ Arrays.toString(buf)); Block block = Block.createBlockByBuffer(buf, false); System.out.println("HopLimit block: "+block.getType()+","+block.getLength()+","+Arrays.toString(block.getValue())); } @Test public void TestHopLimit_WireDecode() throws EncoderException, ComponentException, BlockException { HopLimit hop = new HopLimit(); System.out.println("interest;"+hop.getHopLimit()); hop.setHopLimit(Long.MAX_VALUE); assertEquals(hop.getHopLimit(),Long.MAX_VALUE); assertTrue(hop.isInitial()); Encoder encoder = new Encoder(); encoder.encoderReset(new SizeT(MaxPacketSize), new SizeT(0)); hop.wireEncode(encoder); byte[] buf = encoder.getBuffer(); System.out.println("HopLimit buf:"+ Arrays.toString(buf)); Block block = Block.createBlockByBuffer(buf, false); System.out.println("HopLimit block: "+block.getType()+","+block.getLength()+","+Arrays.toString(block.getValue())); InterestLifeTime interest1 = new InterestLifeTime(); interest1.wireDecode(block); System.out.println("interest1: "+hop.getHopLimit()); System.out.println("interest1: "+hop.isInitial()); } }