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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations