use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class KubevirtFlowRuleManager method initializeGatewayNodePipeline.
protected void initializeGatewayNodePipeline(KubevirtNode kubevirtNode) {
DeviceId deviceId = kubevirtNode.intgBridge();
// for inbound to gateway entry table transition
connectTables(deviceId, STAT_INBOUND_TABLE, GW_ENTRY_TABLE);
// for gateway entry to gateway drop table transition
connectTables(deviceId, GW_ENTRY_TABLE, GW_DROP_TABLE);
// for setting up default gateway drop table
setupGatewayNodeDropTable(deviceId);
// for setting up default Forwarding table behavior which is NORMAL
setupNormalTable(deviceId, FORWARDING_TABLE);
kubevirtNode.phyIntfs().stream().filter(intf -> intf.physBridge() != null).forEach(phyIntf -> {
setupNormalTable(phyIntf.physBridge(), STAT_INBOUND_TABLE);
});
}
use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class KubevirtRoutingSnatHandler method initGatewayNodeSnatForRouter.
private void initGatewayNodeSnatForRouter(KubevirtRouter router, String gateway, boolean install) {
if (gateway == null) {
log.warn("Fail to initialize gateway node snat for router {} " + "because there's no gateway assigned to it", router.name());
return;
}
KubevirtNode electedGw = kubevirtNodeService.node(gateway);
if (electedGw == null) {
log.warn("Fail to initialize gateway node snat for router {} " + "because there's no gateway assigned to it", router.name());
return;
}
String routerSnatIp = router.external().keySet().stream().findAny().orElse(null);
if (routerSnatIp == null) {
log.warn("Fail to initialize gateway node snat for router {} " + "because there's no gateway snat ip assigned to it", router.name());
return;
}
String externalNet = router.external().values().stream().findAny().orElse(null);
if (externalNet == null) {
return;
}
if (router.peerRouter() != null && router.peerRouter().ipAddress() != null && router.peerRouter().macAddress() != null) {
setArpResponseToPeerRouter(electedGw, Ip4Address.valueOf(routerSnatIp), install);
setStatefulSnatUpstreamRules(electedGw, router, Ip4Address.valueOf(routerSnatIp), router.peerRouter().macAddress(), install);
setStatefulSnatDownstreamRuleForRouter(electedGw, router, Ip4Address.valueOf(routerSnatIp), kubevirtNetworkService.network(externalNet), install);
}
}
use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class KubevirtSwitchingTenantHandler method setEgressRules.
private void setEgressRules(KubevirtPort port, boolean install) {
if (port.ipAddress() == null) {
return;
}
KubevirtNetwork network = kubevirtNetworkService.network(port.networkId());
if (network == null) {
return;
}
if (network.type() == FLAT || network.type() == VLAN) {
return;
}
if (network.segmentId() == null) {
return;
}
KubevirtNode localNode = kubevirtNodeService.node(port.deviceId());
if (localNode == null || localNode.type() == MASTER) {
return;
}
for (KubevirtNode remoteNode : kubevirtNodeService.completeNodes(WORKER)) {
if (remoteNode.hostname().equals(localNode.hostname())) {
continue;
}
while (true) {
KubevirtNode updatedNode = kubevirtNodeService.node(localNode.hostname());
if (tunnelToTenantPort(deviceService, updatedNode, network) != null) {
break;
} else {
log.info("Waiting for tunnel to tenant patch port creation " + "on egress rule setup on node {}", updatedNode);
waitFor(3);
}
}
PortNumber patchPortNumber = tunnelToTenantPort(deviceService, remoteNode, network);
PortNumber tunnelPortNumber = tunnelPort(remoteNode, network);
if (tunnelPortNumber == null) {
return;
}
TrafficSelector.Builder sIpBuilder = DefaultTrafficSelector.builder().matchInPort(patchPortNumber).matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(port.ipAddress(), 32));
TrafficSelector.Builder sArpBuilder = DefaultTrafficSelector.builder().matchInPort(patchPortNumber).matchEthType(Ethernet.TYPE_ARP).matchArpTpa(Ip4Address.valueOf(port.ipAddress().toString()));
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.parseLong(network.segmentId())).extension(buildExtension(deviceService, remoteNode.tunBridge(), localNode.dataIp().getIp4Address()), remoteNode.tunBridge()).setOutput(tunnelPortNumber);
flowRuleService.setRule(appId, remoteNode.tunBridge(), sIpBuilder.build(), tBuilder.build(), PRIORITY_TUNNEL_RULE, TUNNEL_DEFAULT_TABLE, install);
flowRuleService.setRule(appId, remoteNode.tunBridge(), sArpBuilder.build(), tBuilder.build(), PRIORITY_TUNNEL_RULE, TUNNEL_DEFAULT_TABLE, install);
}
log.debug("Install egress rules for instance {}, segment ID {}", port.ipAddress(), network.segmentId());
}
use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class KubevirtSwitchingTenantHandler method setIngressRules.
private void setIngressRules(KubevirtNetwork network, boolean install) {
if (network == null) {
return;
}
if (network.type() == FLAT || network.type() == VLAN) {
return;
}
if (network.segmentId() == null) {
return;
}
for (KubevirtNode localNode : kubevirtNodeService.completeNodes(WORKER)) {
while (true) {
KubevirtNode updatedNode = kubevirtNodeService.node(localNode.hostname());
if (tunnelToTenantPort(deviceService, updatedNode, network) != null) {
break;
} else {
log.info("Waiting for tunnel to tenant patch port creation " + "on ingress rule setup on node {}", updatedNode);
waitFor(3);
}
}
PortNumber patchPortNumber = tunnelToTenantPort(deviceService, localNode, network);
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchTunnelId(Long.parseLong(network.segmentId()));
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setOutput(patchPortNumber);
flowRuleService.setRule(appId, localNode.tunBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_TUNNEL_RULE, TUNNEL_DEFAULT_TABLE, install);
log.debug("Install ingress rules for segment ID {}", network.segmentId());
}
}
use of org.onosproject.kubevirtnode.api.KubevirtNode in project onos by opennetworkinglab.
the class KubevirtNodeCodec method decode.
@Override
public KubevirtNode decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
String hostname = nullIsIllegal(json.get(HOST_NAME).asText(), HOST_NAME + MISSING_MESSAGE);
String type = nullIsIllegal(json.get(TYPE).asText(), TYPE + MISSING_MESSAGE);
String mIp = nullIsIllegal(json.get(MANAGEMENT_IP).asText(), MANAGEMENT_IP + MISSING_MESSAGE);
KubevirtNode.Builder nodeBuilder = DefaultKubevirtNode.builder().hostname(hostname).type(KubevirtNode.Type.valueOf(type)).state(KubevirtNodeState.INIT).managementIp(IpAddress.valueOf(mIp));
if (json.get(DATA_IP) != null) {
nodeBuilder.dataIp(IpAddress.valueOf(json.get(DATA_IP).asText()));
}
JsonNode intBridgeJson = json.get(INTEGRATION_BRIDGE);
if (intBridgeJson != null) {
nodeBuilder.intgBridge(DeviceId.deviceId(intBridgeJson.asText()));
}
JsonNode tunBridgeJson = json.get(TUNNEL_BRIDGE);
if (tunBridgeJson != null) {
nodeBuilder.tunBridge(DeviceId.deviceId(tunBridgeJson.asText()));
}
// parse physical interfaces
List<KubevirtPhyInterface> phyIntfs = new ArrayList<>();
JsonNode phyIntfsJson = json.get(PHYSICAL_INTERFACES);
if (phyIntfsJson != null) {
final JsonCodec<KubevirtPhyInterface> phyIntfCodec = context.codec(KubevirtPhyInterface.class);
IntStream.range(0, phyIntfsJson.size()).forEach(i -> {
ObjectNode intfJson = get(phyIntfsJson, i);
phyIntfs.add(phyIntfCodec.decode(intfJson, context));
});
}
nodeBuilder.phyIntfs(phyIntfs);
JsonNode externalBridgeJson = json.get(GATEWAY_BRIDGE_NAME);
if (externalBridgeJson != null) {
nodeBuilder.gatewayBridgeName(externalBridgeJson.asText());
}
log.trace("node is {}", nodeBuilder.build().toString());
return nodeBuilder.build();
}
Aggregations