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
......
......@@ -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);
}
}
......