Search in sources :

Example 1 with InstancePort

use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.

the class OpenstackSecurityGroupHandler method populateSecurityGroupRule.

private void populateSecurityGroupRule(SecurityGroupRule sgRule, InstancePort instPort, IpPrefix remoteIp, boolean install) {
    if (!checkProtocol(sgRule.getProtocol())) {
        return;
    }
    Set<TrafficSelector> selectors = buildSelectors(sgRule, Ip4Address.valueOf(instPort.ipAddress().toInetAddress()), remoteIp, instPort.networkId());
    if (selectors == null || selectors.isEmpty()) {
        return;
    }
    // if the device is not available we do not perform any action
    if (instPort.deviceId() == null || !deviceService.isAvailable(instPort.deviceId())) {
        return;
    }
    // in case a port is bound to multiple security groups, we do NOT remove
    // egress rules unless all security groups bound to the port to be removed
    Port osPort = osNetService.port(instPort.portId());
    if (!install && osPort != null && sgRule.getDirection().equalsIgnoreCase(EGRESS)) {
        List<String> sgIds = osPort.getSecurityGroups();
        if (!sgIds.contains(sgRule.getSecurityGroupId()) && !sgIds.isEmpty()) {
            return;
        }
    }
    // XXX All egress traffic needs to go through connection tracking module,
    // which might hurt its performance.
    ExtensionTreatment ctTreatment = niciraConnTrackTreatmentBuilder(driverService, instPort.deviceId()).commit(true).build();
    TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
    int aclTable;
    if (sgRule.getDirection().equalsIgnoreCase(EGRESS)) {
        aclTable = ACL_EGRESS_TABLE;
        tBuilder.transition(ACL_RECIRC_TABLE);
    } else {
        aclTable = ACL_INGRESS_TABLE;
        tBuilder.extension(ctTreatment, instPort.deviceId()).transition(JUMP_TABLE);
    }
    int finalAclTable = aclTable;
    selectors.forEach(selector -> {
        osFlowRuleService.setRule(appId, instPort.deviceId(), selector, tBuilder.build(), PRIORITY_ACL_RULE, finalAclTable, install);
    });
}
Also used : InstancePort(org.onosproject.openstacknetworking.api.InstancePort) Port(org.openstack4j.model.network.Port) TpPort(org.onlab.packet.TpPort) NeutronPort(org.openstack4j.openstack.networking.domain.NeutronPort) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ExtensionTreatment(org.onosproject.net.flow.instructions.ExtensionTreatment)

Example 2 with InstancePort

use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.

the class OpenstackSwitchingArpHandler method getMacFromHostOpenstack.

/**
 * Returns MAC address of a host with a given target IP address by asking to
 * instance port service.
 *
 * @param targetIp target ip
 * @param osNetId  openstack network id of the source instance port
 * @return mac address, or none mac address if it fails to find the mac
 */
private MacAddress getMacFromHostOpenstack(IpAddress targetIp, String osNetId) {
    checkNotNull(targetIp);
    InstancePort instPort = instancePortService.instancePort(targetIp, osNetId);
    if (instPort != null) {
        log.trace("Found MAC from host service for {}", targetIp);
        return instPort.macAddress();
    } else {
        return MacAddress.NONE;
    }
}
Also used : InstancePort(org.onosproject.openstacknetworking.api.InstancePort)

Example 3 with InstancePort

use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.

the class OpenstackSwitchingHandler method setForwardingRulesForVlan.

/**
 * Configures the flow rules which are used for L2 VLAN packet switching.
 * Note that these rules will be inserted in switching table (table 5).
 *
 * @param instPort instance port object
 * @param install install flag, add the rule if true, remove it otherwise
 */
private void setForwardingRulesForVlan(InstancePort instPort, boolean install) {
    // switching rules for the instPorts in the same node
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(instPort.ipAddress().toIpPrefix()).matchVlanId(getVlanId(instPort)).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().popVlan().setEthDst(instPort.macAddress()).setOutput(instPort.portNumber()).build();
    osFlowRuleService.setRule(appId, instPort.deviceId(), selector, treatment, PRIORITY_SWITCHING_RULE, FORWARDING_TABLE, install);
    // switching rules for the instPorts in the remote node
    osNodeService.completeNodes(COMPUTE).stream().filter(remoteNode -> !remoteNode.intgBridge().equals(instPort.deviceId()) && remoteNode.vlanIntf() != null).forEach(remoteNode -> {
        TrafficTreatment treatmentToRemote = DefaultTrafficTreatment.builder().setEthDst(instPort.macAddress()).setOutput(remoteNode.vlanPortNum()).build();
        osFlowRuleService.setRule(appId, remoteNode.intgBridge(), selector, treatmentToRemote, PRIORITY_SWITCHING_RULE, FORWARDING_TABLE, install);
    });
}
Also used : CoreService(org.onosproject.core.CoreService) InstancePort(org.onosproject.openstacknetworking.api.InstancePort) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) OpenstackNetworkListener(org.onosproject.openstacknetworking.api.OpenstackNetworkListener) InstancePortEvent(org.onosproject.openstacknetworking.api.InstancePortEvent) OPENSTACK_INSTANCE_MIGRATION_STARTED(org.onosproject.openstacknetworking.api.InstancePortEvent.Type.OPENSTACK_INSTANCE_MIGRATION_STARTED) DriverService(org.onosproject.net.driver.DriverService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) Ethernet(org.onlab.packet.Ethernet) PRIORITY_TUNNEL_TAG_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_TUNNEL_TAG_RULE) Type(org.onosproject.openstacknetworking.api.OpenstackNetwork.Type) ApplicationId(org.onosproject.core.ApplicationId) OpenstackNetworkEvent(org.onosproject.openstacknetworking.api.OpenstackNetworkEvent) MastershipService(org.onosproject.mastership.MastershipService) ACL_EGRESS_TABLE(org.onosproject.openstacknetworking.api.Constants.ACL_EGRESS_TABLE) NodeId(org.onosproject.cluster.NodeId) OpenstackNodeService(org.onosproject.openstacknode.api.OpenstackNodeService) OpenstackFlowRuleService(org.onosproject.openstacknetworking.api.OpenstackFlowRuleService) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) PRIORITY_ADMIN_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_ADMIN_RULE) Executors.newSingleThreadExecutor(java.util.concurrent.Executors.newSingleThreadExecutor) InstancePortListener(org.onosproject.openstacknetworking.api.InstancePortListener) Objects(java.util.Objects) OPENSTACK_NETWORKING_APP_ID(org.onosproject.openstacknetworking.api.Constants.OPENSTACK_NETWORKING_APP_ID) OpenstackNetworkingUtil.swapStaleLocation(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.swapStaleLocation) ClusterService(org.onosproject.cluster.ClusterService) OpenstackNetworkingUtil.tunnelPortNumByNetId(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetId) PRE_FLAT_TABLE(org.onosproject.openstacknetworking.api.Constants.PRE_FLAT_TABLE) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) Network(org.openstack4j.model.network.Network) COMPUTE(org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE) RulePopulatorUtil.buildExtension(org.onosproject.openstacknetworking.util.RulePopulatorUtil.buildExtension) Strings(com.google.common.base.Strings) OpenstackNetworkService(org.onosproject.openstacknetworking.api.OpenstackNetworkService) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Activate(org.osgi.service.component.annotations.Activate) ARP_TABLE(org.onosproject.openstacknetworking.api.Constants.ARP_TABLE) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) ExecutorService(java.util.concurrent.ExecutorService) Port(org.openstack4j.model.network.Port) ComponentConfigService(org.onosproject.cfg.ComponentConfigService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FORWARDING_TABLE(org.onosproject.openstacknetworking.api.Constants.FORWARDING_TABLE) Logger(org.slf4j.Logger) VlanId(org.onlab.packet.VlanId) PRIORITY_SWITCHING_RULE(org.onosproject.openstacknetworking.api.Constants.PRIORITY_SWITCHING_RULE) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) OpenstackNetworkingUtil.getPropertyValue(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue) ConfigProperty(org.onosproject.cfg.ConfigProperty) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) OpenstackNetworkingUtil.deriveResourceName(org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName) Reference(org.osgi.service.component.annotations.Reference) LeadershipService(org.onosproject.cluster.LeadershipService) VTAG_TABLE(org.onosproject.openstacknetworking.api.Constants.VTAG_TABLE) InstancePortService(org.onosproject.openstacknetworking.api.InstancePortService) ARP_BROADCAST_MODE(org.onosproject.openstacknetworking.api.Constants.ARP_BROADCAST_MODE) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 4 with InstancePort

use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.

the class OpenstackK8sIntegrationManager method setPodToNodeIpRules.

private void setPodToNodeIpRules(IpAddress k8sNodeIp, IpAddress gatewayIp, String osK8sIntPortName, boolean install) {
    InstancePort instPort = instPortByNodeIp(k8sNodeIp);
    if (instPort == null) {
        return;
    }
    OpenstackNode osNode = osNodeByNodeIp(k8sNodeIp);
    if (osNode == null) {
        return;
    }
    PortNumber osK8sIntPortNum = osNode.portNumByName(osK8sIntPortName);
    if (osK8sIntPortNum == null) {
        return;
    }
    TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(gatewayIp, 32)).matchInPort(osK8sIntPortNum).build();
    TrafficTreatment treatment = DefaultTrafficTreatment.builder().setIpDst(k8sNodeIp).setEthDst(instPort.macAddress()).transition(FLAT_TABLE).build();
    osFlowRuleService.setRule(appId, osNode.intgBridge(), selector, treatment, PRIORITY_CNI_PT_IP_RULE, PRE_FLAT_TABLE, install);
    setJumpRules(osK8sIntPortNum, osNode, install);
}
Also used : InstancePort(org.onosproject.openstacknetworking.api.InstancePort) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OpenstackNode(org.onosproject.openstacknode.api.OpenstackNode) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 5 with InstancePort

use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.

the class InstancePortCodecTest method testInstancePortDecode.

/**
 * Tests the instance port decoding.
 */
@Test
public void testInstancePortDecode() throws IOException {
    InstancePort port = getInstancePort("InstancePort.json");
    assertThat(port.networkId(), is("net-id-1"));
    assertThat(port.portId(), is("port-id-1"));
    assertThat(port.deviceId(), is(DeviceId.deviceId("of:000000000000000a")));
    assertThat(port.portNumber(), is(PortNumber.portNumber(1, "tap-1")));
    assertThat(port.ipAddress(), is(IpAddress.valueOf("10.10.10.1")));
    assertThat(port.macAddress(), is(MacAddress.valueOf("11:22:33:44:55:66")));
    assertThat(port.state().name(), is("ACTIVE"));
}
Also used : InstancePort(org.onosproject.openstacknetworking.api.InstancePort) DefaultInstancePort(org.onosproject.openstacknetworking.impl.DefaultInstancePort) InstancePortJsonMatcher.matchesInstancePort(org.onosproject.openstacknetworking.codec.InstancePortJsonMatcher.matchesInstancePort) Test(org.junit.Test)

Aggregations

InstancePort (org.onosproject.openstacknetworking.api.InstancePort)36 Test (org.junit.Test)13 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)10 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)10 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)9 TrafficSelector (org.onosproject.net.flow.TrafficSelector)9 InstancePortService (org.onosproject.openstacknetworking.api.InstancePortService)9 OpenstackNode (org.onosproject.openstacknode.api.OpenstackNode)9 Set (java.util.Set)7 Argument (org.apache.karaf.shell.api.action.Argument)7 Command (org.apache.karaf.shell.api.action.Command)7 Service (org.apache.karaf.shell.api.action.lifecycle.Service)7 AbstractShellCommand (org.onosproject.cli.AbstractShellCommand)7 PortNumber (org.onosproject.net.PortNumber)7 Port (org.openstack4j.model.network.Port)7 IpAddress (org.onlab.packet.IpAddress)6 ApplicationId (org.onosproject.core.ApplicationId)6 CoreService (org.onosproject.core.CoreService)6 OpenstackNetworkService (org.onosproject.openstacknetworking.api.OpenstackNetworkService)6 OpenstackNodeService (org.onosproject.openstacknode.api.OpenstackNodeService)6