| 1 | package cz.vutbr.feec.packets.ttp; |
| 2 | |
| 3 | import org.junit.Assert; |
| 4 | import org.junit.Test; |
| 5 | |
| 6 | import cz.vutbr.feec.packets.PacketGenerateException; |
| 7 | import cz.vutbr.feec.packets.PacketParseException; |
| 8 | import cz.vutbr.feec.packets.rtp.RTPPacket; |
| 9 | import cz.vutbr.feec.packets.rtp.RTP_CSRC_Group; |
| 10 | import cz.vutbr.feec.packets.ttp.FTAPacket; |
| 11 | import cz.vutbr.feec.packets.ttp.FTSGroupBlock; |
| 12 | import cz.vutbr.feec.packets.ttp.FTSPacket; |
| 13 | import cz.vutbr.feec.packets.ttp.GeneralTTPHeader; |
| 14 | import cz.vutbr.feec.packets.ttp.LMSLandMarkGroup; |
| 15 | import cz.vutbr.feec.packets.ttp.LMSPacket; |
| 16 | |
| 17 | public class TTPHeaderTest { |
| 18 | private byte buffer[] = new byte[500]; |
| 19 | |
| 20 | @Test |
| 21 | public void testTTPHeader() throws PacketParseException, |
| 22 | PacketGenerateException { |
| 23 | GeneralTTPHeader hdr1 = new GeneralTTPHeader(7); |
| 24 | // filling the reader |
| 25 | hdr1.setVersion(5); |
| 26 | hdr1.setPadding(0); |
| 27 | // packet type already set in definition |
| 28 | hdr1.setFeedbackTreeId(65535); |
| 29 | hdr1.setLength(5); |
| 30 | |
| 31 | int length = -1; |
| 32 | length = hdr1.generate(buffer, 0); |
| 33 | |
| 34 | GeneralTTPHeader hdr2 = new GeneralTTPHeader(7); |
| 35 | int length2 = hdr2.parse(buffer, 0, length); |
| 36 | Assert.assertTrue(hdr1.getVersion() == hdr2.getVersion()); |
| 37 | Assert.assertTrue(length == length2); |
| 38 | Assert.assertTrue(hdr1.equals(hdr2)); |
| 39 | } |
| 40 | |
| 41 | @Test |
| 42 | public void FTAPacket() throws PacketParseException, |
| 43 | PacketGenerateException { |
| 44 | FTAPacket packetFTA = new FTAPacket(); |
| 45 | packetFTA.setVersion(0); |
| 46 | packetFTA.setPadding(1); |
| 47 | packetFTA.setPacketType(2); |
| 48 | packetFTA.setFeedbackTreeId(3); |
| 49 | packetFTA.setLength(200); |
| 50 | |
| 51 | packetFTA.setFeedbackGroupSize(0); |
| 52 | packetFTA.setPriority(1); |
| 53 | packetFTA.setFeedBackSize(2); |
| 54 | packetFTA.setParameters(3); |
| 55 | packetFTA.setReserved(4); |
| 56 | |
| 57 | packetFTA.setSessionInformationIP(4294967290L); |
| 58 | packetFTA.setSessionPort(50); |
| 59 | packetFTA.setReservedEnd(25); |
| 60 | |
| 61 | int length = packetFTA.generate(buffer, 0); |
| 62 | |
| 63 | FTAPacket packetFTA2 = new FTAPacket(); |
| 64 | int length2 = packetFTA2.parse(buffer, 0, length); |
| 65 | // testing FTA packet |
| 66 | |
| 67 | Assert.assertTrue("Musi byt zarovnano na 4 byty", length % 4 == 0); |
| 68 | Assert.assertTrue(length == length2); |
| 69 | Assert.assertTrue(packetFTA.equals(packetFTA2)); |
| 70 | } |
| 71 | |
| 72 | @Test |
| 73 | public void LMSPacket() throws PacketParseException, |
| 74 | PacketGenerateException { |
| 75 | LMSPacket packetLMS = new LMSPacket(); |
| 76 | packetLMS.setVersion(1); |
| 77 | packetLMS.setPadding(1); |
| 78 | packetLMS.setPacketType(1); |
| 79 | packetLMS.setFeedbackTreeId(1); |
| 80 | packetLMS.setLength(1); |
| 81 | |
| 82 | packetLMS.setLMSseqNumber(1); |
| 83 | |
| 84 | packetLMS.setSessionSize(1); |
| 85 | packetLMS.setIncreaseFactor(1); |
| 86 | packetLMS.setSessionSize(1); |
| 87 | packetLMS.setReservedEnd(1); |
| 88 | LMSLandMarkGroup item1 = new LMSLandMarkGroup(); |
| 89 | LMSLandMarkGroup item2 = new LMSLandMarkGroup(); |
| 90 | LMSLandMarkGroup item3 = new LMSLandMarkGroup(); |
| 91 | LMSLandMarkGroup item4 = new LMSLandMarkGroup(); |
| 92 | item1.setLandmarkIPaddr(55555555L); |
| 93 | item2.setLandmarkIPaddr(44444444L); |
| 94 | item3.setLandmarkIPaddr(33333333L); |
| 95 | item4.setLandmarkIPaddr(22222222L); |
| 96 | packetLMS.addGroupBlock(item1); |
| 97 | packetLMS.addGroupBlock(item2); |
| 98 | packetLMS.addGroupBlock(item3); |
| 99 | packetLMS.addGroupBlock(item4); |
| 100 | |
| 101 | int length = packetLMS.generate(buffer, 0); |
| 102 | |
| 103 | LMSPacket packetLMS2 = new LMSPacket(); |
| 104 | int length2 = packetLMS2.parse(buffer, 0, length); |
| 105 | |
| 106 | Assert.assertTrue("Musi byt zarovnano na 4 byty", length % 4 == 0); |
| 107 | Assert.assertTrue(length == length2); |
| 108 | Assert.assertTrue(packetLMS.equals(packetLMS2)); |
| 109 | |
| 110 | } |
| 111 | |
| 112 | @Test |
| 113 | public void FTSPacket() throws PacketParseException, |
| 114 | PacketGenerateException { |
| 115 | FTSPacket packetFTS = new FTSPacket(); |
| 116 | packetFTS.setVersion(1); |
| 117 | packetFTS.setPadding(1); |
| 118 | packetFTS.setPacketType(1); |
| 119 | packetFTS.setFeedbackTreeId(1); |
| 120 | packetFTS.setLength(1); |
| 121 | packetFTS.setLMSseqNumber(1); |
| 122 | packetFTS.setSessionSize(1); |
| 123 | packetFTS.setIncreaseFactor(1); |
| 124 | packetFTS.setReservedEnd(1); |
| 125 | |
| 126 | FTSGroupBlock group1 = new FTSGroupBlock(); |
| 127 | FTSGroupBlock group2 = new FTSGroupBlock(); |
| 128 | FTSGroupBlock group3 = new FTSGroupBlock(); |
| 129 | FTSGroupBlock group4 = new FTSGroupBlock(); |
| 130 | FTSGroupBlock group5 = new FTSGroupBlock(); |
| 131 | group1.setFeedbackTargerIP(1); |
| 132 | group1.setFeedbackTargetPort(1); |
| 133 | group1.setGroupSize(1); |
| 134 | group1.setVectorSpecification(1); |
| 135 | group1.setLenght(1); |
| 136 | group1.setReservedEnd(1); |
| 137 | group1.setLMidVector(1); |
| 138 | |
| 139 | group2.setFeedbackTargerIP(2); |
| 140 | group2.setFeedbackTargetPort(2); |
| 141 | group2.setGroupSize(2); |
| 142 | group2.setVectorSpecification(2); |
| 143 | group2.setLenght(2); |
| 144 | group2.setReservedEnd(2); |
| 145 | group2.setLMidVector(2); |
| 146 | |
| 147 | group3.setFeedbackTargerIP(62626262); |
| 148 | group3.setFeedbackTargetPort(90); |
| 149 | group3.setGroupSize(41); |
| 150 | group3.setVectorSpecification(77); |
| 151 | group3.setLenght(12); |
| 152 | group3.setReservedEnd(63); |
| 153 | group3.setLMidVector(51515151); |
| 154 | |
| 155 | group4.setFeedbackTargerIP(32323232); |
| 156 | group4.setFeedbackTargetPort(90); |
| 157 | group4.setGroupSize(41); |
| 158 | group4.setVectorSpecification(77); |
| 159 | group4.setLenght(12); |
| 160 | group4.setReservedEnd(63); |
| 161 | group4.setLMidVector(84848484); |
| 162 | |
| 163 | group5.setFeedbackTargerIP(95959595); |
| 164 | group5.setFeedbackTargetPort(90); |
| 165 | group5.setGroupSize(41); |
| 166 | group5.setVectorSpecification(77); |
| 167 | group5.setLenght(12); |
| 168 | group5.setReservedEnd(63); |
| 169 | group5.setLMidVector(58585858); |
| 170 | |
| 171 | packetFTS.addGroupBlock(group1); |
| 172 | packetFTS.addGroupBlock(group2); |
| 173 | packetFTS.addGroupBlock(group3); |
| 174 | packetFTS.addGroupBlock(group4); |
| 175 | packetFTS.addGroupBlock(group5); |
| 176 | |
| 177 | int length = packetFTS.generate(buffer, 0); |
| 178 | |
| 179 | FTSPacket packetFTS2 = new FTSPacket(); |
| 180 | int length2 = packetFTS2.parse(buffer, 0, length); |
| 181 | |
| 182 | Assert.assertTrue(length == length2); |
| 183 | Assert.assertTrue(packetFTS.equals(packetFTS2)); |
| 184 | |
| 185 | RTPPacket orig = new RTPPacket(); |
| 186 | |
| 187 | orig.setVersion(2); |
| 188 | orig.setPadding(1); |
| 189 | orig.setExtension(1); |
| 190 | orig.setCSRCcount(3); |
| 191 | orig.setMarker(1); |
| 192 | orig.setPayloadtype(110); |
| 193 | orig.setSeqNum(5566); |
| 194 | orig.setTimeStamp(1122334455); |
| 195 | orig.setSSRC(225522); |
| 196 | |
| 197 | RTP_CSRC_Group item11 = new RTP_CSRC_Group(); |
| 198 | RTP_CSRC_Group item22 = new RTP_CSRC_Group(); |
| 199 | RTP_CSRC_Group item33 = new RTP_CSRC_Group(); |
| 200 | item11.setCSRCidentifier(111); |
| 201 | item22.setCSRCidentifier(222); |
| 202 | item33.setCSRCidentifier(333); |
| 203 | |
| 204 | orig.addGroupBlock(item11); |
| 205 | orig.addGroupBlock(item22); |
| 206 | orig.addGroupBlock(item33); |
| 207 | |
| 208 | int delka = orig.getDataLength(); |
| 209 | orig.clearData(delka); |
| 210 | |
| 211 | String text = "111122889966551144778888888"; |
| 212 | byte[] data = text.getBytes(); |
| 213 | orig.setData(data, 0, text.length()); |
| 214 | |
| 215 | length = orig.generate(buffer, 0); |
| 216 | |
| 217 | RTPPacket gener = new RTPPacket(); |
| 218 | |
| 219 | gener.parse(buffer, 0, length); |
| 220 | |
| 221 | Assert.assertTrue("Musi byt zarovnano na 4 byty", length % 4 == 0); |
| 222 | Assert.assertTrue(length == length2); |
| 223 | Assert.assertTrue(orig.equals(gener)); |
| 224 | } |
| 225 | } |