use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.
the class IcmpHandler method sendPacketOut.
/**
* Utility function to send packet out.
*
* @param outport the output port
* @param payload the packet to send
* @param destSid the segment id of the dest device
* @param destIpAddress the destination ip address
* @param allowedHops the hop limit/ttl
*/
private void sendPacketOut(ConnectPoint outport, Ethernet payload, int destSid, IpAddress destIpAddress, byte allowedHops) {
int origSid;
try {
if (destIpAddress.isIp4()) {
origSid = config.getIPv4SegmentId(outport.deviceId());
} else {
origSid = config.getIPv6SegmentId(outport.deviceId());
}
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting sendPacketOut");
return;
}
if (destSid == -1 || origSid == destSid || srManager.interfaceService.isConfigured(outport)) {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outport.port()).build();
OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(), treatment, ByteBuffer.wrap(payload.serialize()));
log.trace("Sending packet {} to {}", payload, outport);
srManager.packetService.emit(packet);
} else {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outport.port()).build();
payload.setEtherType(Ethernet.MPLS_UNICAST);
MPLS mplsPkt = new MPLS();
mplsPkt.setLabel(destSid);
mplsPkt.setTtl(allowedHops);
mplsPkt.setPayload(payload.getPayload());
payload.setPayload(mplsPkt);
OutboundPacket packet = new DefaultOutboundPacket(outport.deviceId(), treatment, ByteBuffer.wrap(payload.serialize()));
log.trace("Sending packet {} to {}", payload, outport);
srManager.packetService.emit(packet);
}
}
use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.
the class SegmentRoutingAppConfig method suppressHostByPort.
/**
* Gets connect points to which SegmentRouting does not push host rules.
*
* @return Set of connect points, empty if not specified, or null
* if not valid
*/
public Set<ConnectPoint> suppressHostByPort() {
if (!object.has(SUPPRESS_HOST_BY_PORT)) {
return ImmutableSet.of();
}
ImmutableSet.Builder<ConnectPoint> builder = ImmutableSet.builder();
ArrayNode arrayNode = (ArrayNode) object.path(SUPPRESS_HOST_BY_PORT);
for (JsonNode jsonNode : arrayNode) {
String portName = jsonNode.asText(null);
if (portName == null) {
return null;
}
try {
builder.add(ConnectPoint.deviceConnectPoint(portName));
} catch (IllegalArgumentException e) {
return null;
}
}
return builder.build();
}
use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method bridgingFwdObjBuilder.
/**
* Generates a forwarding objective builder for bridging rules.
* <p>
* The forwarding objective bridges packets destined to a given MAC to
* given port on given device.
*
* @param deviceId Device that host attaches to
* @param mac MAC address of the host
* @param hostVlanId VLAN ID of the host
* @param outport Port that host attaches to
* @param revoke true if forwarding objective is meant to revoke forwarding rule
* @return Forwarding objective builder
*/
private ForwardingObjective.Builder bridgingFwdObjBuilder(DeviceId deviceId, MacAddress mac, VlanId hostVlanId, PortNumber outport, boolean revoke) {
ConnectPoint connectPoint = new ConnectPoint(deviceId, outport);
VlanId untaggedVlan = srManager.interfaceService.getUntaggedVlanId(connectPoint);
Set<VlanId> taggedVlans = srManager.interfaceService.getTaggedVlanId(connectPoint);
VlanId nativeVlan = srManager.interfaceService.getNativeVlanId(connectPoint);
// Create host selector
TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
sbuilder.matchEthDst(mac);
// Create host treatment
TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder();
tbuilder.immediate().setOutput(outport);
// Create host meta
TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder();
// Adjust the selector, treatment and meta according to VLAN configuration
if (taggedVlans.contains(hostVlanId)) {
sbuilder.matchVlanId(hostVlanId);
mbuilder.matchVlanId(hostVlanId);
} else if (hostVlanId.equals(VlanId.NONE)) {
if (untaggedVlan != null) {
sbuilder.matchVlanId(untaggedVlan);
mbuilder.matchVlanId(untaggedVlan);
tbuilder.immediate().popVlan();
} else if (nativeVlan != null) {
sbuilder.matchVlanId(nativeVlan);
mbuilder.matchVlanId(nativeVlan);
tbuilder.immediate().popVlan();
} else {
log.warn("Untagged host {}/{} is not allowed on {} without untagged or native " + "vlan config", mac, hostVlanId, connectPoint);
return null;
}
} else {
log.warn("Tagged host {}/{} is not allowed on {} without VLAN listed in tagged vlan", mac, hostVlanId, connectPoint);
return null;
}
// All forwarding is via Groups. Drivers can re-purpose to flow-actions if needed.
// If the objective is to revoke an existing rule, and for some reason
// the next-objective does not exist, then a new one should not be created
int portNextObjId = srManager.getPortNextObjectiveId(deviceId, outport, tbuilder.build(), mbuilder.build(), !revoke);
if (portNextObjId == -1) {
// Warning log will come from getPortNextObjective method
return null;
}
return DefaultForwardingObjective.builder().withFlag(ForwardingObjective.Flag.SPECIFIC).withSelector(sbuilder.build()).nextStep(portNextObjId).withPriority(100).fromApp(srManager.appId).makePermanent();
}
use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method anyDoubleTaggedHost.
/**
* Checks if there is any double tagged host attached to given location.
* This method will match on the effective location of a host.
* That is, it will match on auxLocations when auxLocations is not null. Otherwise, it will match on locations.
*
* @param deviceId device ID
* @param portNum port number
* @return true if there is any host attached to given location.
*/
private boolean anyDoubleTaggedHost(DeviceId deviceId, PortNumber portNum) {
ConnectPoint cp = new ConnectPoint(deviceId, portNum);
Set<Host> connectedHosts = srManager.hostService.getConnectedHosts(cp, false);
Set<Host> auxConnectedHosts = srManager.hostService.getConnectedHosts(cp, true);
return !auxConnectedHosts.isEmpty() || connectedHosts.stream().anyMatch(host -> host.auxLocations() == null);
}
use of org.onosproject.net.ConnectPoint in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method getTreatmentAndMeta.
private ImmutablePair<TrafficTreatment, TrafficSelector> getTreatmentAndMeta(DeviceId deviceId, MacAddress hostMac, VlanId hostVlanId, PortNumber outPort, VlanId innerVlan, EthType outerTpid) throws DeviceConfigNotFoundException {
MacAddress routerMac;
routerMac = config.getDeviceMac(deviceId);
ConnectPoint connectPoint = new ConnectPoint(deviceId, outPort);
VlanId untaggedVlan = srManager.interfaceService.getUntaggedVlanId(connectPoint);
Set<VlanId> taggedVlans = srManager.interfaceService.getTaggedVlanId(connectPoint);
VlanId nativeVlan = srManager.interfaceService.getNativeVlanId(connectPoint);
// Create route treatment
TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder().deferred().setEthDst(hostMac).setEthSrc(routerMac).setOutput(outPort);
// Create route meta
TrafficSelector.Builder mbuilder = DefaultTrafficSelector.builder();
// Adjust treatment and meta according to VLAN configuration
if (taggedVlans.contains(hostVlanId)) {
mbuilder.matchVlanId(hostVlanId);
tbuilder.setVlanId(hostVlanId);
} else if (hostVlanId.equals(VlanId.NONE)) {
if (untaggedVlan != null) {
mbuilder.matchVlanId(untaggedVlan);
tbuilder.popVlan();
} else if (nativeVlan != null) {
mbuilder.matchVlanId(nativeVlan);
tbuilder.popVlan();
} else {
log.warn("Untagged nexthop {}/{} is not allowed on {} without untagged or native vlan", hostMac, hostVlanId, connectPoint);
return null;
}
} else {
// Double tagged hosts
if (innerVlan == null || outerTpid == null) {
log.warn("Failed to construct NextObj for double tagged hosts {}/{}. {} {}", hostMac, hostVlanId, (innerVlan == null) ? "innerVlan = null." : "", (outerTpid == null) ? "outerTpid = null." : "");
return null;
}
tbuilder.setVlanId(innerVlan);
tbuilder.pushVlan(outerTpid);
tbuilder.setVlanId(hostVlanId);
mbuilder.matchVlanId(VlanId.ANY);
}
return ImmutablePair.of(tbuilder.build(), mbuilder.build());
}
Aggregations