use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class SimpleIntManager method configDevice.
protected boolean configDevice(DeviceId deviceId) {
// Returns true if config was successful, false if not and a clean up is
// needed.
final Device device = deviceService.getDevice(deviceId);
if (device == null || !device.is(IntProgrammable.class)) {
return true;
}
if (isNotIntConfigured()) {
log.warn("Missing INT config, aborting programming of INT device {}", deviceId);
return true;
}
final boolean isEdge = !hostService.getConnectedHosts(deviceId).isEmpty();
final IntDeviceRole intDeviceRole = isEdge ? IntDeviceRole.SOURCE_SINK : IntDeviceRole.TRANSIT;
log.info("Started programming of INT device {} with role {}...", deviceId, intDeviceRole);
final IntProgrammable intProg = device.as(IntProgrammable.class);
if (!isIntStarted()) {
// Leave device with no INT configuration.
return true;
}
if (!intProg.init()) {
log.warn("Unable to init INT pipeline on {}", deviceId);
return false;
}
boolean supportSource = intProg.supportsFunctionality(IntProgrammable.IntFunctionality.SOURCE);
boolean supportSink = intProg.supportsFunctionality(IntProgrammable.IntFunctionality.SINK);
boolean supportPostcard = intProg.supportsFunctionality(IntProgrammable.IntFunctionality.POSTCARD);
if (intDeviceRole != IntDeviceRole.SOURCE_SINK && !supportPostcard) {
// Stop here, no more configuration needed for transit devices unless it support postcard.
return true;
}
if (supportSink || supportPostcard) {
if (!intProg.setupIntConfig(intConfig.get())) {
log.warn("Unable to apply INT report config on {}", deviceId);
return false;
}
}
// Port configuration.
final Set<PortNumber> hostPorts = deviceService.getPorts(deviceId).stream().map(port -> new ConnectPoint(deviceId, port.number())).filter(cp -> !hostService.getConnectedHosts(cp).isEmpty()).map(ConnectPoint::port).collect(Collectors.toSet());
for (PortNumber port : hostPorts) {
if (supportSource) {
log.info("Setting port {}/{} as INT source port...", deviceId, port);
if (!intProg.setSourcePort(port)) {
log.warn("Unable to set INT source port {} on {}", port, deviceId);
return false;
}
}
if (supportSink) {
log.info("Setting port {}/{} as INT sink port...", deviceId, port);
if (!intProg.setSinkPort(port)) {
log.warn("Unable to set INT sink port {} on {}", port, deviceId);
return false;
}
}
}
if (!supportSource && !supportPostcard) {
// it supports postcard mode.
return true;
}
// Apply intents.
// This is a trivial implementation where we simply get the
// corresponding INT objective from an intent and we apply to all
// device which support reporting.
int appliedCount = 0;
for (Versioned<IntIntent> versionedIntent : intentMap.values()) {
IntIntent intent = versionedIntent.value();
IntObjective intObjective = getIntObjective(intent);
if (intent.telemetryMode() == IntIntent.TelemetryMode.INBAND_TELEMETRY && supportSource) {
intProg.addIntObjective(intObjective);
appliedCount++;
} else if (intent.telemetryMode() == IntIntent.TelemetryMode.POSTCARD && supportPostcard) {
intProg.addIntObjective(intObjective);
appliedCount++;
} else {
log.warn("Device {} does not support intent {}.", deviceId, intent);
}
}
log.info("Completed programming of {}, applied {} INT objectives of {} total", deviceId, appliedCount, intentMap.size());
return true;
}
use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class IntentSynchronizerTest method intentBuilder.
/**
* MultiPointToSinglePointIntent builder.
*
* @param ipPrefix the ipPrefix to match
* @param nextHopMacAddress to which the destination MAC address in packet
* should be rewritten
* @param egressPoint to which packets should be sent
* @return the constructed MultiPointToSinglePointIntent
*/
private MultiPointToSinglePointIntent intentBuilder(IpPrefix ipPrefix, String nextHopMacAddress, ConnectPoint egressPoint) {
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
if (ipPrefix.isIp4()) {
selectorBuilder.matchEthType(Ethernet.TYPE_IPV4);
selectorBuilder.matchIPDst(ipPrefix);
} else {
selectorBuilder.matchEthType(Ethernet.TYPE_IPV6);
selectorBuilder.matchIPv6Dst(ipPrefix);
}
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
treatmentBuilder.setEthDst(MacAddress.valueOf(nextHopMacAddress));
Set<ConnectPoint> ingressPoints = new HashSet<>(connectPoints);
ingressPoints.remove(egressPoint);
MultiPointToSinglePointIntent intent = MultiPointToSinglePointIntent.builder().appId(APPID).key(Key.of(ipPrefix.toString(), APPID)).selector(selectorBuilder.build()).treatment(treatmentBuilder.build()).ingressPoints(ingressPoints).egressPoint(egressPoint).build();
return intent;
}
use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class K8sSwitchingArpHandler method processArpRequest.
private void processArpRequest(PacketContext context, Ethernet ethPacket) {
ARP arpPacket = (ARP) ethPacket.getPayload();
K8sPort srcK8sPort = k8sNetworkService.ports().stream().filter(p -> p.macAddress().equals(ethPacket.getSourceMAC())).findAny().orElse(null);
PortNumber srcPortNum = context.inPacket().receivedFrom().port();
DeviceId srcDeviceId = context.inPacket().receivedFrom().deviceId();
boolean isEntryPort = false;
for (K8sNode node : k8sNodeService.completeNodes()) {
if (srcDeviceId.equals(node.intgBridge()) && srcPortNum.equals(node.intgEntryPortNum())) {
isEntryPort = true;
}
}
// integration bridge entry port, we simply ignore the ARP request...
if (srcK8sPort == null && !isEntryPort) {
log.warn("Failed to find source port(MAC:{})", ethPacket.getSourceMAC());
return;
}
IpAddress targetIp = Ip4Address.valueOf(arpPacket.getTargetProtocolAddress());
// look up the MAC address from regular k8s ports
MacAddress replyMac = k8sNetworkService.ports().stream().filter(p -> p.ipAddress().equals(targetIp)).map(K8sPort::macAddress).findAny().orElse(null);
// look up the MAC address from special integration entry port (e.g., LOCAL, k8s-int-os)
for (K8sNetwork network : k8sNetworkService.networks()) {
if (network.gatewayIp().equals(targetIp)) {
K8sNode node = k8sNodeService.node(network.name());
replyMac = node.intgEntryPortMac();
}
}
if (replyMac == null) {
String cidr = k8sNetworkService.networks().stream().map(K8sNetwork::cidr).findAny().orElse(null);
if (cidr != null) {
String unshiftedIp = unshiftIpDomain(targetIp.toString(), SHIFTED_IP_PREFIX, cidr);
replyMac = k8sNetworkService.ports().stream().filter(p -> p.ipAddress().equals(IpAddress.valueOf(unshiftedIp))).map(K8sPort::macAddress).findAny().orElse(null);
}
}
if (replyMac == null) {
Set<String> serviceIps = k8sServiceService.services().stream().map(s -> s.getSpec().getClusterIP()).collect(Collectors.toSet());
if (serviceIps.contains(targetIp.toString())) {
replyMac = MacAddress.valueOf(SERVICE_FAKE_MAC_STR);
}
}
if (replyMac == null) {
if (targetIp.toString().startsWith(NODE_IP_PREFIX)) {
String targetIpPrefix = targetIp.toString().split("\\.")[1];
String nodePrefix = NODE_IP_PREFIX + "." + targetIpPrefix;
String origNodeCidr = k8sNodeService.completeNodes().stream().map(n -> n.nodeIp().toString()).findAny().orElse(null);
if (origNodeCidr != null) {
String origNodeIp = unshiftIpDomain(targetIp.toString(), nodePrefix, origNodeCidr);
IpPrefix k8sNodeIpCidr = IpPrefix.valueOf(IpAddress.valueOf(origNodeCidr), 24);
SubnetUtils k8sNodeSubnet = new SubnetUtils(k8sNodeIpCidr.toString());
String k8sNodeGateway = getGatewayIp(k8sNodeIpCidr.toString()).toString();
String seekIp = "";
if (!k8sNodeSubnet.getInfo().isInRange(origNodeIp)) {
replyMac = extHostMacStore.asJavaMap().get(IpAddress.valueOf(k8sNodeGateway));
seekIp = k8sNodeGateway;
} else {
replyMac = extHostMacStore.asJavaMap().get(IpAddress.valueOf(origNodeIp));
seekIp = origNodeIp;
}
// we need to manually learn their MAC addresses
if (replyMac == null) {
ConnectPoint cp = context.inPacket().receivedFrom();
K8sNode k8sNode = k8sNodeService.node(cp.deviceId());
if (k8sNode != null) {
// we use fake IP and MAC address as a source to
// query destination MAC address
setArpRequest(MacAddress.valueOf(NODE_FAKE_MAC_STR).toBytes(), IpAddress.valueOf(NODE_FAKE_IP_STR).toOctets(), IpAddress.valueOf(seekIp).toOctets(), k8sNode);
context.block();
return;
}
}
}
}
}
if (replyMac == null) {
replyMac = MacAddress.valueOf(gatewayMac);
}
Ethernet ethReply = ARP.buildArpReply(targetIp.getIp4Address(), replyMac, ethPacket);
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();
}
use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class K8sSwitchingHostProvider method processPortAdded.
/**
* Processes port addition event.
*
* @param port port object used in ONOS
*/
private void processPortAdded(Port port) {
K8sPort k8sPort = portToK8sPortByName(port);
if (k8sPort == null) {
k8sPort = portToK8sPortByMac(port);
if (k8sPort == null) {
log.warn(ERR_ADD_HOST + "Kubernetes port for {} not found", port);
return;
}
}
K8sNetwork k8sNet = k8sNetworkService.network(k8sPort.networkId());
if (k8sNet == null) {
log.warn(ERR_ADD_HOST + "Kubernetes network {} not found", k8sPort.networkId());
return;
}
MacAddress mac = k8sPort.macAddress();
HostId hostId = HostId.hostId(mac);
// connect point is the combination of switch ID with port number where
// the host is attached to
ConnectPoint connectPoint = new ConnectPoint(port.element().id(), port.number());
long createTime = System.currentTimeMillis();
// update k8s port number by referring to ONOS port number
k8sNetworkService.updatePort(k8sPort.updatePortNumber(port.number()).updateState(K8sPort.State.ACTIVE));
// we check whether the host already attached to same locations
Host host = hostService.getHost(hostId);
// build host annotations to include a set of meta info from neutron
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder().set(ANNOTATION_NETWORK_ID, k8sPort.networkId()).set(ANNOTATION_PORT_ID, k8sPort.portId()).set(ANNOTATION_CREATE_TIME, String.valueOf(createTime)).set(ANNOTATION_SEGMENT_ID, k8sNet.segmentId());
HostDescription hostDesc = new DefaultHostDescription(mac, VlanId.NONE, new HostLocation(connectPoint, createTime), ImmutableSet.of(k8sPort.ipAddress()), annotations.build());
if (host != null) {
Set<HostLocation> locations = host.locations().stream().filter(l -> l.deviceId().equals(connectPoint.deviceId())).filter(l -> l.port().equals(connectPoint.port())).collect(Collectors.toSet());
// therefore, we simply add this into the location list
if (locations.isEmpty()) {
hostProviderService.addLocationToHost(hostId, new HostLocation(connectPoint, createTime));
}
// the hostDetected method invocation in turn triggers host Update event
if (locations.size() == 1) {
hostProviderService.hostDetected(hostId, hostDesc, false);
}
} else {
hostProviderService.hostDetected(hostId, hostDesc, false);
}
}
use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class MulticastRouteManager method addSink.
@Override
public void addSink(McastRoute route, HostId hostId) {
if (checkRoute(route)) {
Set<ConnectPoint> sinks = new HashSet<>();
Host host = hostService.getHost(hostId);
if (host != null) {
sinks.addAll(host.locations());
}
store.addSink(route, hostId, sinks);
}
}
Aggregations