use of org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE 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.NodeType.COMPUTE 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.openstacknode.api.OpenstackNode.NodeType.COMPUTE in project onos by opennetworkinglab.
the class OpenstackRoutingHandler method setGatewayRules.
private void setGatewayRules(Subnet osSubnet, Router osRouter, boolean install) {
OpenstackNode srcNatGw = osNodeService.completeNodes(GATEWAY).stream().findFirst().orElse(null);
if (srcNatGw == null) {
return;
}
if (Strings.isNullOrEmpty(osSubnet.getGateway())) {
// do nothing if no gateway is set
return;
}
Network net = osNetworkAdminService.network(osSubnet.getNetworkId());
Type netType = osNetworkAdminService.networkType(osSubnet.getNetworkId());
Set<Subnet> routableSubnets = routableSubnets(osRouter, osSubnet.getId());
// install rules to each compute node for routing IP packets to gateways
osNodeService.completeNodes(COMPUTE).stream().filter(cNode -> cNode.dataIp() != null).forEach(cNode -> setRulesToGatewayWithRoutableSubnets(cNode, srcNatGw, net.getProviderSegID(), osSubnet, routableSubnets, netType, install));
// install rules to punt ICMP packets to controller at gateway node
// this rule is only valid for stateless ICMP SNAT case
osNodeService.completeNodes(GATEWAY).forEach(gNode -> setReactiveGatewayIcmpRule(IpAddress.valueOf(osSubnet.getGateway()), gNode.intgBridge(), install));
final String updateStr = install ? MSG_ENABLED : MSG_DISABLED;
log.debug(updateStr + "IP to {}", osSubnet.getGateway());
}
use of org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE in project onos by opennetworkinglab.
the class OpenstackRoutingHandler method setRouterAdminRules.
private void setRouterAdminRules(String segmentId, Type networkType, boolean install) {
TrafficTreatment treatment;
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4);
switch(networkType) {
case VXLAN:
case GRE:
case GENEVE:
sBuilder.matchTunnelId(Long.parseLong(segmentId));
break;
case VLAN:
sBuilder.matchVlanId(VlanId.vlanId(segmentId));
break;
default:
final String error = String.format("%s %s", ERR_UNSUPPORTED_NET_TYPE, networkType.toString());
throw new IllegalStateException(error);
}
treatment = DefaultTrafficTreatment.builder().drop().build();
osNodeService.completeNodes().stream().filter(osNode -> osNode.type() == COMPUTE).forEach(osNode -> {
osFlowRuleService.setRule(appId, osNode.intgBridge(), sBuilder.build(), treatment, PRIORITY_ADMIN_RULE, ROUTING_TABLE, install);
});
}
use of org.onosproject.openstacknode.api.OpenstackNode.NodeType.COMPUTE in project onos by opennetworkinglab.
the class StatsFlowRuleManager method getOverlayDstPortBasedFlowInfos.
/**
* Gets a set of flow infos by referring to overlay destination VM port.
*
* @return flow infos
*/
private Set<FlowInfo> getOverlayDstPortBasedFlowInfos() {
Set<FlowInfo> flowInfos = Sets.newConcurrentHashSet();
Set<PortNumber> instPortNums = instPortService.instancePorts().stream().map(InstancePort::portNumber).collect(Collectors.toSet());
Set<DeviceId> deviceIds = osNodeService.completeNodes(COMPUTE).stream().map(OpenstackNode::intgBridge).collect(Collectors.toSet());
deviceIds.forEach(d -> {
List<PortStatistics> stats = deviceService.getPortStatistics(d).stream().filter(s -> instPortNums.contains(s.portNumber())).collect(Collectors.toList());
stats.forEach(s -> {
InstancePort instPort = getInstancePort(d, s.portNumber());
if (instPort != null) {
flowInfos.add(buildTxFlowInfoFromInstancePort(instPort, s));
flowInfos.add(buildRxFlowInfoFromInstancePort(instPort, s));
}
});
});
return flowInfos;
}
Aggregations