Skip to content

Commit

Permalink
SCMP echo problems, see #79
Browse files Browse the repository at this point in the history
  • Loading branch information
Tilmann Zäschke committed Jun 24, 2024
1 parent 88d2133 commit 8e0b638
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/test/java/org/scion/jpan/testutil/MockNetwork.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The mock network is a simplified version of the test network available in scionproto. The mock is
* primarily used to run the "tiny" network. Some simplifications:<br>
*
* <p>- The mock has only two "border routers". They act as border routers for _all_ ASes. There are
* two border routers to allow having multiple links between ASes.<br>
* - The mock border routers forward traffic directly to the target AS, even if there is no direct
* link in the topology.<br>
* - the border routers do only marginal verification on packets.<br>
*/
public class MockNetwork {

public static final String BORDER_ROUTER_HOST = "127.0.0.1";
Expand Down Expand Up @@ -265,7 +275,7 @@ public void run() {
chnRemote.register(selector, SelectionKey.OP_READ, chnLocal);
ByteBuffer buffer = ByteBuffer.allocate(66000);
MockNetwork.barrier.countDown();
logger.info(name + " started on ports " + bind1 + " <-> " + bind2);
logger.info("{} started on ports {} <-> {}", name, bind1, bind2);

while (true) {
if (selector.select() == 0) {
Expand Down Expand Up @@ -308,7 +318,7 @@ public void run() {
break;
default:
logger.error(
"HDR not supported: " + PackageVisibilityHelper.getNextHdr(buffer).code());
"HDR not supported: {}", PackageVisibilityHelper.getNextHdr(buffer).code());
throw new UnsupportedOperationException();
}
}
Expand All @@ -326,13 +336,7 @@ private void forwardPacket(ByteBuffer buffer, SocketAddress srcAddress, Datagram
throws IOException {
InetSocketAddress dstAddress = PackageVisibilityHelper.getDstAddress(buffer);
logger.info(
name
+ " forwarding "
+ buffer.remaining()
+ " bytes from "
+ srcAddress
+ " to "
+ dstAddress);
"{} forwarding {} bytes from {} to {}", name, buffer.remaining(), srcAddress, dstAddress);

outgoing.send(buffer, dstAddress);
buffer.clear();
Expand Down Expand Up @@ -372,8 +376,8 @@ private void handleScmp(
Scmp.Type type = ScmpParser.extractType(buffer);
Scmp.Message scmpMsg = PackageVisibilityHelper.createMessage(type, path);
ScmpParser.consume(buffer, scmpMsg);
logger.info(
" received SCMP " + scmpMsg.getTypeCode().name() + " " + scmpMsg.getTypeCode().getText());
Scmp.TypeCode typeCode = scmpMsg.getTypeCode();
logger.info("{} received SCMP {} {}", name, typeCode.name(), typeCode.getText());

if (scmpMsg instanceof Scmp.EchoMessage) {
// send back!
Expand All @@ -386,13 +390,11 @@ private void handleScmp(
} else {
// forward error
logger.info(
name
+ " forwarding SCMP error "
+ scmpMsg.getTypeCode().getText()
+ " from "
+ srcAddress
+ " to "
+ dstAddress);
"{} forwarding SCMP error {} from {} to {}",
name,
typeCode.getText(),
srcAddress,
dstAddress);
outgoing.send(buffer, dstAddress);
buffer.clear();
}
Expand Down

0 comments on commit 8e0b638

Please sign in to comment.