use of org.onosproject.net.Device in project TFG by mattinelorza.
the class Ipv6RoutingComponent method setUpSpineRoutes.
/**
* Insert routing rules on the given spine switch, matching on leaf
* interface subnets and forwarding packets to the corresponding leaf.
*
* @param spineId the spine device ID
*/
private void setUpSpineRoutes(DeviceId spineId) {
log.info("Adding up spine routes on {}...", spineId);
for (Device device : deviceService.getDevices()) {
if (isSpine(device.id())) {
// We only need routes to leaf switches. Ignore spines.
continue;
}
final DeviceId leafId = device.id();
final MacAddress leafMac = getMyStationMac(leafId);
final Set<Ip6Prefix> subnetsToRoute = getInterfaceIpv6Prefixes(leafId);
// Since we're here, we also add a route for SRv6 (Exercise 7), to
// forward packets with IPv6 dst the SID of a leaf switch.
final Ip6Address leafSid = getDeviceSid(leafId);
subnetsToRoute.add(Ip6Prefix.valueOf(leafSid, 128));
// Create a group with only one member.
int groupId = macToGroupId(leafMac);
GroupDescription group = createNextHopGroup(groupId, Collections.singleton(leafMac), spineId);
List<FlowRule> flowRules = subnetsToRoute.stream().map(subnet -> createRoutingRule(spineId, subnet, groupId)).collect(Collectors.toList());
insertInOrder(group, flowRules);
}
}
use of org.onosproject.net.Device in project TFG by mattinelorza.
the class Ipv6RoutingComponent method setUpLeafRoutes.
/**
* Insert routing rules on the given leaf switch, matching on interface
* subnets associated to other leaves and forwarding packets the spines
* using ECMP.
*
* @param leafId the leaf device ID
*/
private void setUpLeafRoutes(DeviceId leafId) {
log.info("Setting up leaf routes: {}", leafId);
// Get the set of subnets (interface IPv6 prefixes) associated to other
// leafs but not this one.
Set<Ip6Prefix> subnetsToRouteViaSpines = stream(deviceService.getDevices()).map(Device::id).filter(this::isLeaf).filter(deviceId -> !deviceId.equals(leafId)).map(this::getInterfaceIpv6Prefixes).flatMap(Collection::stream).collect(Collectors.toSet());
// Get myStationMac address of all spines.
Set<MacAddress> spineMacs = stream(deviceService.getDevices()).map(Device::id).filter(this::isSpine).map(this::getMyStationMac).collect(Collectors.toSet());
// Create an ECMP group to distribute traffic across all spines.
final int groupId = DEFAULT_ECMP_GROUP_ID;
final GroupDescription ecmpGroup = createNextHopGroup(groupId, spineMacs, leafId);
// Generate a flow rule for each subnet pointing to the ECMP group.
List<FlowRule> flowRules = subnetsToRouteViaSpines.stream().map(subnet -> createRoutingRule(leafId, subnet, groupId)).collect(Collectors.toList());
insertInOrder(ecmpGroup, flowRules);
// Since we're here, we also add a route for SRv6 (Exercise 7), to
// forward packets with IPv6 dst the SID of a spine switch, in this case
// using a single-member group.
stream(deviceService.getDevices()).map(Device::id).filter(this::isSpine).forEach(spineId -> {
MacAddress spineMac = getMyStationMac(spineId);
Ip6Address spineSid = getDeviceSid(spineId);
int spineGroupId = macToGroupId(spineMac);
GroupDescription group = createNextHopGroup(spineGroupId, Collections.singleton(spineMac), leafId);
FlowRule routingRule = createRoutingRule(leafId, Ip6Prefix.valueOf(spineSid, 128), spineGroupId);
insertInOrder(group, Collections.singleton(routingRule));
});
}
use of org.onosproject.net.Device in project onos by opennetworkinglab.
the class VirtualNetworkTopologyManager method currentTopology.
@Override
public Topology currentTopology() {
Iterable<Device> devices = manager.getVirtualDevices(networkId()).stream().collect(Collectors.toSet());
Iterable<Link> links = manager.getVirtualLinks(networkId()).stream().collect(Collectors.toSet());
DefaultGraphDescription graph = new DefaultGraphDescription(System.nanoTime(), System.currentTimeMillis(), devices, links);
return new DefaultTopology(PID, graph);
}
use of org.onosproject.net.Device in project onos by opennetworkinglab.
the class VirtualFlowsListCommand method doExecute.
@Override
protected void doExecute() {
CoreService coreService = get(CoreService.class);
VirtualNetworkService vnetservice = get(VirtualNetworkService.class);
DeviceService deviceService = vnetservice.get(NetworkId.networkId(networkId), DeviceService.class);
FlowRuleService service = vnetservice.get(NetworkId.networkId(networkId), FlowRuleService.class);
contentFilter = new StringFilter(filter, StringFilter.Strategy.AND);
compilePredicate();
SortedMap<Device, List<FlowEntry>> flows = getSortedFlows(deviceService, service);
if (outputJson()) {
print("%s", json(flows.keySet(), flows));
} else {
flows.forEach((device, flow) -> printFlows(device, flow, coreService));
}
}
use of org.onosproject.net.Device in project onos by opennetworkinglab.
the class VirtualFlowsListCommand method json.
/**
* Produces a JSON array of flows grouped by the each device.
*
* @param devices collection of devices to group flow by
* @param flows collection of flows per each device
* @return JSON array
*/
private JsonNode json(Iterable<Device> devices, Map<Device, List<FlowEntry>> flows) {
ObjectMapper mapper = new ObjectMapper();
ArrayNode result = mapper.createArrayNode();
for (Device device : devices) {
result.add(json(mapper, device, flows.get(device)));
}
return result;
}
Aggregations