Search in sources :

Example 1 with LinkPropsDto

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

the class LinkOperationsBoltTest method shouldCreateLinkProps.

@Test
public void shouldCreateLinkProps() {
    SwitchRepository switchRepository = persistenceManager.getRepositoryFactory().createSwitchRepository();
    switchRepository.add(Switch.builder().switchId(SWITCH_ID_1).build());
    switchRepository.add(Switch.builder().switchId(SWITCH_ID_2).build());
    LinkOperationsBolt bolt = new LinkOperationsBolt(persistenceManager);
    bolt.prepare(null, topologyContext, null);
    LinkPropsPut linkPropsPutRequest = new LinkPropsPut(new LinkPropsDto(new NetworkEndpoint(SWITCH_ID_1, 1), new NetworkEndpoint(SWITCH_ID_2, 1), Collections.emptyMap()));
    LinkPropsResponse response = (LinkPropsResponse) bolt.processRequest(null, linkPropsPutRequest).get(0);
    assertNotNull(response.getLinkProps());
}
Also used : LinkPropsResponse(org.openkilda.messaging.nbtopology.response.LinkPropsResponse) NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) LinkPropsPut(org.openkilda.messaging.nbtopology.request.LinkPropsPut) LinkPropsDto(org.openkilda.messaging.model.LinkPropsDto) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) Test(org.junit.Test)

Example 2 with LinkPropsDto

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

the class LinkPropsResponseTest method serializeLoop.

@Test
public void serializeLoop() throws Exception {
    LinkPropsRequest[] requestsBatch = new LinkPropsRequest[] { makePutRequest(), makeDropRequest() };
    for (LinkPropsRequest request : requestsBatch) {
        LinkPropsDto result = LinkPropsTest.makeSubject();
        LinkPropsResponse origin = new LinkPropsResponse(request, result, null);
        InfoMessage wrapper = new InfoMessage(origin, System.currentTimeMillis(), getClass().getCanonicalName());
        serializer.serialize(wrapper);
        InfoMessage reconstructedWrapper = (InfoMessage) serializer.deserialize();
        LinkPropsResponse reconstructed = (LinkPropsResponse) reconstructedWrapper.getData();
        Assert.assertEquals(origin, reconstructed);
    }
}
Also used : LinkPropsRequest(org.openkilda.messaging.nbtopology.request.LinkPropsRequest) InfoMessage(org.openkilda.messaging.info.InfoMessage) LinkPropsDto(org.openkilda.messaging.model.LinkPropsDto) LinkPropsDropTest(org.openkilda.messaging.nbtopology.request.LinkPropsDropTest) LinkPropsPutTest(org.openkilda.messaging.nbtopology.request.LinkPropsPutTest) Test(org.junit.Test) LinkPropsTest(org.openkilda.messaging.model.LinkPropsTest)

Example 3 with LinkPropsDto

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

the class LinkPropsMapper method toLinkProps.

/**
 * Converts {@link org.openkilda.northbound.dto.v1.links.LinkPropsDto} into {@link LinkPropsDto}.
 */
default LinkPropsDto toLinkProps(org.openkilda.northbound.dto.v1.links.LinkPropsDto input) {
    NetworkEndpoint source = new NetworkEndpoint(new SwitchId(input.getSrcSwitch()), input.getSrcPort());
    NetworkEndpoint dest = new NetworkEndpoint(new SwitchId(input.getDstSwitch()), input.getDstPort());
    return new LinkPropsDto(source, dest, input.getProps());
}
Also used : NetworkEndpoint(org.openkilda.messaging.model.NetworkEndpoint) LinkPropsDto(org.openkilda.messaging.model.LinkPropsDto) SwitchId(org.openkilda.model.SwitchId)

Example 4 with LinkPropsDto

use of org.openkilda.messaging.model.LinkPropsDto 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 5 with LinkPropsDto

use of org.openkilda.messaging.model.LinkPropsDto 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)

Aggregations

LinkPropsDto (org.openkilda.messaging.model.LinkPropsDto)5 NetworkEndpoint (org.openkilda.messaging.model.NetworkEndpoint)4 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 SwitchId (org.openkilda.model.SwitchId)2 InfoMessage (org.openkilda.messaging.info.InfoMessage)1 LinkPropsTest (org.openkilda.messaging.model.LinkPropsTest)1 LinkPropsDropTest (org.openkilda.messaging.nbtopology.request.LinkPropsDropTest)1 LinkPropsPut (org.openkilda.messaging.nbtopology.request.LinkPropsPut)1 LinkPropsPutTest (org.openkilda.messaging.nbtopology.request.LinkPropsPutTest)1 LinkPropsRequest (org.openkilda.messaging.nbtopology.request.LinkPropsRequest)1 LinkPropsResponse (org.openkilda.messaging.nbtopology.response.LinkPropsResponse)1 SwitchRepository (org.openkilda.persistence.repositories.SwitchRepository)1