use of org.onosproject.kubevirtnetworking.api.KubevirtPort in project onos by opennetworkinglab.
the class KubevirtListPortCommand method json.
private String json(List<KubevirtPort> ports) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
for (KubevirtPort port : ports) {
result.add(jsonForEntity(port, KubevirtPort.class));
}
return prettyJson(mapper, result.toString());
}
use of org.onosproject.kubevirtnetworking.api.KubevirtPort in project onos by opennetworkinglab.
the class KubevirtPortCodec method decode.
@Override
public KubevirtPort decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
String vmName = nullIsIllegal(json.get(VM_NAME).asText(), VM_NAME + MISSING_MESSAGE);
String networkId = nullIsIllegal(json.get(NETWORK_ID).asText(), NETWORK_ID + MISSING_MESSAGE);
String macAddress = nullIsIllegal(json.get(MAC_ADDRESS).asText(), MAC_ADDRESS + MISSING_MESSAGE);
KubevirtPort.Builder builder = DefaultKubevirtPort.builder().vmName(vmName).networkId(networkId).macAddress(MacAddress.valueOf(macAddress));
JsonNode ipAddressJson = json.get(IP_ADDRESS);
if (ipAddressJson != null) {
final IpAddress ipAddress = IpAddress.valueOf(ipAddressJson.asText());
builder.ipAddress(ipAddress);
}
JsonNode deviceIdJson = json.get(DEVICE_ID);
if (deviceIdJson != null) {
final DeviceId deviceId = DeviceId.deviceId(deviceIdJson.asText());
builder.deviceId(deviceId);
}
JsonNode portNumberJson = json.get(PORT_NUMBER);
if (portNumberJson != null) {
final PortNumber portNumber = PortNumber.portNumber(portNumberJson.asText());
builder.portNumber(portNumber);
}
log.trace("Port is {}", builder.build().toString());
return builder.build();
}
use of org.onosproject.kubevirtnetworking.api.KubevirtPort in project onos by opennetworkinglab.
the class KubevirtFloatingIpHandler method processGarpPacketForFloatingIp.
private void processGarpPacketForFloatingIp(KubevirtFloatingIp floatingIp, KubevirtNode electedGw) {
if (floatingIp == null) {
return;
}
KubevirtPort kubevirtPort = getKubevirtPortByFloatingIp(floatingIp);
if (kubevirtPort == null) {
return;
}
Ethernet ethernet = buildGarpPacket(kubevirtPort.macAddress(), floatingIp.floatingIp());
if (ethernet == null) {
return;
}
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(externalPatchPortNum(deviceService, electedGw)).build();
packetService.emit(new DefaultOutboundPacket(electedGw.intgBridge(), treatment, ByteBuffer.wrap(ethernet.serialize())));
}
use of org.onosproject.kubevirtnetworking.api.KubevirtPort in project onos by opennetworkinglab.
the class KubevirtFloatingIpHandler method setFloatingIpRulesForFip.
private void setFloatingIpRulesForFip(KubevirtRouter router, KubevirtFloatingIp floatingIp, KubevirtNode electedGw, boolean install) {
KubevirtPort kubevirtPort = getKubevirtPortByFloatingIp(floatingIp);
if (kubevirtPort == null) {
return;
}
KubevirtNetwork kubevirtNetwork = kubevirtNetworkService.network(kubevirtPort.networkId());
if (kubevirtNetwork.type() == VXLAN || kubevirtNetwork.type() == GENEVE || kubevirtNetwork.type() == GRE) {
setFloatingIpDownstreamRulesToGatewayTunBridge(floatingIp, electedGw, kubevirtNetwork, kubevirtPort, install);
}
setFloatingIpArpResponseRules(router, floatingIp, kubevirtPort, electedGw, install);
setFloatingIpUpstreamRules(router, floatingIp, kubevirtPort, electedGw, install);
setFloatingIpDownstreamRules(router, floatingIp, kubevirtPort, electedGw, install);
}
use of org.onosproject.kubevirtnetworking.api.KubevirtPort in project onos by opennetworkinglab.
the class KubevirtLbHandler method setLbDownStreamRulesForTunBridge.
private void setLbDownStreamRulesForTunBridge(KubevirtLoadBalancer loadBalancer, KubevirtNode gateway, boolean install) {
Set<KubevirtPort> ports = portService.ports(loadBalancer.networkId());
KubevirtNetwork network = networkService.network(loadBalancer.networkId());
PortNumber tunnelPortNumber = tunnelPort(gateway, network);
if (tunnelPortNumber == null) {
return;
}
loadBalancer.members().forEach(ip -> {
ports.stream().filter(port -> port.ipAddress().equals(ip) && port.macAddress() != null).findAny().ifPresent(port -> {
KubevirtNode workerNode = nodeService.node(port.deviceId());
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(port.ipAddress(), 32)).matchEthDst(port.macAddress());
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setTunnelId(Long.parseLong(network.segmentId())).extension(buildExtension(deviceService, gateway.tunBridge(), workerNode.dataIp().getIp4Address()), gateway.tunBridge()).setOutput(tunnelPortNumber);
flowRuleService.setRule(appId, gateway.tunBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_LB_GATEWAY_TUN_BRIDGE_RULE, TUNNEL_DEFAULT_TABLE, install);
});
});
}
Aggregations