use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackRoutingSnatHandler method setGatewayToInstanceDownstreamRule.
private void setGatewayToInstanceDownstreamRule(OpenstackNode gwNode, InstancePort instPort, boolean install) {
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPDst(IpPrefix.valueOf(instPort.ipAddress(), VM_PREFIX)).build();
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder().setEthDst(instPort.macAddress());
Type netType = osNetworkAdminService.networkType(instPort.networkId());
String segId = osNetworkAdminService.segmentId(instPort.networkId());
switch(netType) {
case VXLAN:
case GRE:
case GENEVE:
tBuilder.setTunnelId(Long.valueOf(segId));
break;
case VLAN:
default:
final String error = String.format("%s %s", ERR_UNSUPPORTED_NET_TYPE, netType.name());
throw new IllegalStateException(error);
}
OpenstackNode srcNode = osNodeService.node(instPort.deviceId());
TrafficTreatment treatment = getDownstreamTreatment(netType, tBuilder, gwNode, srcNode);
osFlowRuleService.setRule(appId, gwNode.intgBridge(), selector, treatment, PRIORITY_STATEFUL_SNAT_RULE, GW_COMMON_TABLE, install);
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackRoutingSnatHandler method packetOut.
private void packetOut(Ethernet ethPacketIn, DeviceId srcDevice, int patPort, IpAddress externalIp, ExternalPeerRouter externalPeerRouter) {
IPv4 iPacket = (IPv4) ethPacketIn.getPayload();
switch(iPacket.getProtocol()) {
case IPv4.PROTOCOL_TCP:
iPacket.setPayload(buildPacketOutTcp(iPacket, patPort));
break;
case IPv4.PROTOCOL_UDP:
iPacket.setPayload(buildPacketOutUdp(iPacket, patPort));
break;
default:
log.trace("Temporally, this method can process UDP and TCP protocol.");
return;
}
iPacket.setSourceAddress(externalIp.toString());
iPacket.resetChecksum();
iPacket.setParent(ethPacketIn);
ethPacketIn.setSourceMACAddress(DEFAULT_GATEWAY_MAC);
ethPacketIn.setDestinationMACAddress(externalPeerRouter.macAddress());
ethPacketIn.setPayload(iPacket);
if (!externalPeerRouter.vlanId().equals(VlanId.NONE)) {
ethPacketIn.setVlanID(externalPeerRouter.vlanId().toShort());
}
ethPacketIn.resetChecksum();
OpenstackNode srcNode = osNodeService.node(srcDevice);
if (srcNode == null) {
final String error = String.format("Cannot find openstack node for %s", srcDevice);
throw new IllegalStateException(error);
}
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
packetService.emit(new DefaultOutboundPacket(srcDevice, tBuilder.setOutput(srcNode.uplinkPortNum()).build(), ByteBuffer.wrap(ethPacketIn.serialize())));
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackSwitchingArpHandler method setArpReplyRuleForGre.
/**
* Installs flow rules to match ARP reply packets only for GRE.
*
* @param port instance port
* @param install installation flag
*/
private void setArpReplyRuleForGre(InstancePort port, boolean install) {
OpenstackNode localNode = osNodeService.node(port.deviceId());
TrafficSelector selector = getArpReplySelectorForGre(port);
setLocalArpReplyTreatmentForGre(selector, port, install);
setRemoteArpTreatmentForTunnel(selector, port, localNode, install);
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackSwitchingArpHandler method setFakeGatewayArpRule.
/**
* Installs flow rules which convert ARP request packet into ARP reply
* by adding a fake gateway MAC address as Source Hardware Address.
*
* @param osSubnet openstack subnet
* @param network openstack network
* @param install flag which indicates whether to install rule or remove rule
* @param osNode openstack node
*/
private void setFakeGatewayArpRule(Subnet osSubnet, Network network, boolean install, OpenstackNode osNode) {
if (ARP_BROADCAST_MODE.equals(getArpMode())) {
Type netType = osNetworkService.networkType(network.getId());
String gateway = osSubnet.getGateway();
if (gateway == null) {
return;
}
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
if (netType == VLAN) {
sBuilder.matchVlanId(VlanId.vlanId(network.getProviderSegID()));
} else if (netType == VXLAN || netType == GRE || netType == GENEVE) {
// different networks
if (!install) {
long numOfDupGws = osNetworkService.subnets().stream().filter(s -> !s.getId().equals(osSubnet.getId())).filter(s -> s.getGateway() != null).filter(s -> s.getGateway().equals(osSubnet.getGateway())).count();
if (numOfDupGws > 0) {
return;
}
}
}
sBuilder.matchEthType(EthType.EtherType.ARP.ethType().toShort()).matchArpOp(ARP.OP_REQUEST).matchArpTpa(Ip4Address.valueOf(gateway));
if (osNode == null) {
osNodeService.completeNodes(COMPUTE).forEach(n -> {
Device device = deviceService.getDevice(n.intgBridge());
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (netType == VLAN) {
tBuilder.popVlan();
}
tBuilder.extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setArpOp(ARP.OP_REPLY).setArpSha(MacAddress.valueOf(gatewayMac)).setArpSpa(Ip4Address.valueOf(gateway)).setEthSrc(MacAddress.valueOf(gatewayMac)).setOutput(PortNumber.IN_PORT);
osFlowRuleService.setRule(appId, n.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_ARP_GATEWAY_RULE, ARP_TABLE, install);
});
} else {
Device device = deviceService.getDevice(osNode.intgBridge());
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (netType == VLAN) {
tBuilder.popVlan();
}
tBuilder.extension(buildMoveEthSrcToDstExtension(device), device.id()).extension(buildMoveArpShaToThaExtension(device), device.id()).extension(buildMoveArpSpaToTpaExtension(device), device.id()).setArpOp(ARP.OP_REPLY).setArpSha(MacAddress.valueOf(gatewayMac)).setArpSpa(Ip4Address.valueOf(gateway)).setOutput(PortNumber.IN_PORT);
osFlowRuleService.setRule(appId, osNode.intgBridge(), sBuilder.build(), tBuilder.build(), PRIORITY_ARP_GATEWAY_RULE, ARP_TABLE, install);
}
}
}
use of org.onosproject.openstacknode.api.OpenstackNode in project onos by opennetworkinglab.
the class OpenstackSwitchingArpHandler method setArpReplyRuleForVxlan.
/**
* Installs flow rules to match ARP reply packets only for VxLAN.
*
* @param port instance port
* @param install installation flag
*/
private void setArpReplyRuleForVxlan(InstancePort port, boolean install) {
OpenstackNode localNode = osNodeService.node(port.deviceId());
TrafficSelector selector = getArpReplySelectorForVxlan(port);
setLocalArpReplyTreatmentForVxlan(selector, port, install);
setRemoteArpTreatmentForTunnel(selector, port, localNode, install);
}
Aggregations