blob: 7a43e73d943f4cbfef9ef89509e413a4d791a09c [file] [log] [blame]
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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 Chan0b4e6182015-11-03 10:42:14 -080026import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException;
27import org.onosproject.segmentrouting.config.DeviceProperties;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070028import org.onosproject.store.service.EventuallyConsistentMap;
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 {
43
44 protected DefaultTransitGroupHandler(DeviceId deviceId,
45 ApplicationId appId,
46 DeviceProperties config,
47 LinkService linkService,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070048 FlowObjectiveService flowObjService,
49 EventuallyConsistentMap<
Charles Chanc42e84e2015-10-20 16:24:19 -070050 NeighborSetNextObjectiveStoreKey,
51 Integer> nsNextObjStore,
52 EventuallyConsistentMap<SubnetNextObjectiveStoreKey,
Saurav Das4ce45962015-11-24 23:21:05 -080053 Integer> subnetNextObjStore,
54 EventuallyConsistentMap<PortNextObjectiveStoreKey,
55 Integer> portNextObjStore) {
Charles Chanc42e84e2015-10-20 16:24:19 -070056 super(deviceId, appId, config, linkService, flowObjService,
Saurav Das4ce45962015-11-24 23:21:05 -080057 nsNextObjStore, subnetNextObjStore, portNextObjStore);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080058 }
59
60 @Override
61 public void createGroups() {
62 Set<DeviceId> neighbors = devicePortMap.keySet();
63 if (neighbors == null || neighbors.isEmpty()) {
64 return;
65 }
66
67 // Create all possible Neighbor sets from this router
68 // NOTE: Avoid any pairings of edge routers only
69 Set<Set<DeviceId>> sets = getPowerSetOfNeighbors(neighbors);
70 sets = filterEdgeRouterOnlyPairings(sets);
71 log.debug("createGroupsAtTransitRouter: The size of neighbor powerset "
72 + "for sw {} is {}", deviceId, sets.size());
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -070073 Set<NeighborSet> nsSet = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080074 for (Set<DeviceId> combo : sets) {
75 if (combo.isEmpty()) {
76 continue;
77 }
78 NeighborSet ns = new NeighborSet(combo);
79 log.debug("createGroupsAtTransitRouter: sw {} combo {} ns {}",
80 deviceId, combo, ns);
81 nsSet.add(ns);
82 }
83 log.debug("createGroupsAtTransitRouter: The neighborset with label "
84 + "for sw {} is {}", deviceId, nsSet);
85
Saurav Das8a0732e2015-11-20 15:27:53 -080086 //createGroupsFromNeighborsets(nsSet);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080087 }
88
89 @Override
90 protected void newNeighbor(Link newNeighborLink) {
91 log.debug("New Neighbor: Updating groups for "
92 + "transit device {}", deviceId);
93 // Recompute neighbor power set
94 addNeighborAtPort(newNeighborLink.dst().deviceId(),
95 newNeighborLink.src().port());
96 // Compute new neighbor sets due to the addition of new neighbor
97 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
98 newNeighborLink.dst().deviceId(),
99 devicePortMap.keySet());
Saurav Das8a0732e2015-11-20 15:27:53 -0800100 //createGroupsFromNeighborsets(nsSet);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800101 }
102
103 @Override
104 protected void newPortToExistingNeighbor(Link newNeighborLink) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700105 /*log.debug("New port to existing neighbor: Updating "
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800106 + "groups for transit device {}", deviceId);
107 addNeighborAtPort(newNeighborLink.dst().deviceId(),
108 newNeighborLink.src().port());
109 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
110 newNeighborLink.dst().deviceId(),
111 devicePortMap.keySet());
112 for (NeighborSet ns : nsSet) {
113 // Create the new bucket to be updated
114 TrafficTreatment.Builder tBuilder =
115 DefaultTrafficTreatment.builder();
116 tBuilder.setOutput(newNeighborLink.src().port())
117 .setEthDst(deviceConfig.getDeviceMac(
118 newNeighborLink.dst().deviceId()))
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700119 .setEthSrc(nodeMacAddr);
120 if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) {
121 tBuilder.pushMpls()
122 .setMpls(MplsLabel.
123 mplsLabel(ns.getEdgeLabel()));
124 }
sangho834e4b02015-05-01 09:38:25 -0700125
126
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700127 Integer nextId = deviceNextObjectiveIds.get(ns);
sangho834e4b02015-05-01 09:38:25 -0700128 if (nextId != null) {
129 NextObjective.Builder nextObjBuilder = DefaultNextObjective
130 .builder().withId(nextId)
131 .withType(NextObjective.Type.HASHED).fromApp(appId);
132
133 nextObjBuilder.addTreatment(tBuilder.build());
134
135 NextObjective nextObjective = nextObjBuilder.add();
136 flowObjectiveService.next(deviceId, nextObjective);
137 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700138 }*/
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800139 }
140
141 @Override
142 protected Set<NeighborSet> computeImpactedNeighborsetForPortEvent(
143 DeviceId impactedNeighbor,
144 Set<DeviceId> updatedNeighbors) {
145 Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(updatedNeighbors);
146
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -0700147 Set<DeviceId> tmp = new HashSet<>();
sanghob35a6192015-04-01 13:05:26 -0700148 tmp.addAll(updatedNeighbors);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800149 tmp.remove(impactedNeighbor);
150 Set<Set<DeviceId>> tmpPowerSet = getPowerSetOfNeighbors(tmp);
151
152 // Compute the impacted neighbor sets
153 powerSet.removeAll(tmpPowerSet);
154
155 powerSet = filterEdgeRouterOnlyPairings(powerSet);
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -0700156 Set<NeighborSet> nsSet = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800157 for (Set<DeviceId> combo : powerSet) {
158 if (combo.isEmpty()) {
159 continue;
160 }
161 NeighborSet ns = new NeighborSet(combo);
162 log.debug("createGroupsAtTransitRouter: sw {} combo {} ns {}",
163 deviceId, combo, ns);
164 nsSet.add(ns);
165 }
166 log.debug("computeImpactedNeighborsetForPortEvent: The neighborset with label "
167 + "for sw {} is {}", deviceId, nsSet);
168
169 return nsSet;
170 }
171
172 private Set<Set<DeviceId>> filterEdgeRouterOnlyPairings(Set<Set<DeviceId>> sets) {
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -0700173 Set<Set<DeviceId>> fiteredSets = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800174 for (Set<DeviceId> deviceSubSet : sets) {
175 if (deviceSubSet.size() > 1) {
176 boolean avoidEdgeRouterPairing = true;
177 for (DeviceId device : deviceSubSet) {
Charles Chan0b4e6182015-11-03 10:42:14 -0800178 boolean isEdge;
179 try {
180 isEdge = deviceConfig.isEdgeDevice(device);
181 } catch (DeviceConfigNotFoundException e) {
182 log.warn(e.getMessage() + " Skipping filterEdgeRouterOnlyPairings on this device.");
183 continue;
184 }
185
186 if (!isEdge) {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800187 avoidEdgeRouterPairing = false;
188 break;
189 }
190 }
191 if (!avoidEdgeRouterPairing) {
192 fiteredSets.add(deviceSubSet);
193 }
194 } else {
195 fiteredSets.add(deviceSubSet);
196 }
197 }
198 return fiteredSets;
199 }
200}