use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork in project onos by opennetworkinglab.
the class KubevirtSecurityGroupHandler method resetSecurityGroupRules.
private void resetSecurityGroupRules() {
if (getUseSecurityGroupFlag()) {
nodeService.completeNodes(WORKER).forEach(node -> {
initializeProviderPipeline(node, true);
for (KubevirtNetwork network : networkService.tenantNetworks()) {
initializeTenantPipeline(network, node, true);
}
});
securityGroupService.securityGroups().forEach(securityGroup -> securityGroup.rules().forEach(this::securityGroupRuleAdded));
} else {
nodeService.completeNodes(WORKER).forEach(node -> {
initializeProviderPipeline(node, false);
for (KubevirtNetwork network : networkService.tenantNetworks()) {
initializeTenantPipeline(network, node, false);
}
});
securityGroupService.securityGroups().forEach(securityGroup -> securityGroup.rules().forEach(this::securityGroupRuleRemoved));
}
log.info("Reset security group info " + (getUseSecurityGroupFlag() ? "with" : "without") + " Security Group");
}
use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork in project onos by opennetworkinglab.
the class KubevirtSwitchingTenantHandler method setIngressRules.
private void setIngressRules(KubevirtNode node, boolean install) {
for (KubevirtNetwork network : kubevirtNetworkService.tenantNetworks()) {
if (node == null || node.type() != WORKER) {
return;
}
while (true) {
KubevirtNode updatedNode = kubevirtNodeService.node(node.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, node, network);
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchTunnelId(Long.parseLong(network.segmentId()));
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setOutput(patchPortNumber);
flowRuleService.setRule(appId, node.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.kubevirtnetworking.api.KubevirtNetwork in project onos by opennetworkinglab.
the class KubevirtNetworkHandler method setGatewayInterNetworkRoutingFromNetworkToPort.
private void setGatewayInterNetworkRoutingFromNetworkToPort(KubevirtRouter router, KubevirtNetwork srcNetwork, KubevirtPort dstPort, KubevirtNode gatewayNode, boolean install) {
Device gwDevice = deviceService.getDevice(gatewayNode.intgBridge());
if (gwDevice == null) {
log.warn("Failed to set internal network routing rule because " + "there's no device Id for device {}", gatewayNode.intgBridge());
return;
}
MacAddress routerMacAddress = getRouterMacAddress(router);
if (routerMacAddress == null) {
log.warn("Failed to set internal network routing rule because " + "there's no br-int port for device {}", gatewayNode.intgBridge());
return;
}
TrafficSelector.Builder sBuilder;
TrafficTreatment treatment;
if (srcNetwork.type() == FLAT || srcNetwork.type() == VLAN) {
sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchEthDst(routerMacAddress).matchIPSrc(IpPrefix.valueOf(srcNetwork.cidr())).matchIPDst(IpPrefix.valueOf(dstPort.ipAddress(), 32));
treatment = DefaultTrafficTreatment.builder().setEthSrc(routerMacAddress).setEthDst(dstPort.macAddress()).transition(FORWARDING_TABLE).build();
flowService.setRule(appId, gwDevice.id(), sBuilder.build(), treatment, PRIORITY_INTERNAL_ROUTING_RULE, GW_ENTRY_TABLE, install);
} else {
KubevirtNetwork dstNetwork = kubevirtNetworkService.network(dstPort.networkId());
if (dstNetwork == null) {
return;
}
KubevirtNode dstPortWorkerNode = kubevirtNodeService.node(dstPort.deviceId());
if (dstPortWorkerNode == null) {
return;
}
sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchEthDst(routerMacAddress).matchTunnelId(Long.parseLong(srcNetwork.segmentId())).matchIPSrc(IpPrefix.valueOf(srcNetwork.cidr())).matchIPDst(IpPrefix.valueOf(dstPort.ipAddress(), 32));
treatment = DefaultTrafficTreatment.builder().setTunnelId(Long.parseLong(dstNetwork.segmentId())).setEthSrc(routerMacAddress).setEthDst(dstPort.macAddress()).extension(buildExtension(deviceService, gatewayNode.tunBridge(), dstPortWorkerNode.dataIp().getIp4Address()), gatewayNode.tunBridge()).setOutput(PortNumber.IN_PORT).build();
flowService.setRule(appId, gatewayNode.tunBridge(), sBuilder.build(), treatment, PRIORITY_INTERNAL_ROUTING_RULE, TUNNEL_DEFAULT_TABLE, install);
}
}
use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork in project onos by opennetworkinglab.
the class KubevirtNetworkManager method reserveIp.
@Override
public boolean reserveIp(String networkId, IpAddress ip) {
checkArgument(!Strings.isNullOrEmpty(networkId), ERR_NULL_NETWORK_ID);
checkArgument(ip != null, ERR_NULL_IP);
KubevirtNetwork network = networkStore.network(networkId);
boolean result = network.ipPool().reserveIp(ip);
if (result) {
networkStore.updateNetwork(network);
} else {
log.warn("Failed to reserve IP address");
}
return result;
}
use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork in project onos by opennetworkinglab.
the class KubevirtRoutingSnatHandler method setStatefulSnatDownStreamRuleForKubevirtPort.
private void setStatefulSnatDownStreamRuleForKubevirtPort(KubevirtRouter router, KubevirtNode gatewayNode, KubevirtPort kubevirtPort, boolean install) {
MacAddress routerMacAddress = getRouterMacAddress(router);
if (routerMacAddress == null) {
log.error("Failed to set stateful snat downstream rule because " + "there's no br-int port for device {}", gatewayNode.intgBridge());
return;
}
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchEthSrc(routerMacAddress).matchIPDst(IpPrefix.valueOf(kubevirtPort.ipAddress(), 32));
KubevirtNetwork network = kubevirtNetworkService.network(kubevirtPort.networkId());
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setEthDst(kubevirtPort.macAddress()).transition(FORWARDING_TABLE);
flowService.setRule(appId, gatewayNode.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_STATEFUL_SNAT_RULE, GW_DROP_TABLE, install);
if (network.type() == VXLAN || network.type() == GENEVE || network.type() == GRE) {
setDownStreamRulesToGatewayTunBridge(network, gatewayNode, kubevirtPort, install);
}
}
Aggregations