@Test public void success() throws Exception { final PingService realPingService = new PingService(); moduleContext.addService(PingService.class, realPingService); final ISwitchManager realSwitchManager = new SwitchManager(); moduleContext.addService(ISwitchManager.class, realSwitchManager); InputService inputService = createMock(InputService.class); moduleContext.addService(InputService.class, inputService); inputService.addTranslator(eq(OFType.PACKET_IN), anyObject()); replayAll(); final DatapathId dpIdBeta = DatapathId.of(0x0000fffe000002L); final Ping ping = new Ping(new NetworkEndpoint(new SwitchId(dpIdBeta.getLong()), 8), new NetworkEndpoint(new SwitchId(dpId.getLong()), 9), new FlowTransitEncapsulation(2, FlowEncapsulationType.TRANSIT_VLAN), 3); final PingData payload = PingData.of(ping); moduleContext.addConfigParam(new PathVerificationService(), "hmac256-secret", "secret"); realPingService.setup(moduleContext); byte[] signedPayload = realPingService.getSignature().sign(payload); byte[] wireData = realPingService.wrapData(ping, signedPayload).serialize(); OFFactory ofFactory = new OFFactoryVer13(); OFPacketIn message = ofFactory.buildPacketIn() .setReason(OFPacketInReason.ACTION).setXid(1L) .setCookie(PingService.OF_CATCH_RULE_COOKIE) .setData(wireData) .build(); FloodlightContext metadata = new FloodlightContext(); IPacket decodedEthernet = new Ethernet().deserialize(wireData, 0, wireData.length); Assert.assertTrue(decodedEthernet instanceof Ethernet); IFloodlightProviderService.bcStore.put( metadata, IFloodlightProviderService.CONTEXT_PI_PAYLOAD, (Ethernet) decodedEthernet); OfInput input = new OfInput(iofSwitch, message, metadata); final PingResponseCommand command = makeCommand(input); command.call(); final List<Message> replies = kafkaMessageCatcher.getValues(); Assert.assertEquals(1, replies.size()); InfoMessage response = (InfoMessage) replies.get(0); PingResponse pingResponse = (PingResponse) response.getData(); Assert.assertNull(pingResponse.getError()); Assert.assertNotNull(pingResponse.getMeters()); Assert.assertEquals(payload.getPingId(), pingResponse.getPingId()); }
@Override public Command call() { log.debug("{} - {}", getClass().getCanonicalName(), input); byte[] payload = unwrap(); if (payload == null) { return null; } log.info("Receive flow ping packet from switch {} OF-xid:{}", input.getDpId(), input.getMessage().getXid()); try { PingData pingData = decode(payload); getContext().setCorrelationId(pingData.getPingId().toString()); process(pingData); } catch (CorruptedNetworkDataException e) { logPing.error(String.format("dpid:%s %s", input.getDpId(), e)); } return null; }
PingResponseCommand extends PingCommand { @Override public Command call() { log.debug("{} - {}", getClass().getCanonicalName(), input); byte[] payload = unwrap(); if (payload == null) { return null; } log.info("Receive flow ping packet from switch {} OF-xid:{}", input.getDpId(), input.getMessage().getXid()); try { PingData pingData = decode(payload); getContext().setCorrelationId(pingData.getPingId().toString()); process(pingData); } catch (CorruptedNetworkDataException e) { logPing.error(String.format("dpid:%s %s", input.getDpId(), e)); } return null; } }
PingResponseCommand extends PingCommand { @Override public Command call() { log.debug("{} - {}", getClass().getCanonicalName(), input); byte[] payload = unwrap(); if (payload == null) { return null; } log.info("Receive flow ping packet from switch {} OF-xid:{}", input.getDpId(), input.getMessage().getXid()); try { PingData pingData = decode(payload); getContext().setCorrelationId(pingData.getPingId().toString()); process(pingData); } catch (CorruptedNetworkDataException e) { logPing.error(String.format("dpid:%s %s", input.getDpId(), e)); } return null; } PingResponseCommand(CommandContext context, OfInput input); }
PingResponseCommand extends PingCommand { @Override public Command call() { log.debug("{} - {}", getClass().getCanonicalName(), input); byte[] payload = unwrap(); if (payload == null) { return null; } log.info("Receive flow ping packet from switch {} OF-xid:{}", input.getDpId(), input.getMessage().getXid()); try { PingData pingData = decode(payload); getContext().setCorrelationId(pingData.getPingId().toString()); process(pingData); } catch (CorruptedNetworkDataException e) { logPing.error(String.format("dpid:%s %s", input.getDpId(), e)); } return null; } PingResponseCommand(CommandContext context, OfInput input); @Override Command call(); }
PingResponseCommand extends PingCommand { @Override public Command call() { log.debug("{} - {}", getClass().getCanonicalName(), input); byte[] payload = unwrap(); if (payload == null) { return null; } log.info("Receive flow ping packet from switch {} OF-xid:{}", input.getDpId(), input.getMessage().getXid()); try { PingData pingData = decode(payload); getContext().setCorrelationId(pingData.getPingId().toString()); process(pingData); } catch (CorruptedNetworkDataException e) { logPing.error(String.format("dpid:%s %s", input.getDpId(), e)); } return null; } PingResponseCommand(CommandContext context, OfInput input); @Override Command call();  }