Search in sources :

Example 1 with KubevirtPort

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());
}
Also used : ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with KubevirtPort

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();
}
Also used : DeviceId(org.onosproject.net.DeviceId) JsonNode(com.fasterxml.jackson.databind.JsonNode) IpAddress(org.onlab.packet.IpAddress) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort) DefaultKubevirtPort(org.onosproject.kubevirtnetworking.api.DefaultKubevirtPort) PortNumber(org.onosproject.net.PortNumber)

Example 3 with KubevirtPort

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())));
}
Also used : Ethernet(org.onlab.packet.Ethernet) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 4 with KubevirtPort

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);
}
Also used : KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort)

Example 5 with KubevirtPort

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);
        });
    });
}
Also used : KubevirtNode(org.onosproject.kubevirtnode.api.KubevirtNode) KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) KubevirtNetworkingUtil.getRouterForKubevirtNetwork(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterForKubevirtNetwork) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) KubevirtPort(org.onosproject.kubevirtnetworking.api.KubevirtPort) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Aggregations

KubevirtPort (org.onosproject.kubevirtnetworking.api.KubevirtPort)9 KubevirtNetwork (org.onosproject.kubevirtnetworking.api.KubevirtNetwork)4 DefaultKubevirtPort (org.onosproject.kubevirtnetworking.api.DefaultKubevirtPort)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 KubevirtNetworkingUtil.getRouterForKubevirtNetwork (org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.getRouterForKubevirtNetwork)2 PortNumber (org.onosproject.net.PortNumber)2 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)2 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 Ethernet (org.onlab.packet.Ethernet)1 IpAddress (org.onlab.packet.IpAddress)1 KubevirtPortService (org.onosproject.kubevirtnetworking.api.KubevirtPortService)1 KubevirtPortJsonMatcher.matchesKubevirtPort (org.onosproject.kubevirtnetworking.codec.KubevirtPortJsonMatcher.matchesKubevirtPort)1 KubevirtNetworkingUtil.genFormatString (org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)1 KubevirtNode (org.onosproject.kubevirtnode.api.KubevirtNode)1