Jonathan Hart

Remove old config classes from routing bundle.

Change-Id: Ifc8ff03674c1cfb9e3cde86b9994b8362744840d
/*
* Copyright 2015-present 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.routing.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import org.onlab.packet.IpAddress;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.NetTools;
import org.onosproject.net.PortNumber;
import java.util.Objects;
/**
* Configuration details for a BGP peer.
*/
public class BgpPeer {
private final ConnectPoint connectPoint;
private final IpAddress ipAddress;
/**
* Creates a new BgpPeer.
*
* @param dpid the DPID of the switch the peer is attached at, as a String
* @param port the port the peer is attached at
* @param ipAddress the IP address of the peer as a String
*/
public BgpPeer(@JsonProperty("attachmentDpid") String dpid,
@JsonProperty("attachmentPort") long port,
@JsonProperty("ipAddress") String ipAddress) {
this.connectPoint = new ConnectPoint(
DeviceId.deviceId(NetTools.dpidToUri(dpid)),
PortNumber.portNumber(port));
this.ipAddress = IpAddress.valueOf(ipAddress);
}
/**
* Gets the connection point of the peer.
*
* @return the connection point
*/
public ConnectPoint connectPoint() {
return connectPoint;
}
/**
* Gets the IP address of the peer.
*
* @return the IP address
*/
public IpAddress ipAddress() {
return ipAddress;
}
@Override
public int hashCode() {
return Objects.hash(connectPoint, ipAddress);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof BgpPeer)) {
return false;
}
BgpPeer that = (BgpPeer) obj;
return Objects.equals(this.connectPoint, that.connectPoint)
&& Objects.equals(this.ipAddress, that.ipAddress);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("connectPoint", connectPoint)
.add("ipAddress", ipAddress)
.toString();
}
}
/*
* Copyright 2015-present 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.routing.config;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import org.onlab.packet.MacAddress;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.NetTools;
import org.onosproject.net.PortNumber;
import java.util.List;
import java.util.Objects;
/**
* Represents a BGP daemon in SDN network.
* <p>
* Each BGP speaker has a attachment point, which includes a switch DPID and a
* switch port. Each BGP speaker has one MAC address and several IP addresses,
* which are used to peer with BGP peers outside the SDN network. For each
* peer outside the SDN network, we configure a different IP address to BGP
* speaker inside the SDN network.
* </p>
* <p>
* Each BGP speaker has a name, which is a unique identifying String that is
* used to reference this speaker in the configuration.
* </p>
*/
public class BgpSpeaker {
private final String name;
private final ConnectPoint connectPoint;
private final MacAddress macAddress;
private List<InterfaceAddress> interfaceAddresses;
/**
* Class constructor used by the JSON library to create an object.
*
* @param name the name of the BGP speaker inside SDN network
* @param attachmentDpid the DPID where the BGP speaker is attached to
* @param attachmentPort the port where the BGP speaker is attached to
* @param macAddress the MAC address of the BGP speaker
*/
@JsonCreator
public BgpSpeaker(@JsonProperty("name") String name,
@JsonProperty("attachmentDpid") String attachmentDpid,
@JsonProperty("attachmentPort") long attachmentPort,
@JsonProperty("macAddress") String macAddress) {
this.name = name;
this.macAddress = MacAddress.valueOf(macAddress);
this.connectPoint = new ConnectPoint(
DeviceId.deviceId(NetTools.dpidToUri(attachmentDpid)),
PortNumber.portNumber(attachmentPort));
}
/**
* Sets the addresses we configured for the BGP speaker on all virtual
* {@link Interface}s.
*
* @param interfaceAddresses a list of IP addresses of the BGP speaker
* configured on all virtual interfaces
*/
@JsonProperty("interfaceAddresses")
public void setInterfaceAddresses(
List<InterfaceAddress> interfaceAddresses) {
this.interfaceAddresses = interfaceAddresses;
}
/**
* Gets the BGP speaker name.
*
* @return the BGP speaker name
*/
public String name() {
return name;
}
/**
* Gets the connect point where the BGP speaker is attached.
*
* @return the connect point
*/
public ConnectPoint connectPoint() {
return connectPoint;
}
/**
* Gets the MAC address of the BGP speaker.
*
* @return the MAC address
*/
public MacAddress macAddress() {
return macAddress;
}
/**
* Gets all IP addresses configured on all {@link Interface}s of the
* BGP speaker.
*
* @return a list of IP addresses of the BGP speaker configured on all
* virtual interfaces
*/
public List<InterfaceAddress> interfaceAddresses() {
return interfaceAddresses;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof BgpSpeaker)) {
return false;
}
BgpSpeaker otherBgpSpeaker = (BgpSpeaker) other;
return name.equals(otherBgpSpeaker.name) &&
connectPoint.equals(
otherBgpSpeaker.connectPoint) &&
macAddress.equals(otherBgpSpeaker.macAddress) &&
interfaceAddresses.equals(otherBgpSpeaker.interfaceAddresses);
}
@Override
public int hashCode() {
return Objects.hash(name, connectPoint, macAddress,
interfaceAddresses);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("speakerName", name)
.add("connectPoint", connectPoint)
.add("macAddress", macAddress)
.add("interfaceAddresses", interfaceAddresses)
.toString();
}
}
/*
* Copyright 2015-present 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.routing.config;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Sets;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.host.InterfaceIpAddress;
import java.util.Objects;
import java.util.Set;
/**
* An Interface is a set of addresses that are logically mapped to a switch
* port in the network.
*/
public class Interface {
private final ConnectPoint connectPoint;
private final Set<InterfaceIpAddress> ipAddresses;
private final MacAddress macAddress;
private final VlanId vlan;
/**
* Creates an Interface based on a connection point, a set of interface
* IP addresses, and a MAC address.
*
* @param connectPoint the connect point this interface is mapped to
* @param ipAddresses the IP addresses for the interface
* @param macAddress the MAC address of the interface
* @param vlan VLAN identifier
*/
public Interface(ConnectPoint connectPoint,
Set<InterfaceIpAddress> ipAddresses,
MacAddress macAddress, VlanId vlan) {
this.connectPoint = connectPoint;
this.ipAddresses = Sets.newHashSet(ipAddresses);
this.macAddress = macAddress;
this.vlan = vlan;
}
/**
* Retrieves the connection point that this interface maps to.
*
* @return the connection point
*/
public ConnectPoint connectPoint() {
return connectPoint;
}
/**
* Retrieves the set of IP addresses that are assigned to the interface.
*
* @return the set of interface IP addresses
*/
public Set<InterfaceIpAddress> ipAddresses() {
return ipAddresses;
}
/**
* Retrieves the MAC address that is assigned to the interface.
*
* @return the MAC address
*/
public MacAddress mac() {
return macAddress;
}
/**
* Retrieves the VLAN ID that is assigned to the interface.
*
* @return the VLAN ID
*/
public VlanId vlan() {
return vlan;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof Interface)) {
return false;
}
Interface otherInterface = (Interface) other;
return connectPoint.equals(otherInterface.connectPoint) &&
ipAddresses.equals(otherInterface.ipAddresses) &&
macAddress.equals(otherInterface.macAddress) &&
vlan.equals(otherInterface.vlan);
}
@Override
public int hashCode() {
return Objects.hash(connectPoint, ipAddresses, macAddress, vlan);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("connectPoint", connectPoint)
.add("ipAddresses", ipAddresses)
.add("macAddress", macAddress)
.add("vlan", vlan)
.toString();
}
}
/*
* Copyright 2015-present 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.routing.config;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import org.onlab.packet.IpAddress;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.NetTools;
import org.onosproject.net.PortNumber;
import java.util.Objects;
/**
* Represents an address of a {@link BgpSpeaker} configured on an
* {@link Interface}.
* <p>
* Each InterfaceAddress includes the interface name and an IP address.
* </p>
*/
public class InterfaceAddress {
private final ConnectPoint connectPoint;
private final IpAddress ipAddress;
/**
* Creates an InterfaceAddress object.
*
* @param dpid the DPID of the interface as a String
* @param port the port of the interface
* @param ipAddress the IP address of a {@link BgpSpeaker} configured on
* the interface
*/
public InterfaceAddress(@JsonProperty("interfaceDpid") String dpid,
@JsonProperty("interfacePort") int port,
@JsonProperty("ipAddress") String ipAddress) {
this.connectPoint = new ConnectPoint(
DeviceId.deviceId(NetTools.dpidToUri(dpid)),
PortNumber.portNumber(port));
this.ipAddress = IpAddress.valueOf(ipAddress);
}
/**
* Gets the connection point of the peer.
*
* @return the connection point
*/
public ConnectPoint connectPoint() {
return connectPoint;
}
/**
* Gets the IP address of a BGP speaker configured on an {@link Interface}.
*
* @return the IP address
*/
public IpAddress ipAddress() {
return ipAddress;
}
@Override
public int hashCode() {
return Objects.hash(connectPoint, ipAddress);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof InterfaceAddress)) {
return false;
}
InterfaceAddress that = (InterfaceAddress) obj;
return Objects.equals(this.connectPoint, that.connectPoint)
&& Objects.equals(this.ipAddress, that.ipAddress);
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("connectPoint", connectPoint)
.add("ipAddress", ipAddress)
.toString();
}
}
/*
* Copyright 2015-present 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.routing.config.impl;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.onlab.packet.MacAddress;
import org.onosproject.routing.config.BgpPeer;
import org.onosproject.routing.config.BgpSpeaker;
import org.onosproject.routing.config.LocalIpPrefixEntry;
import java.util.Collections;
import java.util.List;
/**
* Contains the configuration data for SDN-IP that has been read from a
* JSON-formatted configuration file.
*/
public class Configuration {
// We call the BGP routers in our SDN network the BGP speakers, and call
// the BGP routers outside our SDN network the BGP peers.
private List<BgpSpeaker> bgpSpeakers = Collections.emptyList();
private List<BgpPeer> peers = Collections.emptyList();
private MacAddress virtualGatewayMacAddress;
// All IP prefixes from the configuration are local
private List<LocalIpPrefixEntry> localIp4PrefixEntries =
Collections.emptyList();
private List<LocalIpPrefixEntry> localIp6PrefixEntries =
Collections.emptyList();
/**
* Default constructor.
*/
public Configuration() {
}
/**
* Gets a list of bgpSpeakers in the system, represented by
* {@link BgpSpeaker} objects.
*
* @return the list of BGP speakers
*/
public List<BgpSpeaker> getBgpSpeakers() {
return Collections.unmodifiableList(bgpSpeakers);
}
/**
* Sets a list of bgpSpeakers in the system.
*
* @param bgpSpeakers the list of BGP speakers
*/
@JsonProperty("bgpSpeakers")
public void setBgpSpeakers(List<BgpSpeaker> bgpSpeakers) {
this.bgpSpeakers = bgpSpeakers;
}
/**
* Gets a list of BGP peers we are configured to peer with. Peers are
* represented by {@link BgpPeer} objects.
*
* @return the list of BGP peers
*/
public List<BgpPeer> getPeers() {
return Collections.unmodifiableList(peers);
}
/**
* Sets a list of BGP peers we configured to peer with.
*
* @param peers the list of BGP peers
*/
@JsonProperty("bgpPeers")
public void setPeers(List<BgpPeer> peers) {
this.peers = peers;
}
/**
* Gets the MAC address we configured for virtual gateway
* in SDN network.
*
* @return the MAC address of virtual gateway
*/
public MacAddress getVirtualGatewayMacAddress() {
return virtualGatewayMacAddress;
}
/**
* Sets the MAC address for virtual gateway in SDN network.
*
* @param virtualGatewayMacAddress the MAC address of virtual gateway
*/
@JsonProperty("virtualGatewayMacAddress")
public void setVirtualGatewayMacAddress(MacAddress virtualGatewayMacAddress) {
this.virtualGatewayMacAddress = virtualGatewayMacAddress;
}
/**
* Gets a list of local IPv4 prefix entries configured for local
* SDN network.
* <p>
* IP prefix entries are represented by {@link LocalIpPrefixEntry}
* objects.
* </p>
*
* @return the list of local IPv4 prefix entries
*/
public List<LocalIpPrefixEntry> getLocalIp4PrefixEntries() {
return Collections.unmodifiableList(localIp4PrefixEntries);
}
/**
* Sets a list of IPv4 prefix entries configured for local SDN network.
*
* @param ip4PrefixEntries the list of Ipv4 prefix entries
*/
@JsonProperty("ip4LocalPrefixes")
public void setLocalIp4PrefixEntries(List<LocalIpPrefixEntry> ip4PrefixEntries) {
this.localIp4PrefixEntries = ip4PrefixEntries;
}
/**
* Gets a list of IPv6 prefix entries configured for local SDN network.
* <p>
* IP prefix entries are represented by {@link LocalIpPrefixEntry}
* objects.
* </p>
*
* @return the list of IPv6 prefix entries
*/
public List<LocalIpPrefixEntry> getLocalIp6PrefixEntries() {
return Collections.unmodifiableList(localIp6PrefixEntries);
}
/**
* Sets a list of IPv6 prefix entries configured for local SDN network.
*
* @param ip6PrefixEntries the list of Ipv6 prefix entries
*/
@JsonProperty("ip6LocalPrefixes")
public void setLocalIp6PrefixEntries(List<LocalIpPrefixEntry> ip6PrefixEntries) {
this.localIp6PrefixEntries = ip6PrefixEntries;
}
}
......@@ -58,7 +58,7 @@ import static org.onosproject.routing.RouteEntry.createBinaryString;
/**
* Implementation of RoutingConfigurationService which reads routing
* configuration from a file.
* configuration from the network configuration service.
*/
@Component(immediate = true)
@Service
......
......@@ -15,20 +15,14 @@
*/
package org.onosproject.routing.impl;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.MoreExecutors;
import org.junit.Before;
import org.junit.Test;
import org.onlab.junit.TestUtils;
import org.onlab.junit.TestUtils.TestUtilsException;
import org.onlab.packet.Ethernet;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip4Prefix;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.TestApplicationId;
import org.onosproject.cluster.ClusterServiceAdapter;
import org.onosproject.cluster.ControllerNode;
......@@ -37,7 +31,6 @@ import org.onosproject.cluster.LeadershipServiceAdapter;
import org.onosproject.cluster.NodeId;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreServiceAdapter;
import org.onosproject.incubator.net.intf.Interface;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.PortNumber;
......@@ -45,19 +38,15 @@ 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.host.InterfaceIpAddress;
import org.onosproject.net.intent.AbstractIntentTest;
import org.onosproject.net.intent.Intent;
import org.onosproject.net.intent.IntentService;
import org.onosproject.net.intent.IntentState;
import org.onosproject.net.intent.IntentUtils;
import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.MultiPointToSinglePointIntent;
import org.onosproject.routing.RouteEntry;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
......@@ -66,9 +55,6 @@ import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.reset;
import static org.easymock.EasyMock.verify;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
/**
* This class tests the intent synchronization function in the
......@@ -95,7 +81,7 @@ public class IntentSynchronizerTest extends AbstractIntentTest {
PortNumber.portNumber(1));
private IntentSynchronizer intentSynchronizer;
private final Set<Interface> interfaces = Sets.newHashSet();
private final Set<ConnectPoint> connectPoints = new HashSet<>();
private static final ApplicationId APPID =
TestApplicationId.create("intent-sync-test");
......@@ -107,7 +93,7 @@ public class IntentSynchronizerTest extends AbstractIntentTest {
public void setUp() throws Exception {
super.setUp();
setUpInterfaceService();
setUpConnectPoints();
intentService = createMock(IntentService.class);
......@@ -115,131 +101,58 @@ public class IntentSynchronizerTest extends AbstractIntentTest {
intentSynchronizer.coreService = new TestCoreService();
intentSynchronizer.clusterService = new TestClusterService();
intentSynchronizer.leadershipService = new TestLeadershipService();
intentSynchronizer.leadershipService = new LeadershipServiceAdapter();
intentSynchronizer.intentService = intentService;
intentSynchronizer.activate();
}
/**
* Sets up InterfaceService.
* Sets up connect points.
*/
private void setUpInterfaceService() {
List<InterfaceIpAddress> interfaceIpAddresses1 = Lists.newArrayList();
interfaceIpAddresses1.add(new InterfaceIpAddress(
IpAddress.valueOf("192.168.10.101"),
IpPrefix.valueOf("192.168.10.0/24")));
Interface sw1Eth1 = new Interface(SW1_ETH1,
interfaceIpAddresses1, MacAddress.valueOf("00:00:00:00:00:01"),
VlanId.NONE);
interfaces.add(sw1Eth1);
List<InterfaceIpAddress> interfaceIpAddresses2 = Lists.newArrayList();
interfaceIpAddresses2.add(
new InterfaceIpAddress(IpAddress.valueOf("192.168.20.101"),
IpPrefix.valueOf("192.168.20.0/24")));
Interface sw2Eth1 = new Interface(SW2_ETH1,
interfaceIpAddresses2, MacAddress.valueOf("00:00:00:00:00:02"),
VlanId.NONE);
interfaces.add(sw2Eth1);
List<InterfaceIpAddress> interfaceIpAddresses3 = Lists.newArrayList();
interfaceIpAddresses3.add(
new InterfaceIpAddress(IpAddress.valueOf("192.168.30.101"),
IpPrefix.valueOf("192.168.30.0/24")));
Interface sw3Eth1 = new Interface(SW3_ETH1,
interfaceIpAddresses3, MacAddress.valueOf("00:00:00:00:00:03"),
VlanId.NONE);
interfaces.add(sw3Eth1);
InterfaceIpAddress interfaceIpAddress4 =
new InterfaceIpAddress(IpAddress.valueOf("192.168.40.101"),
IpPrefix.valueOf("192.168.40.0/24"));
Interface sw4Eth1 = new Interface(SW4_ETH1,
Lists.newArrayList(interfaceIpAddress4),
MacAddress.valueOf("00:00:00:00:00:04"),
VlanId.vlanId((short) 1));
interfaces.add(sw4Eth1);
private void setUpConnectPoints() {
connectPoints.add(SW1_ETH1);
connectPoints.add(SW2_ETH1);
connectPoints.add(SW3_ETH1);
connectPoints.add(SW4_ETH1);
}
/**
* Tests the synchronization behavior of intent synchronizer. We set up
* a discrepancy between the intent service state and the intent
* synchronizer's state and ensure that this is reconciled correctly.
*
* @throws TestUtilsException
*/
@Test
public void testIntentSync() throws TestUtilsException {
public void testIntentSync() {
//
// Construct routes and intents.
// This test simulates the following cases during the master change
// time interval:
// 1. RouteEntry1 did not change and the intent also did not change.
// 2. RouteEntry2 was deleted, but the intent was not deleted.
// 3. RouteEntry3 was newly added, and the intent was also submitted.
// 4. RouteEntry4 was updated to RouteEntry4Update, and the intent was
// 1. intent1 did not change and the intent also did not change.
// 2. intent2 was deleted, but the intent was not deleted.
// 3. intent3 was newly added, and the intent was also submitted.
// 4. intent4 was updated to RouteEntry4Update, and the intent was
// also updated to a new one.
// 5. RouteEntry5 did not change, but its intent id changed.
// 6. RouteEntry6 was newly added, but the intent was not submitted.
//
RouteEntry routeEntry1 = new RouteEntry(
Ip4Prefix.valueOf("1.1.1.0/24"),
Ip4Address.valueOf("192.168.10.1"));
RouteEntry routeEntry2 = new RouteEntry(
Ip4Prefix.valueOf("2.2.2.0/24"),
Ip4Address.valueOf("192.168.20.1"));
RouteEntry routeEntry3 = new RouteEntry(
Ip4Prefix.valueOf("3.3.3.0/24"),
Ip4Address.valueOf("192.168.30.1"));
RouteEntry routeEntry4 = new RouteEntry(
Ip4Prefix.valueOf("4.4.4.0/24"),
Ip4Address.valueOf("192.168.30.1"));
RouteEntry routeEntry4Update = new RouteEntry(
Ip4Prefix.valueOf("4.4.4.0/24"),
Ip4Address.valueOf("192.168.20.1"));
RouteEntry routeEntry5 = new RouteEntry(
Ip4Prefix.valueOf("5.5.5.0/24"),
Ip4Address.valueOf("192.168.10.1"));
RouteEntry routeEntry6 = new RouteEntry(
Ip4Prefix.valueOf("6.6.6.0/24"),
Ip4Address.valueOf("192.168.10.1"));
RouteEntry routeEntry7 = new RouteEntry(
Ip4Prefix.valueOf("7.7.7.0/24"),
Ip4Address.valueOf("192.168.10.1"));
// 5. intent5 did not change, but its intent id changed.
// 6. intent6 was newly added, but the intent was not submitted.
MultiPointToSinglePointIntent intent1 = intentBuilder(
routeEntry1.prefix(), "00:00:00:00:00:01", SW1_ETH1);
Ip4Prefix.valueOf("1.1.1.0/24"), "00:00:00:00:00:01", SW1_ETH1);
MultiPointToSinglePointIntent intent2 = intentBuilder(
routeEntry2.prefix(), "00:00:00:00:00:02", SW2_ETH1);
Ip4Prefix.valueOf("2.2.2.0/24"), "00:00:00:00:00:02", SW2_ETH1);
MultiPointToSinglePointIntent intent3 = intentBuilder(
routeEntry3.prefix(), "00:00:00:00:00:03", SW3_ETH1);
Ip4Prefix.valueOf("3.3.3.0/24"), "00:00:00:00:00:03", SW3_ETH1);
MultiPointToSinglePointIntent intent4 = intentBuilder(
routeEntry4.prefix(), "00:00:00:00:00:03", SW3_ETH1);
Ip4Prefix.valueOf("4.4.4.0/24"), "00:00:00:00:00:03", SW3_ETH1);
MultiPointToSinglePointIntent intent4Update = intentBuilder(
routeEntry4Update.prefix(), "00:00:00:00:00:02", SW2_ETH1);
Ip4Prefix.valueOf("4.4.4.0/24"), "00:00:00:00:00:02", SW2_ETH1);
MultiPointToSinglePointIntent intent5 = intentBuilder(
routeEntry5.prefix(), "00:00:00:00:00:01", SW1_ETH1);
Ip4Prefix.valueOf("5.5.5.0/24"), "00:00:00:00:00:01", SW1_ETH1);
MultiPointToSinglePointIntent intent7 = intentBuilder(
routeEntry7.prefix(), "00:00:00:00:00:01", SW1_ETH1);
// Compose a intent, which is equal to intent5 but the id is different.
MultiPointToSinglePointIntent intent5New =
staticIntentBuilder(intent5, routeEntry5, "00:00:00:00:00:01");
assertThat(IntentUtils.intentsAreEqual(intent5, intent5New), is(true));
assertFalse(intent5.equals(intent5New));
Ip4Prefix.valueOf("7.7.7.0/24"), "00:00:00:00:00:01", SW1_ETH1);
MultiPointToSinglePointIntent intent6 = intentBuilder(
routeEntry6.prefix(), "00:00:00:00:00:01", SW1_ETH1);
Ip4Prefix.valueOf("6.6.6.0/24"), "00:00:00:00:00:01", SW1_ETH1);
// Set up expectation
Set<Intent> intents = new HashSet<>();
......@@ -395,13 +308,9 @@ public class IntentSynchronizerTest extends AbstractIntentTest {
DefaultTrafficTreatment.builder();
treatmentBuilder.setEthDst(MacAddress.valueOf(nextHopMacAddress));
Set<ConnectPoint> ingressPoints = new HashSet<>();
for (Interface intf : interfaces) {
if (!intf.connectPoint().equals(egressPoint)) {
ConnectPoint srcPort = intf.connectPoint();
ingressPoints.add(srcPort);
}
}
Set<ConnectPoint> ingressPoints = new HashSet<>(connectPoints);
ingressPoints.remove(egressPoint);
MultiPointToSinglePointIntent intent =
MultiPointToSinglePointIntent.builder()
.appId(APPID)
......@@ -414,29 +323,6 @@ public class IntentSynchronizerTest extends AbstractIntentTest {
return intent;
}
/**
* A static MultiPointToSinglePointIntent builder, the returned intent is
* equal to the input intent except that the id is different.
*
* @param intent the intent to be used for building a new intent
* @param routeEntry the relative routeEntry of the intent
* @return the newly constructed MultiPointToSinglePointIntent
* @throws TestUtilsException
*/
private MultiPointToSinglePointIntent staticIntentBuilder(
MultiPointToSinglePointIntent intent, RouteEntry routeEntry,
String nextHopMacAddress) throws TestUtilsException {
// Use a different egress ConnectPoint with that in intent
// to generate a different id
MultiPointToSinglePointIntent intentNew = intentBuilder(
routeEntry.prefix(), nextHopMacAddress, SW2_ETH1);
TestUtils.setField(intentNew, "egressPoint", intent.egressPoint());
TestUtils.setField(intentNew,
"ingressPoints", intent.ingressPoints());
return intentNew;
}
private class TestIntentSynchronizer extends IntentSynchronizer {
@Override
protected ExecutorService createExecutor() {
......@@ -457,8 +343,4 @@ public class IntentSynchronizerTest extends AbstractIntentTest {
return LOCAL_NODE;
}
}
private class TestLeadershipService extends LeadershipServiceAdapter {
}
}
......
......@@ -18,7 +18,6 @@ package org.onosproject.sdnip;
import com.google.common.collect.Sets;
import org.junit.Before;
import org.junit.Test;
import org.onlab.junit.TestUtils.TestUtilsException;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IPv4;
import org.onlab.packet.IpAddress;
......@@ -47,7 +46,6 @@ import org.onosproject.net.intent.Key;
import org.onosproject.net.intent.PointToPointIntent;
import org.onosproject.routing.IntentSynchronizationService;
import org.onosproject.routing.config.BgpConfig;
import org.onosproject.routing.config.BgpPeer;
import java.util.ArrayList;
import java.util.Collections;
......@@ -82,7 +80,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
private Set<BgpConfig.BgpSpeakerConfig> bgpSpeakers;
private Map<String, Interface> interfaces;
private Map<IpAddress, BgpPeer> peers;
private BgpConfig bgpConfig;
......@@ -135,7 +132,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
// These will set expectations on routingConfig and interfaceService
bgpSpeakers = setUpBgpSpeakers();
interfaces = Collections.unmodifiableMap(setUpInterfaces());
peers = setUpPeers();
initPeerConnectivity();
intentList = setUpIntentList();
......@@ -280,39 +276,6 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
}
/**
* Sets up BGP daemon peers.
*
* @return configured BGP peers as a MAP from peer IP address to BgpPeer
*/
private Map<IpAddress, BgpPeer> setUpPeers() {
Map<IpAddress, BgpPeer> configuredPeers = new HashMap<>();
String peerSw1Eth1 = "192.168.10.1";
configuredPeers.put(IpAddress.valueOf(peerSw1Eth1),
new BgpPeer(dpid1, 1, peerSw1Eth1));
// Two BGP peers are connected to switch 2 port 1.
String peer1Sw2Eth1 = "192.168.20.1";
configuredPeers.put(IpAddress.valueOf(peer1Sw2Eth1),
new BgpPeer(dpid2, 1, peer1Sw2Eth1));
String peer2Sw2Eth1 = "192.168.30.1";
configuredPeers.put(IpAddress.valueOf(peer2Sw2Eth1),
new BgpPeer(dpid2, 1, peer2Sw2Eth1));
String peer3Sw3Eth1 = "192.168.40.1";
configuredPeers.put(IpAddress.valueOf(peer3Sw3Eth1),
new BgpPeer(dpid3, 1, peer3Sw3Eth1));
String peer4Sw3Eth1 = "192.168.50.1";
configuredPeers.put(IpAddress.valueOf(peer4Sw3Eth1),
new BgpPeer(dpid3, 1, peer4Sw3Eth1));
return configuredPeers;
}
/**
* Sets up expected point to point intent list.
*
* @return point to point intent list
......@@ -613,10 +576,8 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
/**
* Initializes peer connectivity testing environment.
*
* @throws TestUtilsException if exceptions when using TestUtils
*/
private void initPeerConnectivity() throws TestUtilsException {
private void initPeerConnectivity() {
expect(bgpConfig.bgpSpeakers()).andReturn(bgpSpeakers).anyTimes();
replay(bgpConfig);
expect(networkConfigService.getConfig(APPID, BgpConfig.class))
......@@ -710,6 +671,7 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
expect(bgpConfig.bgpSpeakers()).andReturn(Collections.emptySet()).anyTimes();
replay(bgpConfig);
// We don't expect any intents in this case
reset(intentSynchronizer);
replay(intentSynchronizer);
peerConnectivityManager.start();
......@@ -722,10 +684,20 @@ public class PeerConnectivityManagerTest extends AbstractIntentTest {
*/
@Test
public void testNoPeerInterface() {
String peerSw100Eth1 = "192.168.200.1";
peers.put(IpAddress.valueOf(peerSw100Eth1),
new BgpPeer("00:00:00:00:00:00:01:00", 1, peerSw100Eth1));
testConnectionSetup();
IpAddress ip = IpAddress.valueOf("1.1.1.1");
bgpSpeakers.clear();
bgpSpeakers.add(new BgpConfig.BgpSpeakerConfig(Optional.of("foo"),
VlanId.NONE, s1Eth100, Collections.singleton(ip)));
reset(interfaceService);
interfaceService.addListener(anyObject(InterfaceListener.class));
expect(interfaceService.getMatchingInterface(ip)).andReturn(null).anyTimes();
replay(interfaceService);
// We don't expect any intents in this case
reset(intentSynchronizer);
replay(intentSynchronizer);
peerConnectivityManager.start();
verify(intentSynchronizer);
}
}
......