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
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.HostId;
import org.onosproject.net.Link;
import org.onosproject.net.flow.DefaultTrafficSelector;
import org.onosproject.net.flow.DefaultTrafficTreatment;
import org.onosproject.net.flow.TrafficSelector;
import org.onosproject.net.flow.TrafficTreatment;
import org.onosproject.net.intent.constraint.LinkTypeConstraint;
import java.util.Collections;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Abstraction of bidirectional connectivity between two points in the network.
*/
public final class TwoWayP2PIntent extends ConnectivityIntent {
private final ConnectPoint one;
private final ConnectPoint two;
/**
* Creates a new host-to-host intent with the supplied host pair and no
* other traffic selection or treatment criteria.
*
* @param appId application identifier
* @param one first host
* @param two second host
* @throws NullPointerException if {@code one} or {@code two} is null.
*/
public TwoWayP2PIntent(ApplicationId appId, ConnectPoint one, ConnectPoint two) {
this(appId, one, two,
DefaultTrafficSelector.builder().build(),
DefaultTrafficTreatment.builder().build(),
ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
}
/**
* Creates a new host-to-host intent with the supplied host pair.
*
* @param appId application identifier
* @param one first host
* @param two second host
* @param selector action
* @param treatment ingress port
* @throws NullPointerException if {@code one} or {@code two} is null.
*/
public TwoWayP2PIntent(ApplicationId appId, ConnectPoint one, ConnectPoint two,
TrafficSelector selector,
TrafficTreatment treatment) {
this(appId, one, two, selector, treatment,
ImmutableList.of(new LinkTypeConstraint(false, Link.Type.OPTICAL)));
}
/**
* Creates a new host-to-host intent with the supplied host pair.
*
* @param appId application identifier
* @param one first host
* @param two second host
* @param selector action
* @param treatment ingress port
* @param constraints optional prioritized list of path selection constraints
* @throws NullPointerException if {@code one} or {@code two} is null.
*/
public TwoWayP2PIntent(ApplicationId appId, ConnectPoint one, ConnectPoint two,
TrafficSelector selector,
TrafficTreatment treatment,
List<Constraint> constraints) {
this(appId, null, one, two, selector, treatment, constraints);
}
/**
* Creates a new host-to-host intent with the supplied host pair.
*
* @param appId application identifier
* @param key intent key
* @param one first host
* @param two second host
* @param selector action
* @param treatment ingress port
* @param constraints optional prioritized list of path selection constraints
* @throws NullPointerException if {@code one} or {@code two} is null.
*/
public TwoWayP2PIntent(ApplicationId appId, Key key,
ConnectPoint one, ConnectPoint two,
TrafficSelector selector,
TrafficTreatment treatment,
List<Constraint> constraints) {
super(appId, key, Collections.emptyList(), selector, treatment, constraints);
// TODO: consider whether the case one and two are same is allowed
this.one = checkNotNull(one);
this.two = checkNotNull(two);
}
private static HostId min(HostId one, HostId two) {
return one.hashCode() < two.hashCode() ? one : two;
}
private static HostId max(HostId one, HostId two) {
return one.hashCode() >= two.hashCode() ? one : two;
}
/**
* Returns identifier of the first host.
*
* @return first host identifier
*/
public ConnectPoint one() {
return one;
}
/**
* Returns identifier of the second host.
*
* @return second host identifier
*/
public ConnectPoint two() {
return two;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("id", id())
.add("key", key())
.add("appId", appId())
.add("resources", resources())
.add("selector", selector())
.add("treatment", treatment())
.add("constraints", constraints())
.add("one", one)
.add("two", two)
.toString();
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.net.intent.impl;
import com.google.common.collect.Lists;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.net.intent.TwoWayP2PIntent;
import org.onosproject.net.resource.LinkResourceAllocations;
import java.util.List;
import java.util.Set;
/**
* A intent compiler for {@link org.onosproject.net.intent.TwoWayP2PIntent}.
*/
@Component(immediate = true)
public class TwoWayP2PIntentCompiler
extends ConnectivityIntentCompiler<TwoWayP2PIntent> {
@Activate
public void activate() {
intentManager.registerCompiler(TwoWayP2PIntent.class, this);
}
@Deactivate
public void deactivate() {
intentManager.unregisterCompiler(TwoWayP2PIntent.class);
}
@Override
public List<Intent> compile(TwoWayP2PIntent intent, List<Intent> installable,
Set<LinkResourceAllocations> resources) {
return Lists.newArrayList(
new PointToPointIntent(intent.appId(), intent.key(),
intent.selector(), intent.treatment(),
intent.one(), intent.two(),
intent.constraints()),
new PointToPointIntent(intent.appId(), intent.key(),
intent.selector(), intent.treatment(),
intent.two(), intent.one(),
intent.constraints()));
}
}