blob: 124ffa723d98d028c911825e20ea85ad8140d1ac [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.List;
20import java.util.Set;
21
22import org.onosproject.core.ApplicationId;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.Link;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070025import org.onosproject.net.flowobjective.FlowObjectiveService;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080026import org.onosproject.net.link.LinkService;
Charles Chan188ebf52015-12-23 00:15:11 -080027import org.onosproject.segmentrouting.SegmentRoutingManager;
Charles Chan0b4e6182015-11-03 10:42:14 -080028import org.onosproject.segmentrouting.config.DeviceProperties;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080029
30/**
31 * Default ECMP group handler creation module for an edge 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 device D0 is connected to 2 neighbors (D1 and D2 ).
38 * The following groups will be created in D0:
Saurav Dasa07f2032015-10-19 14:37:36 -070039 * 1) all ports to D1 + with no label push, // direct attach case, seen
40 * 2) all ports to D1 + with label 102 pushed, // this is not needed
41 * 3) all ports to D1 + with label 103 pushed, // maybe needed, sometimes seen
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080042 * 4) all ports to D2 + with no label push,
43 * 5) all ports to D2 + with label 101 pushed,
44 * 6) all ports to D2 + with label 103 pushed,
Saurav Dasa07f2032015-10-19 14:37:36 -070045 * 7) all ports to D1 and D2 + with label 103 pushed // ecmp case
46 * 8) what about ecmp no label case
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080047 */
48public class DefaultEdgeGroupHandler extends DefaultGroupHandler {
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080049 protected DefaultEdgeGroupHandler(DeviceId deviceId,
50 ApplicationId appId,
51 DeviceProperties config,
52 LinkService linkService,
Srikanth Vavilapalli23181912015-05-04 09:48:09 -070053 FlowObjectiveService flowObjService,
Charles Chan188ebf52015-12-23 00:15:11 -080054 SegmentRoutingManager srManager) {
Charles Chane849c192016-01-11 18:28:54 -080055 super(deviceId, appId, config, linkService, flowObjService, srManager);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080056 }
57
58 @Override
59 public void createGroups() {
60 log.debug("Creating default groups "
61 + "for edge device {}", deviceId);
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 Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(neighbors);
69 log.trace("createGroupsAtEdgeRouter: The size of neighbor powerset "
70 + "for sw {} is {}", deviceId, powerSet.size());
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -070071 Set<NeighborSet> nsSet = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080072 for (Set<DeviceId> combo : powerSet) {
73 if (combo.isEmpty()) {
74 continue;
75 }
76 List<Integer> groupSegmentIds =
77 getSegmentIdsTobePairedWithNeighborSet(combo);
78 for (Integer sId : groupSegmentIds) {
79 NeighborSet ns = new NeighborSet(combo, sId);
80 log.trace("createGroupsAtEdgeRouter: sw {} "
81 + "combo {} sId {} ns {}",
82 deviceId, combo, sId, ns);
83 nsSet.add(ns);
84 }
85 }
86 log.trace("createGroupsAtEdgeRouter: The neighborset "
87 + "with label for sw {} is {}",
88 deviceId, nsSet);
89
Saurav Das8a0732e2015-11-20 15:27:53 -080090 //createGroupsFromNeighborsets(nsSet);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080091 }
92
93 @Override
94 protected void newNeighbor(Link newNeighborLink) {
95 log.debug("New Neighbor: Updating groups "
96 + "for edge device {}", deviceId);
97 // Recompute neighbor power set
98 addNeighborAtPort(newNeighborLink.dst().deviceId(),
99 newNeighborLink.src().port());
100 // Compute new neighbor sets due to the addition of new neighbor
101 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
102 newNeighborLink.dst().deviceId(),
103 devicePortMap.keySet());
Saurav Das8a0732e2015-11-20 15:27:53 -0800104 //createGroupsFromNeighborsets(nsSet);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800105 }
106
107 @Override
108 protected void newPortToExistingNeighbor(Link newNeighborLink) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700109 /*log.debug("New port to existing neighbor: Updating "
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800110 + "groups for edge device {}", deviceId);
111 addNeighborAtPort(newNeighborLink.dst().deviceId(),
112 newNeighborLink.src().port());
113 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
114 newNeighborLink.dst().deviceId(),
115 devicePortMap.keySet());
116 for (NeighborSet ns : nsSet) {
117 // Create the new bucket to be updated
118 TrafficTreatment.Builder tBuilder =
119 DefaultTrafficTreatment.builder();
120 tBuilder.setOutput(newNeighborLink.src().port())
121 .setEthDst(deviceConfig.getDeviceMac(
122 newNeighborLink.dst().deviceId()))
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700123 .setEthSrc(nodeMacAddr);
124 if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) {
125 tBuilder.pushMpls()
126 .setMpls(MplsLabel.
127 mplsLabel(ns.getEdgeLabel()));
128 }
sangho834e4b02015-05-01 09:38:25 -0700129
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700130 Integer nextId = deviceNextObjectiveIds.get(ns);
sangho834e4b02015-05-01 09:38:25 -0700131 if (nextId != null) {
132 NextObjective.Builder nextObjBuilder = DefaultNextObjective
133 .builder().withId(nextId)
134 .withType(NextObjective.Type.HASHED).fromApp(appId);
135
136 nextObjBuilder.addTreatment(tBuilder.build());
137
138 NextObjective nextObjective = nextObjBuilder.add();
139 flowObjectiveService.next(deviceId, nextObjective);
140 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700141 }*/
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800142 }
143
144 @Override
145 protected Set<NeighborSet> computeImpactedNeighborsetForPortEvent(
146 DeviceId impactedNeighbor,
147 Set<DeviceId> updatedNeighbors) {
148 Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(updatedNeighbors);
149
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -0700150 Set<DeviceId> tmp = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800151 tmp.addAll(updatedNeighbors);
152 tmp.remove(impactedNeighbor);
153 Set<Set<DeviceId>> tmpPowerSet = getPowerSetOfNeighbors(tmp);
154
155 // Compute the impacted neighbor sets
156 powerSet.removeAll(tmpPowerSet);
157
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -0700158 Set<NeighborSet> nsSet = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800159 for (Set<DeviceId> combo : powerSet) {
160 if (combo.isEmpty()) {
161 continue;
162 }
163 List<Integer> groupSegmentIds =
164 getSegmentIdsTobePairedWithNeighborSet(combo);
165 for (Integer sId : groupSegmentIds) {
166 NeighborSet ns = new NeighborSet(combo, sId);
167 log.trace("computeImpactedNeighborsetForPortEvent: sw {} "
168 + "combo {} sId {} ns {}",
169 deviceId, combo, sId, ns);
170 nsSet.add(ns);
171 }
172 }
173 log.trace("computeImpactedNeighborsetForPortEvent: The neighborset "
174 + "with label for sw {} is {}",
175 deviceId, nsSet);
176 return nsSet;
177 }
178
179}