Hongtao Yin
Committed by Gerrit Code Review

Updated calendar server code. Added intent for bi-dirctional path. Added latency…

… as one more parameter in constraints.

Added exception catch for parsing parameters.

Fixed Jenkins checking errors.

Use intent key and 2way intent P2P setup.

Change-Id: Ib2bd25deb793b2a34179cbf8794ca5aa3e427f91
1 +/*
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 + */
16 +package org.onosproject.net.intent;
17 +
18 +import com.google.common.base.MoreObjects;
19 +import com.google.common.collect.ImmutableList;
20 +import org.onosproject.core.ApplicationId;
21 +import org.onosproject.net.ConnectPoint;
22 +import org.onosproject.net.HostId;
23 +import org.onosproject.net.Link;
24 +import org.onosproject.net.flow.DefaultTrafficSelector;
25 +import org.onosproject.net.flow.DefaultTrafficTreatment;
26 +import org.onosproject.net.flow.TrafficSelector;
27 +import org.onosproject.net.flow.TrafficTreatment;
28 +import org.onosproject.net.intent.constraint.LinkTypeConstraint;
29 +
30 +import java.util.Collections;
31 +import java.util.List;
32 +
33 +import static com.google.common.base.Preconditions.checkNotNull;
34 +
35 +/**
36 + * Abstraction of bidirectional connectivity between two points in the network.
37 + */
38 +public final class TwoWayP2PIntent extends ConnectivityIntent {
39 +
40 + private final ConnectPoint one;
41 + private final ConnectPoint two;
42 +
43 + /**
44 + * Creates a new host-to-host intent with the supplied host pair and no
45 + * other traffic selection or treatment criteria.
46 + *
47 + * @param appId application identifier
48 + * @param one first host
49 + * @param two second host
50 + * @throws NullPointerException if {@code one} or {@code two} is null.
51 + */
52 + public TwoWayP2PIntent(ApplicationId appId, ConnectPoint one, ConnectPoint two) {
53 + this(appId, one, two,
54 + DefaultTrafficSelector.builder().build(),
55 + DefaultTrafficTreatment.builder().build(),
56 + ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
57 + }
58 +
59 + /**
60 + * Creates a new host-to-host intent with the supplied host pair.
61 + *
62 + * @param appId application identifier
63 + * @param one first host
64 + * @param two second host
65 + * @param selector action
66 + * @param treatment ingress port
67 + * @throws NullPointerException if {@code one} or {@code two} is null.
68 + */
69 + public TwoWayP2PIntent(ApplicationId appId, ConnectPoint one, ConnectPoint two,
70 + TrafficSelector selector,
71 + TrafficTreatment treatment) {
72 + this(appId, one, two, selector, treatment,
73 + ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
74 + }
75 +
76 + /**
77 + * Creates a new host-to-host intent with the supplied host pair.
78 + *
79 + * @param appId application identifier
80 + * @param one first host
81 + * @param two second host
82 + * @param selector action
83 + * @param treatment ingress port
84 + * @param constraints optional prioritized list of path selection constraints
85 + * @throws NullPointerException if {@code one} or {@code two} is null.
86 + */
87 + public TwoWayP2PIntent(ApplicationId appId, ConnectPoint one, ConnectPoint two,
88 + TrafficSelector selector,
89 + TrafficTreatment treatment,
90 + List<Constraint> constraints) {
91 + this(appId, null, one, two, selector, treatment, constraints);
92 + }
93 + /**
94 + * Creates a new host-to-host intent with the supplied host pair.
95 + *
96 + * @param appId application identifier
97 + * @param key intent key
98 + * @param one first host
99 + * @param two second host
100 + * @param selector action
101 + * @param treatment ingress port
102 + * @param constraints optional prioritized list of path selection constraints
103 + * @throws NullPointerException if {@code one} or {@code two} is null.
104 + */
105 + public TwoWayP2PIntent(ApplicationId appId, Key key,
106 + ConnectPoint one, ConnectPoint two,
107 + TrafficSelector selector,
108 + TrafficTreatment treatment,
109 + List<Constraint> constraints) {
110 + super(appId, key, Collections.emptyList(), selector, treatment, constraints);
111 +
112 + // TODO: consider whether the case one and two are same is allowed
113 + this.one = checkNotNull(one);
114 + this.two = checkNotNull(two);
115 +
116 + }
117 +
118 + private static HostId min(HostId one, HostId two) {
119 + return one.hashCode() < two.hashCode() ? one : two;
120 + }
121 +
122 + private static HostId max(HostId one, HostId two) {
123 + return one.hashCode() >= two.hashCode() ? one : two;
124 + }
125 +
126 + /**
127 + * Returns identifier of the first host.
128 + *
129 + * @return first host identifier
130 + */
131 + public ConnectPoint one() {
132 + return one;
133 + }
134 +
135 + /**
136 + * Returns identifier of the second host.
137 + *
138 + * @return second host identifier
139 + */
140 + public ConnectPoint two() {
141 + return two;
142 + }
143 +
144 + @Override
145 + public String toString() {
146 + return MoreObjects.toStringHelper(getClass())
147 + .add("id", id())
148 + .add("key", key())
149 + .add("appId", appId())
150 + .add("resources", resources())
151 + .add("selector", selector())
152 + .add("treatment", treatment())
153 + .add("constraints", constraints())
154 + .add("one", one)
155 + .add("two", two)
156 + .toString();
157 + }
158 +
159 +}
1 +/*
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 + */
16 +package org.onosproject.net.intent.impl;
17 +
18 +import com.google.common.collect.Lists;
19 +import org.apache.felix.scr.annotations.Activate;
20 +import org.apache.felix.scr.annotations.Component;
21 +import org.apache.felix.scr.annotations.Deactivate;
22 +import org.onosproject.net.intent.Intent;
23 +import org.onosproject.net.intent.PointToPointIntent;
24 +import org.onosproject.net.intent.TwoWayP2PIntent;
25 +import org.onosproject.net.resource.LinkResourceAllocations;
26 +
27 +import java.util.List;
28 +import java.util.Set;
29 +
30 +/**
31 + * A intent compiler for {@link org.onosproject.net.intent.TwoWayP2PIntent}.
32 + */
33 +@Component(immediate = true)
34 +public class TwoWayP2PIntentCompiler
35 + extends ConnectivityIntentCompiler<TwoWayP2PIntent> {
36 +
37 + @Activate
38 + public void activate() {
39 + intentManager.registerCompiler(TwoWayP2PIntent.class, this);
40 + }
41 +
42 + @Deactivate
43 + public void deactivate() {
44 + intentManager.unregisterCompiler(TwoWayP2PIntent.class);
45 + }
46 +
47 + @Override
48 + public List<Intent> compile(TwoWayP2PIntent intent, List<Intent> installable,
49 + Set<LinkResourceAllocations> resources) {
50 + return Lists.newArrayList(
51 + new PointToPointIntent(intent.appId(), intent.key(),
52 + intent.selector(), intent.treatment(),
53 + intent.one(), intent.two(),
54 + intent.constraints()),
55 + new PointToPointIntent(intent.appId(), intent.key(),
56 + intent.selector(), intent.treatment(),
57 + intent.two(), intent.one(),
58 + intent.constraints()));
59 +
60 + }
61 +}