@Test public void testValiantPassAckThirdOfHandshake() { when(packet.getSourceId()).thenReturn(4); when(packet.getDestinationId()).thenReturn(3); when(packet.isACK()).thenReturn(true); when(packet.getAcknowledgementNumber()).thenReturn(1L); device4identity.receiveFromIntermediary(packet); ArgumentCaptor<ValiantEncapsulation> captor = ArgumentCaptor.forClass(ValiantEncapsulation.class); verify(topology.getPort(4, 2), atMost(1)).enqueue(captor.capture()); verify(topology.getPort(4, 3), atMost(1)).enqueue(captor.capture()); assertFalse(captor.getValue().passedValiant()); verify(layer4, times(0)).receive(packet); }
@Override public void receiveFromIntermediary(Packet genericPacket) { TcpPacket packet = (TcpPacket) genericPacket; assert(this.identifier == packet.getSourceId()); int sourceToR; int destinationToR; if (isWithinExtendedTopology) { sourceToR = Simulator.getConfiguration().getGraphDetails().getTorIdOfServer(packet.getSourceId()); destinationToR = Simulator.getConfiguration().getGraphDetails().getTorIdOfServer(packet.getDestinationId()); } else { sourceToR = packet.getSourceId(); destinationToR = packet.getDestinationId(); } int chosen; int i = 0; do { chosen = lowBoundValiantRangeIncl + packet.getHash(this.identifier, i) % valiantRangeSize; i++; if (i > 10000) { throw new RuntimeException( "Chose a wrong random number more than a 10000 times. This is extremely unlikely to happen; " + "presumably there is an extremely poor hashing function at work." ); } } while (chosen == sourceToR || chosen == destinationToR); if (!flowSeen.contains(packet.getFlowId())) { SimulationLogger.increaseStatisticCounter("VAL_NODE_" + chosen); flowSeen.add(packet.getFlowId()); } ValiantEncapsulation encapsulation = new ValiantEncapsulation( packet, chosen ); if (packet.isSYN() || (packet.isACK() && packet.getAcknowledgementNumber() != 1)) { encapsulation.markPassedValiant(); } receiveEncapsulationPassOn(encapsulation); }
RangeValiantSwitch extends ValiantEcmpSwitch { @Override public void receiveFromIntermediary(Packet genericPacket) { TcpPacket packet = (TcpPacket) genericPacket; assert(this.identifier == packet.getSourceId()); int sourceToR; int destinationToR; if (isWithinExtendedTopology) { sourceToR = Simulator.getConfiguration().getGraphDetails().getTorIdOfServer(packet.getSourceId()); destinationToR = Simulator.getConfiguration().getGraphDetails().getTorIdOfServer(packet.getDestinationId()); } else { sourceToR = packet.getSourceId(); destinationToR = packet.getDestinationId(); } int chosen; int i = 0; do { chosen = lowBoundValiantRangeIncl + packet.getHash(this.identifier, i) % valiantRangeSize; i++; if (i > 10000) { throw new RuntimeException( "Chose a wrong random number more than a 10000 times. This is extremely unlikely to happen; " + "presumably there is an extremely poor hashing function at work." ); } } while (chosen == sourceToR || chosen == destinationToR); if (!flowSeen.contains(packet.getFlowId())) { SimulationLogger.increaseStatisticCounter("VAL_NODE_" + chosen); flowSeen.add(packet.getFlowId()); } ValiantEncapsulation encapsulation = new ValiantEncapsulation( packet, chosen ); if (packet.isSYN() || (packet.isACK() && packet.getAcknowledgementNumber() != 1)) { encapsulation.markPassedValiant(); } receiveEncapsulationPassOn(encapsulation); } }
RangeValiantSwitch extends ValiantEcmpSwitch { @Override public void receiveFromIntermediary(Packet genericPacket) { TcpPacket packet = (TcpPacket) genericPacket; assert(this.identifier == packet.getSourceId()); int sourceToR; int destinationToR; if (isWithinExtendedTopology) { sourceToR = Simulator.getConfiguration().getGraphDetails().getTorIdOfServer(packet.getSourceId()); destinationToR = Simulator.getConfiguration().getGraphDetails().getTorIdOfServer(packet.getDestinationId()); } else { sourceToR = packet.getSourceId(); destinationToR = packet.getDestinationId(); } int chosen; int i = 0; do { chosen = lowBoundValiantRangeIncl + packet.getHash(this.identifier, i) % valiantRangeSize; i++; if (i > 10000) { throw new RuntimeException( "Chose a wrong random number more than a 10000 times. This is extremely unlikely to happen; " + "presumably there is an extremely poor hashing function at work." ); } } while (chosen == sourceToR || chosen == destinationToR); if (!flowSeen.contains(packet.getFlowId())) { SimulationLogger.increaseStatisticCounter("VAL_NODE_" + chosen); flowSeen.add(packet.getFlowId()); } ValiantEncapsulation encapsulation = new ValiantEncapsulation( packet, chosen ); if (packet.isSYN() || (packet.isACK() && packet.getAcknowledgementNumber() != 1)) { encapsulation.markPassedValiant(); } receiveEncapsulationPassOn(encapsulation); } RangeValiantSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary, int lowBoundValiantRangeIncl, int highBoundValiantRangeIncl); }
RangeValiantSwitch extends ValiantEcmpSwitch { @Override public void receiveFromIntermediary(Packet genericPacket) { TcpPacket packet = (TcpPacket) genericPacket; assert(this.identifier == packet.getSourceId()); int sourceToR; int destinationToR; if (isWithinExtendedTopology) { sourceToR = Simulator.getConfiguration().getGraphDetails().getTorIdOfServer(packet.getSourceId()); destinationToR = Simulator.getConfiguration().getGraphDetails().getTorIdOfServer(packet.getDestinationId()); } else { sourceToR = packet.getSourceId(); destinationToR = packet.getDestinationId(); } int chosen; int i = 0; do { chosen = lowBoundValiantRangeIncl + packet.getHash(this.identifier, i) % valiantRangeSize; i++; if (i > 10000) { throw new RuntimeException( "Chose a wrong random number more than a 10000 times. This is extremely unlikely to happen; " + "presumably there is an extremely poor hashing function at work." ); } } while (chosen == sourceToR || chosen == destinationToR); if (!flowSeen.contains(packet.getFlowId())) { SimulationLogger.increaseStatisticCounter("VAL_NODE_" + chosen); flowSeen.add(packet.getFlowId()); } ValiantEncapsulation encapsulation = new ValiantEncapsulation( packet, chosen ); if (packet.isSYN() || (packet.isACK() && packet.getAcknowledgementNumber() != 1)) { encapsulation.markPassedValiant(); } receiveEncapsulationPassOn(encapsulation); } RangeValiantSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary, int lowBoundValiantRangeIncl, int highBoundValiantRangeIncl); @Override void receiveFromIntermediary(Packet genericPacket); @Override String toString(); }
RangeValiantSwitch extends ValiantEcmpSwitch { @Override public void receiveFromIntermediary(Packet genericPacket) { TcpPacket packet = (TcpPacket) genericPacket; assert(this.identifier == packet.getSourceId()); int sourceToR; int destinationToR; if (isWithinExtendedTopology) { sourceToR = Simulator.getConfiguration().getGraphDetails().getTorIdOfServer(packet.getSourceId()); destinationToR = Simulator.getConfiguration().getGraphDetails().getTorIdOfServer(packet.getDestinationId()); } else { sourceToR = packet.getSourceId(); destinationToR = packet.getDestinationId(); } int chosen; int i = 0; do { chosen = lowBoundValiantRangeIncl + packet.getHash(this.identifier, i) % valiantRangeSize; i++; if (i > 10000) { throw new RuntimeException( "Chose a wrong random number more than a 10000 times. This is extremely unlikely to happen; " + "presumably there is an extremely poor hashing function at work." ); } } while (chosen == sourceToR || chosen == destinationToR); if (!flowSeen.contains(packet.getFlowId())) { SimulationLogger.increaseStatisticCounter("VAL_NODE_" + chosen); flowSeen.add(packet.getFlowId()); } ValiantEncapsulation encapsulation = new ValiantEncapsulation( packet, chosen ); if (packet.isSYN() || (packet.isACK() && packet.getAcknowledgementNumber() != 1)) { encapsulation.markPassedValiant(); } receiveEncapsulationPassOn(encapsulation); } RangeValiantSwitch(int identifier, TransportLayer transportLayer, int n, Intermediary intermediary, int lowBoundValiantRangeIncl, int highBoundValiantRangeIncl); @Override void receiveFromIntermediary(Packet genericPacket); @Override String toString();  }