blob: 7fc9480a991f4e45a92292a9c4f191d3748ff500 [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 org.onosproject.core.ApplicationId;
19import org.onosproject.net.DeviceId;
20import org.onosproject.net.Link;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070021import org.onosproject.net.flowobjective.FlowObjectiveService;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080022import org.onosproject.net.link.LinkService;
Charles Chan188ebf52015-12-23 00:15:11 -080023import org.onosproject.segmentrouting.SegmentRoutingManager;
Charles Chan0b4e6182015-11-03 10:42:14 -080024import org.onosproject.segmentrouting.config.DeviceProperties;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080025
Pier Ventre917127a2016-10-31 16:49:19 -070026import java.util.HashSet;
27import java.util.List;
28import java.util.Set;
29
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080030/**
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) {
Pier Ventre917127a2016-10-31 16:49:19 -070079 // For these NeighborSet isMpls is meaningless.
80 NeighborSet ns = new NeighborSet(combo, false, sId);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080081 log.trace("createGroupsAtEdgeRouter: sw {} "
82 + "combo {} sId {} ns {}",
83 deviceId, combo, sId, ns);
84 nsSet.add(ns);
85 }
86 }
87 log.trace("createGroupsAtEdgeRouter: The neighborset "
88 + "with label for sw {} is {}",
89 deviceId, nsSet);
90
Saurav Das8a0732e2015-11-20 15:27:53 -080091 //createGroupsFromNeighborsets(nsSet);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080092 }
93
94 @Override
95 protected void newNeighbor(Link newNeighborLink) {
96 log.debug("New Neighbor: Updating groups "
97 + "for edge device {}", deviceId);
98 // Recompute neighbor power set
99 addNeighborAtPort(newNeighborLink.dst().deviceId(),
100 newNeighborLink.src().port());
101 // Compute new neighbor sets due to the addition of new neighbor
102 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
103 newNeighborLink.dst().deviceId(),
104 devicePortMap.keySet());
Saurav Das8a0732e2015-11-20 15:27:53 -0800105 //createGroupsFromNeighborsets(nsSet);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800106 }
107
108 @Override
109 protected void newPortToExistingNeighbor(Link newNeighborLink) {
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700110 /*log.debug("New port to existing neighbor: Updating "
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800111 + "groups for edge device {}", deviceId);
112 addNeighborAtPort(newNeighborLink.dst().deviceId(),
113 newNeighborLink.src().port());
114 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
115 newNeighborLink.dst().deviceId(),
116 devicePortMap.keySet());
117 for (NeighborSet ns : nsSet) {
118 // Create the new bucket to be updated
119 TrafficTreatment.Builder tBuilder =
120 DefaultTrafficTreatment.builder();
121 tBuilder.setOutput(newNeighborLink.src().port())
122 .setEthDst(deviceConfig.getDeviceMac(
123 newNeighborLink.dst().deviceId()))
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700124 .setEthSrc(nodeMacAddr);
125 if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) {
126 tBuilder.pushMpls()
127 .setMpls(MplsLabel.
128 mplsLabel(ns.getEdgeLabel()));
129 }
sangho834e4b02015-05-01 09:38:25 -0700130
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700131 Integer nextId = deviceNextObjectiveIds.get(ns);
sangho834e4b02015-05-01 09:38:25 -0700132 if (nextId != null) {
133 NextObjective.Builder nextObjBuilder = DefaultNextObjective
134 .builder().withId(nextId)
135 .withType(NextObjective.Type.HASHED).fromApp(appId);
136
137 nextObjBuilder.addTreatment(tBuilder.build());
138
139 NextObjective nextObjective = nextObjBuilder.add();
140 flowObjectiveService.next(deviceId, nextObjective);
141 }
Srikanth Vavilapalli23181912015-05-04 09:48:09 -0700142 }*/
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800143 }
144
145 @Override
146 protected Set<NeighborSet> computeImpactedNeighborsetForPortEvent(
147 DeviceId impactedNeighbor,
148 Set<DeviceId> updatedNeighbors) {
149 Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(updatedNeighbors);
150
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -0700151 Set<DeviceId> tmp = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800152 tmp.addAll(updatedNeighbors);
153 tmp.remove(impactedNeighbor);
154 Set<Set<DeviceId>> tmpPowerSet = getPowerSetOfNeighbors(tmp);
155
156 // Compute the impacted neighbor sets
157 powerSet.removeAll(tmpPowerSet);
158
Sho SHIMIZU6cfc02d2015-09-11 11:19:11 -0700159 Set<NeighborSet> nsSet = new HashSet<>();
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800160 for (Set<DeviceId> combo : powerSet) {
161 if (combo.isEmpty()) {
162 continue;
163 }
164 List<Integer> groupSegmentIds =
165 getSegmentIdsTobePairedWithNeighborSet(combo);
166 for (Integer sId : groupSegmentIds) {
Pier Ventre917127a2016-10-31 16:49:19 -0700167 // For these NeighborSet isMpls is meaningless.
168 NeighborSet ns = new NeighborSet(combo, false, sId);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800169 log.trace("computeImpactedNeighborsetForPortEvent: sw {} "
170 + "combo {} sId {} ns {}",
171 deviceId, combo, sId, ns);
172 nsSet.add(ns);
173 }
174 }
175 log.trace("computeImpactedNeighborsetForPortEvent: The neighborset "
176 + "with label for sw {} is {}",
177 deviceId, nsSet);
178 return nsSet;
179 }
180
181}