use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackRoutingFloatingIpHandler method processGratuitousArpPacket.
private void processGratuitousArpPacket(NetFloatingIP floatingIP, InstancePort instancePort) {
Set<OpenstackNode> gws = ImmutableSet.copyOf(osNodeService.completeNodes(GATEWAY));
Network osNet = osNetworkService.network(instancePort.networkId());
OpenstackNode selectedGw = getGwByInstancePort(gws, instancePort);
ExternalPeerRouter externalPeerRouter = externalPeerRouterForNetwork(osNet, osNetworkService, osRouterAdminService);
if (externalPeerRouter == null) {
log.error("Failed to process GARP packet for floating ip {}, because ", NO_EXT_PEER_ROUTER_MSG);
return;
}
processGarpPacketForFloatingIp(floatingIP, instancePort, externalPeerRouter.vlanId(), selectedGw, packetService);
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackRoutingFloatingIpHandler method setComputeNodeToGatewayHelper.
// a helper method
private void setComputeNodeToGatewayHelper(InstancePort instPort, Network osNet, Set<OpenstackNode> gateways, boolean install) {
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(instPort.ipAddress().toIpPrefix()).matchEthDst(Constants.DEFAULT_GATEWAY_MAC);
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
OpenstackNode selectedGatewayNode = getGwByComputeDevId(gateways, instPort.deviceId());
if (selectedGatewayNode == null) {
log.warn(ERR_FLOW + "no gateway node selected");
return;
}
Type netType = osNetworkService.networkType(osNet.getId());
switch(netType) {
case VXLAN:
case GRE:
case GENEVE:
PortNumber portNum = tunnelPortNumByNetId(instPort.networkId(), osNetworkService, osNodeService.node(instPort.deviceId()));
if (portNum == null) {
log.warn(ERR_FLOW + "no tunnel port");
return;
}
sBuilder.matchTunnelId(Long.parseLong(osNet.getProviderSegID()));
tBuilder.extension(buildExtension(deviceService, instPort.deviceId(), selectedGatewayNode.dataIp().getIp4Address()), instPort.deviceId()).setOutput(portNum);
break;
case VLAN:
if (osNodeService.node(instPort.deviceId()).vlanPortNum() == null) {
log.warn(ERR_FLOW + "no vlan port");
return;
}
sBuilder.matchVlanId(VlanId.vlanId(osNet.getProviderSegID()));
tBuilder.setOutput(osNodeService.node(instPort.deviceId()).vlanPortNum());
break;
default:
log.warn(ERR_FLOW + "no supported network type");
}
osFlowRuleService.setRule(appId, instPort.deviceId(), sBuilder.build(), tBuilder.build(), PRIORITY_EXTERNAL_FLOATING_ROUTING_RULE, ROUTING_TABLE, install);
log.trace("Succeeded to set flow rules from compute node to gateway on compute node");
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackNetworkingUtilTest method testGetGwByComputeDevId.
/**
* Tests the getGwByComputeDevId method.
*/
@Test
public void testGetGwByComputeDevId() {
Set<OpenstackNode> gws = Sets.newConcurrentHashSet();
OpenstackNode nullGw = getGwByComputeDevId(gws, genDeviceId(1));
assertNull(nullGw);
gws.add(genGateway(1));
gws.add(genGateway(2));
gws.add(genGateway(3));
Set<OpenstackNode> cloneOfGws = ImmutableSet.copyOf(gws);
Map<String, Integer> gwCountMap = Maps.newConcurrentMap();
int numOfDev = 99;
for (int i = 1; i < 1 + numOfDev; i++) {
OpenstackNode gw = getGwByComputeDevId(gws, genDeviceId(i));
if (gwCountMap.get(gw.hostname()) == null) {
gwCountMap.put(gw.hostname(), 1);
} else {
gwCountMap.compute(gw.hostname(), (k, v) -> v + 1);
}
new EqualsTester().addEqualityGroup(getGwByComputeDevId(gws, genDeviceId(i)), getGwByComputeDevId(cloneOfGws, genDeviceId(i))).testEquals();
}
int sum = gwCountMap.values().stream().mapToInt(Integer::intValue).sum();
assertEquals(numOfDev, sum);
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackManagementWebResource method syncRulesBaseForNode.
private void syncRulesBaseForNode(OpenstackNode osNode) {
OpenstackNode updated = osNode.updateState(NodeState.INIT);
osNodeAdminService.updateNode(updated);
boolean result = true;
long timeoutExpiredMs = System.currentTimeMillis() + TIMEOUT_MS;
while (osNodeAdminService.node(osNode.hostname()).state() != COMPLETE) {
long waitMs = timeoutExpiredMs - System.currentTimeMillis();
try {
sleep(SLEEP_MS);
} catch (InterruptedException e) {
log.error("Exception caused during node synchronization...");
}
if (osNodeAdminService.node(osNode.hostname()).state() == COMPLETE) {
break;
} else {
osNodeAdminService.updateNode(updated);
log.info("Failed to synchronize flow rules, retrying...");
}
if (waitMs <= 0) {
result = false;
break;
}
}
if (result) {
log.info("Successfully synchronize flow rules for node {}!", osNode.hostname());
} else {
log.warn("Failed to synchronize flow rules for node {}.", osNode.hostname());
}
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackManagementWebResource method syncStates.
/**
* Synchronizes the network states with openstack.
*
* @return 200 OK with sync result, 404 not found
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("sync/states")
public Response syncStates() {
Map<String, String> headerMap = new HashMap();
headerMap.put(HTTP_HEADER_ACCEPT, HTTP_HEADER_VALUE_JSON);
Optional<OpenstackNode> node = osNodeAdminService.nodes(CONTROLLER).stream().findFirst();
if (!node.isPresent()) {
log.error(AUTH_INFO_NOT_FOUND);
throw new ItemNotFoundException(AUTH_INFO_NOT_FOUND);
}
OSClient osClient = OpenstackNetworkingUtil.getConnectedClient(node.get());
if (osClient == null) {
log.error(AUTH_INFO_NOT_CORRECT);
throw new ItemNotFoundException(AUTH_INFO_NOT_CORRECT);
}
try {
osClient.headers(headerMap).networking().securitygroup().list().forEach(osSg -> {
if (osSgAdminService.securityGroup(osSg.getId()) != null) {
osSgAdminService.updateSecurityGroup(osSg);
} else {
osSgAdminService.createSecurityGroup(osSg);
}
});
} catch (Exception e) {
log.warn("Failed to retrieve security group due to {}", e.getMessage());
return Response.serverError().build();
}
try {
osClient.headers(headerMap).networking().network().list().forEach(osNet -> {
if (osNetAdminService.network(osNet.getId()) != null) {
osNetAdminService.updateNetwork(osNet);
} else {
osNetAdminService.createNetwork(osNet);
}
});
} catch (Exception e) {
log.warn("Failed to retrieve network due to {}", e.getMessage());
return Response.serverError().build();
}
try {
osClient.headers(headerMap).networking().subnet().list().forEach(osSubnet -> {
if (osNetAdminService.subnet(osSubnet.getId()) != null) {
osNetAdminService.updateSubnet(osSubnet);
} else {
osNetAdminService.createSubnet(osSubnet);
}
});
} catch (Exception e) {
log.warn("Failed to retrieve subnet due to {}", e.getMessage());
return Response.serverError().build();
}
try {
osClient.headers(headerMap).networking().port().list().forEach(osPort -> {
if (osNetAdminService.port(osPort.getId()) != null) {
osNetAdminService.updatePort(osPort);
} else {
osNetAdminService.createPort(osPort);
}
});
} catch (Exception e) {
log.warn("Failed to retrieve port due to {}", e.getMessage());
return Response.serverError().build();
}
try {
osClient.headers(headerMap).networking().router().list().forEach(osRouter -> {
if (osRouterAdminService.router(osRouter.getId()) != null) {
osRouterAdminService.updateRouter(osRouter);
} else {
osRouterAdminService.createRouter(osRouter);
}
osNetAdminService.ports().stream().filter(osPort -> Objects.equals(osPort.getDeviceId(), osRouter.getId()) && Objects.equals(osPort.getDeviceOwner(), DEVICE_OWNER_IFACE)).forEach(osPort -> addRouterIface(osPort, osRouterAdminService));
});
} catch (Exception e) {
log.warn("Failed to retrieve router due to {}", e.getMessage());
return Response.serverError().build();
}
try {
osClient.headers(headerMap).networking().floatingip().list().forEach(osFloating -> {
if (osRouterAdminService.floatingIp(osFloating.getId()) != null) {
osRouterAdminService.updateFloatingIp(osFloating);
} else {
osRouterAdminService.createFloatingIp(osFloating);
}
});
} catch (Exception e) {
log.warn("Failed to retrieve floating IP due to {}", e.getMessage());
return Response.serverError().build();
}
return ok(mapper().createObjectNode()).build();
}
Aggregations