Search in sources :

Example 21 with NetworkEndpoint

use of org.openkilda.messaging.model.NetworkEndpoint in project open-kilda by telstra.

the class PingResponseCommandTest method success.

@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());
}
Also used : OfInput(org.openkilda.floodlight.model.OfInput) IPacket(net.floodlightcontroller.packet.IPacket) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) OFMessage(org.projectfloodlight.openflow.protocol.OFMessage) OFFactoryVer13(org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13) OFFactory(org.projectfloodlight.openflow.protocol.OFFactory) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) DatapathId(org.projectfloodlight.openflow.types.DatapathId) SwitchId(org.openkilda.model.SwitchId) PingResponse(org.openkilda.messaging.floodlight.response.PingResponse) SwitchManager(org.openkilda.floodlight.switchmanager.SwitchManager) ISwitchManager(org.openkilda.floodlight.switchmanager.ISwitchManager) PingData(org.openkilda.floodlight.model.PingData) InputService(org.openkilda.floodlight.service.of.InputService) PathVerificationService(org.openkilda.floodlight.pathverification.PathVerificationService) InfoMessage(org.openkilda.messaging.info.InfoMessage) PingService(org.openkilda.floodlight.service.ping.PingService) Ping(org.openkilda.messaging.model.Ping) Ethernet(net.floodlightcontroller.packet.Ethernet) OFPacketIn(org.projectfloodlight.openflow.protocol.OFPacketIn) FloodlightContext(net.floodlightcontroller.core.FloodlightContext) Test(org.junit.Test)

Example 22 with NetworkEndpoint

use of org.openkilda.messaging.model.NetworkEndpoint in project open-kilda by telstra.

the class LinkPropsPutTest method makeRequest.

/**
 * Produce {@link LinkPropsPut} request with predefined data.
 */
public static LinkPropsPut makeRequest() {
    HashMap<String, String> keyValuePairs = new HashMap<>();
    keyValuePairs.put("cost", "10000");
    LinkPropsDto linkProps = new LinkPropsDto(new NetworkEndpoint(new SwitchId("ff:fe:00:00:00:00:00:01"), 8), new NetworkEndpoint(new SwitchId("ff:fe:00:00:00:00:00:02"), 8), keyValuePairs);
    return new LinkPropsPut(linkProps);
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) HashMap(java.util.HashMap) LinkPropsDto(org.openkilda.messaging.model.LinkPropsDto) SwitchId(org.openkilda.model.SwitchId)

Example 23 with NetworkEndpoint

use of org.openkilda.messaging.model.NetworkEndpoint in project open-kilda by telstra.

the class LinkPropsMapper method map.

/**
 * Convert {@link LinkProps} to {@link LinkPropsDto}.
 */
public LinkPropsDto map(LinkProps linkProps) {
    if (linkProps == null) {
        return null;
    }
    Map<String, String> props = new HashMap<>();
    if (linkProps.getCost() != null) {
        props.put(LinkProps.COST_PROP_NAME, Integer.toString(linkProps.getCost()));
    }
    if (linkProps.getMaxBandwidth() != null) {
        props.put(LinkProps.MAX_BANDWIDTH_PROP_NAME, Long.toString(linkProps.getMaxBandwidth()));
    }
    Long created = Optional.ofNullable(linkProps.getTimeCreate()).map(Instant::toEpochMilli).orElse(null);
    Long modified = Optional.ofNullable(linkProps.getTimeModify()).map(Instant::toEpochMilli).orElse(null);
    NetworkEndpoint source = new NetworkEndpoint(linkProps.getSrcSwitchId(), linkProps.getSrcPort());
    NetworkEndpoint destination = new NetworkEndpoint(linkProps.getDstSwitchId(), linkProps.getDstPort());
    return new LinkPropsDto(source, destination, props, created, modified);
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) HashMap(java.util.HashMap) LinkPropsDto(org.openkilda.messaging.model.LinkPropsDto)

Example 24 with NetworkEndpoint

use of org.openkilda.messaging.model.NetworkEndpoint in project open-kilda by telstra.

the class IslHandler method islChangedNotifyFlowMonitor.

@Override
public void islChangedNotifyFlowMonitor(IslReference reference, boolean removed) {
    Endpoint src = reference.getSource();
    Endpoint dst = reference.getDest();
    IslChangedInfoData islChangedInfoData = IslChangedInfoData.builder().source(new NetworkEndpoint(src.getDatapath(), src.getPortNumber())).destination(new NetworkEndpoint(dst.getDatapath(), dst.getPortNumber())).removed(removed).build();
    emit(STREAM_FLOW_MONITORING_ID, getCurrentTuple(), makeIslChangedTuple(islChangedInfoData));
}
Also used : IslChangedInfoData(org.openkilda.messaging.info.event.IslChangedInfoData) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) Endpoint(org.openkilda.wfm.share.model.Endpoint) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint)

Example 25 with NetworkEndpoint

use of org.openkilda.messaging.model.NetworkEndpoint in project open-kilda by telstra.

the class LinkServiceTest method updateMaxBandwidth.

@Test
public void updateMaxBandwidth() {
    final String correlationId = "update-max-bw-corrId";
    Long maxBandwidth = 1000L;
    SwitchId srcSwitch = new SwitchId("ff:fe:00:00:00:00:00:01");
    Integer srcPort = 8;
    SwitchId dstSwitch = new SwitchId("ff:fe:00:00:00:00:00:02");
    Integer dstPort = 9;
    LinkMaxBandwidthRequest inputRequest = new LinkMaxBandwidthRequest();
    inputRequest.setMaxBandwidth(maxBandwidth);
    HashMap<String, String> requestProps = new HashMap<>();
    requestProps.put(LinkProps.MAX_BANDWIDTH_PROP_NAME, String.valueOf(maxBandwidth));
    org.openkilda.messaging.model.LinkPropsDto linkProps = new org.openkilda.messaging.model.LinkPropsDto(new NetworkEndpoint(srcSwitch, srcPort), new NetworkEndpoint(dstSwitch, dstPort), requestProps);
    LinkPropsRequest request = new LinkPropsPut(linkProps);
    LinkPropsResponse payload = new LinkPropsResponse(request, linkProps, null);
    messageExchanger.mockResponse(correlationId, payload);
    RequestCorrelationId.create(correlationId);
    LinkMaxBandwidthDto result = linkService.updateLinkBandwidth(srcSwitch, srcPort, dstSwitch, dstPort, inputRequest).join();
    assertEquals(srcSwitch.toString(), result.getSrcSwitch());
    assertEquals(dstSwitch.toString(), result.getDstSwitch());
    assertEquals(srcPort, result.getSrcPort());
    assertEquals(dstPort, result.getDstPort());
    assertEquals(maxBandwidth, result.getMaxBandwidth());
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) HashMap(java.util.HashMap) LinkPropsDto(org.openkilda.northbound.dto.v1.links.LinkPropsDto) SwitchId(org.openkilda.model.SwitchId) LinkMaxBandwidthRequest(org.openkilda.northbound.dto.v1.links.LinkMaxBandwidthRequest) LinkPropsResponse(org.openkilda.messaging.nbtopology.response.LinkPropsResponse) LinkPropsRequest(org.openkilda.messaging.nbtopology.request.LinkPropsRequest) LinkPropsPut(org.openkilda.messaging.nbtopology.request.LinkPropsPut) LinkMaxBandwidthDto(org.openkilda.northbound.dto.v1.links.LinkMaxBandwidthDto) Test(org.junit.Test)

Aggregations

NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)32 SwitchId (org.openkilda.model.SwitchId)16 Test (org.junit.Test)14 Ping (org.openkilda.messaging.model.Ping)7 CommandMessage (org.openkilda.messaging.command.CommandMessage)5 InfoMessage (org.openkilda.messaging.info.InfoMessage)5 LinkPropsDto (org.openkilda.messaging.model.LinkPropsDto)5 LinkPropsResponse (org.openkilda.messaging.nbtopology.response.LinkPropsResponse)5 FlowTransitEncapsulation (org.openkilda.model.FlowTransitEncapsulation)5 ApiOperation (io.swagger.annotations.ApiOperation)4 HashMap (java.util.HashMap)4 MessageException (org.openkilda.messaging.error.MessageException)4 LinkPropsPut (org.openkilda.messaging.nbtopology.request.LinkPropsPut)4 LinkPropsDto (org.openkilda.northbound.dto.v1.links.LinkPropsDto)4 Ethernet (net.floodlightcontroller.packet.Ethernet)3 IPacket (net.floodlightcontroller.packet.IPacket)3 InputService (org.openkilda.floodlight.service.of.InputService)3 DatapathId (org.projectfloodlight.openflow.types.DatapathId)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 Date (java.util.Date)2