|
| 1 | +// Copyright 2024 ETH Zurich |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package org.scion.multiping; |
| 16 | + |
| 17 | +import org.scion.jpan.*; |
| 18 | +import org.scion.multiping.util.Config; |
| 19 | +import org.scion.multiping.util.Util; |
| 20 | + |
| 21 | +import java.io.IOException; |
| 22 | + |
| 23 | +import static org.scion.multiping.util.Util.PRINT; |
| 24 | +import static org.scion.multiping.util.Util.println; |
| 25 | + |
| 26 | +/** |
| 27 | + * A simple echo responder that responds to SCMP echo requests. |
| 28 | + */ |
| 29 | +public class EchoResponder { |
| 30 | + private static final String FILE_CONFIG = "EchoResponderConfig.json"; |
| 31 | + |
| 32 | + public static void main(String[] args) throws IOException { |
| 33 | + Config config = Config.read(FILE_CONFIG); |
| 34 | + PRINT = config.consoleOutput; |
| 35 | + |
| 36 | + try (ScmpChannel responder = Scmp.createChannel(Constants.SCMP_PORT)) { |
| 37 | + responder.setScmpErrorListener(EchoResponder::printError); |
| 38 | + responder.setOption(ScionSocketOptions.SCION_API_THROW_PARSER_FAILURE, true); |
| 39 | + responder.setScmpEchoListener(EchoResponder::print); |
| 40 | + responder.setUpScmpEchoResponder(); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + private static boolean print(Scmp.EchoMessage msg) { |
| 45 | + Util.print("Received: " + msg.getTypeCode().getText() + " from " + msg.getPath().getRemoteAddress() + "via "); |
| 46 | + Util.println(ScionUtil.toStringPath(msg.getPath().getMetadata())); |
| 47 | + return true; |
| 48 | + } |
| 49 | + |
| 50 | + private static void printError(Scmp.Message msg) { |
| 51 | + println("ERROR: " + msg.getTypeCode().getText()); |
| 52 | + } |
| 53 | +} |
0 commit comments