blob: 0cd5743786b8caeefb5397f193991f8ec1f6d8bc [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
18import java.util.Arrays;
19import java.util.HashSet;
20import java.util.List;
21import java.util.Set;
22
sangho32a59322015-02-17 12:07:41 -080023import org.onlab.packet.MplsLabel;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080024import org.onosproject.core.ApplicationId;
25import org.onosproject.net.DeviceId;
26import org.onosproject.net.Link;
27import org.onosproject.net.flow.DefaultTrafficTreatment;
28import org.onosproject.net.flow.TrafficTreatment;
29import org.onosproject.net.group.DefaultGroupBucket;
30import org.onosproject.net.group.GroupBucket;
31import org.onosproject.net.group.GroupBuckets;
32import org.onosproject.net.group.GroupService;
33import org.onosproject.net.link.LinkService;
34
35/**
36 * Default ECMP group handler creation module for an edge device.
37 * This component creates a set of ECMP groups for every neighbor
38 * that this device is connected to.
39 * For example, consider a network of 4 devices: D0 (Segment ID: 100),
40 * D1 (Segment ID: 101), D2 (Segment ID: 102) and D3 (Segment ID: 103),
41 * where D0 and D3 are edge devices and D1 and D2 are transit devices.
42 * Assume device D0 is connected to 2 neighbors (D1 and D2 ).
43 * The following groups will be created in D0:
44 * 1) all ports to D1 + with no label push,
45 * 2) all ports to D1 + with label 102 pushed,
46 * 3) all ports to D1 + with label 103 pushed,
47 * 4) all ports to D2 + with no label push,
48 * 5) all ports to D2 + with label 101 pushed,
49 * 6) all ports to D2 + with label 103 pushed,
50 * 7) all ports to D1 and D2 + with label 103 pushed
51 */
52public class DefaultEdgeGroupHandler extends DefaultGroupHandler {
53
54 protected DefaultEdgeGroupHandler(DeviceId deviceId,
55 ApplicationId appId,
56 DeviceProperties config,
57 LinkService linkService,
58 GroupService groupService) {
59 super(deviceId, appId, config, linkService, groupService);
60 }
61
62 @Override
63 public void createGroups() {
64 log.debug("Creating default groups "
65 + "for edge device {}", deviceId);
66 Set<DeviceId> neighbors = devicePortMap.keySet();
67 if (neighbors == null || neighbors.isEmpty()) {
68 return;
69 }
70
71 // Create all possible Neighbor sets from this router
72 Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(neighbors);
73 log.trace("createGroupsAtEdgeRouter: The size of neighbor powerset "
74 + "for sw {} is {}", deviceId, powerSet.size());
75 Set<NeighborSet> nsSet = new HashSet<NeighborSet>();
76 for (Set<DeviceId> combo : powerSet) {
77 if (combo.isEmpty()) {
78 continue;
79 }
80 List<Integer> groupSegmentIds =
81 getSegmentIdsTobePairedWithNeighborSet(combo);
82 for (Integer sId : groupSegmentIds) {
83 NeighborSet ns = new NeighborSet(combo, sId);
84 log.trace("createGroupsAtEdgeRouter: sw {} "
85 + "combo {} sId {} ns {}",
86 deviceId, combo, sId, ns);
87 nsSet.add(ns);
88 }
89 }
90 log.trace("createGroupsAtEdgeRouter: The neighborset "
91 + "with label for sw {} is {}",
92 deviceId, nsSet);
93
94 createGroupsFromNeighborsets(nsSet);
95 }
96
97 @Override
98 protected void newNeighbor(Link newNeighborLink) {
99 log.debug("New Neighbor: Updating groups "
100 + "for edge device {}", deviceId);
101 // Recompute neighbor power set
102 addNeighborAtPort(newNeighborLink.dst().deviceId(),
103 newNeighborLink.src().port());
104 // Compute new neighbor sets due to the addition of new neighbor
105 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
106 newNeighborLink.dst().deviceId(),
107 devicePortMap.keySet());
108 createGroupsFromNeighborsets(nsSet);
109 }
110
111 @Override
112 protected void newPortToExistingNeighbor(Link newNeighborLink) {
113 log.debug("New port to existing neighbor: Updating "
114 + "groups for edge device {}", deviceId);
115 addNeighborAtPort(newNeighborLink.dst().deviceId(),
116 newNeighborLink.src().port());
117 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
118 newNeighborLink.dst().deviceId(),
119 devicePortMap.keySet());
120 for (NeighborSet ns : nsSet) {
121 // Create the new bucket to be updated
122 TrafficTreatment.Builder tBuilder =
123 DefaultTrafficTreatment.builder();
124 tBuilder.setOutput(newNeighborLink.src().port())
125 .setEthDst(deviceConfig.getDeviceMac(
126 newNeighborLink.dst().deviceId()))
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700127 .setEthSrc(nodeMacAddr);
128 if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) {
129 tBuilder.pushMpls()
130 .setMpls(MplsLabel.
131 mplsLabel(ns.getEdgeLabel()));
132 }
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800133 GroupBucket updatedBucket = DefaultGroupBucket.
134 createSelectGroupBucket(tBuilder.build());
135 GroupBuckets updatedBuckets = new GroupBuckets(
136 Arrays.asList(updatedBucket));
137 log.debug("newPortToExistingNeighborAtEdgeRouter: "
138 + "groupService.addBucketsToGroup for neighborset{}", ns);
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700139 groupService.addBucketsToGroup(deviceId,
140 getGroupKey(ns),
141 updatedBuckets,
142 getGroupKey(ns),
143 appId);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800144 }
145 }
146
147 @Override
148 protected Set<NeighborSet> computeImpactedNeighborsetForPortEvent(
149 DeviceId impactedNeighbor,
150 Set<DeviceId> updatedNeighbors) {
151 Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(updatedNeighbors);
152
153 Set<DeviceId> tmp = new HashSet<DeviceId>();
154 tmp.addAll(updatedNeighbors);
155 tmp.remove(impactedNeighbor);
156 Set<Set<DeviceId>> tmpPowerSet = getPowerSetOfNeighbors(tmp);
157
158 // Compute the impacted neighbor sets
159 powerSet.removeAll(tmpPowerSet);
160
161 Set<NeighborSet> nsSet = new HashSet<NeighborSet>();
162 for (Set<DeviceId> combo : powerSet) {
163 if (combo.isEmpty()) {
164 continue;
165 }
166 List<Integer> groupSegmentIds =
167 getSegmentIdsTobePairedWithNeighborSet(combo);
168 for (Integer sId : groupSegmentIds) {
169 NeighborSet ns = new NeighborSet(combo, sId);
170 log.trace("computeImpactedNeighborsetForPortEvent: sw {} "
171 + "combo {} sId {} ns {}",
172 deviceId, combo, sId, ns);
173 nsSet.add(ns);
174 }
175 }
176 log.trace("computeImpactedNeighborsetForPortEvent: The neighborset "
177 + "with label for sw {} is {}",
178 deviceId, nsSet);
179 return nsSet;
180 }
181
182}