use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.
the class OpenstackK8sIntegrationManager method setNodePortEgressRules.
private void setNodePortEgressRules(IpAddress k8sNodeIp, String osK8sExtPortName, boolean install) {
InstancePort instPort = instPortByNodeIp(k8sNodeIp);
if (instPort == null) {
return;
}
OpenstackNode osNode = osNodeByNodeIp(k8sNodeIp);
if (osNode == null) {
return;
}
PortNumber osK8sExtPortNum = portNumberByNodeIpAndPortName(k8sNodeIp, osK8sExtPortName);
Port phyPort = phyPortByInstPort(instPort);
if (phyPort == null) {
log.warn("No phys interface found for instance port {}", instPort);
return;
}
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchInPort(osK8sExtPortNum).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setEthSrc(instPort.macAddress()).setOutput(phyPort.number()).build();
osFlowRuleService.setRule(appId, osNode.intgBridge(), selector, treatment, PRIORITY_CNI_PT_NODE_PORT_IP_RULE, PRE_FLAT_TABLE, install);
setJumpRules(osK8sExtPortNum, osNode, install);
}
use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.
the class OpenstackRoutingArpHandler method processArpPacket.
private void processArpPacket(PacketContext context, Ethernet ethernet) {
ARP arp = (ARP) ethernet.getPayload();
if (arp.getOpCode() == ARP.OP_REQUEST && ARP_PROXY_MODE.equals(getArpMode())) {
if (log.isTraceEnabled()) {
log.trace("ARP request received from {} for {}", Ip4Address.valueOf(arp.getSenderProtocolAddress()).toString(), Ip4Address.valueOf(arp.getTargetProtocolAddress()).toString());
}
IpAddress targetIp = Ip4Address.valueOf(arp.getTargetProtocolAddress());
MacAddress targetMac = null;
NetFloatingIP floatingIP = osRouterAdminService.floatingIps().stream().filter(ip -> ip.getFloatingIpAddress().equals(targetIp.toString())).findAny().orElse(null);
// In case target ip is for associated floating ip, sets target mac to vm's.
if (floatingIP != null && floatingIP.getPortId() != null) {
InstancePort instPort = instancePortService.instancePort(floatingIP.getPortId());
if (instPort == null) {
log.trace("Unknown target ARP request for {}, ignore it", targetIp);
return;
} else {
targetMac = instPort.macAddress();
}
OpenstackNode gw = getGwByInstancePort(osNodeService.completeNodes(GATEWAY), instPort);
if (gw == null) {
return;
}
// if the ARP packet_in received from non-relevant GWs, we simply ignore it
if (!Objects.equals(gw.intgBridge(), context.inPacket().receivedFrom().deviceId())) {
return;
}
}
if (isExternalGatewaySourceIp(targetIp)) {
targetMac = Constants.DEFAULT_GATEWAY_MAC;
}
if (targetMac == null) {
log.trace("Unknown target ARP request for {}, ignore it", targetIp);
return;
}
Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), targetMac, ethernet);
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(context.inPacket().receivedFrom().port()).build();
packetService.emit(new DefaultOutboundPacket(context.inPacket().receivedFrom().deviceId(), treatment, ByteBuffer.wrap(ethReply.serialize())));
context.block();
}
if (arp.getOpCode() == ARP.OP_REPLY) {
ConnectPoint cp = context.inPacket().receivedFrom();
PortNumber receivedPortNum = cp.port();
IpAddress spa = Ip4Address.valueOf(arp.getSenderProtocolAddress());
MacAddress sha = MacAddress.valueOf(arp.getSenderHardwareAddress());
log.debug("ARP reply ip: {}, mac: {}", spa, sha);
try {
Set<String> extRouterIps = osNetworkService.externalPeerRouters().stream().map(r -> r.ipAddress().toString()).collect(Collectors.toSet());
// if SPA is NOT contained in existing external router IP set, we ignore it
if (!extRouterIps.contains(spa.toString())) {
return;
}
OpenstackNode node = osNodeService.node(cp.deviceId());
if (node == null) {
return;
}
// we only handles the ARP-Reply message received by gateway node
if (node.type() != GATEWAY) {
return;
}
if (receivedPortNum.equals(node.uplinkPortNum())) {
osNetworkAdminService.updateExternalPeerRouterMac(spa, sha);
}
} catch (Exception e) {
log.error("Exception occurred because of {}", e);
}
}
}
use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.
the class OpenstackRoutingFloatingIpHandler method associateFloatingIp.
private void associateFloatingIp(NetFloatingIP osFip) {
InstancePort instPort = instancePortService.instancePort(osFip.getPortId());
if (instPort == null) {
log.warn("Failed to insert floating IP rule for {} due to missing of port info.", osFip.getFloatingIpAddress());
return;
}
// set floating IP rules only if the port is associated to a VM
if (!Strings.isNullOrEmpty(instPort.deviceId().toString())) {
setFloatingIpRules(osFip, instPort, null, null, true);
processGratuitousArpPacket(osFip, instPort);
}
}
use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.
the class OpenstackRemoveAclCommand method doExecute.
@Override
protected void doExecute() {
OpenstackFlowRuleService flowRuleService = get(OpenstackFlowRuleService.class);
CoreService coreService = get(CoreService.class);
ApplicationId appId = coreService.getAppId(OPENSTACK_NETWORKING_APP_ID);
InstancePortService instancePortService = get(InstancePortService.class);
IpAddress srcIpAddress = null;
IpAddress dstIpAddress = null;
try {
srcIpAddress = IpAddress.valueOf(srcIpStr);
dstIpAddress = IpAddress.valueOf(dstIpStr);
} catch (IllegalArgumentException e) {
log.error("IllegalArgumentException occurred because of {}", e);
return;
}
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(srcIpAddress.toIpPrefix()).matchIPDst(dstIpAddress.toIpPrefix());
TrafficTreatment treatment = DefaultTrafficTreatment.builder().drop().build();
if (srcPort != 0 || dstPort != 0) {
sBuilder.matchIPProtocol(IPv4.PROTOCOL_TCP);
if (srcPort != 0) {
sBuilder.matchTcpSrc(TpPort.tpPort(srcPort));
}
if (dstPort != 0) {
sBuilder.matchTcpDst(TpPort.tpPort(dstPort));
}
}
log.info("Deny the packet from srcIp: {}, dstPort: {} to dstIp: {}, dstPort: {}", srcIpAddress.toString(), srcPort, dstIpAddress.toString(), dstPort);
Optional<InstancePort> instancePort = instancePortService.instancePorts().stream().filter(port -> port.ipAddress().toString().equals(dstIpStr)).findAny();
if (!instancePort.isPresent()) {
log.info("Instance port that matches with the given dst ip address isn't present {}");
return;
}
flowRuleService.setRule(appId, instancePort.get().deviceId(), sBuilder.build(), treatment, PRIORITY_FORCED_ACL_RULE, DHCP_TABLE, false);
}
use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.
the class OpenstackResetPortsCommand method resetPort.
private void resetPort(InstancePortAdminService service, String portId) {
InstancePort instancePort = service.instancePort(portId);
service.removeInstancePort(portId);
try {
sleep(SLEEP_MS);
} catch (InterruptedException e) {
log.error("Exception caused during port synchronization...");
}
service.createInstancePort(instancePort);
}
Aggregations