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);
});
}
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;
}
}
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);
});
}
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);
}
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"));
}
Aggregations