blob: b009e869de5a3c8c8cc15774513f5ad304391e69 [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;
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070026import org.onosproject.store.service.EventuallyConsistentMap;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080027
28/**
29 * Default ECMP group handler creation module for a transit device.
30 * This component creates a set of ECMP groups for every neighbor
31 * that this device is connected to.
32 * For example, consider a network of 4 devices: D0 (Segment ID: 100),
33 * D1 (Segment ID: 101), D2 (Segment ID: 102) and D3 (Segment ID: 103),
34 * where D0 and D3 are edge devices and D1 and D2 are transit devices.
35 * Assume transit device D1 is connected to 2 neighbors (D0 and D3 ).
36 * The following groups will be created in D1:
37 * 1) all ports to D0 + with no label push,
38 * 2) all ports to D3 + with no label push,
39 */
40public class DefaultTransitGroupHandler extends DefaultGroupHandler {
41
42 protected DefaultTransitGroupHandler(DeviceId deviceId,
43 ApplicationId appId,
44 DeviceProperties config,
45 LinkService linkService,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070046 FlowObjectiveService flowObjService,
47 EventuallyConsistentMap<
Charles Chanc42e84e2015-10-20 16:24:19 -070048 NeighborSetNextObjectiveStoreKey,
49 Integer> nsNextObjStore,
50 EventuallyConsistentMap<SubnetNextObjectiveStoreKey,
51 Integer> subnetNextObjStore) {
52 super(deviceId, appId, config, linkService, flowObjService,
53 nsNextObjStore, subnetNextObjStore);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080054 }
55
56 @Override
57 public void createGroups() {
58 Set<DeviceId> neighbors = devicePortMap.keySet();
59 if (neighbors == null || neighbors.isEmpty()) {
60 return;
61 }
62
63 // Create all possible Neighbor sets from this router
64 // NOTE: Avoid any pairings of edge routers only
65 Set<Set<DeviceId>> sets = getPowerSetOfNeighbors(neighbors);
66 sets = filterEdgeRouterOnlyPairings(sets);
67 log.debug("createGroupsAtTransitRouter: The size of neighbor powerset "
68 + "for sw {} is {}", deviceId, sets.size());
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -070069 Set<NeighborSet> nsSet = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080070 for (Set<DeviceId> combo : sets) {
71 if (combo.isEmpty()) {
72 continue;
73 }
74 NeighborSet ns = new NeighborSet(combo);
75 log.debug("createGroupsAtTransitRouter: sw {} combo {} ns {}",
76 deviceId, combo, ns);
77 nsSet.add(ns);
78 }
79 log.debug("createGroupsAtTransitRouter: The neighborset with label "
80 + "for sw {} is {}", deviceId, nsSet);
81
82 createGroupsFromNeighborsets(nsSet);
83 }
84
85 @Override
86 protected void newNeighbor(Link newNeighborLink) {
87 log.debug("New Neighbor: Updating groups for "
88 + "transit device {}", deviceId);
89 // Recompute neighbor power set
90 addNeighborAtPort(newNeighborLink.dst().deviceId(),
91 newNeighborLink.src().port());
92 // Compute new neighbor sets due to the addition of new neighbor
93 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
94 newNeighborLink.dst().deviceId(),
95 devicePortMap.keySet());
96 createGroupsFromNeighborsets(nsSet);
97 }
98
99 @Override
100 protected void newPortToExistingNeighbor(Link newNeighborLink) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700101 /*log.debug("New port to existing neighbor: Updating "
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800102 + "groups for transit device {}", deviceId);
103 addNeighborAtPort(newNeighborLink.dst().deviceId(),
104 newNeighborLink.src().port());
105 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
106 newNeighborLink.dst().deviceId(),
107 devicePortMap.keySet());
108 for (NeighborSet ns : nsSet) {
109 // Create the new bucket to be updated
110 TrafficTreatment.Builder tBuilder =
111 DefaultTrafficTreatment.builder();
112 tBuilder.setOutput(newNeighborLink.src().port())
113 .setEthDst(deviceConfig.getDeviceMac(
114 newNeighborLink.dst().deviceId()))
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700115 .setEthSrc(nodeMacAddr);
116 if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) {
117 tBuilder.pushMpls()
118 .setMpls(MplsLabel.
119 mplsLabel(ns.getEdgeLabel()));
120 }
sangho834e4b02015-05-01 09:38:25 -0700121
122
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700123 Integer nextId = deviceNextObjectiveIds.get(ns);
sangho834e4b02015-05-01 09:38:25 -0700124 if (nextId != null) {
125 NextObjective.Builder nextObjBuilder = DefaultNextObjective
126 .builder().withId(nextId)
127 .withType(NextObjective.Type.HASHED).fromApp(appId);
128
129 nextObjBuilder.addTreatment(tBuilder.build());
130
131 NextObjective nextObjective = nextObjBuilder.add();
132 flowObjectiveService.next(deviceId, nextObjective);
133 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700134 }*/
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800135 }
136
137 @Override
138 protected Set<NeighborSet> computeImpactedNeighborsetForPortEvent(
139 DeviceId impactedNeighbor,
140 Set<DeviceId> updatedNeighbors) {
141 Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(updatedNeighbors);
142
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -0700143 Set<DeviceId> tmp = new HashSet<>();
sanghob35a6192015-04-01 13:05:26 -0700144 tmp.addAll(updatedNeighbors);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800145 tmp.remove(impactedNeighbor);
146 Set<Set<DeviceId>> tmpPowerSet = getPowerSetOfNeighbors(tmp);
147
148 // Compute the impacted neighbor sets
149 powerSet.removeAll(tmpPowerSet);
150
151 powerSet = filterEdgeRouterOnlyPairings(powerSet);
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -0700152 Set<NeighborSet> nsSet = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800153 for (Set<DeviceId> combo : powerSet) {
154 if (combo.isEmpty()) {
155 continue;
156 }
157 NeighborSet ns = new NeighborSet(combo);
158 log.debug("createGroupsAtTransitRouter: sw {} combo {} ns {}",
159 deviceId, combo, ns);
160 nsSet.add(ns);
161 }
162 log.debug("computeImpactedNeighborsetForPortEvent: The neighborset with label "
163 + "for sw {} is {}", deviceId, nsSet);
164
165 return nsSet;
166 }
167
168 private Set<Set<DeviceId>> filterEdgeRouterOnlyPairings(Set<Set<DeviceId>> sets) {
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -0700169 Set<Set<DeviceId>> fiteredSets = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800170 for (Set<DeviceId> deviceSubSet : sets) {
171 if (deviceSubSet.size() > 1) {
172 boolean avoidEdgeRouterPairing = true;
173 for (DeviceId device : deviceSubSet) {
174 if (!deviceConfig.isEdgeDevice(device)) {
175 avoidEdgeRouterPairing = false;
176 break;
177 }
178 }
179 if (!avoidEdgeRouterPairing) {
180 fiteredSets.add(deviceSubSet);
181 }
182 } else {
183 fiteredSets.add(deviceSubSet);
184 }
185 }
186 return fiteredSets;
187 }
188}