use of org.onosproject.net.Link in project trellis-control by opennetworkinglab.
the class LinkHandler method isBidirectionalLinkUp.
/**
* Returns true if the link being queried is a bidirectional link that is
* up. A bidi-link is defined as a component unidirectional link, whose
* reverse link - ie. the component unidirectional link in the reverse
* direction - has been seen-before and is up. It is NOT necessary for the
* link being queried to be a previously seen-link.
*
* @param link the infrastructure (unidirectional) link being queried
* @return true if another unidirectional link exists in the reverse
* direction, has been seen-before and is up
*/
boolean isBidirectionalLinkUp(Link link) {
// cannot call linkService as link may be gone
Link reverseLink = getReverseLink(link);
if (reverseLink == null) {
return false;
}
Boolean result = isSeenLinkUp(reverseLink);
if (result == null) {
return false;
}
return result.booleanValue();
}
use of org.onosproject.net.Link in project trellis-control by opennetworkinglab.
the class PolicyManager method redirectPolicyNextObjective.
private NextObjective.Builder redirectPolicyNextObjective(DeviceId srcDevice, RedirectPolicy redirectPolicy) {
Set<Link> egressLinks = linkService.getDeviceEgressLinks(srcDevice);
Map<ConnectPoint, DeviceId> egressPortsToEnforce = Maps.newHashMap();
List<DeviceId> edgeDevices = getEdgeDeviceIds();
egressLinks.stream().filter(link -> redirectPolicy.spinesToEnforce().contains(link.dst().deviceId()) && !edgeDevices.contains(link.dst().deviceId())).forEach(link -> egressPortsToEnforce.put(link.src(), link.dst().deviceId()));
// No ports no friend
if (egressPortsToEnforce.isEmpty()) {
log.warn("There are no port available for the REDIRECT policy {}", redirectPolicy.policyId());
return null;
}
// We need to add a treatment for each valid egress port. The treatment
// requires to set src and dst mac address and set the egress port. We are
// deliberately not providing the metadata to prevent the programming of
// some tables which are already controlled by SegmentRouting or are unnecessary
int nextId = flowObjectiveService.allocateNextId();
DefaultNextObjective.Builder builder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.HASHED).fromApp(appId);
MacAddress srcDeviceMac;
try {
srcDeviceMac = getDeviceMacAddress(srcDevice);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting installation REDIRECT policy {}", redirectPolicy.policyId());
return null;
}
MacAddress neigborDeviceMac;
TrafficTreatment.Builder tBuilder;
for (Map.Entry<ConnectPoint, DeviceId> entry : egressPortsToEnforce.entrySet()) {
try {
neigborDeviceMac = getDeviceMacAddress(entry.getValue());
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting installation REDIRECT policy {}", redirectPolicy.policyId());
return null;
}
tBuilder = DefaultTrafficTreatment.builder().setEthSrc(srcDeviceMac).setEthDst(neigborDeviceMac).setOutput(entry.getKey().port());
builder.addTreatment(tBuilder.build());
}
return builder;
}
use of org.onosproject.net.Link in project trellis-control by opennetworkinglab.
the class DefaultL2TunnelHandler method deployPseudowire.
/**
* Adds a single pseudowire.
*
* @param pw The pseudowire to deploy
* @return result of pseudowire deployment
*/
public Result deployPseudowire(L2TunnelDescription pw) {
try {
// take the lock
pwLock.lock();
Result result;
long l2TunnelId;
log.debug("Pseudowire with {} deployment started, check log for any errors in this process!", pw.l2Tunnel().tunnelId());
l2TunnelId = pw.l2Tunnel().tunnelId();
// The tunnel id cannot be 0.
if (l2TunnelId == 0) {
log.warn("Tunnel id id must be > 0 in {}", l2TunnelId);
return Result.WRONG_PARAMETERS.appendError("Tunnel id id must be > 0");
}
result = verifyGlobalValidity(pw);
if (result != SUCCESS) {
log.error("Global validity for pseudowire {} is wrong!", l2TunnelId);
return result;
}
// leafSpinePw determines if this is a leaf-leaf
// or leaf-spine pseudowire
boolean leafSpinePw;
ConnectPoint cp1 = pw.l2TunnelPolicy().cP1();
ConnectPoint cp2 = pw.l2TunnelPolicy().cP2();
try {
// differentiate between leaf-leaf pseudowires and leaf-spine
if (!srManager.deviceConfiguration().isEdgeDevice(cp1.deviceId()) && !srManager.deviceConfiguration().isEdgeDevice(cp2.deviceId())) {
log.error("Can not deploy pseudowire {} from spine to spine!", l2TunnelId);
return Result.WRONG_PARAMETERS.appendError("Can not deploy pseudowire from spine to spine!");
} else if (srManager.deviceConfiguration().isEdgeDevice(cp1.deviceId()) && srManager.deviceConfiguration().isEdgeDevice(cp2.deviceId())) {
leafSpinePw = false;
} else {
leafSpinePw = true;
}
} catch (DeviceConfigNotFoundException e) {
log.error("Device for pseudowire {} connection points does not exist in the configuration", l2TunnelId);
return Result.INTERNAL_ERROR.appendError("Device for pseudowire connection points does not exist in the configuration");
}
// reverse the policy in order for leaf switch to be at CP1
// this will help us for re-using SRLinkWeigher for computing valid paths
L2TunnelPolicy reversedPolicy = reverseL2TunnelPolicy(pw.l2TunnelPolicy());
if (reversedPolicy == null) {
log.error("Error in reversing policy, device configuration was not found for pseudowire {}.", l2TunnelId);
return INTERNAL_ERROR.appendError("Device configuration not found when reversing the policy.");
}
pw.setL2TunnelPolicy(reversedPolicy);
// get path here, need to use the same for fwd and rev direction
List<Link> path = getPath(pw.l2TunnelPolicy().cP1(), pw.l2TunnelPolicy().cP2());
if (path == null || path.isEmpty()) {
log.error("Deploying process : No path between the connection points for pseudowire {}", l2TunnelId);
return PATH_NOT_FOUND.appendError("No path between the connection points for pseudowire!");
}
Link fwdNextHop;
Link revNextHop;
if (!isValidPath(path, leafSpinePw)) {
log.error("Deploying process : Path for pseudowire {} is not valid", l2TunnelId);
return INTERNAL_ERROR.appendError("Internal error : path for pseudowire is not valid!");
}
// oneHope flag is used to determine if we need to
// install transit mpls rules
boolean oneHop = true;
if (path.size() > 1) {
oneHop = false;
}
fwdNextHop = path.get(0);
revNextHop = reverseLink(path.get(path.size() - 1));
pw.l2Tunnel().setPath(path);
pw.l2Tunnel().setTransportVlan(srManager.getPwTransportVlan());
// next hops for next objectives
log.info("Deploying process : Establishing forward direction for pseudowire {}", l2TunnelId);
VlanId egressVlan = determineEgressVlan(pw.l2TunnelPolicy().cP1OuterTag(), pw.l2TunnelPolicy().cP1InnerTag(), pw.l2TunnelPolicy().cP2OuterTag(), pw.l2TunnelPolicy().cP2InnerTag());
result = deployPseudoWireInit(pw.l2Tunnel(), pw.l2TunnelPolicy().cP1(), pw.l2TunnelPolicy().cP2(), FWD, fwdNextHop, oneHop, egressVlan);
if (result != SUCCESS) {
log.error("Deploying process : Error in deploying pseudowire {} initiation for CP1", l2TunnelId);
return Result.INTERNAL_ERROR.appendError("Error in deploying pseudowire initiation for CP1");
}
result = deployPolicy(l2TunnelId, pw.l2TunnelPolicy().cP1(), pw.l2TunnelPolicy().cP1InnerTag(), pw.l2TunnelPolicy().cP1OuterTag(), egressVlan, result.getNextId());
if (result != SUCCESS) {
log.error("Deploying process : Error in deploying pseudowire {} policy for CP1", l2TunnelId);
return Result.INTERNAL_ERROR.appendError("Error in deploying pseudowire policy for CP1");
}
result = deployPseudoWireTerm(pw.l2Tunnel(), pw.l2TunnelPolicy().cP2(), egressVlan, FWD, oneHop);
if (result != SUCCESS) {
log.error("Deploying process : Error in deploying pseudowire {} termination for CP1", l2TunnelId);
return Result.INTERNAL_ERROR.appendError("Error in deploying pseudowire termination for CP1");
}
// We establish the reverse tunnel.
log.info("Deploying process : Establishing reverse direction for pseudowire {}", l2TunnelId);
egressVlan = determineEgressVlan(pw.l2TunnelPolicy().cP2OuterTag(), pw.l2TunnelPolicy().cP2InnerTag(), pw.l2TunnelPolicy().cP1OuterTag(), pw.l2TunnelPolicy().cP1InnerTag());
result = deployPseudoWireInit(pw.l2Tunnel(), pw.l2TunnelPolicy().cP2(), pw.l2TunnelPolicy().cP1(), REV, revNextHop, oneHop, egressVlan);
if (result != SUCCESS) {
log.error("Deploying process : Error in deploying pseudowire {} initiation for CP2", l2TunnelId);
return Result.INTERNAL_ERROR.appendError("Error in deploying pseudowire initiation for CP2");
}
result = deployPolicy(l2TunnelId, pw.l2TunnelPolicy().cP2(), pw.l2TunnelPolicy().cP2InnerTag(), pw.l2TunnelPolicy().cP2OuterTag(), egressVlan, result.getNextId());
if (result != SUCCESS) {
log.error("Deploying process : Error in deploying policy {} for CP2", l2TunnelId);
return Result.INTERNAL_ERROR.appendError("Deploying process : Error in deploying policy for CP2");
}
result = deployPseudoWireTerm(pw.l2Tunnel(), pw.l2TunnelPolicy().cP1(), egressVlan, REV, oneHop);
if (result != SUCCESS) {
log.error("Deploying process : Error in deploying pseudowire {} termination for CP2", l2TunnelId);
return Result.INTERNAL_ERROR.appendError("Error in deploying pseudowire termination for CP2");
}
log.info("Deploying process : Updating relevant information for pseudowire {}", l2TunnelId);
// Populate stores as the final step of the process
l2TunnelStore.put(Long.toString(l2TunnelId), pw.l2Tunnel());
l2PolicyStore.put(Long.toString(l2TunnelId), pw.l2TunnelPolicy());
return Result.SUCCESS;
} catch (StorageException.Timeout e) {
log.error("Can not acquire distributed lock for pseudowire {}!", pw.l2Tunnel().tunnelId());
return Result.INTERNAL_ERROR.appendError("Can not acquire distributed lock!");
} finally {
// release the lock
pwLock.unlock();
}
}
use of org.onosproject.net.Link in project ddosdn by ssulca.
the class Monitoring method getStatisticsEdgePorts.
/**
* Retorna Conjunto de los PortStatistics de los puertos conectados a los edges
* @param devId DeviceId del disposivo del cual se quiere obtener las estadisticas
* delta cada 10s
* @return a Set con todos los PortStatics
*/
default Set<PortStatistics> getStatisticsEdgePorts(DeviceService deviceService, LinkService linkService, DeviceId devId, Logger log) {
Device dev;
Set<PortStatistics> portSet;
portSet = new HashSet<>();
// se obtienen todos los links conectado al dispostivo
Set<Link> ingressLinks = linkService.getDeviceIngressLinks(devId);
// busqueda en los enlaces, buscado conexiones con los edges
for (Link link : ingressLinks) {
dev = deviceService.getDevice(link.src().deviceId());
try {
if (dev.annotations().value(ANNT).equals(EDGE)) {
// True: se agrega la estadistica del puerto.
// log.info("dev/port: {}/{}",devId,link.dst().port()); //cometar
portSet.add(deviceService.getDeltaStatisticsForPort(devId, link.dst().port()));
}
} catch (NullPointerException e) {
log.error("No se encuentran las anotaciones EDGE :dev{}", dev.id().toString());
}
}
return portSet;
}
use of org.onosproject.net.Link in project ddosdn by ssulca.
the class Monitoring method getEdgeConnected.
/**
* Get first EDGE device conetect to DISTRIBUTION device with next parameters
* @param deviceService DeviceService
* @param linkService LinkService
* @param devId DISTRIBUTION DeviceId
* @param portNumber DISTRIBUTION deviceId port conect
* @param log Logger
* @return EDGE device ID.
*/
default DeviceId getEdgeConnected(DeviceService deviceService, LinkService linkService, DeviceId devId, PortNumber portNumber, Logger log) {
Device dev;
Set<Link> ingressLinks;
// se obtienen todos los links conectado al dispostivo
ingressLinks = linkService.getDeviceIngressLinks(devId);
// busqueda en los enlaces, buscado conexiones con los edges
for (Link link : ingressLinks) {
if (link.dst().port().equals(portNumber)) {
dev = deviceService.getDevice(link.src().deviceId());
try {
if (dev.annotations().value(ANNT).equals(EDGE)) {
// log.info("dev/port: {}/{}",devId,link.dst().port()); //cometar
return dev.id();
}
} catch (NullPointerException e) {
log.error("No se encuentran las anotaciones EDGE :dev{}", dev.id().toString());
}
}
}
return null;
}
Aggregations