blob: 67e9eef42c19e586fd448dae388de98e5d5b7f7a [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
sangho32a59322015-02-17 12:07:41 -080021import org.onlab.packet.MplsLabel;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080022import org.onosproject.core.ApplicationId;
23import org.onosproject.net.DeviceId;
24import org.onosproject.net.Link;
25import org.onosproject.net.flow.DefaultTrafficTreatment;
26import org.onosproject.net.flow.TrafficTreatment;
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -070027import org.onosproject.net.flowobjective.FlowObjectiveService;
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080028import org.onosproject.net.link.LinkService;
29
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 Vavilapallif5b234a2015-04-21 13:04:13 -070048 FlowObjectiveService flowObjService) {
49 super(deviceId, appId, config, linkService, flowObjService);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -080050 }
51
52 @Override
53 public void createGroups() {
54 Set<DeviceId> neighbors = devicePortMap.keySet();
55 if (neighbors == null || neighbors.isEmpty()) {
56 return;
57 }
58
59 // Create all possible Neighbor sets from this router
60 // NOTE: Avoid any pairings of edge routers only
61 Set<Set<DeviceId>> sets = getPowerSetOfNeighbors(neighbors);
62 sets = filterEdgeRouterOnlyPairings(sets);
63 log.debug("createGroupsAtTransitRouter: The size of neighbor powerset "
64 + "for sw {} is {}", deviceId, sets.size());
65 Set<NeighborSet> nsSet = new HashSet<NeighborSet>();
66 for (Set<DeviceId> combo : sets) {
67 if (combo.isEmpty()) {
68 continue;
69 }
70 NeighborSet ns = new NeighborSet(combo);
71 log.debug("createGroupsAtTransitRouter: sw {} combo {} ns {}",
72 deviceId, combo, ns);
73 nsSet.add(ns);
74 }
75 log.debug("createGroupsAtTransitRouter: The neighborset with label "
76 + "for sw {} is {}", deviceId, nsSet);
77
78 createGroupsFromNeighborsets(nsSet);
79 }
80
81 @Override
82 protected void newNeighbor(Link newNeighborLink) {
83 log.debug("New Neighbor: Updating groups for "
84 + "transit device {}", deviceId);
85 // Recompute neighbor power set
86 addNeighborAtPort(newNeighborLink.dst().deviceId(),
87 newNeighborLink.src().port());
88 // Compute new neighbor sets due to the addition of new neighbor
89 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
90 newNeighborLink.dst().deviceId(),
91 devicePortMap.keySet());
92 createGroupsFromNeighborsets(nsSet);
93 }
94
95 @Override
96 protected void newPortToExistingNeighbor(Link newNeighborLink) {
97 log.debug("New port to existing neighbor: Updating "
98 + "groups for transit device {}", deviceId);
99 addNeighborAtPort(newNeighborLink.dst().deviceId(),
100 newNeighborLink.src().port());
101 Set<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(
102 newNeighborLink.dst().deviceId(),
103 devicePortMap.keySet());
104 for (NeighborSet ns : nsSet) {
105 // Create the new bucket to be updated
106 TrafficTreatment.Builder tBuilder =
107 DefaultTrafficTreatment.builder();
108 tBuilder.setOutput(newNeighborLink.src().port())
109 .setEthDst(deviceConfig.getDeviceMac(
110 newNeighborLink.dst().deviceId()))
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700111 .setEthSrc(nodeMacAddr);
112 if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) {
113 tBuilder.pushMpls()
114 .setMpls(MplsLabel.
115 mplsLabel(ns.getEdgeLabel()));
116 }
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700117 /*GroupBucket updatedBucket = DefaultGroupBucket.
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800118 createSelectGroupBucket(tBuilder.build());
119 GroupBuckets updatedBuckets = new GroupBuckets(
120 Arrays.asList(updatedBucket));
121 log.debug("newPortToExistingNeighborAtEdgeRouter: "
122 + "groupService.addBucketsToGroup for neighborset{}", ns);
Srikanth Vavilapalli717361f2015-03-16 12:06:04 -0700123 groupService.addBucketsToGroup(deviceId,
124 getGroupKey(ns),
125 updatedBuckets,
126 getGroupKey(ns),
Srikanth Vavilapallif5b234a2015-04-21 13:04:13 -0700127 appId);*/
128 //TODO: Use nextObjective APIs to update the next objective
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800129 }
130 }
131
132 @Override
133 protected Set<NeighborSet> computeImpactedNeighborsetForPortEvent(
134 DeviceId impactedNeighbor,
135 Set<DeviceId> updatedNeighbors) {
136 Set<Set<DeviceId>> powerSet = getPowerSetOfNeighbors(updatedNeighbors);
137
sanghob35a6192015-04-01 13:05:26 -0700138 Set<DeviceId> tmp = new HashSet<DeviceId>();
139 tmp.addAll(updatedNeighbors);
Srikanth Vavilapallied12ae52015-02-09 14:43:19 -0800140 tmp.remove(impactedNeighbor);
141 Set<Set<DeviceId>> tmpPowerSet = getPowerSetOfNeighbors(tmp);
142
143 // Compute the impacted neighbor sets
144 powerSet.removeAll(tmpPowerSet);
145
146 powerSet = filterEdgeRouterOnlyPairings(powerSet);
147 Set<NeighborSet> nsSet = new HashSet<NeighborSet>();
148 for (Set<DeviceId> combo : powerSet) {
149 if (combo.isEmpty()) {
150 continue;
151 }
152 NeighborSet ns = new NeighborSet(combo);
153 log.debug("createGroupsAtTransitRouter: sw {} combo {} ns {}",
154 deviceId, combo, ns);
155 nsSet.add(ns);
156 }
157 log.debug("computeImpactedNeighborsetForPortEvent: The neighborset with label "
158 + "for sw {} is {}", deviceId, nsSet);
159
160 return nsSet;
161 }
162
163 private Set<Set<DeviceId>> filterEdgeRouterOnlyPairings(Set<Set<DeviceId>> sets) {
164 Set<Set<DeviceId>> fiteredSets = new HashSet<Set<DeviceId>>();
165 for (Set<DeviceId> deviceSubSet : sets) {
166 if (deviceSubSet.size() > 1) {
167 boolean avoidEdgeRouterPairing = true;
168 for (DeviceId device : deviceSubSet) {
169 if (!deviceConfig.isEdgeDevice(device)) {
170 avoidEdgeRouterPairing = false;
171 break;
172 }
173 }
174 if (!avoidEdgeRouterPairing) {
175 fiteredSets.add(deviceSubSet);
176 }
177 } else {
178 fiteredSets.add(deviceSubSet);
179 }
180 }
181 return fiteredSets;
182 }
183}