use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork in project onos by opennetworkinglab.
the class KubevirtLbHandler method setBucketsToGroup.
private void setBucketsToGroup(KubevirtLoadBalancer loadBalancer, KubevirtNode gateway, boolean install) {
int groupId = loadBalancer.hashCode();
KubevirtNetwork network = networkService.network(loadBalancer.networkId());
Set<KubevirtPort> ports = portService.ports(loadBalancer.networkId());
List<GroupBucket> bkts = Lists.newArrayList();
loadBalancer.members().forEach(ip -> {
ports.stream().filter(port -> port.ipAddress().equals(ip) && port.macAddress() != null).findAny().ifPresent(port -> bkts.add(buildGroupBucket(port)));
});
groupRuleService.setBuckets(appId, gateway.intgBridge(), groupId, bkts, install);
}
use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork in project onos by opennetworkinglab.
the class KubevirtNetworkManager method allocateIp.
@Override
public IpAddress allocateIp(String networkId) {
checkArgument(!Strings.isNullOrEmpty(networkId), ERR_NULL_NETWORK_ID);
try {
KubevirtNetwork network = networkStore.network(networkId);
IpAddress ip = network.ipPool().allocateIp();
networkStore.updateNetwork(network);
return ip;
} catch (Exception e) {
log.error("Failed to allocate IP address", e);
}
return null;
}
use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork in project onos by opennetworkinglab.
the class KubevirtListNetworkCommand method json.
private String json(List<KubevirtNetwork> networks) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
for (KubevirtNetwork network : networks) {
result.add(jsonForEntity(network, KubevirtNetwork.class));
}
return prettyJson(mapper, result.toString());
}
use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork in project onos by opennetworkinglab.
the class KubevirtListNetworkCommand method doExecute.
@Override
protected void doExecute() throws Exception {
KubevirtNetworkService service = get(KubevirtNetworkService.class);
List<KubevirtNetwork> networks = Lists.newArrayList(service.networks());
networks.sort(Comparator.comparing(KubevirtNetwork::name));
String format = genFormatString(ImmutableList.of(CLI_ID_LENGTH, CLI_NAME_LENGTH, CLI_TYPE_LENGTH, CLI_SEG_ID_LENGTH, CLI_IP_ADDRESS_LENGTH));
if (outputJson()) {
print("%s", json(networks));
} else {
print(format, "ID", "Name", "Type", "SegId", "Gateway");
for (KubevirtNetwork net : networks) {
print(format, StringUtils.substring(net.networkId(), 0, CLI_ID_LENGTH - CLI_MARGIN_LENGTH), StringUtils.substring(net.name(), 0, CLI_NAME_LENGTH - CLI_MARGIN_LENGTH), net.type().toString(), net.segmentId() == null ? "N/A" : net.segmentId(), net.gatewayIp() == null ? "N/A" : net.gatewayIp().toString());
}
}
}
use of org.onosproject.kubevirtnetworking.api.KubevirtNetwork 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());
}
Aggregations