blob: 820960bd2efa6f323d3ad16ccf1bf6b2264e18f9 [file] [log] [blame]
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Srikanth Vavilapalli4db76e32015-04-07 15:12:32 -070016package org.onosproject.segmentrouting.grouphandler;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080017
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080018import java.util.HashSet;
19import java.util.Set;
20
21import org.onosproject.core.ApplicationId;
22import org.onosproject.net.DeviceId;
23import org.onosproject.net.Link;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070024import org.onosproject.net.flowobjective.FlowObjectiveService;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080025import org.onosproject.net.link.LinkService;
Charles Chan188ebf52015-12-23 00:15:11 -080026import org.onosproject.segmentrouting.SegmentRoutingManager;
Charles Chan0b4e6182015-11-03 10:42:14 -080027import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
28import org.onosproject.segmentrouting.config.DeviceProperties;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080029
30/**
31 * Default ECMP group handler creation module for a transit device.
32 * This component creates a set of ECMP groups for every neighbor
33 * that this device is connected to.
34 * For example, consider a network of 4 devices: D0 (Segment ID: 100),
35 * D1 (Segment ID: 101), D2 (Segment ID: 102) and D3 (Segment ID: 103),
36 * where D0 and D3 are edge devices and D1 and D2 are transit devices.
37 * Assume transit device D1 is connected to 2 neighbors (D0 and D3 ).
38 * The following groups will be created in D1:
39 * 1) all ports to D0 + with no label push,
40 * 2) all ports to D3 + with no label push,
41 */
42public class DefaultTransitGroupHandler extends DefaultGroupHandler {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080043 protected DefaultTransitGroupHandler(DeviceId deviceId,
44 ApplicationId appId,
45 DeviceProperties config,
46 LinkService linkService,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070047 FlowObjectiveService flowObjService,
Charles Chan188ebf52015-12-23 00:15:11 -080048 SegmentRoutingManager srManager) {
Charles Chane849c192016-01-11 18:28:54 -080049 super(deviceId, appId, config, linkService, flowObjService, srManager);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080050 }
51
52 @Override
53 public void createGroups() {
54 Set<DeviceId> neighbors = devicePortMap.keySet();
55 if (neighbors == null || neighbors.isEmpty()) {
56 return;
57 }
58
59 // Create all possible Neighbor sets from this router
60 // NOTE: Avoid any pairings of edge routers only
61 Set<Set<DeviceId>> sets = getPowerSetOfNeighbors(neighbors);
62 sets = filterEdgeRouterOnlyPairings(sets);
63 log.debug("createGroupsAtTransitRouter: The size of neighbor powerset "
64 + "for sw {} is {}", deviceId, sets.size());
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -070065 Set<NeighborSet> nsSet = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080066 for (Set<DeviceId> combo : sets) {
67 if (combo.isEmpty()) {
68 continue;
69 }
70 NeighborSet ns = new NeighborSet(combo);
71 log.debug("createGroupsAtTransitRouter: sw {} combo {} ns {}",
72 deviceId, combo, ns);
73 nsSet.add(ns);
74 }
75 log.debug("createGroupsAtTransitRouter: The neighborset with label "
76 + "for sw {} is {}", deviceId, nsSet);
77
Saurav Das8a0732e2015-11-20 15:27:53 -080078 //createGroupsFromNeighborsets(nsSet);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080079 }
80
81 @Override
82 protected void newNeighbor(Link newNeighborLink) {
83 log.debug("New Neighbor: Updating groups for "
84 + "transit device {}", deviceId);
85 // Recompute neighbor power set
86 addNeighborAtPort(newNeighborLink.dst().deviceId(),
87 newNeighborLink.src().port());
88 // Compute new neighbor sets due to the addition of new neighbor
89 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
90 newNeighborLink.dst().deviceId(),
91 devicePortMap.keySet());
Saurav Das8a0732e2015-11-20 15:27:53 -080092 //createGroupsFromNeighborsets(nsSet);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080093 }
94
95 @Override
96 protected void newPortToExistingNeighbor(Link newNeighborLink) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070097 /*log.debug("New port to existing neighbor: Updating "
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080098 + "groups for transit device {}", deviceId);
99 addNeighborAtPort(newNeighborLink.dst().deviceId(),
100 newNeighborLink.src().port());
101 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
102 newNeighborLink.dst().deviceId(),
103 devicePortMap.keySet());
104 for (NeighborSet ns : nsSet) {
105 // Create the new bucket to be updated
106 TrafficTreatment.Builder tBuilder =
107 DefaultTrafficTreatment.builder();
108 tBuilder.setOutput(newNeighborLink.src().port())
109 .setEthDst(deviceConfig.getDeviceMac(
110 newNeighborLink.dst().deviceId()))
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700111 .setEthSrc(nodeMacAddr);
112 if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) {
113 tBuilder.pushMpls()
114 .setMpls(MplsLabel.
115 mplsLabel(ns.getEdgeLabel()));
116 }
sangho834e4b02015-05-01 09:38:25 -0700117
118
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700119 Integer nextId = deviceNextObjectiveIds.get(ns);
sangho834e4b02015-05-01 09:38:25 -0700120 if (nextId != null) {
121 NextObjective.Builder nextObjBuilder = DefaultNextObjective
122 .builder().withId(nextId)
123 .withType(NextObjective.Type.HASHED).fromApp(appId);
124
125 nextObjBuilder.addTreatment(tBuilder.build());
126
127 NextObjective nextObjective = nextObjBuilder.add();
128 flowObjectiveService.next(deviceId, nextObjective);
129 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700130 }*/
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800131 }
132
133 @Override
134 protected Set<NeighborSet> computeImpactedNeighborsetForPortEvent(
135 DeviceId impactedNeighbor,
136 Set<DeviceId> updatedNeighbors) {
137 Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(updatedNeighbors);
138
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -0700139 Set<DeviceId> tmp = new HashSet<>();
sanghob35a6192015-04-01 13:05:26 -0700140 tmp.addAll(updatedNeighbors);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800141 tmp.remove(impactedNeighbor);
142 Set<Set<DeviceId>> tmpPowerSet = getPowerSetOfNeighbors(tmp);
143
144 // Compute the impacted neighbor sets
145 powerSet.removeAll(tmpPowerSet);
146
147 powerSet = filterEdgeRouterOnlyPairings(powerSet);
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -0700148 Set<NeighborSet> nsSet = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800149 for (Set<DeviceId> combo : powerSet) {
150 if (combo.isEmpty()) {
151 continue;
152 }
153 NeighborSet ns = new NeighborSet(combo);
154 log.debug("createGroupsAtTransitRouter: sw {} combo {} ns {}",
155 deviceId, combo, ns);
156 nsSet.add(ns);
157 }
158 log.debug("computeImpactedNeighborsetForPortEvent: The neighborset with label "
159 + "for sw {} is {}", deviceId, nsSet);
160
161 return nsSet;
162 }
163
164 private Set<Set<DeviceId>> filterEdgeRouterOnlyPairings(Set<Set<DeviceId>> sets) {
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -0700165 Set<Set<DeviceId>> fiteredSets = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800166 for (Set<DeviceId> deviceSubSet : sets) {
167 if (deviceSubSet.size() > 1) {
168 boolean avoidEdgeRouterPairing = true;
169 for (DeviceId device : deviceSubSet) {
Charles Chan0b4e6182015-11-03 10:42:14 -0800170 boolean isEdge;
171 try {
172 isEdge = deviceConfig.isEdgeDevice(device);
173 } catch (DeviceConfigNotFoundException e) {
174 log.warn(e.getMessage() + " Skipping filterEdgeRouterOnlyPairings on this device.");
175 continue;
176 }
177
178 if (!isEdge) {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800179 avoidEdgeRouterPairing = false;
180 break;
181 }
182 }
183 if (!avoidEdgeRouterPairing) {
184 fiteredSets.add(deviceSubSet);
185 }
186 } else {
187 fiteredSets.add(deviceSubSet);
188 }
189 }
190 return fiteredSets;
191 }
192}