blob: 3a6c33db00b16736865f78da7660399c5a11b368 [file] [log] [blame]
Carolina Fernandezad893432016-07-18 11:11:34 +02001/*
2 * Copyright 2016-present 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 */
16
17package org.onosproject.sdxl2;
18
19
20import org.onlab.packet.VlanId;
21import org.onosproject.core.ApplicationId;
22import org.onosproject.net.EncapsulationType;
23import org.onosproject.net.flow.DefaultTrafficTreatment;
24import org.onosproject.net.flow.TrafficSelector;
25import org.onosproject.net.flow.TrafficTreatment;
26import org.onosproject.net.intent.Constraint;
27import org.onosproject.net.intent.Intent;
28import org.onosproject.net.intent.IntentService;
29import org.onosproject.net.intent.Key;
30import org.onosproject.net.intent.PointToPointIntent;
31import org.onosproject.net.intent.constraint.EncapsulationConstraint;
32import org.slf4j.Logger;
33import org.slf4j.LoggerFactory;
34
35import java.util.ArrayList;
36import java.util.Collection;
37import java.util.Iterator;
38import java.util.LinkedList;
39import java.util.List;
40
41/**
42 * Manages Virtual Circuits using MPLS headers.
43 */
44public class SdxL2MplsVCManager extends SdxL2VCManager {
45
46 private static final int PRIORITY_OFFSET = 2000;
47 private static Logger log = LoggerFactory.getLogger(SdxL2MplsVCManager.class);
48
49 // TODO Remember to create two intents: one for IPv4 and one for IPv6
50
51 /**
52 * Creates an SDX-L2 MPLS VC Manager.
53 *
54 * @param sdxl2id application ID
55 * @param store reference to the SDX-L2 store
56 * @param intentService reference to the Intent service
57 */
58 public SdxL2MplsVCManager(ApplicationId sdxl2id,
59 SdxL2Store store,
60 IntentService intentService) {
61
62 super(sdxl2id, store, intentService);
63 log.info("Started");
64 }
65
66 @Override
67 public Collection<Intent> buildIntents(String sdxl2, SdxL2ConnectionPoint ingress,
68 SdxL2ConnectionPoint egress) {
69 List<Intent> intents = null;
70 TrafficSelector selector;
71 TrafficTreatment treatment;
72 List<Constraint> encapsulation;
73 Key key;
74
75 if (ingress.vlanIds().size() == egress.vlanIds().size()) {
76 intents = new ArrayList<Intent>();
77 if (ingress.vlanIds().size() == 0) {
78
79 selector = buildSelector(null, null);
80 treatment = DefaultTrafficTreatment.emptyTreatment();
81 encapsulation = buildConstraints();
82
83 key = generateIntentKey(sdxl2, ingress, egress, "1");
84
85 intents.add(PointToPointIntent.builder()
86 .appId(appId)
87 .key(key)
88 .selector(selector)
89 .treatment(treatment)
90 .constraints(encapsulation)
91 .ingressPoint(ingress.connectPoint())
92 .egressPoint(egress.connectPoint())
93 .priority(PRIORITY_OFFSET)
94 .build());
95 } else {
96
97 Iterator<VlanId> ingressTags = ingress.vlanIds().iterator();
98 Iterator<VlanId> egressTags = egress.vlanIds().iterator();
99 int index = 1;
100 while (ingressTags.hasNext()) {
101 selector = buildSelector(null, ingressTags.next());
102 treatment = buildTreatment(egressTags.next(),
103 null,
104 false);
105 encapsulation = buildConstraints();
106
107 key = generateIntentKey(sdxl2, ingress, egress, String.valueOf(index));
108
109 intents.add(PointToPointIntent.builder()
110 .appId(appId)
111 .key(key)
112 .selector(selector)
113 .treatment(treatment)
114 .constraints(encapsulation)
115 .ingressPoint(ingress.connectPoint())
116 .egressPoint(egress.connectPoint())
117 .priority(PRIORITY_OFFSET)
118 .build());
119 index = index + 1;
120 }
121
122 }
123 return intents;
124 }
125
126 if (ingress.vlanIds().size() == 1 && egress.vlanIds().size() == 0) {
127
128 Iterator<VlanId> ingressTags = ingress.vlanIds().iterator();
129 intents = new ArrayList<Intent>();
130
131 selector = buildSelector(null, ingressTags.next());
132 treatment = buildTreatment(null,
133 null,
134 true);
135 encapsulation = buildConstraints();
136
137
138 key = generateIntentKey(sdxl2, ingress, egress, "1");
139
140 intents.add(PointToPointIntent.builder()
141 .appId(appId)
142 .key(key)
143 .selector(selector)
144 .treatment(treatment)
145 .constraints(encapsulation)
146 .ingressPoint(ingress.connectPoint())
147 .egressPoint(egress.connectPoint())
148 .priority(PRIORITY_OFFSET)
149 .build());
150 return intents;
151
152 }
153
154 if (ingress.vlanIds().size() == 0 && egress.vlanIds().size() == 1) {
155
156 Iterator<VlanId> egressTags = egress.vlanIds().iterator();
157 intents = new ArrayList<Intent>();
158
159 selector = buildSelector(null, null);
160 treatment = buildTreatment(null,
161 egressTags.next(),
162 false);
163 encapsulation = buildConstraints();
164
165 key = generateIntentKey(sdxl2, ingress, egress, "1");
166
167 intents.add(PointToPointIntent.builder()
168 .appId(appId)
169 .key(key)
170 .selector(selector)
171 .treatment(treatment)
172 .constraints(encapsulation)
173 .ingressPoint(ingress.connectPoint())
174 .egressPoint(egress.connectPoint())
175 .priority(PRIORITY_OFFSET)
176 .build());
177 return intents;
178 }
179
180 log.warn(String.format(errorCreateIntents, ingress.name(), egress.name()));
181
182 return intents;
183 }
184
185 @Override
186 protected List<Constraint> buildConstraints() {
187 final List<Constraint> constraints = new LinkedList<>();
188 constraints.add(new EncapsulationConstraint(EncapsulationType.MPLS));
189 return constraints;
190 }
191
192}