Michele Santuari
Committed by Gerrit Code Review

encapsulation constraint related to ONOS-3445

Change-Id: I5f7d912e34c343703108e0cb95c4ea94290663a8
1 +/*
2 + * Copyright 2014-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 + */
16 +
17 +package org.onosproject.net;
18 +
19 +public enum EncapsulationType {
20 + /**
21 + * Indicates an MPLS encapsulation.
22 + */
23 + MPLS,
24 + /**
25 + * Indicates a VLAN encapsulation.
26 + */
27 + VLAN,
28 +};
29 +
30 +
1 +/*
2 + * Copyright 2014-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 + */
16 +
17 +package org.onosproject.net.intent.constraint;
18 +
19 +
20 +import org.onosproject.net.EncapsulationType;
21 +import org.onosproject.net.Link;
22 +import org.onosproject.net.resource.link.LinkResourceService;
23 +
24 +import static com.google.common.base.MoreObjects.toStringHelper;
25 +import static com.google.common.base.Preconditions.checkNotNull;
26 +
27 +/**
28 + * Encapsulation to manage core transportation.
29 + */
30 +public class EncapsulationConstraint extends BooleanConstraint {
31 +
32 + private EncapsulationType encapType;
33 +
34 + /**
35 + * Creates a new encapsulation constraint.
36 + *
37 + * @param encapType the encapsulation type {@link EncapsulationType}
38 + */
39 + public EncapsulationConstraint(EncapsulationType encapType) {
40 + checkNotNull(encapType, "EncapsulationType cannot be null");
41 + this.encapType = encapType;
42 + }
43 +
44 +
45 + @Override
46 + public boolean isValid(Link link, LinkResourceService resourceService) {
47 + //TODO: validate the availability of the resources for each link in the path.
48 + //e.g., availability of MPLSlabels, VLANID
49 +
50 + return true;
51 + }
52 +
53 + /**
54 + * Returns the encapsulation type required by this constraint.
55 + *
56 + * @return encapType
57 + */
58 + public EncapsulationType encapType() {
59 + return encapType;
60 + }
61 +
62 + @Override
63 + public int hashCode() {
64 + return encapType.hashCode();
65 + }
66 +
67 + @Override
68 + public boolean equals(Object obj) {
69 + if (this == obj) {
70 + return true;
71 + }
72 + if (obj == null || getClass() != obj.getClass()) {
73 + return false;
74 + }
75 + final EncapsulationConstraint other = (EncapsulationConstraint) obj;
76 + return this.encapType() == other.encapType();
77 + }
78 +
79 + @Override
80 + public String toString() {
81 + return toStringHelper(this).add("encapType", encapType).toString();
82 + }
83 +}