blob: ddf689628b894069ded518b8ec242e49cff81aaa [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 VLANs.
43 */
44public class SdxL2VlanVCManager extends SdxL2VCManager {
45
46 private static final int PRIORITY_OFFSET = 2000;
47 private static Logger log = LoggerFactory.getLogger(SdxL2VlanVCManager.class);
48
49 /**
50 * Creates an SDX-L2 VLAN VC Manager.
51 *
52 * @param sdxl2id application ID
53 * @param store reference to the SDX-L2 store
54 * @param intentService reference to the Intent service
55 */
56 public SdxL2VlanVCManager(ApplicationId sdxl2id,
57 SdxL2Store store,
58 IntentService intentService) {
59 super(sdxl2id, store, intentService);
60 log.info("Started");
61 }
62
63 @Override
64 public Collection<Intent> buildIntents(String sdxl2, SdxL2ConnectionPoint ingress, SdxL2ConnectionPoint egress) {
65 List<Intent> intents = null;
66 TrafficSelector selector;
67 TrafficTreatment treatment;
68 List<Constraint> encapsulation;
69 Key key;
70
71 if (ingress.vlanIds().size() == egress.vlanIds().size()) {
72 intents = new ArrayList<Intent>();
73 if (ingress.vlanIds().size() == 0) {
74
75 selector = buildSelector(null, null);
76 treatment = DefaultTrafficTreatment.emptyTreatment();
77 encapsulation = buildConstraints();
78
79 key = generateIntentKey(sdxl2, ingress, egress, "1");
80
81 intents.add(PointToPointIntent.builder()
82 .appId(appId)
83 .key(key)
84 .selector(selector)
85 .treatment(treatment)
86 .constraints(encapsulation)
87 .ingressPoint(ingress.connectPoint())
88 .egressPoint(egress.connectPoint())
89 .priority(PRIORITY_OFFSET)
90 .build());
91 } else {
92
93 Iterator<VlanId> ingressTags = ingress.vlanIds().iterator();
94 Iterator<VlanId> egressTags = egress.vlanIds().iterator();
95 int index = 1;
96 while (ingressTags.hasNext()) {
97
98 selector = buildSelector(null, ingressTags.next());
99 treatment = buildTreatment(egressTags.next(),
100 null,
101 false);
102 encapsulation = buildConstraints();
103
104 key = generateIntentKey(sdxl2, ingress, egress, String.valueOf(index));
105
106 intents.add(PointToPointIntent.builder()
107 .appId(appId)
108 .key(key)
109 .selector(selector)
110 .treatment(treatment)
111 .constraints(encapsulation)
112 .ingressPoint(ingress.connectPoint())
113 .egressPoint(egress.connectPoint())
114 .priority(PRIORITY_OFFSET)
115 .build());
116 index = index + 1;
117 }
118
119 }
120 return intents;
121 }
122
123 if (ingress.vlanIds().size() == 1 && egress.vlanIds().size() == 0) {
124
125 Iterator<VlanId> ingressTags = ingress.vlanIds().iterator();
126 intents = new ArrayList<Intent>();
127
128 selector = buildSelector(null, ingressTags.next());
129 treatment = buildTreatment(null,
130 null,
131 true);
132 encapsulation = buildConstraints();
133
134
135 key = generateIntentKey(sdxl2, ingress, egress, "1");
136
137 intents.add(PointToPointIntent.builder()
138 .appId(appId)
139 .key(key)
140 .selector(selector)
141 .treatment(treatment)
142 .constraints(encapsulation)
143 .ingressPoint(ingress.connectPoint())
144 .egressPoint(egress.connectPoint())
145 .priority(PRIORITY_OFFSET)
146 .build());
147 return intents;
148
149 }
150
151 if (ingress.vlanIds().size() == 0 && egress.vlanIds().size() == 1) {
152
153 Iterator<VlanId> egressTags = egress.vlanIds().iterator();
154 intents = new ArrayList<Intent>();
155
156 selector = buildSelector(null, null);
157 treatment = buildTreatment(null,
158 egressTags.next(),
159 false);
160 encapsulation = buildConstraints();
161
162 key = generateIntentKey(sdxl2, ingress, egress, "1");
163
164 intents.add(PointToPointIntent.builder()
165 .appId(appId)
166 .key(key)
167 .selector(selector)
168 .treatment(treatment)
169 .constraints(encapsulation)
170 .ingressPoint(ingress.connectPoint())
171 .egressPoint(egress.connectPoint())
172 .priority(PRIORITY_OFFSET)
173 .build());
174 return intents;
175 }
176
177 log.warn(String.format(errorCreateIntents, ingress.name(), egress.name()));
178
179 return intents;
180 }
181
182 @Override
183 protected List<Constraint> buildConstraints() {
184 final List<Constraint> constraints = new LinkedList<>();
185 constraints.add(new EncapsulationConstraint(EncapsulationType.VLAN));
186 return constraints;
187 }
188
189}