Search in sources :

Example 1 with IslLinkInfo

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

the class IslLinkConverter method toIslLinkInfo.

public static IslLinkInfo toIslLinkInfo(final IslLink islLink) {
    IslLinkInfo islLinkInfo = new IslLinkInfo();
    islLinkInfo.setAvailableBandwidth(islLink.getAvailableBandwidth());
    islLinkInfo.setSpeed(islLink.getSpeed());
    List<IslPath> islPaths = islLink.getPath();
    if (islPaths != null && !islPaths.isEmpty()) {
        if (islPaths.get(0) != null) {
            islLinkInfo.setSrcPort(islPaths.get(0).getPortNo());
            islLinkInfo.setSrcSwitch(islPaths.get(0).getSwitchId());
        }
        if (islPaths.get(1) != null) {
            islLinkInfo.setDstPort(islPaths.get(1).getPortNo());
            islLinkInfo.setDstSwitch(islPaths.get(1).getSwitchId());
        }
    }
    return islLinkInfo;
}
Also used : IslLinkInfo(org.openkilda.model.IslLinkInfo) IslPath(org.openkilda.integration.model.response.IslPath)

Example 2 with IslLinkInfo

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

the class SwitchControllerTest method testDeleteIsl.

@Test
public void testDeleteIsl() throws Exception {
    LinkParametersDto linkParametersDto = new LinkParametersDto();
    linkParametersDto.setSrcPort(Integer.valueOf(TestIslMock.SRC_PORT));
    linkParametersDto.setSrcSwitch(TestIslMock.SRC_SWITCH);
    linkParametersDto.setDstPort(Integer.valueOf(TestIslMock.DST_PORT));
    linkParametersDto.setDstSwitch(TestIslMock.DST_SWITCH);
    List<IslLinkInfo> islLinkInfo = new ArrayList<IslLinkInfo>();
    String inputJson = mapToJson(linkParametersDto);
    when(serviceSwitch.deleteLink(linkParametersDto, TestIslMock.USER_ID)).thenReturn(islLinkInfo);
    MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.delete("/api/switch/links").content(inputJson).contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)).andReturn();
    int status = mvcResult.getResponse().getStatus();
    assertEquals(200, status);
}
Also used : LinkParametersDto(org.openkilda.model.LinkParametersDto) ArrayList(java.util.ArrayList) IslLinkInfo(org.openkilda.model.IslLinkInfo) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test)

Example 3 with IslLinkInfo

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

the class IslLinkConverter method toIslLinksInfo.

/**
 * To isl links info.
 *
 * @param islLinks the isl links
 * @param islCostMap the isl cost map
 * @return the list
 */
public List<IslLinkInfo> toIslLinksInfo(final List<IslLink> islLinks, Map<String, String> islCostMap) {
    if (islLinks != null) {
        final List<IslLinkInfo> islLinkInfos = new ArrayList<>();
        final Map<String, String> csNames = switchIntegrationService.getSwitchNames();
        islLinks.forEach(islLink -> {
            IslLinkInfo islLinkInfo = toIslLinkInfo(islLink, csNames, islCostMap);
            if (islLinkInfos.size() == 0) {
                islLinkInfos.add(islLinkInfo);
            } else {
                boolean isSwitchRelationAdd = true;
                for (IslLinkInfo flowInfo : islLinkInfos) {
                    if (islLinkInfo.getForwardKey().equalsIgnoreCase(flowInfo.getReverseKey())) {
                        isSwitchRelationAdd = false;
                        flowInfo.setUnidirectional(false);
                        flowInfo.setState1(islLinkInfo.getState());
                        if (!flowInfo.getState().equalsIgnoreCase(islLinkInfo.getState())) {
                            flowInfo.setAffected(true);
                        }
                        break;
                    }
                }
                if (isSwitchRelationAdd) {
                    islLinkInfos.add(islLinkInfo);
                }
            }
        });
        return islLinkInfos;
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) IslLinkInfo(org.openkilda.model.IslLinkInfo)

Example 4 with IslLinkInfo

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

the class IslLinkConverter method toIslLinksInfo.

public static List<IslLinkInfo> toIslLinksInfo(final List<IslLink> islLinks) {
    if (islLinks != null) {
        final List<IslLinkInfo> islLinkInfos = new ArrayList<>();
        islLinks.forEach(islLink -> {
            IslLinkInfo islLinkInfo = toIslLinkInfo(islLink);
            boolean isSwitchRelationAdd = false;
            if (islLinkInfos.size() == 0) {
                islLinkInfos.add(islLinkInfo);
            } else {
                for (int i = 0; i < islLinkInfos.size(); i++) {
                    IslLinkInfo flowInfo = islLinkInfos.get(i);
                    if (flowInfo.getDstPort() == islLinkInfo.getSrcPort() && flowInfo.getDstSwitch().equalsIgnoreCase(islLinkInfo.getSrcSwitch()) && flowInfo.getSrcPort() == islLinkInfo.getDstPort() && flowInfo.getSrcSwitch().equalsIgnoreCase(islLinkInfo.getDstSwitch())) {
                        isSwitchRelationAdd = false;
                        break;
                    } else {
                        isSwitchRelationAdd = true;
                    }
                }
                if (isSwitchRelationAdd) {
                    islLinkInfos.add(islLinkInfo);
                }
            }
        });
        return islLinkInfos;
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) IslLinkInfo(org.openkilda.model.IslLinkInfo)

Example 5 with IslLinkInfo

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

the class IslLinkConverter method toIslLinkInfo.

/**
 * To isl link info.
 *
 * @param islLink the isl link
 * @param csNames the cs names
 * @param islCostMap the isl cost map
 * @return the isl link info
 */
private IslLinkInfo toIslLinkInfo(final IslLink islLink, final Map<String, String> csNames, Map<String, String> islCostMap) {
    IslLinkInfo islLinkInfo = new IslLinkInfo();
    islLinkInfo.setUnidirectional(true);
    islLinkInfo.setAvailableBandwidth(islLink.getAvailableBandwidth());
    islLinkInfo.setMaxBandwidth(islLink.getMaxBandwidth());
    islLinkInfo.setDefaultMaxBandwidth(islLink.getDefaultMaxBandwidth());
    islLinkInfo.setCost(islLink.getCost());
    islLinkInfo.setActualState(islLink.getActualState());
    islLinkInfo.setSpeed(islLink.getSpeed());
    islLinkInfo.setState(islLink.getState());
    islLinkInfo.setUnderMaintenance(islLink.isUnderMaintenance());
    islLinkInfo.setEvacuate(islLink.isEvacuate());
    islLinkInfo.setEnableBfd(islLink.isEnableBfd());
    islLinkInfo.setBfdSessionStatus(islLink.getBfdSessionStatus());
    List<IslPath> islPaths = islLink.getPath();
    if (islPaths != null && !islPaths.isEmpty()) {
        if (islPaths.get(0) != null) {
            islLinkInfo.setSrcPort(islPaths.get(0).getPortNo());
            islLinkInfo.setSrcSwitch(islPaths.get(0).getSwitchId());
            islLinkInfo.setSrcSwitchName(switchIntegrationService.customSwitchName(csNames, islPaths.get(0).getSwitchId()));
            if (islPaths.get(0).getSegmentLatency() > 0) {
                islLinkInfo.setLatency(islPaths.get(0).getSegmentLatency());
            }
        }
        if (islPaths.get(1) != null) {
            islLinkInfo.setDstPort(islPaths.get(1).getPortNo());
            islLinkInfo.setDstSwitch(islPaths.get(1).getSwitchId());
            islLinkInfo.setDstSwitchName(switchIntegrationService.customSwitchName(csNames, islPaths.get(1).getSwitchId()));
            if (islPaths.get(1).getSegmentLatency() > 0) {
                islLinkInfo.setLatency(islPaths.get(1).getSegmentLatency());
            }
        }
    }
    // set isl cost
    if (islCostMap.containsKey(islLinkInfo.getForwardKey())) {
        islLinkInfo.setCost(islCostMap.get(islLinkInfo.getForwardKey()));
    } else if (islCostMap.containsKey(islLinkInfo.getReverseKey())) {
        islLinkInfo.setCost(islCostMap.get(islLinkInfo.getReverseKey()));
    }
    return islLinkInfo;
}
Also used : IslLinkInfo(org.openkilda.model.IslLinkInfo) IslPath(org.openkilda.integration.model.response.IslPath)

Aggregations

IslLinkInfo (org.openkilda.model.IslLinkInfo)5 ArrayList (java.util.ArrayList)3 IslPath (org.openkilda.integration.model.response.IslPath)2 Test (org.junit.Test)1 LinkParametersDto (org.openkilda.model.LinkParametersDto)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1