From 8f92448e4f2f5d9c98036097bdabd1c40166908a Mon Sep 17 00:00:00 2001 From: Ashlee Young Date: Sat, 7 Nov 2015 09:43:53 -0800 Subject: Updated ONOS sources to commit ID 3f28c6803193d493b636dd3c43e08a3e6b35acca Change-Id: I08d1eb7ee31b38491b046933c502894d133b2a2d Signed-off-by: Ashlee Young --- .../org/onosproject/pim/impl/PIMInterface.java | 2 + .../org/onosproject/segmentrouting/ArpHandler.java | 15 +- .../segmentrouting/DefaultRoutingHandler.java | 23 +- .../segmentrouting/DeviceConfiguration.java | 488 --------------------- .../onosproject/segmentrouting/IcmpHandler.java | 10 +- .../org/onosproject/segmentrouting/IpHandler.java | 12 +- .../onosproject/segmentrouting/PolicyHandler.java | 1 + .../segmentrouting/RoutingRulePopulator.java | 79 +++- .../segmentrouting/SegmentRoutingManager.java | 51 ++- .../onosproject/segmentrouting/TunnelHandler.java | 1 + .../config/DeviceConfigNotFoundException.java | 32 ++ .../segmentrouting/config/DeviceConfiguration.java | 454 +++++++++++++++++++ .../segmentrouting/config/DeviceProperties.java | 96 ++++ .../grouphandler/DefaultEdgeGroupHandler.java | 1 + .../grouphandler/DefaultGroupHandler.java | 71 ++- .../grouphandler/DefaultTransitGroupHandler.java | 12 +- .../grouphandler/DeviceProperties.java | 75 ---- .../grouphandler/PolicyGroupHandler.java | 30 +- .../onosproject/vtnweb/web/PortChainCodecTest.java | 95 ++++ .../vtnweb/web/PortPairGroupCodecTest.java | 93 ++++ .../org/onosproject/vtnweb/web/portChain.json | 14 + .../org/onosproject/vtnweb/web/portPairGroup.json | 10 + .../bgpio/types/attr/BgpPrefixAttrIGPFlags.java | 180 -------- .../bgpio/types/attr/BgpPrefixAttrIgpFlags.java | 198 +++++++++ .../test/java/org/onosproject/bgp/AreaIdTest.java | 40 -- .../test/java/org/onosproject/bgp/As4PathTest.java | 56 --- .../test/java/org/onosproject/bgp/AsPathTest.java | 56 --- .../org/onosproject/bgp/AutonomousSystemTest.java | 40 -- .../org/onosproject/bgp/BGPKeepaliveMsgTest.java | 70 --- .../org/onosproject/bgp/BGPLSIdentifierTest.java | 40 -- .../java/org/onosproject/bgp/BGPOpenMsgTest.java | 318 -------------- .../onosproject/bgp/BgpAttrNodeFlagBitTlvTest.java | 51 --- .../org/onosproject/bgp/BgpAttrRouterIdV6Test.java | 50 --- .../onosproject/bgp/BgpLinkAttrIgpMetricTest.java | 44 -- .../bgp/BgpLinkAttrMplsProtocolMaskTest.java | 43 -- .../bgp/BgpLinkAttrProtectionTypeTest.java | 57 --- .../onosproject/bgp/BgpNotificationMsgTest.java | 228 ---------- .../onosproject/bgp/BgpPrefixAttrMetricTest.java | 40 -- .../bgp/BgpPrefixAttrOspfFwdAddrTest.java | 52 --- .../bgp/IPReachabilityInformationTest.java | 41 -- .../java/org/onosproject/bgp/IPv4AddressTest.java | 41 -- .../java/org/onosproject/bgp/IPv6AddressTest.java | 41 -- .../org/onosproject/bgp/IsIsNonPseudonodeTest.java | 40 -- .../org/onosproject/bgp/IsIsPseudonodeTest.java | 40 -- .../bgp/LinkLocalRemoteIdentifiersTest.java | 40 -- .../test/java/org/onosproject/bgp/NextHopTest.java | 41 -- .../test/java/org/onosproject/bgp/OriginTest.java | 40 -- .../org/onosproject/bgp/OspfNonPseudonodeTest.java | 40 -- .../org/onosproject/bgp/OspfPseudonodeTest.java | 43 -- .../org/onosproject/bgp/OspfRouteTypeTest.java | 40 -- .../bgpio/protocol/BGPKeepaliveMsgTest.java | 66 +++ .../onosproject/bgpio/protocol/BGPOpenMsgTest.java | 314 +++++++++++++ .../bgpio/protocol/BgpNotificationMsgTest.java | 224 ++++++++++ .../org/onosproject/bgpio/types/AreaIdTest.java | 77 ++++ .../org/onosproject/bgpio/types/As4PathTest.java | 55 +++ .../org/onosproject/bgpio/types/AsPathTest.java | 55 +++ .../bgpio/types/AutonomousSystemTest.java | 39 ++ .../bgpio/types/BGPLSIdentifierTest.java | 39 ++ .../bgpio/types/IPReachabilityInformationTest.java | 40 ++ .../onosproject/bgpio/types/IPv4AddressTest.java | 40 ++ .../onosproject/bgpio/types/IPv6AddressTest.java | 40 ++ .../bgpio/types/IsIsPseudonodeTest.java | 39 ++ .../types/LinkLocalRemoteIdentifiersTest.java | 39 ++ .../org/onosproject/bgpio/types/NextHopTest.java | 40 ++ .../org/onosproject/bgpio/types/OriginTest.java | 39 ++ .../bgpio/types/OspfPseudonodeTest.java | 42 ++ .../onosproject/bgpio/types/OspfRouteTypeTest.java | 39 ++ .../types/attr/BgpAttrNodeFlagBitTlvTest.java | 50 +++ .../bgpio/types/attr/BgpAttrRouterIdV6Test.java | 49 +++ .../bgpio/types/attr/BgpLinkAttrIgpMetricTest.java | 43 ++ .../attr/BgpLinkAttrMplsProtocolMaskTest.java | 42 ++ .../types/attr/BgpLinkAttrProtectionTypeTest.java | 56 +++ .../types/attr/BgpPrefixAttrIgpFlagsTest.java | 53 +++ .../bgpio/types/attr/BgpPrefixAttrMetricTest.java | 39 ++ .../types/attr/BgpPrefixAttrOspfFwdAddrTest.java | 51 +++ .../org/onosproject/cli/net/GroupsListCommand.java | 4 +- .../net/flow/instructions/Instructions.java | 3 +- .../onosproject/net/newresource/ResourceEvent.java | 54 +++ .../net/newresource/ResourceListener.java | 26 ++ .../net/newresource/ResourceService.java | 3 +- .../onosproject/net/newresource/ResourceStore.java | 3 +- .../net/newresource/ResourceStoreDelegate.java | 24 + .../net/resource/link/BandwidthResource.java | 3 + .../resource/link/BandwidthResourceAllocation.java | 3 + .../resource/link/BandwidthResourceRequest.java | 3 + .../link/DefaultLinkResourceAllocations.java | 3 + .../resource/link/DefaultLinkResourceRequest.java | 3 + .../net/resource/link/LambdaResource.java | 3 + .../resource/link/LambdaResourceAllocation.java | 3 + .../net/resource/link/LambdaResourceRequest.java | 3 + .../net/resource/link/LinkResource.java | 3 + .../net/resource/link/LinkResourceAllocations.java | 3 + .../net/resource/link/LinkResourceEvent.java | 3 + .../net/resource/link/LinkResourceListener.java | 3 + .../net/resource/link/LinkResourceRequest.java | 3 + .../net/resource/link/LinkResourceStore.java | 3 + .../resource/link/LinkResourceStoreDelegate.java | 3 + .../net/resource/link/LinkResources.java | 6 + .../onosproject/net/resource/link/MplsLabel.java | 3 + .../resource/link/MplsLabelResourceAllocation.java | 3 + .../resource/link/MplsLabelResourceRequest.java | 3 + .../net/resource/link/package-info.java | 6 + .../org/onosproject/net/resource/package-info.java | 4 + .../store/trivial/SimpleLinkResourceStore.java | 3 + .../net/intent/impl/ObjectiveTracker.java | 55 +-- .../net/newresource/impl/ResourceManager.java | 30 +- .../net/intent/impl/ObjectiveTrackerTest.java | 19 +- .../intent/impl/compiler/MockResourceService.java | 7 + .../cluster/impl/StaticClusterMetadataStore.java | 24 +- .../newresource/impl/ConsistentResourceStore.java | 30 +- .../resource/impl/ConsistentLinkResourceStore.java | 3 + .../driver/extensions/NiciraSetTunnelDst.java | 2 + .../driver/pipeline/CpqdOFDPA2Pipeline.java | 23 +- .../driver/pipeline/OFDPA2Pipeline.java | 341 +++++++++++--- .../incubator/net/intf/package-info.java | 20 - .../openflow/controller/impl/Controller.java | 2 +- .../openflow/controller/impl/OFChannelHandler.java | 5 +- .../controller/impl/OpenFlowControllerImpl.java | 8 +- .../openflow/controller/impl/RoleManager.java | 15 +- .../org/onosproject/openflow/DriverAdapter.java | 104 +++++ .../onosproject/openflow/DriverServiceAdapter.java | 59 +++ .../openflow/OFDescStatsReplyAdapter.java | 97 ++++ .../openflow/OpenflowSwitchDriverAdapter.java | 299 +++++++++++++ .../openflow/controller/impl/ControllerTest.java | 219 +++++++++ .../openflow/controller/impl/RoleManagerTest.java | 223 +--------- .../ovsdb/controller/OvsdbClientService.java | 26 +- .../onosproject/ovsdb/controller/OvsdbNodeId.java | 2 +- .../provider/of/flow/impl/FlowModBuilder.java | 2 + .../provider/of/flow/impl/FlowModBuilderVer10.java | 1 + .../provider/of/flow/impl/FlowModBuilderVer13.java | 1 + .../src/main/java/org/onlab/junit/TestTools.java | 17 + .../controller/impl/ControllerTestKeystore.jks | Bin 0 -> 1295 bytes 132 files changed, 4304 insertions(+), 2805 deletions(-) delete mode 100644 framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java create mode 100644 framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfigNotFoundException.java create mode 100644 framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java create mode 100644 framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceProperties.java delete mode 100644 framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DeviceProperties.java create mode 100644 framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortChainCodecTest.java create mode 100644 framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairGroupCodecTest.java create mode 100644 framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portChain.json create mode 100644 framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portPairGroup.json delete mode 100755 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIGPFlags.java create mode 100755 framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/AreaIdTest.java delete mode 100755 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/As4PathTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/AsPathTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/AutonomousSystemTest.java delete mode 100755 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BGPKeepaliveMsgTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BGPLSIdentifierTest.java delete mode 100755 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BGPOpenMsgTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpAttrNodeFlagBitTlvTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpAttrRouterIdV6Test.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrIgpMetricTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMplsProtocolMaskTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrProtectionTypeTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpNotificationMsgTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrMetricTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrOspfFwdAddrTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IPReachabilityInformationTest.java delete mode 100755 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IPv4AddressTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IPv6AddressTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IsIsNonPseudonodeTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IsIsPseudonodeTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/LinkLocalRemoteIdentifiersTest.java delete mode 100755 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/NextHopTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OriginTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OspfNonPseudonodeTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OspfPseudonodeTest.java delete mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OspfRouteTypeTest.java create mode 100755 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPKeepaliveMsgTest.java create mode 100755 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPOpenMsgTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpNotificationMsgTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AreaIdTest.java create mode 100755 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/As4PathTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AsPathTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AutonomousSystemTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BGPLSIdentifierTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPReachabilityInformationTest.java create mode 100755 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPv4AddressTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPv6AddressTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTest.java create mode 100755 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/NextHopTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OriginTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OspfPseudonodeTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OspfRouteTypeTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlvTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6Test.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIgpMetricTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMaskTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrProtectionTypeTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlagsTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetricTest.java create mode 100644 framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOspfFwdAddrTest.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceEvent.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceListener.java create mode 100644 framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStoreDelegate.java delete mode 100644 framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/intf/package-info.java create mode 100644 framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/DriverAdapter.java create mode 100644 framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/DriverServiceAdapter.java create mode 100644 framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/OFDescStatsReplyAdapter.java create mode 100644 framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/OpenflowSwitchDriverAdapter.java create mode 100644 framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/controller/impl/ControllerTest.java create mode 100644 framework/src/onos/utils/junit/src/main/resources/org/onosproject/openflow/controller/impl/ControllerTestKeystore.jks (limited to 'framework') diff --git a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterface.java b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterface.java index 28d1e8ba..5da5c2b3 100644 --- a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterface.java +++ b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterface.java @@ -65,6 +65,8 @@ public class PIMInterface { /** * Create a PIMInterface. + * + * @param intf the network interface configuration */ public PIMInterface(Interface intf) { diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java index 36563f01..96c85ba8 100644 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/ArpHandler.java @@ -31,6 +31,8 @@ import org.onosproject.net.packet.DefaultOutboundPacket; import org.onosproject.net.packet.InboundPacket; import org.onosproject.net.HostId; import org.onosproject.net.packet.OutboundPacket; +import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; +import org.onosproject.segmentrouting.config.DeviceConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -140,9 +142,16 @@ public class ArpHandler { * @param inPort in-port */ public void sendArpRequest(DeviceId deviceId, IpAddress targetAddress, ConnectPoint inPort) { - - byte[] senderMacAddress = config.getDeviceMac(deviceId).toBytes(); - byte[] senderIpAddress = config.getRouterIp(deviceId).toOctets(); + byte[] senderMacAddress; + byte[] senderIpAddress; + + try { + senderMacAddress = config.getDeviceMac(deviceId).toBytes(); + senderIpAddress = config.getRouterIp(deviceId).toOctets(); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting sendArpRequest."); + return; + } ARP arpRequest = new ARP(); arpRequest.setHardwareType(ARP.HW_TYPE_ETHERNET) diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java index c4a91c75..a737339f 100644 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DefaultRoutingHandler.java @@ -23,6 +23,8 @@ import org.onlab.packet.IpPrefix; import org.onosproject.net.Device; import org.onosproject.net.DeviceId; import org.onosproject.net.Link; +import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; +import org.onosproject.segmentrouting.config.DeviceConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -449,7 +451,20 @@ public class DefaultRoutingHandler { // If both target switch and dest switch are edge routers, then set IP // rule for both subnet and router IP. - if (config.isEdgeDevice(targetSw) && config.isEdgeDevice(destSw)) { + boolean targetIsEdge; + boolean destIsEdge; + Ip4Address destRouterIp; + + try { + targetIsEdge = config.isEdgeDevice(targetSw); + destIsEdge = config.isEdgeDevice(destSw); + destRouterIp = config.getRouterIp(destSw); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting populateEcmpRoutingRulePartial."); + return false; + } + + if (targetIsEdge && destIsEdge) { Set subnets = config.getSubnets(destSw); log.debug("* populateEcmpRoutingRulePartial in device {} towards {} for subnets {}", targetSw, destSw, subnets); @@ -461,7 +476,7 @@ public class DefaultRoutingHandler { return false; } - Ip4Address routerIp = config.getRouterIp(destSw); + Ip4Address routerIp = destRouterIp; IpPrefix routerIpPrefix = IpPrefix.valueOf(routerIp, IpPrefix.MAX_INET_MASK_LENGTH); log.debug("* populateEcmpRoutingRulePartial in device {} towards {} for router IP {}", targetSw, destSw, routerIpPrefix); @@ -471,8 +486,8 @@ public class DefaultRoutingHandler { } // If the target switch is an edge router, then set IP rules for the router IP. - } else if (config.isEdgeDevice(targetSw)) { - Ip4Address routerIp = config.getRouterIp(destSw); + } else if (targetIsEdge) { + Ip4Address routerIp = destRouterIp; IpPrefix routerIpPrefix = IpPrefix.valueOf(routerIp, IpPrefix.MAX_INET_MASK_LENGTH); log.debug("* populateEcmpRoutingRulePartial in device {} towards {} for router IP {}", targetSw, destSw, routerIpPrefix); diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java deleted file mode 100644 index 828c51ce..00000000 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DeviceConfiguration.java +++ /dev/null @@ -1,488 +0,0 @@ -/* - * Copyright 2014-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.segmentrouting; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; -import org.onlab.packet.Ip4Address; -import org.onlab.packet.Ip4Prefix; -import org.onlab.packet.MacAddress; -import org.onosproject.incubator.net.config.basics.ConfigException; -import org.onosproject.incubator.net.config.basics.InterfaceConfig; -import org.onosproject.incubator.net.intf.Interface; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.config.NetworkConfigRegistry; -import org.onosproject.net.host.InterfaceIpAddress; -import org.onosproject.segmentrouting.config.SegmentRoutingConfig; -import org.onosproject.segmentrouting.config.SegmentRoutingConfig.AdjacencySid; -import org.onosproject.segmentrouting.grouphandler.DeviceProperties; -import org.onosproject.net.DeviceId; -import org.onosproject.net.PortNumber; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -/** - * Segment Routing configuration component that reads the - * segment routing related configuration from Network Configuration Manager - * component and organizes in more accessible formats. - */ -public class DeviceConfiguration implements DeviceProperties { - - private static final Logger log = LoggerFactory - .getLogger(DeviceConfiguration.class); - private final List allSegmentIds = new ArrayList<>(); - private final ConcurrentHashMap deviceConfigMap - = new ConcurrentHashMap<>(); - - private class SegmentRouterInfo { - int nodeSid; - DeviceId deviceId; - Ip4Address ip; - MacAddress mac; - boolean isEdge; - HashMap gatewayIps; - HashMap subnets; - List adjacencySids; - - public SegmentRouterInfo() { - this.gatewayIps = new HashMap<>(); - this.subnets = new HashMap<>(); - } - } - - /** - * Constructor. Reads all the configuration for all devices of type - * Segment Router and organizes into various maps for easier access. - * - * @param cfgService config service - */ - public DeviceConfiguration(NetworkConfigRegistry cfgService) { - // Read config from device subject, excluding gatewayIps and subnets. - Set deviceSubjects = - cfgService.getSubjects(DeviceId.class, SegmentRoutingConfig.class); - deviceSubjects.forEach(subject -> { - SegmentRoutingConfig config = - cfgService.getConfig(subject, SegmentRoutingConfig.class); - SegmentRouterInfo info = new SegmentRouterInfo(); - info.deviceId = subject; - info.nodeSid = config.getSid(); - info.ip = config.getIp(); - info.mac = config.getMac(); - info.isEdge = config.isEdgeRouter(); - info.adjacencySids = config.getAdjacencySids(); - - this.deviceConfigMap.put(info.deviceId, info); - this.allSegmentIds.add(info.nodeSid); - }); - - // Read gatewayIps and subnets from port subject. - Set portSubjects = - cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class); - portSubjects.forEach(subject -> { - InterfaceConfig config = - cfgService.getConfig(subject, InterfaceConfig.class); - Set networkInterfaces; - try { - networkInterfaces = config.getInterfaces(); - } catch (ConfigException e) { - log.error("Error loading port configuration"); - return; - } - networkInterfaces.forEach(networkInterface -> { - DeviceId dpid = networkInterface.connectPoint().deviceId(); - PortNumber port = networkInterface.connectPoint().port(); - SegmentRouterInfo info = this.deviceConfigMap.get(dpid); - - // skip if there is no corresponding device for this ConenctPoint - if (info != null) { - Set interfaceAddresses = networkInterface.ipAddresses(); - interfaceAddresses.forEach(interfaceAddress -> { - info.gatewayIps.put(port, interfaceAddress.ipAddress().getIp4Address()); - info.subnets.put(port, interfaceAddress.subnetAddress().getIp4Prefix()); - }); - } - }); - - }); - } - - /** - * Returns the Node segment id of a segment router. - * - * @param deviceId device identifier - * @return segment id - */ - @Override - public int getSegmentId(DeviceId deviceId) { - SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); - if (srinfo != null) { - log.trace("getSegmentId for device{} is {}", deviceId, srinfo.nodeSid); - return srinfo.nodeSid; - } else { - log.warn("getSegmentId for device {} " - + "throwing IllegalStateException " - + "because device does not exist in config", deviceId); - throw new IllegalStateException(); - } - } - - /** - * Returns the Node segment id of a segment router given its Router mac address. - * - * @param routerMac router mac address - * @return node segment id, or -1 if not found in config - */ - public int getSegmentId(MacAddress routerMac) { - for (Map.Entry entry: - deviceConfigMap.entrySet()) { - if (entry.getValue().mac.equals(routerMac)) { - return entry.getValue().nodeSid; - } - } - - return -1; - } - - /** - * Returns the Node segment id of a segment router given its Router ip address. - * - * @param routerAddress router ip address - * @return node segment id, or -1 if not found in config - */ - public int getSegmentId(Ip4Address routerAddress) { - for (Map.Entry entry: - deviceConfigMap.entrySet()) { - if (entry.getValue().ip.equals(routerAddress)) { - return entry.getValue().nodeSid; - } - } - - return -1; - } - - /** - * Returns the router mac of a segment router. - * - * @param deviceId device identifier - * @return router mac address - */ - @Override - public MacAddress getDeviceMac(DeviceId deviceId) { - SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); - if (srinfo != null) { - log.trace("getDeviceMac for device{} is {}", deviceId, srinfo.mac); - return srinfo.mac; - } else { - log.warn("getDeviceMac for device {} " - + "throwing IllegalStateException " - + "because device does not exist in config", deviceId); - throw new IllegalStateException(); - } - } - - /** - * Returns the router ip address of a segment router. - * - * @param deviceId device identifier - * @return router ip address - */ - public Ip4Address getRouterIp(DeviceId deviceId) { - SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); - if (srinfo != null) { - log.trace("getDeviceIp for device{} is {}", deviceId, srinfo.ip); - return srinfo.ip; - } else { - log.warn("getRouterIp for device {} " - + "throwing IllegalStateException " - + "because device does not exist in config", deviceId); - throw new IllegalStateException(); - } - } - - /** - * Indicates if the segment router is a edge router or - * a core/backbone router. - * - * @param deviceId device identifier - * @return boolean - */ - @Override - public boolean isEdgeDevice(DeviceId deviceId) { - SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); - if (srinfo != null) { - log.trace("isEdgeDevice for device{} is {}", deviceId, srinfo.isEdge); - return srinfo.isEdge; - } else { - log.warn("isEdgeDevice for device {} " - + "throwing IllegalStateException " - + "because device does not exist in config", deviceId); - throw new IllegalStateException(); - } - } - - /** - * Returns the node segment ids of all configured segment routers. - * - * @return list of node segment ids - */ - @Override - public List getAllDeviceSegmentIds() { - return allSegmentIds; - } - - @Override - public Map> getSubnetPortsMap(DeviceId deviceId) { - Map> subnetPortMap = new HashMap<>(); - - // Construct subnet-port mapping from port-subnet mapping - Map portSubnetMap = - this.deviceConfigMap.get(deviceId).subnets; - portSubnetMap.forEach((port, subnet) -> { - if (subnetPortMap.containsKey(subnet)) { - subnetPortMap.get(subnet).add(port); - } else { - ArrayList ports = new ArrayList<>(); - ports.add(port); - subnetPortMap.put(subnet, ports); - } - }); - - return subnetPortMap; - } - - /** - * Returns the device identifier or data plane identifier (dpid) - * of a segment router given its segment id. - * - * @param sid segment id - * @return deviceId device identifier - */ - public DeviceId getDeviceId(int sid) { - for (Map.Entry entry: - deviceConfigMap.entrySet()) { - if (entry.getValue().nodeSid == sid) { - return entry.getValue().deviceId; - } - } - - return null; - } - - /** - * Returns the device identifier or data plane identifier (dpid) - * of a segment router given its router ip address. - * - * @param ipAddress router ip address - * @return deviceId device identifier - */ - public DeviceId getDeviceId(Ip4Address ipAddress) { - for (Map.Entry entry: - deviceConfigMap.entrySet()) { - if (entry.getValue().ip.equals(ipAddress)) { - return entry.getValue().deviceId; - } - } - - return null; - } - - /** - * Returns the configured port ip addresses for a segment router. - * These addresses serve as gateway IP addresses for the subnets configured - * on those ports. - * - * @param deviceId device identifier - * @return immutable set of ip addresses configured on the ports or null if not found - */ - public Set getPortIPs(DeviceId deviceId) { - SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); - if (srinfo != null) { - log.trace("getSubnetGatewayIps for device{} is {}", deviceId, - srinfo.gatewayIps.values()); - return ImmutableSet.copyOf(srinfo.gatewayIps.values()); - } - return null; - } - - /** - * Returns the configured IP addresses per port - * for a segment router. - * - * @param deviceId device identifier - * @return map of port to gateway IP addresses or null if not found - */ - public Map getPortIPMap(DeviceId deviceId) { - SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); - if (srinfo != null) { - return srinfo.gatewayIps; - } - return null; - } - - /** - * Returns the configured subnet prefixes for a segment router. - * - * @param deviceId device identifier - * @return list of ip prefixes or null if not found - */ - public Set getSubnets(DeviceId deviceId) { - SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); - if (srinfo != null) { - log.trace("getSubnets for device{} is {}", deviceId, - srinfo.subnets.values()); - return ImmutableSet.copyOf(srinfo.subnets.values()); - } - return null; - } - - /** - * Returns the configured subnet on the given port, or null if no - * subnet has been configured on the port. - * - * @param deviceId device identifier - * @param pnum port identifier - * @return configured subnet on port, or null - */ - public Ip4Prefix getPortSubnet(DeviceId deviceId, PortNumber pnum) { - SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); - if (srinfo != null) { - return srinfo.subnets.get(pnum); - } - return null; - } - - /** - * Returns the router ip address of segment router that has the - * specified ip address in its subnets. - * - * @param destIpAddress target ip address - * @return router ip address - */ - public Ip4Address getRouterIpAddressForASubnetHost(Ip4Address destIpAddress) { - for (Map.Entry entry: - deviceConfigMap.entrySet()) { - for (Ip4Prefix prefix:entry.getValue().subnets.values()) { - if (prefix.contains(destIpAddress)) { - return entry.getValue().ip; - } - } - } - - log.debug("No router was found for {}", destIpAddress); - return null; - } - - /** - * Returns the router mac address of segment router that has the - * specified ip address as one of its subnet gateway ip address. - * - * @param gatewayIpAddress router gateway ip address - * @return router mac address or null if not found - */ - public MacAddress getRouterMacForAGatewayIp(Ip4Address gatewayIpAddress) { - for (Map.Entry entry: - deviceConfigMap.entrySet()) { - if (entry.getValue().gatewayIps. - values().contains(gatewayIpAddress)) { - return entry.getValue().mac; - } - } - - log.debug("Cannot find a router for {}", gatewayIpAddress); - return null; - } - - - /** - * Checks if the host is in the subnet defined in the router with the - * device ID given. - * - * @param deviceId device identification of the router - * @param hostIp host IP address to check - * @return true if the host is within the subnet of the router, - * false if no subnet is defined under the router or if the host is not - * within the subnet defined in the router - */ - public boolean inSameSubnet(DeviceId deviceId, Ip4Address hostIp) { - - Set subnets = getSubnets(deviceId); - if (subnets == null) { - return false; - } - - for (Ip4Prefix subnet: subnets) { - if (subnet.contains(hostIp)) { - return true; - } - } - - return false; - } - - /** - * Returns the ports corresponding to the adjacency Sid given. - * - * @param deviceId device identification of the router - * @param sid adjacency Sid - * @return list of port numbers - */ - public List getPortsForAdjacencySid(DeviceId deviceId, int sid) { - SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); - if (srinfo != null) { - for (AdjacencySid asid : srinfo.adjacencySids) { - if (asid.getAsid() == sid) { - return asid.getPorts(); - } - } - } - - return Lists.newArrayList(); - } - - /** - * Check if the Sid given is whether adjacency Sid of the router device or not. - * - * @param deviceId device identification of the router - * @param sid Sid to check - * @return true if the Sid given is the adjacency Sid of the device, - * otherwise false - */ - public boolean isAdjacencySid(DeviceId deviceId, int sid) { - SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); - if (srinfo != null) { - if (srinfo.adjacencySids.isEmpty()) { - return false; - } else { - for (AdjacencySid asid: - srinfo.adjacencySids) { - if (asid.getAsid() == sid) { - return true; - } - } - return false; - } - } - - return false; - } -} \ No newline at end of file diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java index b3916b06..c4267ebb 100644 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IcmpHandler.java @@ -28,6 +28,8 @@ import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.packet.DefaultOutboundPacket; import org.onosproject.net.packet.InboundPacket; import org.onosproject.net.packet.OutboundPacket; +import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; +import org.onosproject.segmentrouting.config.DeviceConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -71,7 +73,13 @@ public class IcmpHandler { Ip4Address destinationAddress = Ip4Address.valueOf(ipv4.getDestinationAddress()); Set gatewayIpAddresses = config.getPortIPs(deviceId); - Ip4Address routerIp = config.getRouterIp(deviceId); + Ip4Address routerIp; + try { + routerIp = config.getRouterIp(deviceId); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting processPacketIn."); + return; + } IpPrefix routerIpPrefix = IpPrefix.valueOf(routerIp, IpPrefix.MAX_INET_MASK_LENGTH); Ip4Address routerIpAddress = routerIpPrefix.getIp4Prefix().address(); diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IpHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IpHandler.java index 14ce679b..b1682e77 100644 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IpHandler.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/IpHandler.java @@ -26,6 +26,8 @@ import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.packet.DefaultOutboundPacket; import org.onosproject.net.packet.InboundPacket; import org.onosproject.net.packet.OutboundPacket; +import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; +import org.onosproject.segmentrouting.config.DeviceConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -127,13 +129,19 @@ public class IpHandler { for (IPv4 ipPacket : ipPacketQueue.get(destIpAddress)) { Ip4Address destAddress = Ip4Address.valueOf(ipPacket.getDestinationAddress()); - if (ipPacket != null && config.inSameSubnet(deviceId, destAddress)) { + if (config.inSameSubnet(deviceId, destAddress)) { ipPacket.setTtl((byte) (ipPacket.getTtl() - 1)); ipPacket.setChecksum((short) 0); for (Host dest: srManager.hostService.getHostsByIp(destIpAddress)) { Ethernet eth = new Ethernet(); eth.setDestinationMACAddress(dest.mac()); - eth.setSourceMACAddress(config.getDeviceMac(deviceId)); + try { + eth.setSourceMACAddress(config.getDeviceMac(deviceId)); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + + " Skipping forwardPackets for this destination."); + continue; + } eth.setEtherType(Ethernet.TYPE_IPV4); eth.setPayload(ipPacket); diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/PolicyHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/PolicyHandler.java index 83cb7e86..0a4c26d9 100644 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/PolicyHandler.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/PolicyHandler.java @@ -27,6 +27,7 @@ import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flowobjective.DefaultForwardingObjective; import org.onosproject.net.flowobjective.FlowObjectiveService; import org.onosproject.net.flowobjective.ForwardingObjective; +import org.onosproject.segmentrouting.config.DeviceConfiguration; import org.onosproject.store.service.EventuallyConsistentMap; import org.slf4j.Logger; diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java index d46028e7..f8274038 100644 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/RoutingRulePopulator.java @@ -22,6 +22,8 @@ import org.onlab.packet.IpPrefix; import org.onlab.packet.MacAddress; import org.onlab.packet.MplsLabel; import org.onlab.packet.VlanId; +import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; +import org.onosproject.segmentrouting.config.DeviceConfiguration; import org.onosproject.segmentrouting.grouphandler.NeighborSet; import org.onosproject.net.DeviceId; import org.onosproject.net.Link; @@ -103,6 +105,14 @@ public class RoutingRulePopulator { */ public void populateIpRuleForHost(DeviceId deviceId, Ip4Address hostIp, MacAddress hostMac, PortNumber outPort) { + MacAddress deviceMac; + try { + deviceMac = config.getDeviceMac(deviceId); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting populateIpRuleForHost."); + return; + } + TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); @@ -111,7 +121,7 @@ public class RoutingRulePopulator { tbuilder.deferred() .setEthDst(hostMac) - .setEthSrc(config.getDeviceMac(deviceId)) + .setEthSrc(deviceMac) .setOutput(outPort); TrafficTreatment treatment = tbuilder.build(); @@ -167,6 +177,13 @@ public class RoutingRulePopulator { public boolean populateIpRuleForRouter(DeviceId deviceId, IpPrefix ipPrefix, DeviceId destSw, Set nextHops) { + int segmentId; + try { + segmentId = config.getSegmentId(destSw); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting populateIpRuleForRouter."); + return false; + } TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); @@ -183,7 +200,7 @@ public class RoutingRulePopulator { ns = new NeighborSet(nextHops); } else { tbuilder.deferred().copyTtlOut(); - ns = new NeighborSet(nextHops, config.getSegmentId(destSw)); + ns = new NeighborSet(nextHops, segmentId); } TrafficTreatment treatment = tbuilder.build(); @@ -227,19 +244,26 @@ public class RoutingRulePopulator { */ public boolean populateMplsRule(DeviceId deviceId, DeviceId destSwId, Set nextHops) { + int segmentId; + try { + segmentId = config.getSegmentId(destSwId); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting populateMplsRule."); + return false; + } TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); List fwdObjBuilders = new ArrayList<>(); // TODO Handle the case of Bos == false - sbuilder.matchMplsLabel(MplsLabel.mplsLabel(config.getSegmentId(destSwId))); + sbuilder.matchMplsLabel(MplsLabel.mplsLabel(segmentId)); sbuilder.matchEthType(Ethernet.MPLS_UNICAST); // If the next hop is the destination router, do PHP if (nextHops.size() == 1 && destSwId.equals(nextHops.toArray()[0])) { log.debug("populateMplsRule: Installing MPLS forwarding objective for " + "label {} in switch {} with PHP", - config.getSegmentId(destSwId), + segmentId, deviceId); ForwardingObjective.Builder fwdObjBosBuilder = @@ -264,7 +288,7 @@ public class RoutingRulePopulator { } else { log.debug("Installing MPLS forwarding objective for " + "label {} in switch {} without PHP", - config.getSegmentId(destSwId), + segmentId, deviceId); ForwardingObjective.Builder fwdObjBosBuilder = @@ -310,9 +334,21 @@ public class RoutingRulePopulator { Set nextHops, boolean phpRequired, boolean isBos) { - ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective .builder().withFlag(ForwardingObjective.Flag.SPECIFIC); + DeviceId nextHop = (DeviceId) nextHops.toArray()[0]; + + boolean isEdge; + MacAddress srcMac; + MacAddress dstMac; + try { + isEdge = config.isEdgeDevice(deviceId); + srcMac = config.getDeviceMac(deviceId); + dstMac = config.getDeviceMac(nextHop); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting getMplsForwardingObjective"); + return null; + } TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); @@ -329,16 +365,15 @@ public class RoutingRulePopulator { tbuilder.deferred().decMplsTtl(); } - if (!isECMPSupportedInTransitRouter() && !config.isEdgeDevice(deviceId)) { + if (!isECMPSupportedInTransitRouter() && !isEdge) { PortNumber port = selectOnePort(deviceId, nextHops); - DeviceId nextHop = (DeviceId) nextHops.toArray()[0]; if (port == null) { log.warn("No link from {} to {}", deviceId, nextHops); return null; } tbuilder.deferred() - .setEthSrc(config.getDeviceMac(deviceId)) - .setEthDst(config.getDeviceMac(nextHop)) + .setEthSrc(srcMac) + .setEthDst(dstMac) .setOutput(port); fwdBuilder.withTreatment(tbuilder.build()); } else { @@ -372,15 +407,27 @@ public class RoutingRulePopulator { public void populateRouterMacVlanFilters(DeviceId deviceId) { log.debug("Installing per-port filtering objective for untagged " + "packets in device {}", deviceId); + + MacAddress deviceMac; + try { + deviceMac = config.getDeviceMac(deviceId); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting populateRouterMacVlanFilters."); + return; + } + for (Port port : srManager.deviceService.getPorts(deviceId)) { if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { Ip4Prefix portSubnet = config.getPortSubnet(deviceId, port.number()); VlanId assignedVlan = (portSubnet == null) ? VlanId.vlanId(SegmentRoutingManager.ASSIGNED_VLAN_NO_SUBNET) : srManager.getSubnetAssignedVlanId(deviceId, portSubnet); + + + FilteringObjective.Builder fob = DefaultFilteringObjective.builder(); fob.withKey(Criteria.matchInPort(port.number())) - .addCondition(Criteria.matchEthDst(config.getDeviceMac(deviceId))) + .addCondition(Criteria.matchEthDst(deviceMac)) .addCondition(Criteria.matchVlanId(VlanId.NONE)); // vlan assignment is valid only if this instance is master if (srManager.mastershipService.isLocalMaster(deviceId)) { @@ -405,6 +452,14 @@ public class RoutingRulePopulator { * @param deviceId the switch dpid for the router */ public void populateRouterIpPunts(DeviceId deviceId) { + Ip4Address routerIp; + try { + routerIp = config.getRouterIp(deviceId); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting populateRouterIpPunts."); + return; + } + if (!srManager.mastershipService.isLocalMaster(deviceId)) { log.debug("Not installing port-IP punts - not the master for dev:{} ", deviceId); @@ -412,7 +467,7 @@ public class RoutingRulePopulator { } ForwardingObjective.Builder puntIp = DefaultForwardingObjective.builder(); Set allIps = new HashSet(config.getPortIPs(deviceId)); - allIps.add(config.getRouterIp(deviceId)); + allIps.add(routerIp); for (Ip4Address ipaddr : allIps) { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java index b82752d6..787f9347 100644 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/SegmentRoutingManager.java @@ -38,6 +38,8 @@ import org.onosproject.net.config.NetworkConfigEvent; import org.onosproject.net.config.NetworkConfigRegistry; import org.onosproject.net.config.NetworkConfigListener; import org.onosproject.net.config.basics.SubjectFactories; +import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; +import org.onosproject.segmentrouting.config.DeviceConfiguration; import org.onosproject.segmentrouting.config.SegmentRoutingConfig; import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler; import org.onosproject.segmentrouting.grouphandler.NeighborSet; @@ -553,7 +555,10 @@ public class SegmentRoutingManager implements SegmentRoutingService { private void processLinkAdded(Link link) { log.debug("A new link {} was added", link.toString()); - + if (!deviceConfiguration.isConfigured(link.src().deviceId())) { + log.warn("Source device of this link is not configured."); + return; + } //Irrespective whether the local is a MASTER or not for this device, //create group handler instance and push default TTP flow rules. //Because in a multi-instance setup, instances can initiate @@ -596,7 +601,7 @@ public class SegmentRoutingManager implements SegmentRoutingService { private void processDeviceAdded(Device device) { log.debug("A new device with ID {} was added", device.id()); - if (deviceConfiguration == null) { + if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) { log.warn("Device configuration uploading. Device {} will be " + "processed after config completes.", device.id()); return; @@ -608,14 +613,20 @@ public class SegmentRoutingManager implements SegmentRoutingService { // to the switch). To handle this, a default-group-handler instance is necessary // per switch. if (groupHandlerMap.get(device.id()) == null) { - DefaultGroupHandler groupHandler = DefaultGroupHandler. - createGroupHandler(device.id(), - appId, - deviceConfiguration, - linkService, - flowObjectiveService, - nsNextObjStore, - subnetNextObjStore); + DefaultGroupHandler groupHandler; + try { + groupHandler = DefaultGroupHandler. + createGroupHandler(device.id(), + appId, + deviceConfiguration, + linkService, + flowObjectiveService, + nsNextObjStore, + subnetNextObjStore); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting processDeviceAdded."); + return; + } groupHandlerMap.put(device.id(), groupHandler); // Also, in some cases, drivers may need extra // information to process rules (eg. Router IP/MAC); and so, we send @@ -667,12 +678,20 @@ public class SegmentRoutingManager implements SegmentRoutingService { // to the switch). To handle this, a default-group-handler instance is necessary // per switch. if (groupHandlerMap.get(device.id()) == null) { - DefaultGroupHandler groupHandler = DefaultGroupHandler - .createGroupHandler(device.id(), appId, - deviceConfiguration, linkService, - flowObjectiveService, - nsNextObjStore, - subnetNextObjStore); + DefaultGroupHandler groupHandler; + try { + groupHandler = DefaultGroupHandler. + createGroupHandler(device.id(), + appId, + deviceConfiguration, + linkService, + flowObjectiveService, + nsNextObjStore, + subnetNextObjStore); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting configureNetwork."); + return; + } groupHandlerMap.put(device.id(), groupHandler); // Also, in some cases, drivers may need extra diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/TunnelHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/TunnelHandler.java index 820bb40a..7d025c72 100644 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/TunnelHandler.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/TunnelHandler.java @@ -18,6 +18,7 @@ package org.onosproject.segmentrouting; import org.onosproject.net.DeviceId; import org.onosproject.net.Link; import org.onosproject.net.link.LinkService; +import org.onosproject.segmentrouting.config.DeviceConfiguration; import org.onosproject.segmentrouting.grouphandler.DefaultGroupHandler; import org.onosproject.segmentrouting.grouphandler.NeighborSet; import org.onosproject.store.service.EventuallyConsistentMap; diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfigNotFoundException.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfigNotFoundException.java new file mode 100644 index 00000000..ae156e60 --- /dev/null +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfigNotFoundException.java @@ -0,0 +1,32 @@ +/* + * Copyright 2014-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.segmentrouting.config; + +/** + * Signals that an error occurred during reading device configuration. + */ +public class DeviceConfigNotFoundException extends Exception { + + /** + * Creates a new ConfigNotFoundException with the given message. + * + * @param message exception message + */ + public DeviceConfigNotFoundException(String message) { + super(message); + } +} diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java new file mode 100644 index 00000000..0ad00679 --- /dev/null +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfiguration.java @@ -0,0 +1,454 @@ +/* + * Copyright 2014-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.segmentrouting.config; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import org.onlab.packet.Ip4Address; +import org.onlab.packet.Ip4Prefix; +import org.onlab.packet.MacAddress; +import org.onosproject.incubator.net.config.basics.ConfigException; +import org.onosproject.incubator.net.config.basics.InterfaceConfig; +import org.onosproject.incubator.net.intf.Interface; +import org.onosproject.net.ConnectPoint; +import org.onosproject.net.config.NetworkConfigRegistry; +import org.onosproject.net.host.InterfaceIpAddress; +import org.onosproject.segmentrouting.config.SegmentRoutingConfig.AdjacencySid; +import org.onosproject.net.DeviceId; +import org.onosproject.net.PortNumber; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Segment Routing configuration component that reads the + * segment routing related configuration from Network Configuration Manager + * component and organizes in more accessible formats. + */ +public class DeviceConfiguration implements DeviceProperties { + + private static final Logger log = LoggerFactory + .getLogger(DeviceConfiguration.class); + private final List allSegmentIds = new ArrayList<>(); + private final ConcurrentHashMap deviceConfigMap + = new ConcurrentHashMap<>(); + + private class SegmentRouterInfo { + int nodeSid; + DeviceId deviceId; + Ip4Address ip; + MacAddress mac; + boolean isEdge; + HashMap gatewayIps; + HashMap subnets; + List adjacencySids; + + public SegmentRouterInfo() { + this.gatewayIps = new HashMap<>(); + this.subnets = new HashMap<>(); + } + } + + /** + * Constructor. Reads all the configuration for all devices of type + * Segment Router and organizes into various maps for easier access. + * + * @param cfgService config service + */ + public DeviceConfiguration(NetworkConfigRegistry cfgService) { + // Read config from device subject, excluding gatewayIps and subnets. + Set deviceSubjects = + cfgService.getSubjects(DeviceId.class, SegmentRoutingConfig.class); + deviceSubjects.forEach(subject -> { + SegmentRoutingConfig config = + cfgService.getConfig(subject, SegmentRoutingConfig.class); + SegmentRouterInfo info = new SegmentRouterInfo(); + info.deviceId = subject; + info.nodeSid = config.getSid(); + info.ip = config.getIp(); + info.mac = config.getMac(); + info.isEdge = config.isEdgeRouter(); + info.adjacencySids = config.getAdjacencySids(); + + this.deviceConfigMap.put(info.deviceId, info); + this.allSegmentIds.add(info.nodeSid); + }); + + // Read gatewayIps and subnets from port subject. + Set portSubjects = + cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class); + portSubjects.forEach(subject -> { + InterfaceConfig config = + cfgService.getConfig(subject, InterfaceConfig.class); + Set networkInterfaces; + try { + networkInterfaces = config.getInterfaces(); + } catch (ConfigException e) { + log.error("Error loading port configuration"); + return; + } + networkInterfaces.forEach(networkInterface -> { + DeviceId dpid = networkInterface.connectPoint().deviceId(); + PortNumber port = networkInterface.connectPoint().port(); + SegmentRouterInfo info = this.deviceConfigMap.get(dpid); + + // skip if there is no corresponding device for this ConenctPoint + if (info != null) { + Set interfaceAddresses = networkInterface.ipAddresses(); + interfaceAddresses.forEach(interfaceAddress -> { + info.gatewayIps.put(port, interfaceAddress.ipAddress().getIp4Address()); + info.subnets.put(port, interfaceAddress.subnetAddress().getIp4Prefix()); + }); + } + }); + + }); + } + + @Override + public boolean isConfigured(DeviceId deviceId) { + return deviceConfigMap.get(deviceId) != null; + } + + @Override + public int getSegmentId(DeviceId deviceId) throws DeviceConfigNotFoundException { + SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); + if (srinfo != null) { + log.trace("getSegmentId for device{} is {}", deviceId, srinfo.nodeSid); + return srinfo.nodeSid; + } else { + String message = "getSegmentId fails for device: " + deviceId + "."; + throw new DeviceConfigNotFoundException(message); + } + } + + /** + * Returns the Node segment id of a segment router given its Router mac address. + * + * @param routerMac router mac address + * @return node segment id, or -1 if not found in config + */ + public int getSegmentId(MacAddress routerMac) { + for (Map.Entry entry: + deviceConfigMap.entrySet()) { + if (entry.getValue().mac.equals(routerMac)) { + return entry.getValue().nodeSid; + } + } + + return -1; + } + + /** + * Returns the Node segment id of a segment router given its Router ip address. + * + * @param routerAddress router ip address + * @return node segment id, or -1 if not found in config + */ + public int getSegmentId(Ip4Address routerAddress) { + for (Map.Entry entry: + deviceConfigMap.entrySet()) { + if (entry.getValue().ip.equals(routerAddress)) { + return entry.getValue().nodeSid; + } + } + + return -1; + } + + @Override + public MacAddress getDeviceMac(DeviceId deviceId) throws DeviceConfigNotFoundException { + SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); + if (srinfo != null) { + log.trace("getDeviceMac for device{} is {}", deviceId, srinfo.mac); + return srinfo.mac; + } else { + String message = "getDeviceMac fails for device: " + deviceId + "."; + throw new DeviceConfigNotFoundException(message); + } + } + + @Override + public Ip4Address getRouterIp(DeviceId deviceId) throws DeviceConfigNotFoundException { + SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); + if (srinfo != null) { + log.trace("getDeviceIp for device{} is {}", deviceId, srinfo.ip); + return srinfo.ip; + } else { + String message = "getRouterIp fails for device: " + deviceId + "."; + throw new DeviceConfigNotFoundException(message); + } + } + + @Override + public boolean isEdgeDevice(DeviceId deviceId) throws DeviceConfigNotFoundException { + SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); + if (srinfo != null) { + log.trace("isEdgeDevice for device{} is {}", deviceId, srinfo.isEdge); + return srinfo.isEdge; + } else { + String message = "isEdgeDevice fails for device: " + deviceId + "."; + throw new DeviceConfigNotFoundException(message); + } + } + + @Override + public List getAllDeviceSegmentIds() { + return allSegmentIds; + } + + @Override + public Map> getSubnetPortsMap(DeviceId deviceId) { + Map> subnetPortMap = new HashMap<>(); + + // Construct subnet-port mapping from port-subnet mapping + Map portSubnetMap = + this.deviceConfigMap.get(deviceId).subnets; + portSubnetMap.forEach((port, subnet) -> { + if (subnetPortMap.containsKey(subnet)) { + subnetPortMap.get(subnet).add(port); + } else { + ArrayList ports = new ArrayList<>(); + ports.add(port); + subnetPortMap.put(subnet, ports); + } + }); + + return subnetPortMap; + } + + /** + * Returns the device identifier or data plane identifier (dpid) + * of a segment router given its segment id. + * + * @param sid segment id + * @return deviceId device identifier + */ + public DeviceId getDeviceId(int sid) { + for (Map.Entry entry: + deviceConfigMap.entrySet()) { + if (entry.getValue().nodeSid == sid) { + return entry.getValue().deviceId; + } + } + + return null; + } + + /** + * Returns the device identifier or data plane identifier (dpid) + * of a segment router given its router ip address. + * + * @param ipAddress router ip address + * @return deviceId device identifier + */ + public DeviceId getDeviceId(Ip4Address ipAddress) { + for (Map.Entry entry: + deviceConfigMap.entrySet()) { + if (entry.getValue().ip.equals(ipAddress)) { + return entry.getValue().deviceId; + } + } + + return null; + } + + /** + * Returns the configured port ip addresses for a segment router. + * These addresses serve as gateway IP addresses for the subnets configured + * on those ports. + * + * @param deviceId device identifier + * @return immutable set of ip addresses configured on the ports or null if not found + */ + public Set getPortIPs(DeviceId deviceId) { + SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); + if (srinfo != null) { + log.trace("getSubnetGatewayIps for device{} is {}", deviceId, + srinfo.gatewayIps.values()); + return ImmutableSet.copyOf(srinfo.gatewayIps.values()); + } + return null; + } + + /** + * Returns the configured IP addresses per port + * for a segment router. + * + * @param deviceId device identifier + * @return map of port to gateway IP addresses or null if not found + */ + public Map getPortIPMap(DeviceId deviceId) { + SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); + if (srinfo != null) { + return srinfo.gatewayIps; + } + return null; + } + + /** + * Returns the configured subnet prefixes for a segment router. + * + * @param deviceId device identifier + * @return list of ip prefixes or null if not found + */ + public Set getSubnets(DeviceId deviceId) { + SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); + if (srinfo != null) { + log.trace("getSubnets for device{} is {}", deviceId, + srinfo.subnets.values()); + return ImmutableSet.copyOf(srinfo.subnets.values()); + } + return null; + } + + /** + * Returns the configured subnet on the given port, or null if no + * subnet has been configured on the port. + * + * @param deviceId device identifier + * @param pnum port identifier + * @return configured subnet on port, or null + */ + public Ip4Prefix getPortSubnet(DeviceId deviceId, PortNumber pnum) { + SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); + if (srinfo != null) { + return srinfo.subnets.get(pnum); + } + return null; + } + + /** + * Returns the router ip address of segment router that has the + * specified ip address in its subnets. + * + * @param destIpAddress target ip address + * @return router ip address + */ + public Ip4Address getRouterIpAddressForASubnetHost(Ip4Address destIpAddress) { + for (Map.Entry entry: + deviceConfigMap.entrySet()) { + for (Ip4Prefix prefix:entry.getValue().subnets.values()) { + if (prefix.contains(destIpAddress)) { + return entry.getValue().ip; + } + } + } + + log.debug("No router was found for {}", destIpAddress); + return null; + } + + /** + * Returns the router mac address of segment router that has the + * specified ip address as one of its subnet gateway ip address. + * + * @param gatewayIpAddress router gateway ip address + * @return router mac address or null if not found + */ + public MacAddress getRouterMacForAGatewayIp(Ip4Address gatewayIpAddress) { + for (Map.Entry entry: + deviceConfigMap.entrySet()) { + if (entry.getValue().gatewayIps. + values().contains(gatewayIpAddress)) { + return entry.getValue().mac; + } + } + + log.debug("Cannot find a router for {}", gatewayIpAddress); + return null; + } + + + /** + * Checks if the host is in the subnet defined in the router with the + * device ID given. + * + * @param deviceId device identification of the router + * @param hostIp host IP address to check + * @return true if the host is within the subnet of the router, + * false if no subnet is defined under the router or if the host is not + * within the subnet defined in the router + */ + public boolean inSameSubnet(DeviceId deviceId, Ip4Address hostIp) { + + Set subnets = getSubnets(deviceId); + if (subnets == null) { + return false; + } + + for (Ip4Prefix subnet: subnets) { + if (subnet.contains(hostIp)) { + return true; + } + } + + return false; + } + + /** + * Returns the ports corresponding to the adjacency Sid given. + * + * @param deviceId device identification of the router + * @param sid adjacency Sid + * @return list of port numbers + */ + public List getPortsForAdjacencySid(DeviceId deviceId, int sid) { + SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); + if (srinfo != null) { + for (AdjacencySid asid : srinfo.adjacencySids) { + if (asid.getAsid() == sid) { + return asid.getPorts(); + } + } + } + + return Lists.newArrayList(); + } + + /** + * Check if the Sid given is whether adjacency Sid of the router device or not. + * + * @param deviceId device identification of the router + * @param sid Sid to check + * @return true if the Sid given is the adjacency Sid of the device, + * otherwise false + */ + public boolean isAdjacencySid(DeviceId deviceId, int sid) { + SegmentRouterInfo srinfo = deviceConfigMap.get(deviceId); + if (srinfo != null) { + if (srinfo.adjacencySids.isEmpty()) { + return false; + } else { + for (AdjacencySid asid: + srinfo.adjacencySids) { + if (asid.getAsid() == sid) { + return true; + } + } + return false; + } + } + + return false; + } +} \ No newline at end of file diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceProperties.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceProperties.java new file mode 100644 index 00000000..a39c9567 --- /dev/null +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceProperties.java @@ -0,0 +1,96 @@ +/* + * Copyright 2014-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.segmentrouting.config; + +import java.util.List; +import java.util.Map; + +import org.onlab.packet.Ip4Address; +import org.onlab.packet.Ip4Prefix; +import org.onlab.packet.MacAddress; +import org.onosproject.net.DeviceId; +import org.onosproject.net.PortNumber; + +/** + * Mechanism through which group handler module retrieves + * the device specific attributes such as segment ID, + * Mac address...etc from group handler applications. + */ +public interface DeviceProperties { + /** + * Checks if the device is configured. + * + * @param deviceId device identifier + * @return true if the device is configured + */ + boolean isConfigured(DeviceId deviceId); + + /** + * Returns the segment id of a device to be used in group creation. + * + * @param deviceId device identifier + * @throws DeviceConfigNotFoundException if the device configuration is not found + * @return segment id of a device + */ + int getSegmentId(DeviceId deviceId) throws DeviceConfigNotFoundException; + + /** + * Returns the Mac address of a device to be used in group creation. + * + * @param deviceId device identifier + * @throws DeviceConfigNotFoundException if the device configuration is not found + * @return mac address of a device + */ + MacAddress getDeviceMac(DeviceId deviceId) throws DeviceConfigNotFoundException; + + /** + * Returns the router ip address of a segment router. + * + * @param deviceId device identifier + * @throws DeviceConfigNotFoundException if the device configuration is not found + * @return router ip address + */ + Ip4Address getRouterIp(DeviceId deviceId) throws DeviceConfigNotFoundException; + + /** + * Indicates whether a device is edge device or transit/core device. + * + * @param deviceId device identifier + * @throws DeviceConfigNotFoundException if the device configuration is not found + * @return boolean + */ + boolean isEdgeDevice(DeviceId deviceId) throws DeviceConfigNotFoundException; + + /** + * Returns all segment IDs to be considered in building auto + * + * created groups. + * @return list of segment IDs + */ + List getAllDeviceSegmentIds(); + + /** + * Returns subnet-to-ports mapping of given device. + * + * For each entry of the map + * Key: a subnet + * Value: a list of ports, which are bound to the subnet + * + * @param deviceId device identifier + * @return a map that contains all subnet-to-ports mapping of given device + */ + Map> getSubnetPortsMap(DeviceId deviceId); +} diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultEdgeGroupHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultEdgeGroupHandler.java index a5c1090f..33496bd7 100644 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultEdgeGroupHandler.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultEdgeGroupHandler.java @@ -24,6 +24,7 @@ import org.onosproject.net.DeviceId; import org.onosproject.net.Link; import org.onosproject.net.flowobjective.FlowObjectiveService; import org.onosproject.net.link.LinkService; +import org.onosproject.segmentrouting.config.DeviceProperties; import org.onosproject.store.service.EventuallyConsistentMap; /** diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultGroupHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultGroupHandler.java index 69a0d86f..55b556eb 100644 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultGroupHandler.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultGroupHandler.java @@ -48,6 +48,8 @@ import org.onosproject.net.flowobjective.ObjectiveError; import org.onosproject.net.group.DefaultGroupKey; import org.onosproject.net.group.GroupKey; import org.onosproject.net.link.LinkService; +import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; +import org.onosproject.segmentrouting.config.DeviceProperties; import org.onosproject.store.service.EventuallyConsistentMap; import org.slf4j.Logger; @@ -63,9 +65,9 @@ public class DefaultGroupHandler { protected final ApplicationId appId; protected final DeviceProperties deviceConfig; protected final List allSegmentIds; - protected final int nodeSegmentId; - protected final boolean isEdgeRouter; - protected final MacAddress nodeMacAddr; + protected int nodeSegmentId = -1; + protected boolean isEdgeRouter = false; + protected MacAddress nodeMacAddr = null; protected LinkService linkService; protected FlowObjectiveService flowObjectiveService; @@ -99,10 +101,15 @@ public class DefaultGroupHandler { this.appId = checkNotNull(appId); this.deviceConfig = checkNotNull(config); this.linkService = checkNotNull(linkService); - allSegmentIds = checkNotNull(config.getAllDeviceSegmentIds()); - nodeSegmentId = config.getSegmentId(deviceId); - isEdgeRouter = config.isEdgeDevice(deviceId); - nodeMacAddr = checkNotNull(config.getDeviceMac(deviceId)); + this.allSegmentIds = checkNotNull(config.getAllDeviceSegmentIds()); + try { + this.nodeSegmentId = config.getSegmentId(deviceId); + this.isEdgeRouter = config.isEdgeDevice(deviceId); + this.nodeMacAddr = checkNotNull(config.getDeviceMac(deviceId)); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + + " Skipping value assignment in DefaultGroupHandler"); + } this.flowObjectiveService = flowObjService; this.nsNextObjStore = nsNextObjStore; this.subnetNextObjStore = subnetNextObjStore; @@ -122,6 +129,7 @@ public class DefaultGroupHandler { * @param flowObjService flow objective service object * @param nsNextObjStore NeighborSet next objective store map * @param subnetNextObjStore subnet next objective store map + * @throws DeviceConfigNotFoundException if the device configuration is not found * @return default group handler type */ public static DefaultGroupHandler createGroupHandler(DeviceId deviceId, @@ -133,7 +141,9 @@ public class DefaultGroupHandler { NeighborSetNextObjectiveStoreKey, Integer> nsNextObjStore, EventuallyConsistentMap subnetNextObjStore) { + Integer> subnetNextObjStore) + throws DeviceConfigNotFoundException { + // handle possible exception in the caller if (config.isEdgeDevice(deviceId)) { return new DefaultEdgeGroupHandler(deviceId, appId, config, linkService, @@ -176,6 +186,14 @@ public class DefaultGroupHandler { return; } + MacAddress dstMac; + try { + dstMac = deviceConfig.getDeviceMac(newLink.dst().deviceId()); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting linkUp."); + return; + } + log.debug("Device {} linkUp at local port {} to neighbor {}", deviceId, newLink.src().port(), newLink.dst().deviceId()); addNeighborAtPort(newLink.dst().deviceId(), @@ -202,8 +220,7 @@ public class DefaultGroupHandler { TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); tBuilder.setOutput(newLink.src().port()) - .setEthDst(deviceConfig.getDeviceMac( - newLink.dst().deviceId())) + .setEthDst(dstMac) .setEthSrc(nodeMacAddr); if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) { tBuilder.pushMpls() @@ -242,6 +259,15 @@ public class DefaultGroupHandler { log.warn("portDown: unknown port"); return; } + + MacAddress dstMac; + try { + dstMac = deviceConfig.getDeviceMac(portDeviceMap.get(port)); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting portDown."); + return; + } + log.debug("Device {} portDown {} to neighbor {}", deviceId, port, portDeviceMap.get(port)); /*Set nsSet = computeImpactedNeighborsetForPortEvent(portDeviceMap @@ -263,8 +289,8 @@ public class DefaultGroupHandler { TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment .builder(); tBuilder.setOutput(port) - .setEthDst(deviceConfig.getDeviceMac(portDeviceMap - .get(port))).setEthSrc(nodeMacAddr); + .setEthDst(dstMac) + .setEthSrc(nodeMacAddr); if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) { tBuilder.pushMpls().setMpls(MplsLabel.mplsLabel(ns .getEdgeLabel())); @@ -432,7 +458,15 @@ public class DefaultGroupHandler { } private boolean isSegmentIdSameAsNodeSegmentId(DeviceId deviceId, int sId) { - return (deviceConfig.getSegmentId(deviceId) == sId); + int segmentId; + try { + segmentId = deviceConfig.getSegmentId(deviceId); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting isSegmentIdSameAsNodeSegmentId."); + return false; + } + + return segmentId == sId; } protected List getSegmentIdsTobePairedWithNeighborSet(Set neighbors) { @@ -487,11 +521,19 @@ public class DefaultGroupHandler { return; } + MacAddress deviceMac; + try { + deviceMac = deviceConfig.getDeviceMac(d); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting createGroupsFromNeighborsets."); + return; + } + for (PortNumber sp : devicePortMap.get(d)) { TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment .builder(); tBuilder.setOutput(sp) - .setEthDst(deviceConfig.getDeviceMac(d)) + .setEthDst(deviceMac) .setEthSrc(nodeMacAddr); if (ns.getEdgeLabel() != NeighborSet.NO_EDGE_LABEL) { tBuilder.pushMpls().setMpls(MplsLabel.mplsLabel(ns @@ -535,6 +577,7 @@ public class DefaultGroupHandler { ports.forEach(port -> { TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); + tBuilder.popVlan(); tBuilder.setOutput(port); nextObjBuilder.addTreatment(tBuilder.build()); }); diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultTransitGroupHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultTransitGroupHandler.java index b009e869..8e1b6a8f 100644 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultTransitGroupHandler.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DefaultTransitGroupHandler.java @@ -23,6 +23,8 @@ import org.onosproject.net.DeviceId; import org.onosproject.net.Link; import org.onosproject.net.flowobjective.FlowObjectiveService; import org.onosproject.net.link.LinkService; +import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; +import org.onosproject.segmentrouting.config.DeviceProperties; import org.onosproject.store.service.EventuallyConsistentMap; /** @@ -171,7 +173,15 @@ public class DefaultTransitGroupHandler extends DefaultGroupHandler { if (deviceSubSet.size() > 1) { boolean avoidEdgeRouterPairing = true; for (DeviceId device : deviceSubSet) { - if (!deviceConfig.isEdgeDevice(device)) { + boolean isEdge; + try { + isEdge = deviceConfig.isEdgeDevice(device); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Skipping filterEdgeRouterOnlyPairings on this device."); + continue; + } + + if (!isEdge) { avoidEdgeRouterPairing = false; break; } diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DeviceProperties.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DeviceProperties.java deleted file mode 100644 index d28d38d5..00000000 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/DeviceProperties.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2014-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.segmentrouting.grouphandler; - -import java.util.List; -import java.util.Map; - -import org.onlab.packet.Ip4Prefix; -import org.onlab.packet.MacAddress; -import org.onosproject.net.DeviceId; -import org.onosproject.net.PortNumber; - -/** - * Mechanism through which group handler module retrieves - * the device specific attributes such as segment ID, - * Mac address...etc from group handler applications. - */ -public interface DeviceProperties { - /** - * Returns the segment id of a device to be used in group creation. - * - * @param deviceId device identifier - * @return segment id of a device - */ - int getSegmentId(DeviceId deviceId); - - /** - * Returns the Mac address of a device to be used in group creation. - * - * @param deviceId device identifier - * @return mac address of a device - */ - MacAddress getDeviceMac(DeviceId deviceId); - - /** - * Indicates whether a device is edge device or transit/core device. - * - * @param deviceId device identifier - * @return boolean - */ - boolean isEdgeDevice(DeviceId deviceId); - - /** - * Returns all segment IDs to be considered in building auto - * - * created groups. - * @return list of segment IDs - */ - List getAllDeviceSegmentIds(); - - /** - * Returns subnet-to-ports mapping of given device. - * - * For each entry of the map - * Key: a subnet - * Value: a list of ports, which are bound to the subnet - * - * @param deviceId device identifier - * @return a map that contains all subnet-to-ports mapping of given device - */ - Map> getSubnetPortsMap(DeviceId deviceId); -} diff --git a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/PolicyGroupHandler.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/PolicyGroupHandler.java index e47a6625..55142078 100644 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/PolicyGroupHandler.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/grouphandler/PolicyGroupHandler.java @@ -24,8 +24,11 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; +import org.onlab.packet.MacAddress; import org.onlab.packet.MplsLabel; import org.onosproject.core.ApplicationId; +import org.onosproject.segmentrouting.config.DeviceConfigNotFoundException; +import org.onosproject.segmentrouting.config.DeviceProperties; import org.onosproject.segmentrouting.grouphandler.GroupBucketIdentifier.BucketOutputType; import org.onosproject.store.service.EventuallyConsistentMap; import org.onosproject.net.DeviceId; @@ -105,11 +108,19 @@ public class PolicyGroupHandler extends DefaultGroupHandler { PolicyGroupIdentifier(id, Collections.singletonList(param), Collections.singletonList(bucketId)); + MacAddress neighborEthDst; + try { + neighborEthDst = deviceConfig.getDeviceMac(neighbor); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + + " Skipping createPolicyGroupChain for this label."); + continue; + } + TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); tBuilder.setOutput(sp) - .setEthDst(deviceConfig. - getDeviceMac(neighbor)) + .setEthDst(neighborEthDst) .setEthSrc(nodeMacAddr) .pushMpls() .setMpls(MplsLabel.mplsLabel(label)); @@ -168,14 +179,23 @@ public class PolicyGroupHandler extends DefaultGroupHandler { if (fullyResolved) { List outBuckets = new ArrayList<>(); - for (GroupBucketIdentifier bucketId:bucketIds) { + for (GroupBucketIdentifier bucketId : bucketIds) { DeviceId neighbor = portDeviceMap. get(bucketId.outPort()); + + MacAddress neighborEthDst; + try { + neighborEthDst = deviceConfig.getDeviceMac(neighbor); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + + " Skipping createPolicyGroupChain for this bucketId."); + continue; + } + TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); tBuilder.setOutput(bucketId.outPort()) - .setEthDst(deviceConfig. - getDeviceMac(neighbor)) + .setEthDst(neighborEthDst) .setEthSrc(nodeMacAddr); if (bucketId.label() != NeighborSet.NO_EDGE_LABEL) { tBuilder.pushMpls() diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortChainCodecTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortChainCodecTest.java new file mode 100644 index 00000000..02681db3 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortChainCodecTest.java @@ -0,0 +1,95 @@ +/* + * 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.vtnweb.web; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +import java.io.IOException; +import java.io.InputStream; + +import org.junit.Before; +import org.junit.Test; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.PortChain; +import org.onosproject.vtnrsc.PortChainId; +import org.onosproject.vtnrsc.TenantId; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Flow rule codec unit tests. + */ +public class PortChainCodecTest { + + SfcCodecContext context; + JsonCodec portChainCodec; + /** + * Sets up for each test. Creates a context and fetches the flow rule + * codec. + */ + @Before + public void setUp() { + context = new SfcCodecContext(); + portChainCodec = context.codec(PortChain.class); + assertThat(portChainCodec, notNullValue()); + } + + /** + * Reads in a rule from the given resource and decodes it. + * + * @param resourceName resource to use to read the JSON for the rule + * @return decoded flow rule + * @throws IOException if processing the resource fails + */ + private PortChain getPortChain(String resourceName) throws IOException { + InputStream jsonStream = PortChainCodecTest.class + .getResourceAsStream(resourceName); + ObjectMapper mapper = new ObjectMapper(); + JsonNode json = mapper.readTree(jsonStream); + assertThat(json, notNullValue()); + PortChain portChain = portChainCodec.decode((ObjectNode) json, context); + assertThat(portChain, notNullValue()); + return portChain; + } + + /** + * Checks that a simple rule decodes properly. + * + * @throws IOException if the resource cannot be processed + */ + @Test + public void codecPortChainTest() throws IOException { + + PortChain portChain = getPortChain("portChain.json"); + + assertThat(portChain, notNullValue()); + + PortChainId portChainId = PortChainId.of("1278dcd4-459f-62ed-754b-87fc5e4a6751"); + TenantId tenantId = TenantId.tenantId("d382007aa9904763a801f68ecf065cf5"); + + assertThat(portChain.portChainId().toString(), is(portChainId.toString())); + assertThat(portChain.name(), is("PC2")); + assertThat(portChain.tenantId().toString(), is(tenantId.toString())); + assertThat(portChain.description(), is("Two flows and two port-pair-groups")); + + assertThat(portChain.flowClassifiers(), notNullValue()); + assertThat(portChain.portPairGroups(), notNullValue()); + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairGroupCodecTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairGroupCodecTest.java new file mode 100644 index 00000000..de2ee001 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairGroupCodecTest.java @@ -0,0 +1,93 @@ +/* + * 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.vtnweb.web; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; + +import java.io.IOException; +import java.io.InputStream; + +import org.junit.Before; +import org.junit.Test; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.PortPairGroup; +import org.onosproject.vtnrsc.PortPairGroupId; +import org.onosproject.vtnrsc.TenantId; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Flow rule codec unit tests. + */ +public class PortPairGroupCodecTest { + + SfcCodecContext context; + JsonCodec portPairGroupCodec; + /** + * Sets up for each test. Creates a context and fetches the flow rule + * codec. + */ + @Before + public void setUp() { + context = new SfcCodecContext(); + portPairGroupCodec = context.codec(PortPairGroup.class); + assertThat(portPairGroupCodec, notNullValue()); + } + + /** + * Reads in a rule from the given resource and decodes it. + * + * @param resourceName resource to use to read the JSON for the rule + * @return decoded flow rule + * @throws IOException if processing the resource fails + */ + private PortPairGroup getPortPairGroup(String resourceName) throws IOException { + InputStream jsonStream = PortPairGroupCodecTest.class + .getResourceAsStream(resourceName); + ObjectMapper mapper = new ObjectMapper(); + JsonNode json = mapper.readTree(jsonStream); + assertThat(json, notNullValue()); + PortPairGroup portPairGroup = portPairGroupCodec.decode((ObjectNode) json, context); + assertThat(portPairGroup, notNullValue()); + return portPairGroup; + } + + /** + * Checks that a simple rule decodes properly. + * + * @throws IOException if the resource cannot be processed + */ + @Test + public void codecPortPairGroupTest() throws IOException { + + PortPairGroup portPairGroup = getPortPairGroup("portPairGroup.json"); + + assertThat(portPairGroup, notNullValue()); + + PortPairGroupId portPairGroupId = PortPairGroupId.of("4512d643-24fc-4fae-af4b-321c5e2eb3d1"); + TenantId tenantId = TenantId.tenantId("d382007aa9904763a801f68ecf065cf5"); + + assertThat(portPairGroup.portPairGroupId().toString(), is(portPairGroupId.toString())); + assertThat(portPairGroup.name(), is("PG1")); + assertThat(portPairGroup.tenantId().toString(), is(tenantId.toString())); + assertThat(portPairGroup.description(), is("Two port-pairs")); + assertThat(portPairGroup.portPairs(), notNullValue()); + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portChain.json b/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portChain.json new file mode 100644 index 00000000..07a1bc21 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portChain.json @@ -0,0 +1,14 @@ +{ + "id": "1278dcd4-459f-62ed-754b-87fc5e4a6751", + "name": "PC2", + "tenant_id": "d382007aa9904763a801f68ecf065cf5", + "description": "Two flows and two port-pair-groups", + "flow_classifiers": [ + "456a4a34-2e9c-14ae-37fb-765feae2eb05", + "4a334cd4-fe9c-4fae-af4b-321c5e2eb051" + ], + "port_pair_groups": [ + "4512d643-24fc-4fae-af4b-321c5e2eb3d1", + "4a634d49-76dc-4fae-af4b-321c5e23d651" + ] +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portPairGroup.json b/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portPairGroup.json new file mode 100644 index 00000000..e19a66fc --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portPairGroup.json @@ -0,0 +1,10 @@ +{ + "id": "4512d643-24fc-4fae-af4b-321c5e2eb3d1", + "name": "PG1", + "tenant_id": "d382007aa9904763a801f68ecf065cf5", + "description": "Two port-pairs", + "port_pairs": [ + "875dfeda-43ed-23fe-454b-764feab2c342", + "78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae" + ] +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIGPFlags.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIGPFlags.java deleted file mode 100755 index 035d706c..00000000 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIGPFlags.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * 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.bgpio.types.attr; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.bgpio.exceptions.BGPParseException; -import org.onosproject.bgpio.types.BGPErrorType; -import org.onosproject.bgpio.types.BGPValueType; -import org.onosproject.bgpio.util.Validation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Implements BGP prefix IGP Flag attribute. - */ -public class BgpPrefixAttrIGPFlags implements BGPValueType { - - protected static final Logger log = LoggerFactory - .getLogger(BgpPrefixAttrIGPFlags.class); - - public static final int ATTR_PREFIX_FLAGBIT = 1152; - public static final int ATTR_PREFIX_FLAG_LEN = 1; - - public static final int FIRST_BIT = 0x80; - public static final int SECOND_BIT = 0x40; - public static final int THIRD_BIT = 0x20; - public static final int FOURTH_BIT = 0x01; - - /* Prefix IGP flag bit TLV */ - private boolean bisisUpDownBit = false; - private boolean bOspfNoUnicastBit = false; - private boolean bOspfLclAddrBit = false; - private boolean bOspfNSSABit = false; - - /** - * Constructor to initialize the value. - * - * @param bisisUpDownBit IS-IS Up/Down Bit - * @param bOspfNoUnicastBit OSPF no unicast Bit - * @param bOspfLclAddrBit OSPF local address Bit - * @param bOspfNSSABit OSPF propagate NSSA Bit - */ - BgpPrefixAttrIGPFlags(boolean bisisUpDownBit, boolean bOspfNoUnicastBit, - boolean bOspfLclAddrBit, boolean bOspfNSSABit) { - this.bisisUpDownBit = bisisUpDownBit; - this.bOspfNoUnicastBit = bOspfNoUnicastBit; - this.bOspfLclAddrBit = bOspfLclAddrBit; - this.bOspfNSSABit = bOspfNSSABit; - } - - /** - * Reads the IGP Flags. - * - * @param cb ChannelBuffer - * @return object of BgpPrefixAttrIGPFlags - * @throws BGPParseException while parsing BgpPrefixAttrIGPFlags - */ - public static BgpPrefixAttrIGPFlags read(ChannelBuffer cb) - throws BGPParseException { - boolean bisisUpDownBit = false; - boolean bOspfNoUnicastBit = false; - boolean bOspfLclAddrBit = false; - boolean bOspfNSSABit = false; - - short lsAttrLength = cb.readShort(); - - if ((lsAttrLength != ATTR_PREFIX_FLAG_LEN) - || (cb.readableBytes() < lsAttrLength)) { - Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, - BGPErrorType.ATTRIBUTE_LENGTH_ERROR, - lsAttrLength); - } - - byte nodeFlagBits = cb.readByte(); - - bisisUpDownBit = ((nodeFlagBits & (byte) FIRST_BIT) == FIRST_BIT); - bOspfNoUnicastBit = ((nodeFlagBits & (byte) SECOND_BIT) == SECOND_BIT); - bOspfLclAddrBit = ((nodeFlagBits & (byte) THIRD_BIT) == THIRD_BIT); - bOspfNSSABit = ((nodeFlagBits & (byte) FOURTH_BIT) == FOURTH_BIT); - - return new BgpPrefixAttrIGPFlags(bisisUpDownBit, bOspfNoUnicastBit, - bOspfLclAddrBit, bOspfNSSABit); - } - - /** - * Returns the IS-IS Up/Down Bit set or not. - * - * @return IS-IS Up/Down Bit set or not - */ - boolean getisisUpDownBit() { - return bisisUpDownBit; - } - - /** - * Returns the OSPF no unicast Bit set or not. - * - * @return OSPF no unicast Bit set or not - */ - boolean getOspfNoUnicastBit() { - return bOspfNoUnicastBit; - } - - /** - * Returns the OSPF local address Bit set or not. - * - * @return OSPF local address Bit set or not - */ - boolean getOspfLclAddrBit() { - return bOspfLclAddrBit; - } - - /** - * Returns the OSPF propagate NSSA Bit set or not. - * - * @return OSPF propagate NSSA Bit set or not - */ - boolean getOspfNSSABit() { - return bOspfNSSABit; - } - - @Override - public short getType() { - return ATTR_PREFIX_FLAGBIT; - } - - @Override - public int write(ChannelBuffer cb) { - // TODO This will be implemented in the next version - return 0; - } - - @Override - public int hashCode() { - return Objects.hash(bisisUpDownBit, bOspfNoUnicastBit, bOspfLclAddrBit, - bOspfNSSABit); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj instanceof BgpPrefixAttrIGPFlags) { - BgpPrefixAttrIGPFlags other = (BgpPrefixAttrIGPFlags) obj; - return Objects.equals(bisisUpDownBit, other.bisisUpDownBit) - && Objects.equals(bOspfNoUnicastBit, - other.bOspfNoUnicastBit) - && Objects.equals(bOspfLclAddrBit, other.bOspfLclAddrBit) - && Objects.equals(bOspfNSSABit, other.bOspfNSSABit); - } - return false; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("bisisUpDownBit", bisisUpDownBit) - .add("bOspfNoUnicastBit", bOspfNoUnicastBit) - .add("bOspfLclAddrBit", bOspfLclAddrBit) - .add("bOspfNSSABit", bOspfNSSABit).toString(); - } -} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java new file mode 100755 index 00000000..a215e6f1 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlags.java @@ -0,0 +1,198 @@ +/* + * 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.bgpio.types.attr; + +import java.util.Objects; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.types.BGPErrorType; +import org.onosproject.bgpio.types.BGPValueType; +import org.onosproject.bgpio.util.Validation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/** + * Implements BGP prefix IGP Flag attribute. + */ +public final class BgpPrefixAttrIgpFlags implements BGPValueType { + + protected static final Logger log = LoggerFactory + .getLogger(BgpPrefixAttrIgpFlags.class); + + public static final int ATTR_PREFIX_FLAGBIT = 1152; + public static final int ATTR_PREFIX_FLAG_LEN = 1; + + public static final byte FIRST_BIT = (byte) 0x80; + public static final byte SECOND_BIT = 0x40; + public static final byte THIRD_BIT = 0x20; + public static final byte FOURTH_BIT = 0x01; + + /* Prefix IGP flag bit TLV */ + private final boolean bisisUpDownBit; + private final boolean bOspfNoUnicastBit; + private final boolean bOspfLclAddrBit; + private final boolean bOspfNSSABit; + + /** + * Constructor to initialize the value. + * + * @param bisisUpDownBit IS-IS Up/Down Bit + * @param bOspfNoUnicastBit OSPF no unicast Bit + * @param bOspfLclAddrBit OSPF local address Bit + * @param bOspfNSSABit OSPF propagate NSSA Bit + */ + BgpPrefixAttrIgpFlags(boolean bisisUpDownBit, + boolean bOspfNoUnicastBit, + boolean bOspfLclAddrBit, boolean bOspfNSSABit) { + this.bisisUpDownBit = bisisUpDownBit; + this.bOspfNoUnicastBit = bOspfNoUnicastBit; + this.bOspfLclAddrBit = bOspfLclAddrBit; + this.bOspfNSSABit = bOspfNSSABit; + } + + /** + * Returns object of this class with specified values. + * + * @param bisisUpDownBit IS-IS Up/Down Bit + * @param bOspfNoUnicastBit OSPF no unicast Bit + * @param bOspfLclAddrBit OSPF local address Bit + * @param bOspfNSSABit OSPF propagate NSSA Bit + * @return object of BgpPrefixAttrIGPFlags + */ + public static BgpPrefixAttrIgpFlags of(final boolean bisisUpDownBit, + final boolean bOspfNoUnicastBit, + final boolean bOspfLclAddrBit, + final boolean bOspfNSSABit) { + return new BgpPrefixAttrIgpFlags(bisisUpDownBit, bOspfNoUnicastBit, + bOspfLclAddrBit, bOspfNSSABit); + } + + /** + * Reads the IGP Flags. + * + * @param cb ChannelBuffer + * @return object of BgpPrefixAttrIGPFlags + * @throws BGPParseException while parsing BgpPrefixAttrIGPFlags + */ + public static BgpPrefixAttrIgpFlags read(ChannelBuffer cb) + throws BGPParseException { + boolean bisisUpDownBit = false; + boolean bOspfNoUnicastBit = false; + boolean bOspfLclAddrBit = false; + boolean bOspfNSSABit = false; + + short lsAttrLength = cb.readShort(); + + if ((lsAttrLength != ATTR_PREFIX_FLAG_LEN) + || (cb.readableBytes() < lsAttrLength)) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, + lsAttrLength); + } + + byte nodeFlagBits = cb.readByte(); + + bisisUpDownBit = ((nodeFlagBits & FIRST_BIT) == FIRST_BIT); + bOspfNoUnicastBit = ((nodeFlagBits & SECOND_BIT) == SECOND_BIT); + bOspfLclAddrBit = ((nodeFlagBits & THIRD_BIT) == THIRD_BIT); + bOspfNSSABit = ((nodeFlagBits & FOURTH_BIT) == FOURTH_BIT); + + return BgpPrefixAttrIgpFlags.of(bisisUpDownBit, bOspfNoUnicastBit, + bOspfLclAddrBit, bOspfNSSABit); + } + + /** + * Returns the IS-IS Up/Down Bit set or not. + * + * @return IS-IS Up/Down Bit set or not + */ + public boolean isisUpDownBit() { + return bisisUpDownBit; + } + + /** + * Returns the OSPF no unicast Bit set or not. + * + * @return OSPF no unicast Bit set or not + */ + public boolean ospfNoUnicastBit() { + return bOspfNoUnicastBit; + } + + /** + * Returns the OSPF local address Bit set or not. + * + * @return OSPF local address Bit set or not + */ + public boolean ospfLclAddrBit() { + return bOspfLclAddrBit; + } + + /** + * Returns the OSPF propagate NSSA Bit set or not. + * + * @return OSPF propagate NSSA Bit set or not + */ + public boolean ospfNSSABit() { + return bOspfNSSABit; + } + + @Override + public short getType() { + return ATTR_PREFIX_FLAGBIT; + } + + @Override + public int write(ChannelBuffer cb) { + // TODO This will be implemented in the next version + return 0; + } + + @Override + public int hashCode() { + return Objects.hash(bisisUpDownBit, bOspfNoUnicastBit, bOspfLclAddrBit, + bOspfNSSABit); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj instanceof BgpPrefixAttrIgpFlags) { + BgpPrefixAttrIgpFlags other = (BgpPrefixAttrIgpFlags) obj; + return Objects.equals(bisisUpDownBit, other.bisisUpDownBit) + && Objects.equals(bOspfNoUnicastBit, + other.bOspfNoUnicastBit) + && Objects.equals(bOspfLclAddrBit, other.bOspfLclAddrBit) + && Objects.equals(bOspfNSSABit, other.bOspfNSSABit); + } + return false; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("bisisUpDownBit", bisisUpDownBit) + .add("bOspfNoUnicastBit", bOspfNoUnicastBit) + .add("bOspfLclAddrBit", bOspfLclAddrBit) + .add("bOspfNSSABit", bOspfNSSABit).toString(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/AreaIdTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/AreaIdTest.java deleted file mode 100644 index 3e7c654e..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/AreaIdTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.bgp; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.bgpio.types.AreaIDTlv; - -/** - * Test for AreaID Tlv. - */ -public class AreaIdTest { - private final int value1 = 10; - private final int value2 = 20; - private final AreaIDTlv tlv1 = AreaIDTlv.of(value1); - private final AreaIDTlv sameAsTlv1 = AreaIDTlv.of(value1); - private final AreaIDTlv tlv2 = AreaIDTlv.of(value2); - - @Test - public void testEquality() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/As4PathTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/As4PathTest.java deleted file mode 100755 index 96d05bf3..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/As4PathTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.bgp; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; -import org.onosproject.bgpio.types.As4Path; - -import com.google.common.testing.EqualsTester; - -/** - * Test for As4Path BGP Path Attribute. - */ -public class As4PathTest { - //Two scenarios as4path set and sequence - private final List as4pathSet1 = new ArrayList<>(); - private final List as4pathSeq1 = new ArrayList<>(); - private final List as4pathSet2 = new ArrayList<>(); - private final List as4pathSeq2 = new ArrayList<>(); - private final As4Path attr1 = new As4Path(as4pathSet1, null); - private final As4Path sameAsAttr1 = new As4Path(as4pathSet1, null); - private final As4Path attr2 = new As4Path(as4pathSet2, null); - private final As4Path attr3 = new As4Path(null, as4pathSeq1); - private final As4Path sameAsAttr3 = new As4Path(null, as4pathSeq1); - private final As4Path attr4 = new As4Path(null, as4pathSeq2); - - @Test - public void basics() { - as4pathSet1.add(197358); - as4pathSet1.add(12883); - as4pathSet2.add(2008989); - as4pathSeq1.add(3009009); - as4pathSeq2.add(409900); - new EqualsTester() - .addEqualityGroup(attr1, sameAsAttr1) - .addEqualityGroup(attr2) - .addEqualityGroup(attr3, sameAsAttr3) - .addEqualityGroup(attr4) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/AsPathTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/AsPathTest.java deleted file mode 100644 index 792164ea..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/AsPathTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.bgp; - -import java.util.ArrayList; -import java.util.List; - -import org.junit.Test; -import org.onosproject.bgpio.types.AsPath; - -import com.google.common.testing.EqualsTester; - -/** - * Test for AsPath BGP Path Attribute. - */ -public class AsPathTest { - //Two scenarios aspath set and sequence - private final List aspathSet1 = new ArrayList<>(); - private final List aspathSet2 = new ArrayList<>(); - private final List aspathSeq1 = new ArrayList<>(); - private final List aspathSeq2 = new ArrayList<>(); - private final AsPath attr1 = new AsPath(aspathSet1, null); - private final AsPath sameAsAttr1 = new AsPath(aspathSet1, null); - private final AsPath attr2 = new AsPath(aspathSet2, null); - private final AsPath attr3 = new AsPath(null, aspathSeq1); - private final AsPath sameAsAttr3 = new AsPath(null, aspathSeq1); - private final AsPath attr4 = new AsPath(null, aspathSeq2); - - @Test - public void basics() { - aspathSet1.add((short) 100); - aspathSet1.add((short) 300); - aspathSet2.add((short) 200); - aspathSeq2.add((short) 400); - aspathSeq1.add((short) 300); - new EqualsTester() - .addEqualityGroup(attr1, sameAsAttr1) - .addEqualityGroup(attr2) - .addEqualityGroup(attr3, sameAsAttr3) - .addEqualityGroup(attr4) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/AutonomousSystemTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/AutonomousSystemTest.java deleted file mode 100644 index c41408de..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/AutonomousSystemTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.bgp; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.bgpio.types.AutonomousSystemTlv; - -/** - * Test for AutonomousSystem Tlv. - */ -public class AutonomousSystemTest { - private final int value1 = 101; - private final int value2 = 201; - private final AutonomousSystemTlv tlv1 = AutonomousSystemTlv.of(value1); - private final AutonomousSystemTlv sameAsTlv1 = AutonomousSystemTlv.of(value1); - private final AutonomousSystemTlv tlv2 = AutonomousSystemTlv.of(value2); - - @Test - public void testEquality() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BGPKeepaliveMsgTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BGPKeepaliveMsgTest.java deleted file mode 100755 index 57ab9d90..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BGPKeepaliveMsgTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2014-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.bgp; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.core.Is.is; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.junit.Test; -import org.onosproject.bgpio.exceptions.BGPParseException; -import org.onosproject.bgpio.protocol.BGPFactories; -import org.onosproject.bgpio.protocol.BGPKeepaliveMsg; -import org.onosproject.bgpio.protocol.BGPMessage; -import org.onosproject.bgpio.protocol.BGPMessageReader; -import org.onosproject.bgpio.types.BGPHeader; - -/** - * Test case for BGP KEEPALIVE Message. - */ -public class BGPKeepaliveMsgTest { - - /** - * This test case checks BGP Keepalive message. - */ - @Test - public void keepaliveMessageTest1() throws BGPParseException { - - // BGP KEEPALIVE Message - byte[] keepaliveMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - 0x00, 0x13, 0x04}; - - byte[] testKeepaliveMsg; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(keepaliveMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message; - BGPHeader bgpHeader = new BGPHeader(); - - message = reader.readFrom(buffer, bgpHeader); - - assertThat(message, instanceOf(BGPKeepaliveMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testKeepaliveMsg = new byte[readLen]; - buf.readBytes(testKeepaliveMsg, 0, readLen); - - assertThat(testKeepaliveMsg, is(keepaliveMsg)); - } -} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BGPLSIdentifierTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BGPLSIdentifierTest.java deleted file mode 100644 index 5f357815..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BGPLSIdentifierTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2014-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.bgp; - -import org.junit.Test; -import org.onosproject.bgpio.types.BGPLSIdentifierTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test for BGPLSIdentifier Tlv. - */ -public class BGPLSIdentifierTest { - private final int value1 = 8738; - private final int value2 = 13107; - private final BGPLSIdentifierTlv tlv1 = BGPLSIdentifierTlv.of(value1); - private final BGPLSIdentifierTlv sameAsTlv1 = new BGPLSIdentifierTlv(value1); - private final BGPLSIdentifierTlv tlv2 = new BGPLSIdentifierTlv(value2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BGPOpenMsgTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BGPOpenMsgTest.java deleted file mode 100755 index d010857e..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BGPOpenMsgTest.java +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright 2014-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.bgp; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.core.Is.is; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.junit.Test; -import org.onosproject.bgpio.exceptions.BGPParseException; -import org.onosproject.bgpio.protocol.BGPFactories; -import org.onosproject.bgpio.protocol.BGPMessage; -import org.onosproject.bgpio.protocol.BGPMessageReader; -import org.onosproject.bgpio.protocol.BGPOpenMsg; -import org.onosproject.bgpio.types.BGPHeader; - -/** - * Test cases for BGP Open Message. - */ -public class BGPOpenMsgTest { - - /** - * This test case checks open message without optional parameter. - */ - @Test - public void openMessageTest1() throws BGPParseException { - //Open message without optional parameter - byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, - 0x00, 0x1d, 0x01, 0X04, (byte) 0xfe, 0x09, 0x00, - (byte) 0xb4, (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f, - 0x00}; - - byte[] testOpenMsg; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message; - BGPHeader bgpHeader = new BGPHeader(); - message = reader.readFrom(buffer, bgpHeader); - - assertThat(message, instanceOf(BGPOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - } - - /** - * This test case checks open message with Multiprotocol extension - * capability. - */ - @Test - public void openMessageTest2() throws BGPParseException { - - // OPEN Message (MultiProtocolExtension-CAPABILITY). - byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, 0x00, 0x25, - 0x01, //BGP Header - 0X04, //Version - (byte) 0x00, (byte) 0xc8, // AS Number - 0x00, (byte) 0xb4, // Hold time - (byte) 0xb6, (byte) 0x02, 0x5d, - (byte) 0xc8, // BGP Identifier - 0x08, 0x02, 0x06, // Opt Parameter length - 0x01, 0x04, 0x00, 0x00, 0x00, (byte) 0xc8}; // Multiprotocol CAPABILITY - - byte[] testOpenMsg; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message; - BGPHeader bgpHeader = new BGPHeader(); - - message = reader.readFrom(buffer, bgpHeader); - - assertThat(message, instanceOf(BGPOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - } - - /** - * This test case checks open message with Four-octet AS number - * capability. - */ - @Test - public void openMessageTest3() throws BGPParseException { - - // OPEN Message (Four-Octet AS number capability). - byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, 0x00, 0x25, - 0x01, //BGPHeader - 0X04, //Version - (byte) 0x00, (byte) 0xc8, //AS Number - 0x00, (byte) 0xb4, //Hold Time - (byte) 0xb6, (byte) 0x02, 0x5d, - (byte) 0xc8, //BGP Identifier - 0x08, 0x02, 0x06, //Opt Parameter Length - 0x41, 0x04, 0x00, 0x01, 0x00, 0x01}; //Four Octet AS Number-CAPABILITY-TLV - - byte[] testOpenMsg; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message; - BGPHeader bgpHeader = new BGPHeader(); - - message = reader.readFrom(buffer, bgpHeader); - - assertThat(message, instanceOf(BGPOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - } - - /** - * This test case checks open message with capabilities. - */ - @Test - public void openMessageTest4() throws BGPParseException { - - // OPEN Message with capabilities. - byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, 0x00, 0x2b, - 0x01, //BGPHeader - 0X04, //Version - (byte) 0x00, (byte) 0xc8, //AS Number - 0x00, (byte) 0xb4, //Hold Time - (byte) 0xb6, (byte) 0x02, 0x5d, (byte) 0xc8, //BGP Identifier - 0x0e, 0x02, 0x0c, //Opt Parameter Length - 0x01, 0x04, 0x00, 0x00, 0x00, (byte) 0xc8, // Multiprotocol extension capability - 0x41, 0x04, 0x00, 0x01, 0x00, 0x01}; //Four Octet AS Number-CAPABILITY-TLV - - byte[] testOpenMsg; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message; - BGPHeader bgpHeader = new BGPHeader(); - - message = reader.readFrom(buffer, bgpHeader); - - assertThat(message, instanceOf(BGPOpenMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - } - - /** - * In this test case, Invalid version is given as input and expecting - * an exception. - */ - @Test(expected = BGPParseException.class) - public void openMessageTest5() throws BGPParseException { - - // OPEN Message with invalid version number. - byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, 0x00, 0x1d, 0x01, 0X05, - (byte) 0xfe, 0x09, 0x00, (byte) 0xb4, - (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f, - 0x00}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message; - BGPHeader bgpHeader = new BGPHeader(); - message = reader.readFrom(buffer, bgpHeader); - - assertThat(message, instanceOf(BGPOpenMsg.class)); - } - - /** - * In this test case, Marker is set as 0 in input and expecting - * an exception. - */ - @Test(expected = BGPParseException.class) - public void openMessageTest6() throws BGPParseException { - - // OPEN Message with marker set to 0. - byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0x00, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - 0x00, 0x00, 0x1d, 0x01, 0X04, - (byte) 0xfe, 0x09, 0x00, (byte) 0xb4, - (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f, - 0x00}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message; - BGPHeader bgpHeader = new BGPHeader(); - message = reader.readFrom(buffer, bgpHeader); - - assertThat(message, instanceOf(BGPOpenMsg.class)); - } - - /** - * In this test case, Invalid message length is given as input and expecting - * an exception. - */ - @Test(expected = BGPParseException.class) - public void openMessageTest7() throws BGPParseException { - - // OPEN Message with invalid header length. - byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, 0x00, 0x1e, 0x01, 0X04, - (byte) 0xfe, 0x09, 0x00, (byte) 0xb4, - (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f, - 0x00}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message; - BGPHeader bgpHeader = new BGPHeader(); - message = reader.readFrom(buffer, bgpHeader); - - assertThat(message, instanceOf(BGPOpenMsg.class)); - } - - /** - * In this test case, Invalid message type is given as input and expecting - * an exception. - */ - @Test(expected = BGPParseException.class) - public void openMessageTest8() throws BGPParseException { - - // OPEN Message with invalid message type. - byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, (byte) 0xff, - (byte) 0xff, 0x00, 0x1d, 0x05, 0X04, - (byte) 0xfe, 0x09, 0x00, (byte) 0xb4, - (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f, - 0x00}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message; - BGPHeader bgpHeader = new BGPHeader(); - message = reader.readFrom(buffer, bgpHeader); - - assertThat(message, instanceOf(BGPOpenMsg.class)); - } -} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpAttrNodeFlagBitTlvTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpAttrNodeFlagBitTlvTest.java deleted file mode 100644 index 5f1411ff..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpAttrNodeFlagBitTlvTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onosproject.bgpio.types.attr.BgpAttrNodeFlagBitTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test for BGP attribute node flag. - */ -public class BgpAttrNodeFlagBitTlvTest { - - private final boolean bOverloadBit = true; - private final boolean bAttachedBit = true; - private final boolean bExternalBit = true; - private final boolean bABRBit = true; - - private final boolean bOverloadBit1 = false; - private final boolean bAttachedBit1 = false; - private final boolean bExternalBit1 = false; - private final boolean bABRBit1 = false; - - private final BgpAttrNodeFlagBitTlv data = BgpAttrNodeFlagBitTlv - .of(bOverloadBit, bAttachedBit, bExternalBit, bABRBit); - private final BgpAttrNodeFlagBitTlv sameAsData = BgpAttrNodeFlagBitTlv - .of(bOverloadBit, bAttachedBit, bExternalBit, bABRBit); - private final BgpAttrNodeFlagBitTlv diffData = BgpAttrNodeFlagBitTlv - .of(bOverloadBit1, bAttachedBit1, bExternalBit1, bABRBit1); - - @Test - public void basics() { - - new EqualsTester().addEqualityGroup(data, sameAsData) - .addEqualityGroup(diffData).testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpAttrRouterIdV6Test.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpAttrRouterIdV6Test.java deleted file mode 100644 index 72ca5dbf..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpAttrRouterIdV6Test.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onlab.packet.Ip6Address; -import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV6; - -import com.google.common.testing.EqualsTester; - -/** - * Test for BGP attribute node router ID. - */ -public class BgpAttrRouterIdV6Test { - - private final short sType = 1; - private final Ip6Address ip6RouterId = Ip6Address - .valueOf("2001:0db8:0a0b:12f0:0000:0000:0000:0001"); - - private final short sType1 = 2; - private final Ip6Address ip6RouterId1 = Ip6Address - .valueOf("2004:0db8:0a0b:12f0:0000:0000:0000:0004"); - - private final BgpAttrRouterIdV6 data = BgpAttrRouterIdV6.of(ip6RouterId, - sType); - private final BgpAttrRouterIdV6 sameAsData = BgpAttrRouterIdV6 - .of(ip6RouterId, sType); - private final BgpAttrRouterIdV6 diffData = BgpAttrRouterIdV6 - .of(ip6RouterId1, sType1); - - @Test - public void basics() { - - new EqualsTester().addEqualityGroup(data, sameAsData) - .addEqualityGroup(diffData).testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrIgpMetricTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrIgpMetricTest.java deleted file mode 100644 index 32280a79..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrIgpMetricTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onosproject.bgpio.types.attr.BgpLinkAttrIgpMetric; - -import com.google.common.testing.EqualsTester; - -/** - * Test for BGP link IGP metric attribute. - */ -public class BgpLinkAttrIgpMetricTest { - private final int val = 0x010203; - private final int valLen = 3; - private final int val1 = 0x01020304; - private final int val1Len = 4; - - private final BgpLinkAttrIgpMetric data = BgpLinkAttrIgpMetric.of(val, - valLen); - private final BgpLinkAttrIgpMetric sameAsData = BgpLinkAttrIgpMetric - .of(val, valLen); - private final BgpLinkAttrIgpMetric diffData = BgpLinkAttrIgpMetric - .of(val1, val1Len); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(data, sameAsData) - .addEqualityGroup(diffData).testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMplsProtocolMaskTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMplsProtocolMaskTest.java deleted file mode 100644 index d218334b..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMplsProtocolMaskTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onosproject.bgpio.types.attr.BgpLinkAttrMplsProtocolMask; - -import com.google.common.testing.EqualsTester; - -/** - * Test for MPLS protocol mask attribute. - */ -public class BgpLinkAttrMplsProtocolMaskTest { - private final boolean val = true; - private final boolean val1 = false; - - private final BgpLinkAttrMplsProtocolMask data = BgpLinkAttrMplsProtocolMask - .of(val, val); - private final BgpLinkAttrMplsProtocolMask sameAsData = BgpLinkAttrMplsProtocolMask - .of(val, val); - private final BgpLinkAttrMplsProtocolMask diffData = BgpLinkAttrMplsProtocolMask - .of(val, val1); - - @Test - public void basics() { - - new EqualsTester().addEqualityGroup(data, sameAsData) - .addEqualityGroup(diffData).testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrProtectionTypeTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrProtectionTypeTest.java deleted file mode 100644 index 89f97a83..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrProtectionTypeTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onosproject.bgpio.types.attr.BgpLinkAttrProtectionType; - -import com.google.common.testing.EqualsTester; - -/** - * Test for MPLS protocol mask attribute. - */ -public class BgpLinkAttrProtectionTypeTest { - boolean bExtraTraffic = true; - boolean bUnprotected = true; - boolean bShared = true; - boolean bDedOneIstoOne = true; - boolean bDedOnePlusOne = true; - boolean bEnhanced = true; - - boolean bExtraTraffic1 = false; - boolean bUnprotected1 = false; - boolean bShared1 = false; - boolean bDedOneIstoOne1 = false; - boolean bDedOnePlusOne1 = false; - boolean bEnhanced1 = false; - - private final BgpLinkAttrProtectionType data = BgpLinkAttrProtectionType - .of(bExtraTraffic, bUnprotected, bShared, bDedOneIstoOne, - bDedOnePlusOne, bEnhanced); - private final BgpLinkAttrProtectionType sameAsData = BgpLinkAttrProtectionType - .of(bExtraTraffic, bUnprotected, bShared, bDedOneIstoOne, - bDedOnePlusOne, bEnhanced); - private final BgpLinkAttrProtectionType diffData = BgpLinkAttrProtectionType - .of(bExtraTraffic1, bUnprotected1, bShared1, bDedOneIstoOne1, - bDedOnePlusOne1, bEnhanced1); - - @Test - public void basics() { - - new EqualsTester().addEqualityGroup(data, sameAsData) - .addEqualityGroup(diffData).testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpNotificationMsgTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpNotificationMsgTest.java deleted file mode 100644 index d3e6e49c..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpNotificationMsgTest.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * 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.bgp; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.core.Is.is; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.junit.Test; -import org.onosproject.bgpio.exceptions.BGPParseException; -import org.onosproject.bgpio.protocol.BGPFactories; -import org.onosproject.bgpio.protocol.BGPMessage; -import org.onosproject.bgpio.protocol.BGPMessageReader; -import org.onosproject.bgpio.protocol.BGPNotificationMsg; -import org.onosproject.bgpio.types.BGPHeader; - -/** - * Test for Notification message. - */ -public class BgpNotificationMsgTest { - - /** - * Notification message with error code, error subcode and data. - * - * @throws BGPParseException while decoding and encoding notification message - */ - @Test - public void bgpNotificationMessageTest1() throws BGPParseException { - byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, 0x00, - 0x17, 0x03, 0x02, 0x02, - (byte) 0xfe, (byte) 0xb0}; - - byte[] testNotificationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(notificationMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message = null; - BGPHeader bgpHeader = new BGPHeader(); - - message = reader.readFrom(buffer, bgpHeader); - assertThat(message, instanceOf(BGPNotificationMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testNotificationMsg = buf.array(); - - int iReadLen = buf.writerIndex() - 0; - testNotificationMsg = new byte[iReadLen]; - buf.readBytes(testNotificationMsg, 0, iReadLen); - assertThat(testNotificationMsg, is(notificationMsg)); - } - - /** - * Notification message without data. - * - * @throws BGPParseException while decoding and encoding notification message - */ - @Test - public void bgpNotificationMessageTest2() throws BGPParseException { - byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, 0x00, - 0x15, 0x03, 0x02, 0x00}; - - byte[] testNotificationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(notificationMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message = null; - BGPHeader bgpHeader = new BGPHeader(); - - message = reader.readFrom(buffer, bgpHeader); - assertThat(message, instanceOf(BGPNotificationMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testNotificationMsg = buf.array(); - - int iReadLen = buf.writerIndex() - 0; - testNotificationMsg = new byte[iReadLen]; - buf.readBytes(testNotificationMsg, 0, iReadLen); - assertThat(testNotificationMsg, is(notificationMsg)); - } - - //Negative scenarios - /** - * Notification message with wrong maker value. - * - * @throws BGPParseException while decoding and encoding notification message - */ - @Test(expected = BGPParseException.class) - public void bgpNotificationMessageTest3() throws BGPParseException { - byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - 0x01, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, 0x00, - 0x15, 0x03, 0x02, 0x00}; - - byte[] testNotificationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(notificationMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message = null; - BGPHeader bgpHeader = new BGPHeader(); - - message = reader.readFrom(buffer, bgpHeader); - assertThat(message, instanceOf(BGPNotificationMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testNotificationMsg = buf.array(); - - int iReadLen = buf.writerIndex() - 0; - testNotificationMsg = new byte[iReadLen]; - buf.readBytes(testNotificationMsg, 0, iReadLen); - assertThat(testNotificationMsg, is(notificationMsg)); - } - - /** - * Notification message without error subcode. - * - * @throws BGPParseException while decoding and encoding notification message - */ - @Test(expected = BGPParseException.class) - public void bgpNotificationMessageTest4() throws BGPParseException { - byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, 0x00, - 0x14, 0x03, 0x02}; - - byte[] testNotificationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(notificationMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message = null; - BGPHeader bgpHeader = new BGPHeader(); - - message = reader.readFrom(buffer, bgpHeader); - assertThat(message, instanceOf(BGPNotificationMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testNotificationMsg = buf.array(); - - int iReadLen = buf.writerIndex() - 0; - testNotificationMsg = new byte[iReadLen]; - buf.readBytes(testNotificationMsg, 0, iReadLen); - assertThat(testNotificationMsg, is(notificationMsg)); - } - - /** - * Notification message with wrong message length. - * - * @throws BGPParseException while decoding and encoding notification message - */ - @Test(expected = BGPParseException.class) - public void bgpNotificationMessageTest5() throws BGPParseException { - byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, - (byte) 0xff, (byte) 0xff, 0x00, - 0x14, 0x03, 0x02, 0x02}; - - byte[] testNotificationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(notificationMsg); - - BGPMessageReader reader = BGPFactories.getGenericReader(); - BGPMessage message = null; - BGPHeader bgpHeader = new BGPHeader(); - - message = reader.readFrom(buffer, bgpHeader); - assertThat(message, instanceOf(BGPNotificationMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testNotificationMsg = buf.array(); - - int iReadLen = buf.writerIndex() - 0; - testNotificationMsg = new byte[iReadLen]; - buf.readBytes(testNotificationMsg, 0, iReadLen); - assertThat(testNotificationMsg, is(notificationMsg)); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrMetricTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrMetricTest.java deleted file mode 100644 index 5a3662be..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrMetricTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onosproject.bgpio.types.attr.BgpPrefixAttrMetric; - -import com.google.common.testing.EqualsTester; - -/** - * Test for BGP prefix metric attribute. - */ -public class BgpPrefixAttrMetricTest { - private final int val = 1111; - private final int val1 = 2222; - - private final BgpPrefixAttrMetric data = BgpPrefixAttrMetric.of(val); - private final BgpPrefixAttrMetric sameAsData = BgpPrefixAttrMetric.of(val); - private final BgpPrefixAttrMetric diffData = BgpPrefixAttrMetric.of(val1); - - @Test - public void basics() { - - new EqualsTester().addEqualityGroup(data, sameAsData) - .addEqualityGroup(diffData).testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrOspfFwdAddrTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrOspfFwdAddrTest.java deleted file mode 100644 index f736bead..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrOspfFwdAddrTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onlab.packet.Ip4Address; -import org.onlab.packet.Ip6Address; -import org.onosproject.bgpio.types.attr.BgpPrefixAttrOspfFwdAddr; - -import com.google.common.testing.EqualsTester; - -/** - * Test for BGP prefix metric attribute. - */ -public class BgpPrefixAttrOspfFwdAddrTest { - - private final short lsAttrLength = 4; - private final Ip4Address ip4RouterId = Ip4Address.valueOf("192.168.1.1"); - private final Ip6Address ip6RouterId = Ip6Address - .valueOf("2001:0db8:0a0b:12f0:0000:0000:0000:0001"); - - private final short lsAttrLength1 = 16; - private final Ip4Address ip4RouterId1 = Ip4Address.valueOf("192.168.1.2"); - private final Ip6Address ip6RouterId1 = Ip6Address - .valueOf("1002:0db8:0a0b:12f0:0000:0000:0000:0002"); - - private final BgpPrefixAttrOspfFwdAddr data = BgpPrefixAttrOspfFwdAddr - .of(lsAttrLength, ip4RouterId, ip6RouterId); - private final BgpPrefixAttrOspfFwdAddr sameAsData = BgpPrefixAttrOspfFwdAddr - .of(lsAttrLength, ip4RouterId, ip6RouterId); - private final BgpPrefixAttrOspfFwdAddr diffData = BgpPrefixAttrOspfFwdAddr - .of(lsAttrLength1, ip4RouterId1, ip6RouterId1); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(data, sameAsData) - .addEqualityGroup(diffData).testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IPReachabilityInformationTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IPReachabilityInformationTest.java deleted file mode 100644 index 81f4b725..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IPReachabilityInformationTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2014-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.bgp; - -import org.junit.Test; -import org.onosproject.bgpio.types.IPReachabilityInformationTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test for IPReachabilityInformation Tlv. - */ -public class IPReachabilityInformationTest { - private final byte[] value1 = new byte[] {(byte) 0xc0, (byte) 0xa8, 0x4d, 0x01}; - private final byte[] value2 = new byte[] {(byte) 0xc0}; - private final IPReachabilityInformationTlv tlv1 = IPReachabilityInformationTlv.of((byte) 0x17, value1, (short) 4); - private final IPReachabilityInformationTlv sameAsTlv1 = IPReachabilityInformationTlv - .of((byte) 0x17, value1, (short) 4); - private final IPReachabilityInformationTlv tlv2 = IPReachabilityInformationTlv.of((byte) 0x05, value2, (short) 1); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IPv4AddressTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IPv4AddressTest.java deleted file mode 100755 index f3a0469c..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IPv4AddressTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2014-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.bgp; - -import org.junit.Test; -import org.onlab.packet.Ip4Address; -import org.onosproject.bgpio.types.IPv4AddressTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test for IPv4Address Tlv. - */ -public class IPv4AddressTest { - private final Ip4Address value1 = Ip4Address.valueOf("127.0.0.1"); - private final Ip4Address value2 = Ip4Address.valueOf("127.0.0.1"); - private final IPv4AddressTlv tlv1 = IPv4AddressTlv.of(value1, (short) 259); - private final IPv4AddressTlv sameAsTlv1 = IPv4AddressTlv.of(value1, (short) 259); - private final IPv4AddressTlv tlv2 = IPv4AddressTlv.of(value2, (short) 260); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IPv6AddressTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IPv6AddressTest.java deleted file mode 100644 index 2023093f..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IPv6AddressTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onlab.packet.Ip6Address; -import org.onosproject.bgpio.types.IPv6AddressTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test for IPv6Address Tlv. - */ -public class IPv6AddressTest { - private final Ip6Address value1 = Ip6Address.valueOf("2001:db8:0:0:0:0:2:1"); - private final Ip6Address value2 = Ip6Address.valueOf("2001:db8:0:0:0:0:2:1"); - private final IPv6AddressTlv tlv1 = IPv6AddressTlv.of(value1, (short) 261); - private final IPv6AddressTlv sameAsTlv1 = IPv6AddressTlv.of(value1, (short) 261); - private final IPv6AddressTlv tlv2 = IPv6AddressTlv.of(value2, (short) 262); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IsIsNonPseudonodeTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IsIsNonPseudonodeTest.java deleted file mode 100644 index 8112b51c..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IsIsNonPseudonodeTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2014-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.bgp; - -import org.junit.Test; -import org.onosproject.bgpio.types.IsIsNonPseudonode; - -import com.google.common.testing.EqualsTester; - -/** - * Test for IsIsNonPseudonode Tlv. - */ -public class IsIsNonPseudonodeTest { - private final byte[] value1 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; - private final byte[] value2 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x59}; - private final IsIsNonPseudonode tlv1 = IsIsNonPseudonode.of(value1); - private final IsIsNonPseudonode sameAsTlv1 = IsIsNonPseudonode.of(value1); - private final IsIsNonPseudonode tlv2 = IsIsNonPseudonode.of(value2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IsIsPseudonodeTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IsIsPseudonodeTest.java deleted file mode 100644 index bbc9e6a2..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/IsIsPseudonodeTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onosproject.bgpio.types.IsIsPseudonode; - -import com.google.common.testing.EqualsTester; - -/** - * Test for IsIsPseudonode Tlv. - */ -public class IsIsPseudonodeTest { - private final byte[] value1 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x02}; - private final byte[] value2 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x03}; - private final IsIsPseudonode tlv1 = IsIsPseudonode.of(value1, (byte) 1); - private final IsIsPseudonode sameAsTlv1 = IsIsPseudonode.of(value1, (byte) 1); - private final IsIsPseudonode tlv2 = IsIsPseudonode.of(value2, (byte) 1); - - @Test - public void testEquality() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/LinkLocalRemoteIdentifiersTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/LinkLocalRemoteIdentifiersTest.java deleted file mode 100644 index 22b9aba3..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/LinkLocalRemoteIdentifiersTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test for LinkLocalRemoteIdentifiers Tlv. - */ -public class LinkLocalRemoteIdentifiersTest { - private final int value1 = 0x12101010; - private final int value2 = 0x12101012; - private final LinkLocalRemoteIdentifiersTlv tlv1 = LinkLocalRemoteIdentifiersTlv.of(value1, value2); - private final LinkLocalRemoteIdentifiersTlv sameAsTlv1 = LinkLocalRemoteIdentifiersTlv.of(value1, value2); - private final LinkLocalRemoteIdentifiersTlv tlv2 = LinkLocalRemoteIdentifiersTlv.of(value2, value1); - - @Test - public void testEquality() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/NextHopTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/NextHopTest.java deleted file mode 100755 index 109197bb..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/NextHopTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onlab.packet.Ip4Address; -import org.onosproject.bgpio.types.NextHop; - -import com.google.common.testing.EqualsTester; - -/** - * Test for NextHop BGP Path Attribute. - */ -public class NextHopTest { - private final Ip4Address value1 = Ip4Address.valueOf("12.12.12.12"); - private final Ip4Address value2 = Ip4Address.valueOf("12.12.12.13"); - private final NextHop attr1 = new NextHop(value1); - private final NextHop sameAsAttr1 = new NextHop(value1); - private final NextHop attr2 = new NextHop(value2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(attr1, sameAsAttr1) - .addEqualityGroup(attr2) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OriginTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OriginTest.java deleted file mode 100644 index 88261ad5..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OriginTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onosproject.bgpio.types.Origin; - -import com.google.common.testing.EqualsTester; - -/** - * Test for Origin BGP Path Attribute. - */ -public class OriginTest { - private final byte value1 = 0x01; - private final byte value2 = 0x02; - private final Origin attr1 = new Origin(value1); - private final Origin sameAsAttr1 = new Origin(value1); - private final Origin attr2 = new Origin(value2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(attr1, sameAsAttr1) - .addEqualityGroup(attr2) - .testEquals(); - } -} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OspfNonPseudonodeTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OspfNonPseudonodeTest.java deleted file mode 100644 index 19002913..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OspfNonPseudonodeTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2014-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.bgp; - -import org.junit.Test; -import org.onosproject.bgpio.types.OSPFNonPseudonode; - -import com.google.common.testing.EqualsTester; - -/** - * Test for OSPFNonPseudonode Tlv. - */ -public class OspfNonPseudonodeTest { - private final int value1 = 0x12121212; - private final int value2 = 0x12121211; - private final OSPFNonPseudonode tlv1 = OSPFNonPseudonode.of(value1); - private final OSPFNonPseudonode sameAsTlv1 = OSPFNonPseudonode.of(value1); - private final OSPFNonPseudonode tlv2 = OSPFNonPseudonode.of(value2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OspfPseudonodeTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OspfPseudonodeTest.java deleted file mode 100644 index 55b1190b..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OspfPseudonodeTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onlab.packet.Ip4Address; -import org.onosproject.bgpio.types.OSPFPseudonode; - -import com.google.common.testing.EqualsTester; - -/** - * Test for OSPFPseudonode Tlv. - */ -public class OspfPseudonodeTest { - private final int value1 = 0xc3223409; - private final int value2 = 0xc3223406; - private final Ip4Address drInterface1 = Ip4Address.valueOf(0xaf91e01); - private final Ip4Address drInterface2 = Ip4Address.valueOf(0xaf91e02); - private final OSPFPseudonode tlv1 = OSPFPseudonode.of(value1, drInterface1); - private final OSPFPseudonode sameAsTlv1 = OSPFPseudonode.of(value1, drInterface1); - private final OSPFPseudonode tlv2 = OSPFPseudonode.of(value2, drInterface2); - - @Test - public void testEquality() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OspfRouteTypeTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OspfRouteTypeTest.java deleted file mode 100644 index e2fd1eaf..00000000 --- a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/OspfRouteTypeTest.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.bgp; - -import org.junit.Test; -import org.onosproject.bgpio.types.OSPFRouteTypeTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test for OSPFRouteType Tlv. - */ -public class OspfRouteTypeTest { - private final byte value1 = 5; - private final byte value2 = 4; - private final OSPFRouteTypeTlv tlv1 = OSPFRouteTypeTlv.of(value1); - private final OSPFRouteTypeTlv sameAsTlv1 = OSPFRouteTypeTlv.of(value1); - private final OSPFRouteTypeTlv tlv2 = OSPFRouteTypeTlv.of(value2); - - @Test - public void testEquality() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} \ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPKeepaliveMsgTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPKeepaliveMsgTest.java new file mode 100755 index 00000000..68ce3070 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPKeepaliveMsgTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2014-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.bgpio.protocol; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.junit.Test; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.types.BGPHeader; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.core.Is.is; + +/** + * Test case for BGP KEEPALIVE Message. + */ +public class BGPKeepaliveMsgTest { + + /** + * This test case checks BGP Keepalive message. + */ + @Test + public void keepaliveMessageTest1() throws BGPParseException { + + // BGP KEEPALIVE Message + byte[] keepaliveMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + 0x00, 0x13, 0x04}; + + byte[] testKeepaliveMsg; + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(keepaliveMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message; + BGPHeader bgpHeader = new BGPHeader(); + + message = reader.readFrom(buffer, bgpHeader); + + assertThat(message, instanceOf(BGPKeepaliveMsg.class)); + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); + message.writeTo(buf); + + int readLen = buf.writerIndex(); + testKeepaliveMsg = new byte[readLen]; + buf.readBytes(testKeepaliveMsg, 0, readLen); + + assertThat(testKeepaliveMsg, is(keepaliveMsg)); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPOpenMsgTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPOpenMsgTest.java new file mode 100755 index 00000000..d5210177 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BGPOpenMsgTest.java @@ -0,0 +1,314 @@ +/* + * Copyright 2014-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.bgpio.protocol; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.junit.Test; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.types.BGPHeader; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.core.Is.is; + +/** + * Test cases for BGP Open Message. + */ +public class BGPOpenMsgTest { + + /** + * This test case checks open message without optional parameter. + */ + @Test + public void openMessageTest1() throws BGPParseException { + //Open message without optional parameter + byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff, + 0x00, 0x1d, 0x01, 0X04, (byte) 0xfe, 0x09, 0x00, + (byte) 0xb4, (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f, + 0x00}; + + byte[] testOpenMsg; + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(openMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message; + BGPHeader bgpHeader = new BGPHeader(); + message = reader.readFrom(buffer, bgpHeader); + + assertThat(message, instanceOf(BGPOpenMsg.class)); + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); + message.writeTo(buf); + + int readLen = buf.writerIndex(); + testOpenMsg = new byte[readLen]; + buf.readBytes(testOpenMsg, 0, readLen); + + assertThat(testOpenMsg, is(openMsg)); + } + + /** + * This test case checks open message with Multiprotocol extension + * capability. + */ + @Test + public void openMessageTest2() throws BGPParseException { + + // OPEN Message (MultiProtocolExtension-CAPABILITY). + byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, 0x00, 0x25, + 0x01, //BGP Header + 0X04, //Version + (byte) 0x00, (byte) 0xc8, // AS Number + 0x00, (byte) 0xb4, // Hold time + (byte) 0xb6, (byte) 0x02, 0x5d, + (byte) 0xc8, // BGP Identifier + 0x08, 0x02, 0x06, // Opt Parameter length + 0x01, 0x04, 0x00, 0x00, 0x00, (byte) 0xc8}; // Multiprotocol CAPABILITY + + byte[] testOpenMsg; + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(openMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message; + BGPHeader bgpHeader = new BGPHeader(); + + message = reader.readFrom(buffer, bgpHeader); + + assertThat(message, instanceOf(BGPOpenMsg.class)); + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); + message.writeTo(buf); + + int readLen = buf.writerIndex(); + testOpenMsg = new byte[readLen]; + buf.readBytes(testOpenMsg, 0, readLen); + + assertThat(testOpenMsg, is(openMsg)); + } + + /** + * This test case checks open message with Four-octet AS number + * capability. + */ + @Test + public void openMessageTest3() throws BGPParseException { + + // OPEN Message (Four-Octet AS number capability). + byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, 0x00, 0x25, + 0x01, //BGPHeader + 0X04, //Version + (byte) 0x00, (byte) 0xc8, //AS Number + 0x00, (byte) 0xb4, //Hold Time + (byte) 0xb6, (byte) 0x02, 0x5d, + (byte) 0xc8, //BGP Identifier + 0x08, 0x02, 0x06, //Opt Parameter Length + 0x41, 0x04, 0x00, 0x01, 0x00, 0x01}; //Four Octet AS Number-CAPABILITY-TLV + + byte[] testOpenMsg; + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(openMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message; + BGPHeader bgpHeader = new BGPHeader(); + + message = reader.readFrom(buffer, bgpHeader); + + assertThat(message, instanceOf(BGPOpenMsg.class)); + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); + message.writeTo(buf); + + int readLen = buf.writerIndex(); + testOpenMsg = new byte[readLen]; + buf.readBytes(testOpenMsg, 0, readLen); + + assertThat(testOpenMsg, is(openMsg)); + } + + /** + * This test case checks open message with capabilities. + */ + @Test + public void openMessageTest4() throws BGPParseException { + + // OPEN Message with capabilities. + byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, 0x00, 0x2b, + 0x01, //BGPHeader + 0X04, //Version + (byte) 0x00, (byte) 0xc8, //AS Number + 0x00, (byte) 0xb4, //Hold Time + (byte) 0xb6, (byte) 0x02, 0x5d, (byte) 0xc8, //BGP Identifier + 0x0e, 0x02, 0x0c, //Opt Parameter Length + 0x01, 0x04, 0x00, 0x00, 0x00, (byte) 0xc8, // Multiprotocol extension capability + 0x41, 0x04, 0x00, 0x01, 0x00, 0x01}; //Four Octet AS Number-CAPABILITY-TLV + + byte[] testOpenMsg; + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(openMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message; + BGPHeader bgpHeader = new BGPHeader(); + + message = reader.readFrom(buffer, bgpHeader); + + assertThat(message, instanceOf(BGPOpenMsg.class)); + + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); + message.writeTo(buf); + + int readLen = buf.writerIndex(); + testOpenMsg = new byte[readLen]; + buf.readBytes(testOpenMsg, 0, readLen); + + assertThat(testOpenMsg, is(openMsg)); + } + + /** + * In this test case, Invalid version is given as input and expecting + * an exception. + */ + @Test(expected = BGPParseException.class) + public void openMessageTest5() throws BGPParseException { + + // OPEN Message with invalid version number. + byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, 0x00, 0x1d, 0x01, 0X05, + (byte) 0xfe, 0x09, 0x00, (byte) 0xb4, + (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f, + 0x00}; + + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(openMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message; + BGPHeader bgpHeader = new BGPHeader(); + message = reader.readFrom(buffer, bgpHeader); + + assertThat(message, instanceOf(BGPOpenMsg.class)); + } + + /** + * In this test case, Marker is set as 0 in input and expecting + * an exception. + */ + @Test(expected = BGPParseException.class) + public void openMessageTest6() throws BGPParseException { + + // OPEN Message with marker set to 0. + byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0x00, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + 0x00, 0x00, 0x1d, 0x01, 0X04, + (byte) 0xfe, 0x09, 0x00, (byte) 0xb4, + (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f, + 0x00}; + + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(openMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message; + BGPHeader bgpHeader = new BGPHeader(); + message = reader.readFrom(buffer, bgpHeader); + + assertThat(message, instanceOf(BGPOpenMsg.class)); + } + + /** + * In this test case, Invalid message length is given as input and expecting + * an exception. + */ + @Test(expected = BGPParseException.class) + public void openMessageTest7() throws BGPParseException { + + // OPEN Message with invalid header length. + byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, 0x00, 0x1e, 0x01, 0X04, + (byte) 0xfe, 0x09, 0x00, (byte) 0xb4, + (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f, + 0x00}; + + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(openMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message; + BGPHeader bgpHeader = new BGPHeader(); + message = reader.readFrom(buffer, bgpHeader); + + assertThat(message, instanceOf(BGPOpenMsg.class)); + } + + /** + * In this test case, Invalid message type is given as input and expecting + * an exception. + */ + @Test(expected = BGPParseException.class) + public void openMessageTest8() throws BGPParseException { + + // OPEN Message with invalid message type. + byte[] openMsg = new byte[] {(byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, (byte) 0xff, + (byte) 0xff, 0x00, 0x1d, 0x05, 0X04, + (byte) 0xfe, 0x09, 0x00, (byte) 0xb4, + (byte) 0xc0, (byte) 0xa8, 0x00, 0x0f, + 0x00}; + + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(openMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message; + BGPHeader bgpHeader = new BGPHeader(); + message = reader.readFrom(buffer, bgpHeader); + + assertThat(message, instanceOf(BGPOpenMsg.class)); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpNotificationMsgTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpNotificationMsgTest.java new file mode 100644 index 00000000..78edf133 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/protocol/BgpNotificationMsgTest.java @@ -0,0 +1,224 @@ +/* + * 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.bgpio.protocol; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +import org.junit.Test; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.types.BGPHeader; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.core.Is.is; + +/** + * Test for Notification message. + */ +public class BgpNotificationMsgTest { + + /** + * Notification message with error code, error subcode and data. + * + * @throws BGPParseException while decoding and encoding notification message + */ + @Test + public void bgpNotificationMessageTest1() throws BGPParseException { + byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, 0x00, + 0x17, 0x03, 0x02, 0x02, + (byte) 0xfe, (byte) 0xb0}; + + byte[] testNotificationMsg = {0}; + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(notificationMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message = null; + BGPHeader bgpHeader = new BGPHeader(); + + message = reader.readFrom(buffer, bgpHeader); + assertThat(message, instanceOf(BGPNotificationMsg.class)); + + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); + message.writeTo(buf); + testNotificationMsg = buf.array(); + + int iReadLen = buf.writerIndex() - 0; + testNotificationMsg = new byte[iReadLen]; + buf.readBytes(testNotificationMsg, 0, iReadLen); + assertThat(testNotificationMsg, is(notificationMsg)); + } + + /** + * Notification message without data. + * + * @throws BGPParseException while decoding and encoding notification message + */ + @Test + public void bgpNotificationMessageTest2() throws BGPParseException { + byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, 0x00, + 0x15, 0x03, 0x02, 0x00}; + + byte[] testNotificationMsg = {0}; + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(notificationMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message = null; + BGPHeader bgpHeader = new BGPHeader(); + + message = reader.readFrom(buffer, bgpHeader); + assertThat(message, instanceOf(BGPNotificationMsg.class)); + + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); + message.writeTo(buf); + testNotificationMsg = buf.array(); + + int iReadLen = buf.writerIndex() - 0; + testNotificationMsg = new byte[iReadLen]; + buf.readBytes(testNotificationMsg, 0, iReadLen); + assertThat(testNotificationMsg, is(notificationMsg)); + } + + //Negative scenarios + /** + * Notification message with wrong maker value. + * + * @throws BGPParseException while decoding and encoding notification message + */ + @Test(expected = BGPParseException.class) + public void bgpNotificationMessageTest3() throws BGPParseException { + byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + 0x01, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, 0x00, + 0x15, 0x03, 0x02, 0x00}; + + byte[] testNotificationMsg = {0}; + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(notificationMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message = null; + BGPHeader bgpHeader = new BGPHeader(); + + message = reader.readFrom(buffer, bgpHeader); + assertThat(message, instanceOf(BGPNotificationMsg.class)); + + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); + message.writeTo(buf); + testNotificationMsg = buf.array(); + + int iReadLen = buf.writerIndex() - 0; + testNotificationMsg = new byte[iReadLen]; + buf.readBytes(testNotificationMsg, 0, iReadLen); + assertThat(testNotificationMsg, is(notificationMsg)); + } + + /** + * Notification message without error subcode. + * + * @throws BGPParseException while decoding and encoding notification message + */ + @Test(expected = BGPParseException.class) + public void bgpNotificationMessageTest4() throws BGPParseException { + byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, 0x00, + 0x14, 0x03, 0x02}; + + byte[] testNotificationMsg = {0}; + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(notificationMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message = null; + BGPHeader bgpHeader = new BGPHeader(); + + message = reader.readFrom(buffer, bgpHeader); + assertThat(message, instanceOf(BGPNotificationMsg.class)); + + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); + message.writeTo(buf); + testNotificationMsg = buf.array(); + + int iReadLen = buf.writerIndex() - 0; + testNotificationMsg = new byte[iReadLen]; + buf.readBytes(testNotificationMsg, 0, iReadLen); + assertThat(testNotificationMsg, is(notificationMsg)); + } + + /** + * Notification message with wrong message length. + * + * @throws BGPParseException while decoding and encoding notification message + */ + @Test(expected = BGPParseException.class) + public void bgpNotificationMessageTest5() throws BGPParseException { + byte[] notificationMsg = new byte[] {(byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, + (byte) 0xff, (byte) 0xff, 0x00, + 0x14, 0x03, 0x02, 0x02}; + + byte[] testNotificationMsg = {0}; + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + buffer.writeBytes(notificationMsg); + + BGPMessageReader reader = BGPFactories.getGenericReader(); + BGPMessage message = null; + BGPHeader bgpHeader = new BGPHeader(); + + message = reader.readFrom(buffer, bgpHeader); + assertThat(message, instanceOf(BGPNotificationMsg.class)); + + ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); + message.writeTo(buf); + testNotificationMsg = buf.array(); + + int iReadLen = buf.writerIndex() - 0; + testNotificationMsg = new byte[iReadLen]; + buf.readBytes(testNotificationMsg, 0, iReadLen); + assertThat(testNotificationMsg, is(notificationMsg)); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AreaIdTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AreaIdTest.java new file mode 100644 index 00000000..6a9e2ec5 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AreaIdTest.java @@ -0,0 +1,77 @@ +/* + * 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.bgpio.types; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for AreaID Tlv. + */ +public class AreaIdTest { + private final int value1 = 10; + private final int value2 = 20; + private final AreaIDTlv tlv1 = AreaIDTlv.of(value1); + private final AreaIDTlv sameAsTlv1 = AreaIDTlv.of(value1); + private final AreaIDTlv tlv2 = AreaIDTlv.of(value2); + + @Test + public void testEquality() { + new EqualsTester() + .addEqualityGroup(tlv1, sameAsTlv1) + .addEqualityGroup(tlv2) + .testEquals(); + } + + /** + * Test for OSPFNonPseudonode Tlv. + */ + public static class OspfNonPseudonodeTest { + private final int value1 = 0x12121212; + private final int value2 = 0x12121211; + private final OSPFNonPseudonode tlv1 = OSPFNonPseudonode.of(value1); + private final OSPFNonPseudonode sameAsTlv1 = OSPFNonPseudonode.of(value1); + private final OSPFNonPseudonode tlv2 = OSPFNonPseudonode.of(value2); + + @Test + public void basics() { + new EqualsTester() + .addEqualityGroup(tlv1, sameAsTlv1) + .addEqualityGroup(tlv2) + .testEquals(); + } + } + + /** + * Test for IsIsNonPseudonode Tlv. + */ + public static class IsIsNonPseudonodeTest { + private final byte[] value1 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x58}; + private final byte[] value2 = new byte[] {0x19, 0x00, (byte) 0x95, 0x01, (byte) 0x90, 0x59}; + private final IsIsNonPseudonode tlv1 = IsIsNonPseudonode.of(value1); + private final IsIsNonPseudonode sameAsTlv1 = IsIsNonPseudonode.of(value1); + private final IsIsNonPseudonode tlv2 = IsIsNonPseudonode.of(value2); + + @Test + public void basics() { + new EqualsTester() + .addEqualityGroup(tlv1, sameAsTlv1) + .addEqualityGroup(tlv2) + .testEquals(); + } + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/As4PathTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/As4PathTest.java new file mode 100755 index 00000000..3ea56b64 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/As4PathTest.java @@ -0,0 +1,55 @@ +/* + * 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.bgpio.types; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for As4Path BGP Path Attribute. + */ +public class As4PathTest { + //Two scenarios as4path set and sequence + private final List as4pathSet1 = new ArrayList<>(); + private final List as4pathSeq1 = new ArrayList<>(); + private final List as4pathSet2 = new ArrayList<>(); + private final List as4pathSeq2 = new ArrayList<>(); + private final As4Path attr1 = new As4Path(as4pathSet1, null); + private final As4Path sameAsAttr1 = new As4Path(as4pathSet1, null); + private final As4Path attr2 = new As4Path(as4pathSet2, null); + private final As4Path attr3 = new As4Path(null, as4pathSeq1); + private final As4Path sameAsAttr3 = new As4Path(null, as4pathSeq1); + private final As4Path attr4 = new As4Path(null, as4pathSeq2); + + @Test + public void basics() { + as4pathSet1.add(197358); + as4pathSet1.add(12883); + as4pathSet2.add(2008989); + as4pathSeq1.add(3009009); + as4pathSeq2.add(409900); + new EqualsTester() + .addEqualityGroup(attr1, sameAsAttr1) + .addEqualityGroup(attr2) + .addEqualityGroup(attr3, sameAsAttr3) + .addEqualityGroup(attr4) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AsPathTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AsPathTest.java new file mode 100644 index 00000000..e56ec5a5 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AsPathTest.java @@ -0,0 +1,55 @@ +/* + * 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.bgpio.types; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for AsPath BGP Path Attribute. + */ +public class AsPathTest { + //Two scenarios aspath set and sequence + private final List aspathSet1 = new ArrayList<>(); + private final List aspathSet2 = new ArrayList<>(); + private final List aspathSeq1 = new ArrayList<>(); + private final List aspathSeq2 = new ArrayList<>(); + private final AsPath attr1 = new AsPath(aspathSet1, null); + private final AsPath sameAsAttr1 = new AsPath(aspathSet1, null); + private final AsPath attr2 = new AsPath(aspathSet2, null); + private final AsPath attr3 = new AsPath(null, aspathSeq1); + private final AsPath sameAsAttr3 = new AsPath(null, aspathSeq1); + private final AsPath attr4 = new AsPath(null, aspathSeq2); + + @Test + public void basics() { + aspathSet1.add((short) 100); + aspathSet1.add((short) 300); + aspathSet2.add((short) 200); + aspathSeq2.add((short) 400); + aspathSeq1.add((short) 300); + new EqualsTester() + .addEqualityGroup(attr1, sameAsAttr1) + .addEqualityGroup(attr2) + .addEqualityGroup(attr3, sameAsAttr3) + .addEqualityGroup(attr4) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AutonomousSystemTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AutonomousSystemTest.java new file mode 100644 index 00000000..1695583b --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AutonomousSystemTest.java @@ -0,0 +1,39 @@ +/* + * 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.bgpio.types; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for AutonomousSystem Tlv. + */ +public class AutonomousSystemTest { + private final int value1 = 101; + private final int value2 = 201; + private final AutonomousSystemTlv tlv1 = AutonomousSystemTlv.of(value1); + private final AutonomousSystemTlv sameAsTlv1 = AutonomousSystemTlv.of(value1); + private final AutonomousSystemTlv tlv2 = AutonomousSystemTlv.of(value2); + + @Test + public void testEquality() { + new EqualsTester() + .addEqualityGroup(tlv1, sameAsTlv1) + .addEqualityGroup(tlv2) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BGPLSIdentifierTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BGPLSIdentifierTest.java new file mode 100644 index 00000000..f3355d35 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BGPLSIdentifierTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2014-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.bgpio.types; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for BGPLSIdentifier Tlv. + */ +public class BGPLSIdentifierTest { + private final int value1 = 8738; + private final int value2 = 13107; + private final BGPLSIdentifierTlv tlv1 = BGPLSIdentifierTlv.of(value1); + private final BGPLSIdentifierTlv sameAsTlv1 = new BGPLSIdentifierTlv(value1); + private final BGPLSIdentifierTlv tlv2 = new BGPLSIdentifierTlv(value2); + + @Test + public void basics() { + new EqualsTester() + .addEqualityGroup(tlv1, sameAsTlv1) + .addEqualityGroup(tlv2) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPReachabilityInformationTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPReachabilityInformationTest.java new file mode 100644 index 00000000..7bea518a --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPReachabilityInformationTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2014-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.bgpio.types; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for IPReachabilityInformation Tlv. + */ +public class IPReachabilityInformationTest { + private final byte[] value1 = new byte[] {(byte) 0xc0, (byte) 0xa8, 0x4d, 0x01}; + private final byte[] value2 = new byte[] {(byte) 0xc0}; + private final IPReachabilityInformationTlv tlv1 = IPReachabilityInformationTlv.of((byte) 0x17, value1, (short) 4); + private final IPReachabilityInformationTlv sameAsTlv1 = IPReachabilityInformationTlv + .of((byte) 0x17, value1, (short) 4); + private final IPReachabilityInformationTlv tlv2 = IPReachabilityInformationTlv.of((byte) 0x05, value2, (short) 1); + + @Test + public void basics() { + new EqualsTester() + .addEqualityGroup(tlv1, sameAsTlv1) + .addEqualityGroup(tlv2) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPv4AddressTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPv4AddressTest.java new file mode 100755 index 00000000..fdb71189 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPv4AddressTest.java @@ -0,0 +1,40 @@ +/* + * Copyright 2014-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.bgpio.types; + +import org.junit.Test; +import org.onlab.packet.Ip4Address; + +import com.google.common.testing.EqualsTester; + +/** + * Test for IPv4Address Tlv. + */ +public class IPv4AddressTest { + private final Ip4Address value1 = Ip4Address.valueOf("127.0.0.1"); + private final Ip4Address value2 = Ip4Address.valueOf("127.0.0.1"); + private final IPv4AddressTlv tlv1 = IPv4AddressTlv.of(value1, (short) 259); + private final IPv4AddressTlv sameAsTlv1 = IPv4AddressTlv.of(value1, (short) 259); + private final IPv4AddressTlv tlv2 = IPv4AddressTlv.of(value2, (short) 260); + + @Test + public void basics() { + new EqualsTester() + .addEqualityGroup(tlv1, sameAsTlv1) + .addEqualityGroup(tlv2) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPv6AddressTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPv6AddressTest.java new file mode 100644 index 00000000..781935b4 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPv6AddressTest.java @@ -0,0 +1,40 @@ +/* + * 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.bgpio.types; + +import org.junit.Test; +import org.onlab.packet.Ip6Address; + +import com.google.common.testing.EqualsTester; + +/** + * Test for IPv6Address Tlv. + */ +public class IPv6AddressTest { + private final Ip6Address value1 = Ip6Address.valueOf("2001:db8:0:0:0:0:2:1"); + private final Ip6Address value2 = Ip6Address.valueOf("2001:db8:0:0:0:0:2:1"); + private final IPv6AddressTlv tlv1 = IPv6AddressTlv.of(value1, (short) 261); + private final IPv6AddressTlv sameAsTlv1 = IPv6AddressTlv.of(value1, (short) 261); + private final IPv6AddressTlv tlv2 = IPv6AddressTlv.of(value2, (short) 262); + + @Test + public void basics() { + new EqualsTester() + .addEqualityGroup(tlv1, sameAsTlv1) + .addEqualityGroup(tlv2) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java new file mode 100644 index 00000000..a2a7c2b5 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.java @@ -0,0 +1,39 @@ +/* + * 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.bgpio.types; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for IsIsPseudonode Tlv. + */ +public class IsIsPseudonodeTest { + private final byte[] value1 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x02}; + private final byte[] value2 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x03}; + private final IsIsPseudonode tlv1 = IsIsPseudonode.of(value1, (byte) 1); + private final IsIsPseudonode sameAsTlv1 = IsIsPseudonode.of(value1, (byte) 1); + private final IsIsPseudonode tlv2 = IsIsPseudonode.of(value2, (byte) 1); + + @Test + public void testEquality() { + new EqualsTester() + .addEqualityGroup(tlv1, sameAsTlv1) + .addEqualityGroup(tlv2) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTest.java new file mode 100644 index 00000000..f1510b17 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTest.java @@ -0,0 +1,39 @@ +/* + * 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.bgpio.types; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for LinkLocalRemoteIdentifiers Tlv. + */ +public class LinkLocalRemoteIdentifiersTest { + private final int value1 = 0x12101010; + private final int value2 = 0x12101012; + private final LinkLocalRemoteIdentifiersTlv tlv1 = LinkLocalRemoteIdentifiersTlv.of(value1, value2); + private final LinkLocalRemoteIdentifiersTlv sameAsTlv1 = LinkLocalRemoteIdentifiersTlv.of(value1, value2); + private final LinkLocalRemoteIdentifiersTlv tlv2 = LinkLocalRemoteIdentifiersTlv.of(value2, value1); + + @Test + public void testEquality() { + new EqualsTester() + .addEqualityGroup(tlv1, sameAsTlv1) + .addEqualityGroup(tlv2) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/NextHopTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/NextHopTest.java new file mode 100755 index 00000000..799419a1 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/NextHopTest.java @@ -0,0 +1,40 @@ +/* + * 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.bgpio.types; + +import org.junit.Test; +import org.onlab.packet.Ip4Address; + +import com.google.common.testing.EqualsTester; + +/** + * Test for NextHop BGP Path Attribute. + */ +public class NextHopTest { + private final Ip4Address value1 = Ip4Address.valueOf("12.12.12.12"); + private final Ip4Address value2 = Ip4Address.valueOf("12.12.12.13"); + private final NextHop attr1 = new NextHop(value1); + private final NextHop sameAsAttr1 = new NextHop(value1); + private final NextHop attr2 = new NextHop(value2); + + @Test + public void basics() { + new EqualsTester() + .addEqualityGroup(attr1, sameAsAttr1) + .addEqualityGroup(attr2) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OriginTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OriginTest.java new file mode 100644 index 00000000..da7b5570 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OriginTest.java @@ -0,0 +1,39 @@ +/* + * 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.bgpio.types; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for Origin BGP Path Attribute. + */ +public class OriginTest { + private final byte value1 = 0x01; + private final byte value2 = 0x02; + private final Origin attr1 = new Origin(value1); + private final Origin sameAsAttr1 = new Origin(value1); + private final Origin attr2 = new Origin(value2); + + @Test + public void basics() { + new EqualsTester() + .addEqualityGroup(attr1, sameAsAttr1) + .addEqualityGroup(attr2) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OspfPseudonodeTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OspfPseudonodeTest.java new file mode 100644 index 00000000..a8002311 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OspfPseudonodeTest.java @@ -0,0 +1,42 @@ +/* + * 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.bgpio.types; + +import org.junit.Test; +import org.onlab.packet.Ip4Address; + +import com.google.common.testing.EqualsTester; + +/** + * Test for OSPFPseudonode Tlv. + */ +public class OspfPseudonodeTest { + private final int value1 = 0xc3223409; + private final int value2 = 0xc3223406; + private final Ip4Address drInterface1 = Ip4Address.valueOf(0xaf91e01); + private final Ip4Address drInterface2 = Ip4Address.valueOf(0xaf91e02); + private final OSPFPseudonode tlv1 = OSPFPseudonode.of(value1, drInterface1); + private final OSPFPseudonode sameAsTlv1 = OSPFPseudonode.of(value1, drInterface1); + private final OSPFPseudonode tlv2 = OSPFPseudonode.of(value2, drInterface2); + + @Test + public void testEquality() { + new EqualsTester() + .addEqualityGroup(tlv1, sameAsTlv1) + .addEqualityGroup(tlv2) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OspfRouteTypeTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OspfRouteTypeTest.java new file mode 100644 index 00000000..859bdbe5 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OspfRouteTypeTest.java @@ -0,0 +1,39 @@ +/* + * 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.bgpio.types; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for OSPFRouteType Tlv. + */ +public class OspfRouteTypeTest { + private final byte value1 = 5; + private final byte value2 = 4; + private final OSPFRouteTypeTlv tlv1 = OSPFRouteTypeTlv.of(value1); + private final OSPFRouteTypeTlv sameAsTlv1 = OSPFRouteTypeTlv.of(value1); + private final OSPFRouteTypeTlv tlv2 = OSPFRouteTypeTlv.of(value2); + + @Test + public void testEquality() { + new EqualsTester() + .addEqualityGroup(tlv1, sameAsTlv1) + .addEqualityGroup(tlv2) + .testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlvTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlvTest.java new file mode 100644 index 00000000..4efb7f5b --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpAttrNodeFlagBitTlvTest.java @@ -0,0 +1,50 @@ +/* + * 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.bgpio.types.attr; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for BGP attribute node flag. + */ +public class BgpAttrNodeFlagBitTlvTest { + + private final boolean bOverloadBit = true; + private final boolean bAttachedBit = true; + private final boolean bExternalBit = true; + private final boolean bABRBit = true; + + private final boolean bOverloadBit1 = false; + private final boolean bAttachedBit1 = false; + private final boolean bExternalBit1 = false; + private final boolean bABRBit1 = false; + + private final BgpAttrNodeFlagBitTlv data = BgpAttrNodeFlagBitTlv + .of(bOverloadBit, bAttachedBit, bExternalBit, bABRBit); + private final BgpAttrNodeFlagBitTlv sameAsData = BgpAttrNodeFlagBitTlv + .of(bOverloadBit, bAttachedBit, bExternalBit, bABRBit); + private final BgpAttrNodeFlagBitTlv diffData = BgpAttrNodeFlagBitTlv + .of(bOverloadBit1, bAttachedBit1, bExternalBit1, bABRBit1); + + @Test + public void basics() { + + new EqualsTester().addEqualityGroup(data, sameAsData) + .addEqualityGroup(diffData).testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6Test.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6Test.java new file mode 100644 index 00000000..16ca58ee --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpAttrRouterIdV6Test.java @@ -0,0 +1,49 @@ +/* + * 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.bgpio.types.attr; + +import org.junit.Test; +import org.onlab.packet.Ip6Address; + +import com.google.common.testing.EqualsTester; + +/** + * Test for BGP attribute node router ID. + */ +public class BgpAttrRouterIdV6Test { + + private final short sType = 1; + private final Ip6Address ip6RouterId = Ip6Address + .valueOf("2001:0db8:0a0b:12f0:0000:0000:0000:0001"); + + private final short sType1 = 2; + private final Ip6Address ip6RouterId1 = Ip6Address + .valueOf("2004:0db8:0a0b:12f0:0000:0000:0000:0004"); + + private final BgpAttrRouterIdV6 data = BgpAttrRouterIdV6.of(ip6RouterId, + sType); + private final BgpAttrRouterIdV6 sameAsData = BgpAttrRouterIdV6 + .of(ip6RouterId, sType); + private final BgpAttrRouterIdV6 diffData = BgpAttrRouterIdV6 + .of(ip6RouterId1, sType1); + + @Test + public void basics() { + + new EqualsTester().addEqualityGroup(data, sameAsData) + .addEqualityGroup(diffData).testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIgpMetricTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIgpMetricTest.java new file mode 100644 index 00000000..ef1cfcea --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIgpMetricTest.java @@ -0,0 +1,43 @@ +/* + * 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.bgpio.types.attr; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for BGP link IGP metric attribute. + */ +public class BgpLinkAttrIgpMetricTest { + private final int val = 0x010203; + private final int valLen = 3; + private final int val1 = 0x01020304; + private final int val1Len = 4; + + private final BgpLinkAttrIgpMetric data = BgpLinkAttrIgpMetric.of(val, + valLen); + private final BgpLinkAttrIgpMetric sameAsData = BgpLinkAttrIgpMetric + .of(val, valLen); + private final BgpLinkAttrIgpMetric diffData = BgpLinkAttrIgpMetric + .of(val1, val1Len); + + @Test + public void basics() { + new EqualsTester().addEqualityGroup(data, sameAsData) + .addEqualityGroup(diffData).testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMaskTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMaskTest.java new file mode 100644 index 00000000..c0d7f986 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMaskTest.java @@ -0,0 +1,42 @@ +/* + * 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.bgpio.types.attr; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for MPLS protocol mask attribute. + */ +public class BgpLinkAttrMplsProtocolMaskTest { + private final boolean val = true; + private final boolean val1 = false; + + private final BgpLinkAttrMplsProtocolMask data = BgpLinkAttrMplsProtocolMask + .of(val, val); + private final BgpLinkAttrMplsProtocolMask sameAsData = BgpLinkAttrMplsProtocolMask + .of(val, val); + private final BgpLinkAttrMplsProtocolMask diffData = BgpLinkAttrMplsProtocolMask + .of(val, val1); + + @Test + public void basics() { + + new EqualsTester().addEqualityGroup(data, sameAsData) + .addEqualityGroup(diffData).testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrProtectionTypeTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrProtectionTypeTest.java new file mode 100644 index 00000000..2fb76352 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrProtectionTypeTest.java @@ -0,0 +1,56 @@ +/* + * 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.bgpio.types.attr; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for MPLS protocol mask attribute. + */ +public class BgpLinkAttrProtectionTypeTest { + boolean bExtraTraffic = true; + boolean bUnprotected = true; + boolean bShared = true; + boolean bDedOneIstoOne = true; + boolean bDedOnePlusOne = true; + boolean bEnhanced = true; + + boolean bExtraTraffic1 = false; + boolean bUnprotected1 = false; + boolean bShared1 = false; + boolean bDedOneIstoOne1 = false; + boolean bDedOnePlusOne1 = false; + boolean bEnhanced1 = false; + + private final BgpLinkAttrProtectionType data = BgpLinkAttrProtectionType + .of(bExtraTraffic, bUnprotected, bShared, bDedOneIstoOne, + bDedOnePlusOne, bEnhanced); + private final BgpLinkAttrProtectionType sameAsData = BgpLinkAttrProtectionType + .of(bExtraTraffic, bUnprotected, bShared, bDedOneIstoOne, + bDedOnePlusOne, bEnhanced); + private final BgpLinkAttrProtectionType diffData = BgpLinkAttrProtectionType + .of(bExtraTraffic1, bUnprotected1, bShared1, bDedOneIstoOne1, + bDedOnePlusOne1, bEnhanced1); + + @Test + public void basics() { + + new EqualsTester().addEqualityGroup(data, sameAsData) + .addEqualityGroup(diffData).testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlagsTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlagsTest.java new file mode 100644 index 00000000..535518f8 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrIgpFlagsTest.java @@ -0,0 +1,53 @@ +/* + * 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.bgpio.types.attr; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for BGP prefix IGP Flag attribute. + */ +public class BgpPrefixAttrIgpFlagsTest { + + private final boolean bisisUpDownBit = true; + private final boolean bOspfNoUnicastBit = true; + private final boolean bOspfLclAddrBit = true; + private final boolean bOspfNSSABit = true; + + private final boolean bisisUpDownBit1 = false; + private final boolean bOspfNoUnicastBit1 = false; + private final boolean bOspfLclAddrBit1 = false; + private final boolean bOspfNSSABit1 = false; + + private final BgpPrefixAttrIgpFlags data = BgpPrefixAttrIgpFlags + .of(bisisUpDownBit, bOspfNoUnicastBit, bOspfLclAddrBit, + bOspfNSSABit); + private final BgpPrefixAttrIgpFlags sameAsData = BgpPrefixAttrIgpFlags + .of(bisisUpDownBit, bOspfNoUnicastBit, bOspfLclAddrBit, + bOspfNSSABit); + private final BgpPrefixAttrIgpFlags diffData = BgpPrefixAttrIgpFlags + .of(bisisUpDownBit1, bOspfNoUnicastBit1, bOspfLclAddrBit1, + bOspfNSSABit1); + + @Test + public void basics() { + + new EqualsTester().addEqualityGroup(data, sameAsData) + .addEqualityGroup(diffData).testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetricTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetricTest.java new file mode 100644 index 00000000..fe6079fd --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetricTest.java @@ -0,0 +1,39 @@ +/* + * 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.bgpio.types.attr; + +import org.junit.Test; + +import com.google.common.testing.EqualsTester; + +/** + * Test for BGP prefix metric attribute. + */ +public class BgpPrefixAttrMetricTest { + private final int val = 1111; + private final int val1 = 2222; + + private final BgpPrefixAttrMetric data = BgpPrefixAttrMetric.of(val); + private final BgpPrefixAttrMetric sameAsData = BgpPrefixAttrMetric.of(val); + private final BgpPrefixAttrMetric diffData = BgpPrefixAttrMetric.of(val1); + + @Test + public void basics() { + + new EqualsTester().addEqualityGroup(data, sameAsData) + .addEqualityGroup(diffData).testEquals(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOspfFwdAddrTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOspfFwdAddrTest.java new file mode 100644 index 00000000..f6fe39f8 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOspfFwdAddrTest.java @@ -0,0 +1,51 @@ +/* + * 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.bgpio.types.attr; + +import org.junit.Test; +import org.onlab.packet.Ip4Address; +import org.onlab.packet.Ip6Address; + +import com.google.common.testing.EqualsTester; + +/** + * Test for BGP prefix metric attribute. + */ +public class BgpPrefixAttrOspfFwdAddrTest { + + private final short lsAttrLength = 4; + private final Ip4Address ip4RouterId = Ip4Address.valueOf("192.168.1.1"); + private final Ip6Address ip6RouterId = Ip6Address + .valueOf("2001:0db8:0a0b:12f0:0000:0000:0000:0001"); + + private final short lsAttrLength1 = 16; + private final Ip4Address ip4RouterId1 = Ip4Address.valueOf("192.168.1.2"); + private final Ip6Address ip6RouterId1 = Ip6Address + .valueOf("1002:0db8:0a0b:12f0:0000:0000:0000:0002"); + + private final BgpPrefixAttrOspfFwdAddr data = BgpPrefixAttrOspfFwdAddr + .of(lsAttrLength, ip4RouterId, ip6RouterId); + private final BgpPrefixAttrOspfFwdAddr sameAsData = BgpPrefixAttrOspfFwdAddr + .of(lsAttrLength, ip4RouterId, ip6RouterId); + private final BgpPrefixAttrOspfFwdAddr diffData = BgpPrefixAttrOspfFwdAddr + .of(lsAttrLength1, ip4RouterId1, ip6RouterId1); + + @Test + public void basics() { + new EqualsTester().addEqualityGroup(data, sameAsData) + .addEqualityGroup(diffData).testEquals(); + } +} diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/GroupsListCommand.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/GroupsListCommand.java index b10621de..8e30fa4c 100644 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/GroupsListCommand.java +++ b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/GroupsListCommand.java @@ -121,11 +121,11 @@ public class GroupsListCommand extends AbstractShellCommand { private void printGroups(DeviceId deviceId, List groups) { print("deviceId=%s", deviceId); for (Group group : groups) { - print(FORMAT, group.id().id(), group.state(), group.type(), + print(FORMAT, Integer.toHexString(group.id().id()), group.state(), group.type(), group.bytes(), group.packets(), group.appId().name()); int i = 0; for (GroupBucket bucket:group.buckets().buckets()) { - print(BUCKET_FORMAT, group.id().id(), ++i, + print(BUCKET_FORMAT, Integer.toHexString(group.id().id()), ++i, bucket.bytes(), bucket.packets(), bucket.treatment().allInstructions()); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java index 4e5d39ab..126e722e 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/Instructions.java @@ -630,7 +630,8 @@ public final class Instructions { @Override public String toString() { return toStringHelper(type().toString()) - .add("group ID", groupId.id()).toString(); + .addValue("group ID=0x" + Integer.toHexString(groupId.id())) + .toString(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceEvent.java new file mode 100644 index 00000000..98abf301 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceEvent.java @@ -0,0 +1,54 @@ +/* + * 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.newresource; + +import com.google.common.annotations.Beta; +import org.onosproject.event.AbstractEvent; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Describes an event related to a resource. + */ +@Beta +public final class ResourceEvent extends AbstractEvent { + + /** + * Type of resource events. + */ + @Beta + public enum Type { + /** + * Signifies that a new resource has been detected. + */ + RESOURCE_ADDED, + + /** + * Signifies that a resource has been removed. + */ + RESOURCE_REMOVED + } + + /** + * Create a resource event. + * + * @param type type of resource event + * @param subject subject of resource event + */ + public ResourceEvent(Type type, ResourcePath subject) { + super(checkNotNull(type), checkNotNull(subject)); + } +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceListener.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceListener.java new file mode 100644 index 00000000..3f871900 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceListener.java @@ -0,0 +1,26 @@ +/* + * 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.newresource; + +import com.google.common.annotations.Beta; +import org.onosproject.event.EventListener; + +/** + * Entity capable of receiving resource related events. + */ +@Beta +public interface ResourceListener extends EventListener { +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java index ad684c8c..966de500 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceService.java @@ -17,6 +17,7 @@ package org.onosproject.net.newresource; import com.google.common.annotations.Beta; import com.google.common.collect.ImmutableList; +import org.onosproject.event.ListenerService; import java.util.Arrays; import java.util.Collection; @@ -29,7 +30,7 @@ import static com.google.common.base.Preconditions.checkNotNull; * Service for allocating/releasing resource(s) and retrieving allocation(s) and availability. */ @Beta -public interface ResourceService { +public interface ResourceService extends ListenerService { /** * Allocates the specified resource to the specified user. * diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java index 2cab9d4b..7c67430e 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStore.java @@ -16,6 +16,7 @@ package org.onosproject.net.newresource; import com.google.common.annotations.Beta; +import org.onosproject.store.Store; import java.util.Collection; import java.util.List; @@ -25,7 +26,7 @@ import java.util.Optional; * Service for storing resource and consumer information. */ @Beta -public interface ResourceStore { +public interface ResourceStore extends Store { /** * Registers the resources in transactional way. diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStoreDelegate.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStoreDelegate.java new file mode 100644 index 00000000..a0b9bb25 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceStoreDelegate.java @@ -0,0 +1,24 @@ +/* + * 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.newresource; + +import org.onosproject.store.StoreDelegate; + +/** + * Resource store delegate abstraction. + */ +public interface ResourceStoreDelegate extends StoreDelegate { +} diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResource.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResource.java index 0bfb3795..d3bd2d7b 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResource.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResource.java @@ -23,7 +23,10 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * Representation of bandwidth resource in bps. + * + * @deprecated in Emu Release */ +@Deprecated public final class BandwidthResource implements LinkResource { private final Bandwidth bandwidth; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java index 05cf28f5..5f36d5f8 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceAllocation.java @@ -23,7 +23,10 @@ import java.util.Objects; /** * Representation of allocated bandwidth resource. + * + * @deprecated in Emu Release */ +@Deprecated public class BandwidthResourceAllocation implements ResourceAllocation { private final BandwidthResource bandwidth; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceRequest.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceRequest.java index 722b870f..ff26e81e 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceRequest.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/BandwidthResourceRequest.java @@ -23,7 +23,10 @@ import org.onosproject.net.resource.ResourceType; /** * Representation of a request for bandwidth resource. + * + * @deprecated in Emu Release */ +@Deprecated public class BandwidthResourceRequest implements ResourceRequest { private final BandwidthResource bandwidth; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceAllocations.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceAllocations.java index 379bf71e..2fa4fa6b 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceAllocations.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceAllocations.java @@ -36,7 +36,10 @@ import java.util.Set; /** * Implementation of {@link LinkResourceAllocations}. + * + * @deprecated in Emu Release */ +@Deprecated public class DefaultLinkResourceAllocations implements LinkResourceAllocations { private final LinkResourceRequest request; // TODO: probably should be using LinkKey instead diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceRequest.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceRequest.java index f8e143a4..b57465f2 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceRequest.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/DefaultLinkResourceRequest.java @@ -39,7 +39,10 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * Implementation of {@link LinkResourceRequest}. + * + * @deprecated in Emu Release */ +@Deprecated public final class DefaultLinkResourceRequest implements LinkResourceRequest { private final IntentId intentId; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResource.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResource.java index 3733e467..06582497 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResource.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResource.java @@ -23,7 +23,10 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * Representation of lambda resource. + * + * @deprecated in Emu Release */ +@Deprecated public final class LambdaResource implements LinkResource { private final IndexedLambda lambda; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceAllocation.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceAllocation.java index 161cf455..930a6b27 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceAllocation.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceAllocation.java @@ -23,7 +23,10 @@ import java.util.Objects; /** * Representation of allocated lambda resource. + * + * @deprecated in Emu Release */ +@Deprecated public class LambdaResourceAllocation implements ResourceAllocation { private final LambdaResource lambda; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceRequest.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceRequest.java index d264d5e5..24d3d78d 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceRequest.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LambdaResourceRequest.java @@ -24,7 +24,10 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * Representation of a request for lambda resource. + * + * @deprecated in Emu Release */ +@Deprecated public class LambdaResourceRequest implements ResourceRequest { private final LambdaResource lambda; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResource.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResource.java index ec06611e..b06f16bf 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResource.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResource.java @@ -17,6 +17,9 @@ package org.onosproject.net.resource.link; /** * Abstraction of link resource. + * + * @deprecated in Emu Release */ +@Deprecated public interface LinkResource { } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceAllocations.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceAllocations.java index 7828867c..d0211e26 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceAllocations.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceAllocations.java @@ -25,7 +25,10 @@ import org.onosproject.net.resource.ResourceRequest; /** * Representation of allocated link resources. + * + * @deprecated */ +@Deprecated public interface LinkResourceAllocations extends ResourceAllocation { /** diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceEvent.java index 3edb386a..a3702923 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceEvent.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceEvent.java @@ -23,7 +23,10 @@ import com.google.common.collect.ImmutableList; /** * Describes an event related to a Link Resource. + * + * @deprecated in Emu Release */ +@Deprecated public final class LinkResourceEvent extends AbstractEvent> { diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceListener.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceListener.java index 599dd4fb..bbb02e2f 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceListener.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceListener.java @@ -19,6 +19,9 @@ import org.onosproject.event.EventListener; /** * Entity for receiving link resource events. + * + * @deprecated in Emu Release */ +@Deprecated public interface LinkResourceListener extends EventListener { } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceRequest.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceRequest.java index 37622e79..9774e8e7 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceRequest.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceRequest.java @@ -27,7 +27,10 @@ import org.onosproject.net.resource.ResourceRequest; /** * Representation of a request for link resource. + * + * @deprecated in Emu Release */ +@Deprecated public interface LinkResourceRequest extends ResourceRequest { /** diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStore.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStore.java index e6674dbd..e8a295c2 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStore.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStore.java @@ -23,7 +23,10 @@ import org.onosproject.net.resource.ResourceAllocation; /** * Manages link resources. + * + * @deprecated in Emu Release. */ +@Deprecated public interface LinkResourceStore { /** * Returns free resources for given link. diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStoreDelegate.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStoreDelegate.java index 6c051d6a..dbfb3b04 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStoreDelegate.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResourceStoreDelegate.java @@ -19,6 +19,9 @@ import org.onosproject.store.StoreDelegate; /** * Link resource store delegate abstraction. + * + * @deprecated in Emu Release */ +@Deprecated public interface LinkResourceStoreDelegate extends StoreDelegate { } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResources.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResources.java index dc005227..46450427 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResources.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/LinkResources.java @@ -19,7 +19,10 @@ import java.util.Set; /** * Abstraction of a resources of a link. + * + * @deprecated in Emu Release */ +@Deprecated public interface LinkResources { /** @@ -31,7 +34,10 @@ public interface LinkResources { /** * Builder of {@link LinkResources}. + * + * @deprecated in Emu Release */ + @Deprecated interface Builder { /** diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabel.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabel.java index 89c87760..5138d02c 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabel.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabel.java @@ -20,7 +20,10 @@ import java.util.Objects; /** * Representation of MPLS label resource. + * + * @deprecated in Emu Release */ +@Deprecated public final class MplsLabel implements LinkResource { private final org.onlab.packet.MplsLabel mplsLabel; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceAllocation.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceAllocation.java index cc9edc2a..7441bee9 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceAllocation.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceAllocation.java @@ -24,7 +24,10 @@ import java.util.Objects; /** * Representation of allocated MPLS label resource. + * + * @deprecated in Emu Release */ +@Deprecated public class MplsLabelResourceAllocation implements ResourceAllocation { private final MplsLabel mplsLabel; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceRequest.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceRequest.java index 01a048b7..5b9c4a0a 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceRequest.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/MplsLabelResourceRequest.java @@ -24,7 +24,10 @@ import static com.google.common.base.Preconditions.checkNotNull; /** * Representation of a request for lambda resource. + * + * @deprecated in Emu Release */ +@Deprecated public class MplsLabelResourceRequest implements ResourceRequest { private final MplsLabel mplsLabel; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/package-info.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/package-info.java index b10e4ba4..f374d778 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/package-info.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/link/package-info.java @@ -17,5 +17,11 @@ /** * Services for reserving links and their capacity as network resources, * e.g. bandwidth, lambdas. + *

+ * Note: Classes under the package will be remove. + * Developers should not use the classes. + * This package is marked as deprecated in Emu Release. + *

*/ +@Deprecated package org.onosproject.net.resource.link; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/package-info.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/package-info.java index e676fc87..a05dfda1 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/package-info.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/resource/package-info.java @@ -16,5 +16,9 @@ /** * Abstractions for reserving network resources. + *

+ * Note: Classes under the package will be removed. + * Developers should not use the classes. + *

*/ package org.onosproject.net.resource; diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkResourceStore.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkResourceStore.java index 58b446cf..22df937b 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkResourceStore.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleLinkResourceStore.java @@ -52,7 +52,10 @@ import static org.slf4j.LoggerFactory.getLogger; /** * Manages link resources using trivial in-memory structures implementation. + * + * @deprecated in Emu Release */ +@Deprecated @Component(immediate = true) @Service public class SimpleLinkResourceStore implements LinkResourceStore { diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java index 5ebc812e..ebf681a2 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/ObjectiveTracker.java @@ -48,9 +48,9 @@ import org.onosproject.net.intent.PartitionEvent; import org.onosproject.net.intent.PartitionEventListener; import org.onosproject.net.intent.PartitionService; import org.onosproject.net.link.LinkEvent; -import org.onosproject.net.resource.link.LinkResourceEvent; -import org.onosproject.net.resource.link.LinkResourceListener; -import org.onosproject.net.resource.link.LinkResourceService; +import org.onosproject.net.newresource.ResourceEvent; +import org.onosproject.net.newresource.ResourceListener; +import org.onosproject.net.newresource.ResourceService; import org.onosproject.net.topology.TopologyEvent; import org.onosproject.net.topology.TopologyListener; import org.onosproject.net.topology.TopologyService; @@ -60,6 +60,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Optional; import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -101,7 +102,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { protected TopologyService topologyService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected LinkResourceService resourceManager; + protected ResourceService resourceService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected DeviceService deviceService; @@ -122,8 +123,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { .newScheduledThreadPool(1); private TopologyListener listener = new InternalTopologyListener(); - private LinkResourceListener linkResourceListener = - new InternalLinkResourceListener(); + private ResourceListener resourceListener = new InternalResourceListener(); private DeviceListener deviceListener = new InternalDeviceListener(); private HostListener hostListener = new InternalHostListener(); private PartitionEventListener partitionListener = new InternalPartitionListener(); @@ -134,7 +134,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { @Activate public void activate() { topologyService.addListener(listener); - resourceManager.addListener(linkResourceListener); + resourceService.addListener(resourceListener); deviceService.addListener(deviceListener); hostService.addListener(hostListener); partitionService.addListener(partitionListener); @@ -144,7 +144,7 @@ public class ObjectiveTracker implements ObjectiveTrackerService { @Deactivate public void deactivate() { topologyService.removeListener(listener); - resourceManager.removeListener(linkResourceListener); + resourceService.removeListener(resourceListener); deviceService.removeListener(deviceListener); hostService.removeListener(hostListener); partitionService.removeListener(partitionListener); @@ -299,35 +299,22 @@ public class ObjectiveTracker implements ObjectiveTrackerService { } } - /** - * Internal re-actor to resource available events. - */ - private class InternalLinkResourceListener implements LinkResourceListener { + private class InternalResourceListener implements ResourceListener { @Override - public void event(LinkResourceEvent event) { - executorService.execute(new ResourceAvailableHandler(event)); - } - } - - /* - * Re-dispatcher of resource available events. - */ - private class ResourceAvailableHandler implements Runnable { - - private final LinkResourceEvent event; - - ResourceAvailableHandler(LinkResourceEvent event) { - this.event = event; - } + public void event(ResourceEvent event) { + Optional> linkEvent = event.subject().components().stream() + .map(Object::getClass) + .filter(x -> x == LinkKey.class) + .findFirst(); + if (linkEvent.isPresent()) { + executorService.execute(() -> { + if (delegate == null) { + return; + } - @Override - public void run() { - // If there is no delegate, why bother? Just bail. - if (delegate == null) { - return; + delegate.triggerCompile(Collections.emptySet(), true); + }); } - - delegate.triggerCompile(Collections.emptySet(), true); } } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java index 1f55b157..db3f6552 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceManager.java @@ -18,16 +18,22 @@ package org.onosproject.net.newresource.impl; import com.google.common.annotations.Beta; import com.google.common.collect.ImmutableList; 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.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.ReferenceCardinality; import org.apache.felix.scr.annotations.Service; +import org.onosproject.event.AbstractListenerManager; import org.onosproject.net.newresource.ResourceAdminService; import org.onosproject.net.newresource.ResourceAllocation; import org.onosproject.net.newresource.ResourceConsumer; +import org.onosproject.net.newresource.ResourceEvent; +import org.onosproject.net.newresource.ResourceListener; import org.onosproject.net.newresource.ResourceService; import org.onosproject.net.newresource.ResourcePath; import org.onosproject.net.newresource.ResourceStore; +import org.onosproject.net.newresource.ResourceStoreDelegate; import java.util.ArrayList; import java.util.Collection; @@ -44,11 +50,26 @@ import static com.google.common.base.Preconditions.checkNotNull; @Component(immediate = true) @Service @Beta -public final class ResourceManager implements ResourceService, ResourceAdminService { +public final class ResourceManager extends AbstractListenerManager + implements ResourceService, ResourceAdminService { @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected ResourceStore store; + private final ResourceStoreDelegate delegate = new InternalStoreDelegate(); + + @Activate + public void activate() { + store.setDelegate(delegate); + eventDispatcher.addSink(ResourceEvent.class, listenerRegistry); + } + + @Deactivate + public void deactivate() { + store.unsetDelegate(delegate); + eventDispatcher.addSink(ResourceEvent.class, listenerRegistry); + } + @Override public List allocate(ResourceConsumer consumer, List resources) { @@ -161,4 +182,11 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ List resources = Lists.transform(children, x -> ResourcePath.child(parent, x)); return store.unregister(resources); } + + private class InternalStoreDelegate implements ResourceStoreDelegate { + @Override + public void notify(ResourceEvent event) { + post(event); + } + } } diff --git a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/ObjectiveTrackerTest.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/ObjectiveTrackerTest.java index 58fa1292..8d7452b3 100644 --- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/ObjectiveTrackerTest.java +++ b/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/ObjectiveTrackerTest.java @@ -16,7 +16,6 @@ package org.onosproject.net.intent.impl; import java.util.Collection; -import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -38,8 +37,9 @@ import org.onosproject.net.intent.Intent; import org.onosproject.net.intent.Key; import org.onosproject.net.intent.MockIdGenerator; import org.onosproject.net.link.LinkEvent; -import org.onosproject.net.resource.link.LinkResourceEvent; -import org.onosproject.net.resource.link.LinkResourceListener; +import org.onosproject.net.newresource.ResourceEvent; +import org.onosproject.net.newresource.ResourceListener; +import org.onosproject.net.newresource.ResourcePath; import org.onosproject.net.topology.Topology; import org.onosproject.net.topology.TopologyEvent; import org.onosproject.net.topology.TopologyListener; @@ -52,6 +52,8 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; +import static org.onosproject.net.LinkKey.linkKey; +import static org.onosproject.net.newresource.ResourceEvent.Type.*; import static org.onosproject.net.NetTestTools.APP_ID; import static org.onosproject.net.NetTestTools.device; import static org.onosproject.net.NetTestTools.link; @@ -67,7 +69,7 @@ public class ObjectiveTrackerTest { private List reasons; private TopologyListener listener; private DeviceListener deviceListener; - private LinkResourceListener linkResourceListener; + private ResourceListener resourceListener; private IdGenerator mockGenerator; /** @@ -84,7 +86,7 @@ public class ObjectiveTrackerTest { reasons = new LinkedList<>(); listener = TestUtils.getField(tracker, "listener"); deviceListener = TestUtils.getField(tracker, "deviceListener"); - linkResourceListener = TestUtils.getField(tracker, "linkResourceListener"); + resourceListener = TestUtils.getField(tracker, "resourceListener"); mockGenerator = new MockIdGenerator(); Intent.bindIdGenerator(mockGenerator); } @@ -228,10 +230,9 @@ public class ObjectiveTrackerTest { */ @Test public void testResourceEvent() throws Exception { - LinkResourceEvent event = new LinkResourceEvent( - LinkResourceEvent.Type.ADDITIONAL_RESOURCES_AVAILABLE, - new HashSet<>()); - linkResourceListener.event(event); + ResourceEvent event = new ResourceEvent(RESOURCE_ADDED, + new ResourcePath(linkKey(link("a", 1, "b", 1)))); + resourceListener.event(event); assertThat( delegate.latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), diff --git a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java index 06b2c81e..8ec09bd1 100644 --- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java +++ b/framework/src/onos/core/net/src/test/java/org/onosproject/net/intent/impl/compiler/MockResourceService.java @@ -19,6 +19,7 @@ import com.google.common.collect.ImmutableList; import org.onlab.packet.MplsLabel; import org.onosproject.net.newresource.ResourceAllocation; import org.onosproject.net.newresource.ResourceConsumer; +import org.onosproject.net.newresource.ResourceListener; import org.onosproject.net.newresource.ResourcePath; import org.onosproject.net.newresource.ResourceService; @@ -97,4 +98,10 @@ class MockResourceService implements ResourceService { public boolean isAvailable(ResourcePath resource) { return true; } + + @Override + public void addListener(ResourceListener listener) {} + + @Override + public void removeListener(ResourceListener listener) {} } diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/StaticClusterMetadataStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/StaticClusterMetadataStore.java index 9f6c4130..e4a09cef 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/StaticClusterMetadataStore.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/cluster/impl/StaticClusterMetadataStore.java @@ -55,6 +55,10 @@ public class StaticClusterMetadataStore implements ClusterMetadataStore { private final Logger log = getLogger(getClass()); + + private static final String ONOS_IP = "ONOS_IP"; + private static final String ONOS_INTERFACE = "ONOS_INTERFACE"; + private static final String DEFAULT_ONOS_INTERFACE = "eth0"; private static final String CLUSTER_METADATA_FILE = "../config/cluster.json"; private static final int DEFAULT_ONOS_PORT = 9876; private final File metadataFile = new File(CLUSTER_METADATA_FILE); @@ -194,6 +198,22 @@ public class StaticClusterMetadataStore private static String getSiteLocalAddress() { + + /* + * If the IP ONOS should use is set via the environment variable we will assume it is valid and should be used. + * Setting the IP address takes presidence over setting the interface via the environment. + */ + String useOnosIp = System.getenv(ONOS_IP); + if (useOnosIp != null) { + return useOnosIp; + } + + // Read environment variables for IP interface information or set to default + String useOnosInterface = System.getenv(ONOS_INTERFACE); + if (useOnosInterface == null) { + useOnosInterface = DEFAULT_ONOS_INTERFACE; + } + Function ipLookup = nif -> { for (InetAddress address : Collections.list(nif.getInetAddresses())) { if (address.isSiteLocalAddress()) { @@ -203,7 +223,7 @@ public class StaticClusterMetadataStore return null; }; try { - IpAddress ip = ipLookup.apply(NetworkInterface.getByName("eth0")); + IpAddress ip = ipLookup.apply(NetworkInterface.getByName(useOnosInterface)); if (ip != null) { return ip.toString(); } @@ -218,4 +238,4 @@ public class StaticClusterMetadataStore } return IpAddress.valueOf(InetAddress.getLoopbackAddress()).toString(); } -} \ No newline at end of file +} diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java index c9aaba5a..82dfe32f 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/newresource/impl/ConsistentResourceStore.java @@ -16,14 +16,18 @@ package org.onosproject.store.newresource.impl; import com.google.common.annotations.Beta; +import com.google.common.collect.ImmutableList; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.ReferenceCardinality; import org.apache.felix.scr.annotations.Service; import org.onosproject.net.newresource.ResourceConsumer; +import org.onosproject.net.newresource.ResourceEvent; import org.onosproject.net.newresource.ResourcePath; import org.onosproject.net.newresource.ResourceStore; +import org.onosproject.net.newresource.ResourceStoreDelegate; +import org.onosproject.store.AbstractStore; import org.onosproject.store.serializers.KryoNamespaces; import org.onosproject.store.service.ConsistentMap; import org.onosproject.store.service.Serializer; @@ -47,6 +51,7 @@ import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static org.onosproject.net.newresource.ResourceEvent.Type.*; /** * Implementation of ResourceStore using TransactionalMap. @@ -54,7 +59,8 @@ import static com.google.common.base.Preconditions.checkNotNull; @Component(immediate = true) @Service @Beta -public class ConsistentResourceStore implements ResourceStore { +public class ConsistentResourceStore extends AbstractStore + implements ResourceStore { private static final Logger log = LoggerFactory.getLogger(ConsistentResourceStore.class); private static final String CONSUMER_MAP = "onos-resource-consumers"; @@ -78,6 +84,8 @@ public class ConsistentResourceStore implements ResourceStore { .withName(CHILD_MAP) .withSerializer(SERIALIZER) .build(); + + childMap.put(ResourcePath.ROOT, ImmutableList.of()); } @Override @@ -116,7 +124,15 @@ public class ConsistentResourceStore implements ResourceStore { } } - return tx.commit(); + boolean success = tx.commit(); + if (success) { + List events = resources.stream() + .filter(x -> x.parent().isPresent()) + .map(x -> new ResourceEvent(RESOURCE_ADDED, x)) + .collect(Collectors.toList()); + notifyDelegate(events); + } + return success; } @Override @@ -147,7 +163,15 @@ public class ConsistentResourceStore implements ResourceStore { } } - return tx.commit(); + boolean success = tx.commit(); + if (success) { + List events = resources.stream() + .filter(x -> x.parent().isPresent()) + .map(x -> new ResourceEvent(RESOURCE_REMOVED, x)) + .collect(Collectors.toList()); + notifyDelegate(events); + } + return success; } @Override diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java index a38550e4..351c7a5f 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/resource/impl/ConsistentLinkResourceStore.java @@ -72,7 +72,10 @@ import static org.onosproject.net.AnnotationKeys.BANDWIDTH; /** * Store that manages link resources using Copycat-backed TransactionalMaps. + * + * @deprecated in Emu Release */ +@Deprecated @Component(immediate = true, enabled = true) @Service public class ConsistentLinkResourceStore extends diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetTunnelDst.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetTunnelDst.java index 16aa1b07..a20b2479 100644 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetTunnelDst.java +++ b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/extensions/NiciraSetTunnelDst.java @@ -49,6 +49,8 @@ public class NiciraSetTunnelDst extends AbstractExtensionInstruction { /** * Creates a new set tunnel destination instruction with a particular IPv4 * address. + * + * @param tunnelDst tunnel destination IPv4 address */ NiciraSetTunnelDst(Ip4Address tunnelDst) { checkNotNull(tunnelDst); diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/CpqdOFDPA2Pipeline.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/CpqdOFDPA2Pipeline.java index 8f976da3..0cb30d28 100644 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/CpqdOFDPA2Pipeline.java +++ b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/CpqdOFDPA2Pipeline.java @@ -18,7 +18,10 @@ package org.onosproject.driver.pipeline; import static org.slf4j.LoggerFactory.getLogger; import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.onlab.packet.VlanId; import org.onosproject.core.ApplicationId; @@ -54,11 +57,16 @@ public class CpqdOFDPA2Pipeline extends OFDPA2Pipeline { TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); selector.matchVlanId(vidCriterion.vlanId()); + treatment.transition(TMAC_TABLE); + + VlanId storeVlan = null; if (vidCriterion.vlanId() == VlanId.NONE) { // untagged packets are assigned vlans treatment.pushVlan().setVlanId(assignedVlan); + storeVlan = assignedVlan; + } else { + storeVlan = vidCriterion.vlanId(); } - treatment.transition(TMAC_TABLE); // ofdpa cannot match on ALL portnumber, so we need to use separate // rules for each port. @@ -72,7 +80,20 @@ public class CpqdOFDPA2Pipeline extends OFDPA2Pipeline { } else { portnums.add(portCriterion.port()); } + for (PortNumber pnum : portnums) { + // update storage + port2Vlan.put(pnum, storeVlan); + Set vlanPorts = vlan2Port.get(storeVlan); + if (vlanPorts == null) { + vlanPorts = Collections.newSetFromMap( + new ConcurrentHashMap()); + vlanPorts.add(pnum); + vlan2Port.put(storeVlan, vlanPorts); + } else { + vlanPorts.add(pnum); + } + // create rest of flowrule selector.matchInPort(pnum); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/OFDPA2Pipeline.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/OFDPA2Pipeline.java index e63a404c..cf3c7e89 100644 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/OFDPA2Pipeline.java +++ b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/OFDPA2Pipeline.java @@ -23,11 +23,13 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import org.onlab.osgi.ServiceDirectory; @@ -147,6 +149,7 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline private static final int L3UNICASTMASK = 0x20000000; //private static final int MPLSINTERFACEMASK = 0x90000000; private static final int L3ECMPMASK = 0x70000000; + private static final int L2FLOODMASK = 0x40000000; private final Logger log = getLogger(getClass()); private ServiceDirectory serviceDirectory; @@ -176,6 +179,13 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline private Set sentIpFilters = Collections.newSetFromMap( new ConcurrentHashMap()); + // local stores for port-vlan mapping + Map port2Vlan = new ConcurrentHashMap(); + Map> vlan2Port = new ConcurrentHashMap>(); + + + @Override public void init(DeviceId deviceId, PipelinerContext context) { this.serviceDirectory = context.directory(); @@ -275,26 +285,23 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline @Override public void next(NextObjective nextObjective) { - switch (nextObjective.type()) { - case SIMPLE: - Collection treatments = nextObjective.next(); - if (treatments.size() != 1) { - log.error("Next Objectives of type Simple should only have a " - + "single Traffic Treatment. Next Objective Id:{}", nextObjective.id()); - fail(nextObjective, ObjectiveError.BADPARAMS); - return; + log.debug("Processing NextObjective id{} op{}", nextObjective.id(), + nextObjective.op()); + if (nextObjective.op() == Objective.Operation.REMOVE) { + if (nextObjective.next().isEmpty()) { + removeGroup(nextObjective); + } else { + removeBucketFromGroup(nextObjective); } - processSimpleNextObjective(nextObjective); - break; - case HASHED: - case BROADCAST: - case FAILOVER: - fail(nextObjective, ObjectiveError.UNSUPPORTED); - log.warn("Unsupported next objective type {}", nextObjective.type()); - break; - default: - fail(nextObjective, ObjectiveError.UNKNOWN); - log.warn("Unknown next objective type {}", nextObjective.type()); + } else if (nextObjective.op() == Objective.Operation.ADD) { + NextGroup nextGroup = flowObjectiveStore.getNextGroup(nextObjective.id()); + if (nextGroup != null) { + addBucketToGroup(nextObjective); + } else { + addGroup(nextObjective); + } + } else { + log.warn("Unsupported operation {}", nextObjective.op()); } } @@ -302,6 +309,7 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline // Flow handling ////////////////////////////////////// + /** * As per OFDPA 2.0 TTP, filtering of VLAN ids, MAC addresses (for routing) * and IP addresses configured on switch ports happen in different tables. @@ -455,14 +463,19 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); selector.matchVlanId(vidCriterion.vlanId()); + treatment.transition(TMAC_TABLE); + + VlanId storeVlan = null; if (vidCriterion.vlanId() == VlanId.NONE) { // untagged packets are assigned vlans treatment.pushVlan().setVlanId(assignedVlan); // XXX ofdpa will require an additional vlan match on the assigned vlan // and it may not require the push. This is not in compliance with OF // standard. Waiting on what the exact flows are going to look like. + storeVlan = assignedVlan; + } else { + storeVlan = vidCriterion.vlanId(); } - treatment.transition(TMAC_TABLE); // ofdpa cannot match on ALL portnumber, so we need to use separate // rules for each port. @@ -476,7 +489,20 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline } else { portnums.add(portCriterion.port()); } + for (PortNumber pnum : portnums) { + // update storage + port2Vlan.put(pnum, storeVlan); + Set vlanPorts = vlan2Port.get(storeVlan); + if (vlanPorts == null) { + vlanPorts = Collections.newSetFromMap( + new ConcurrentHashMap()); + vlanPorts.add(pnum); + vlan2Port.put(storeVlan, vlanPorts); + } else { + vlanPorts.add(pnum); + } + // create rest of flowrule selector.matchInPort(pnum); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) @@ -708,10 +734,39 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline // Group handling ////////////////////////////////////// + private void addGroup(NextObjective nextObjective) { + switch (nextObjective.type()) { + case SIMPLE: + Collection treatments = nextObjective.next(); + if (treatments.size() != 1) { + log.error("Next Objectives of type Simple should only have a " + + "single Traffic Treatment. Next Objective Id:{}", + nextObjective.id()); + fail(nextObjective, ObjectiveError.BADPARAMS); + return; + } + processSimpleNextObjective(nextObjective); + break; + case BROADCAST: + processBroadcastNextObjective(nextObjective); + break; + case HASHED: + processHashedNextObjective(nextObjective); + break; + case FAILOVER: + fail(nextObjective, ObjectiveError.UNSUPPORTED); + log.warn("Unsupported next objective type {}", nextObjective.type()); + break; + default: + fail(nextObjective, ObjectiveError.UNKNOWN); + log.warn("Unknown next objective type {}", nextObjective.type()); + } + } + /** * As per the OFDPA 2.0 TTP, packets are sent out of ports by using * a chain of groups, namely an L3 Unicast Group that points to an L2 Interface - * Group which in turns points to an output port. The Next Objective passed + * Group which in-turn points to an output port. The Next Objective passed * in by the application has to be broken up into a group chain * to satisfy this TTP. * @@ -770,7 +825,9 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline Integer l3groupId = L3UNICASTMASK | (int) portNum; l3utt.group(new DefaultGroupId(l2groupId)); GroupChainElem gce = new GroupChainElem(l3groupkey, l3groupId, - l3utt.build(), nextObj.appId()); + GroupDescription.Type.INDIRECT, + Collections.singletonList(l3utt.build()), + nextObj.appId(), 1); // create object for local and distributed storage List gkeys = new ArrayList(); @@ -796,6 +853,145 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline groupService.addGroup(groupDescription); } + /** + * As per the OFDPA 2.0 TTP, packets are sent out of ports by using + * a chain of groups. The Next Objective passed in by the application + * has to be broken up into a group chain comprising of an + * L2 Flood group whose buckets point to L2 Interface groups. + * + * @param nextObj the nextObjective of type BROADCAST + */ + private void processBroadcastNextObjective(NextObjective nextObj) { + // break up broadcast next objective to multiple groups + Collection buckets = nextObj.next(); + + // each treatment is converted to an L2 interface group + int indicator = 0; + VlanId vlanid = null; + List groupInfoCollection = new ArrayList<>(); + for (TrafficTreatment treatment : buckets) { + TrafficTreatment.Builder newTreatment = DefaultTrafficTreatment.builder(); + PortNumber portNum = null; + // ensure that the only allowed treatments are pop-vlan and output + for (Instruction ins : treatment.allInstructions()) { + if (ins.type() == Instruction.Type.L2MODIFICATION) { + L2ModificationInstruction l2ins = (L2ModificationInstruction) ins; + switch (l2ins.subtype()) { + case VLAN_POP: + newTreatment.add(l2ins); + break; + default: + log.debug("action {} not permitted for broadcast nextObj", + l2ins.subtype()); + break; + } + } else if (ins.type() == Instruction.Type.OUTPUT) { + portNum = ((OutputInstruction) ins).port(); + newTreatment.add(ins); + } else { + log.debug("TrafficTreatment of type {} not permitted in " + + " broadcast nextObjective", ins.type()); + } + } + + // also ensure that all ports are in the same vlan + VlanId thisvlanid = port2Vlan.get(portNum); + if (vlanid == null) { + vlanid = thisvlanid; + } else { + if (!vlanid.equals(thisvlanid)) { + log.error("Driver requires all ports in a broadcast nextObj " + + "to be in the same vlan. Different vlans found " + + "{} and {}. Aborting group creation", vlanid, thisvlanid); + return; + } + } + + // assemble info for all l2 interface groups + indicator += GROUP1MASK; + int l2gk = nextObj.id() | indicator; + final GroupKey l2groupkey = new DefaultGroupKey(appKryo.serialize(l2gk)); + Integer l2groupId = L2INTERFACEMASK | (vlanid.toShort() << 16) | + (int) portNum.toLong(); + GroupBucket newbucket = + DefaultGroupBucket.createIndirectGroupBucket(newTreatment.build()); + + // store the info needed to create this group + groupInfoCollection.add(new GroupInfo(l2groupId, l2groupkey, newbucket)); + } + + // assemble info for l2 flood group + int l2floodgk = nextObj.id() | GROUP0MASK; + final GroupKey l2floodgroupkey = new DefaultGroupKey(appKryo.serialize(l2floodgk)); + Integer l2floodgroupId = L2FLOODMASK | (vlanid.toShort() << 16) | nextObj.id(); + // collection of treatment with groupids of l2 interface groups + List floodtt = new ArrayList<>(); + for (GroupInfo gi : groupInfoCollection) { + TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder(); + ttb.group(new DefaultGroupId(gi.groupId)); + floodtt.add(ttb.build()); + } + GroupChainElem gce = new GroupChainElem(l2floodgroupkey, l2floodgroupId, + GroupDescription.Type.ALL, + floodtt, + nextObj.appId(), + groupInfoCollection.size()); + + // create objects for local and distributed storage + List gkeys = new ArrayList(); + gkeys.add(l2floodgroupkey); // group0 in chain + OfdpaGroupChain ofdpaGrp = new OfdpaGroupChain(gkeys, nextObj); + + // store l2floodgroupkey with the ofdpaGroupChain for the nextObjective + // that depends on it + pendingNextObjectives.put(l2floodgroupkey, ofdpaGrp); + + for (GroupInfo gi : groupInfoCollection) { + // store all l2groupkeys with the groupChainElem for the l2floodgroup + // that depends on it + pendingGroups.put(gi.groupKey, gce); + + // create and send groups for all l2 interface groups + GroupDescription groupDescription = + new DefaultGroupDescription( + deviceId, + GroupDescription.Type.INDIRECT, + new GroupBuckets(Collections.singletonList(gi.groupBucket)), + gi.groupKey, + gi.groupId, + nextObj.appId()); + groupService.addGroup(groupDescription); + } + } + + private class GroupInfo { + private Integer groupId; + private GroupKey groupKey; + private GroupBucket groupBucket; + + GroupInfo(Integer groupId, GroupKey groupKey, GroupBucket groupBucket) { + this.groupBucket = groupBucket; + this.groupId = groupId; + this.groupKey = groupKey; + } + } + + private void processHashedNextObjective(NextObjective nextObj) { + // TODO Auto-generated method stub + } + + private void addBucketToGroup(NextObjective nextObjective) { + // TODO Auto-generated method stub + } + + private void removeBucketFromGroup(NextObjective nextObjective) { + // TODO Auto-generated method stub + } + + private void removeGroup(NextObjective nextObjective) { + // TODO Auto-generated method stub + } + /** * Processes next element of a group chain. Assumption is that if this * group points to another group, the latter has already been created @@ -803,21 +999,56 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline * that if there is another group waiting for this group then the appropriate * stores already have the information to act upon the notification for the * creating of this group. + *

+ * The processing of the GroupChainElement depends on the number of groups + * this element is waiting on. For all group types other than SIMPLE, a + * GroupChainElement could be waiting on multiple groups. * * @param gce the group chain element to be processed next */ private void processGroupChain(GroupChainElem gce) { - GroupBucket bucket = DefaultGroupBucket - .createIndirectGroupBucket(gce.getBucketActions()); - GroupDescription groupDesc = new DefaultGroupDescription(deviceId, - GroupDescription.Type.INDIRECT, - new GroupBuckets(Collections.singletonList(bucket)), - gce.getGkey(), - gce.getGivenGroupId(), - gce.getAppId()); - groupService.addGroup(groupDesc); - } + int waitOnGroups = gce.decrementAndGetGroupsWaitedOn(); + if (waitOnGroups != 0) { + log.debug("GCE: {} waiting on {} groups. Not processing yet", + gce, waitOnGroups); + return; + } + List buckets = new ArrayList<>(); + switch (gce.groupType) { + case INDIRECT: + GroupBucket ibucket = DefaultGroupBucket + .createIndirectGroupBucket(gce.bucketActions.iterator().next()); + buckets.add(ibucket); + break; + case ALL: + for (TrafficTreatment tt : gce.bucketActions) { + GroupBucket abucket = DefaultGroupBucket + .createAllGroupBucket(tt); + buckets.add(abucket); + } + break; + case SELECT: + for (TrafficTreatment tt : gce.bucketActions) { + GroupBucket sbucket = DefaultGroupBucket + .createSelectGroupBucket(tt); + buckets.add(sbucket); + } + break; + case FAILOVER: + default: + log.error("Unknown or unimplemented GroupChainElem {}", gce); + } + if (buckets.size() > 0) { + GroupDescription groupDesc = new DefaultGroupDescription( + deviceId, gce.groupType, + new GroupBuckets(buckets), + gce.gkey, + gce.givenGroupId, + gce.appId); + groupService.addGroup(groupDesc); + } + } private class GroupChecker implements Runnable { @Override @@ -837,7 +1068,7 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline log.info("Group service processed group key {}. Processing next " + "group in group chain with group key {}", appKryo.deserialize(key.key()), - appKryo.deserialize(gce.getGkey().key())); + appKryo.deserialize(gce.gkey.key())); processGroupChain(gce); } else { OfdpaGroupChain obj = pendingNextObjectives.getIfPresent(key); @@ -866,7 +1097,7 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline log.info("group ADDED with group key {} .. " + "Processing next group in group chain with group key {}", appKryo.deserialize(key.key()), - appKryo.deserialize(gce.getGkey().key())); + appKryo.deserialize(gce.gkey.key())); processGroupChain(gce); } else { OfdpaGroupChain obj = pendingNextObjectives.getIfPresent(key); @@ -890,6 +1121,11 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline * look like group0 --> group 1 --> outPort. Information about the groups * themselves can be fetched from the Group Service using the group keys from * objects instantiating this class. + * + * XXX Revisit this - since the forwarding objective only ever needs the + * groupkey of the top-level group in the group chain, why store a series + * of groupkeys. Also the group-chain list only works for 1-to-1 chaining, + * not for 1-to-many chaining. */ private class OfdpaGroupChain implements NextGroup { private final NextObjective nextObj; @@ -925,33 +1161,40 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline * preceding groups in the group chain to be created. */ private class GroupChainElem { - private TrafficTreatment bucketActions; + private Collection bucketActions; private Integer givenGroupId; + private GroupDescription.Type groupType; private GroupKey gkey; private ApplicationId appId; + private AtomicInteger waitOnGroups; - public GroupChainElem(GroupKey gkey, Integer givenGroupId, - TrafficTreatment tr, ApplicationId appId) { + GroupChainElem(GroupKey gkey, Integer givenGroupId, + GroupDescription.Type groupType, + Collection tr, ApplicationId appId, + int waitOnGroups) { this.bucketActions = tr; this.givenGroupId = givenGroupId; + this.groupType = groupType; this.gkey = gkey; this.appId = appId; + this.waitOnGroups = new AtomicInteger(waitOnGroups); } - public TrafficTreatment getBucketActions() { - return bucketActions; - } - - public Integer getGivenGroupId() { - return givenGroupId; + /** + * This methods atomically decrements the counter for the number of + * groups this GroupChainElement is waiting on, for notifications from + * the Group Service. When this method returns a value of 0, this + * GroupChainElement is ready to be processed. + * + * @return integer indication of the number of notifications being waited on + */ + int decrementAndGetGroupsWaitedOn() { + return waitOnGroups.decrementAndGet(); } - public GroupKey getGkey() { - return gkey; - } - - public ApplicationId getAppId() { - return appId; + @Override + public String toString() { + return Integer.toHexString(givenGroupId); } } diff --git a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/intf/package-info.java b/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/intf/package-info.java deleted file mode 100644 index 00f42ead..00000000 --- a/framework/src/onos/incubator/net/src/main/java/org/onosproject/incubator/net/intf/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * 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. - */ - -/** - * Service for interacting with interfaces. - */ -package org.onosproject.incubator.net.intf; diff --git a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java index 69c06165..d9848be5 100644 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java +++ b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java @@ -94,7 +94,7 @@ public class Controller { protected String tsLocation; protected char[] ksPwd; protected char[] tsPwd; - private SSLEngine serverSSLEngine; + protected SSLEngine serverSSLEngine; // Perf. related configuration protected static final int SEND_BUFFER_SIZE = 4 * 1024 * 1024; diff --git a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFChannelHandler.java b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFChannelHandler.java index 1a088ff7..ff92b77e 100644 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFChannelHandler.java +++ b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFChannelHandler.java @@ -445,7 +445,7 @@ class OFChannelHandler extends IdleStateAwareChannelHandler { log.debug("Switch {} bound to class {}, description {}", - new Object[] {h.sw, h.sw.getClass(), drep }); + h.sw, h.sw.getClass(), drep); //Put switch in EQUAL mode until we hear back from the global registry //log.debug("Setting new switch {} to EQUAL and sending Role request", // h.sw.getStringId()); @@ -730,10 +730,9 @@ class OFChannelHandler extends IdleStateAwareChannelHandler { */ protected void logError(OFChannelHandler h, OFErrorMsg error) { log.error("{} from switch {} in state {}", - new Object[] { error, h.getSwitchInfoString(), - this.toString()}); + this.toString()); } /** diff --git a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenFlowControllerImpl.java b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenFlowControllerImpl.java index d0429947..fdcd2f00 100644 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenFlowControllerImpl.java +++ b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenFlowControllerImpl.java @@ -498,10 +498,10 @@ public class OpenFlowControllerImpl implements OpenFlowController { activeEqualSwitches.get(dpid) != null) { log.error("Trying to activate switch but it is already " + "activated: dpid {}. Found in activeMaster: {} " - + "Found in activeEqual: {}. Aborting ..", new Object[]{ - dpid, - (activeMasterSwitches.get(dpid) == null) ? 'N' : 'Y', - (activeEqualSwitches.get(dpid) == null) ? 'N' : 'Y'}); + + "Found in activeEqual: {}. Aborting ..", + dpid, + (activeMasterSwitches.get(dpid) == null) ? 'N' : 'Y', + (activeEqualSwitches.get(dpid) == null) ? 'N' : 'Y'); return false; } return true; diff --git a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/RoleManager.java b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/RoleManager.java index e7e5ffee..bd4875cf 100644 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/RoleManager.java +++ b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/RoleManager.java @@ -213,8 +213,9 @@ class RoleManager implements RoleHandler { log.debug("Received unexpected RoleReply {} from " + "Switch: {}. " + "This controller has no current role for this sw. " - + "Ignoring ...", new Object[] {rri, - sw == null ? "(null)" : sw.getStringId(), }); + + "Ignoring ...", + rri, + sw == null ? "(null)" : sw.getStringId()); return RoleRecvStatus.OTHER_EXPECTATION; } @@ -232,7 +233,7 @@ class RoleManager implements RoleHandler { if (expectedRole == receivedRole) { log.debug("Received role reply message from {} that matched " + "expected role-reply {} with expectations {}", - new Object[] {sw.getStringId(), receivedRole, expectation}); + sw.getStringId(), receivedRole, expectation); // Done with this RoleReply; Invalidate pendingReplies.invalidate(xid); @@ -283,10 +284,10 @@ class RoleManager implements RoleHandler { log.error("Received a error msg {} from sw {} for " + "pending role request {}. Switch driver indicates " + "role-messaging is supported. Possible issues in " - + "switch driver configuration?", new Object[] { - ((OFBadRequestErrorMsg) error).toString(), - sw.getStringId(), errorRole - }); + + "switch driver configuration?", + ((OFBadRequestErrorMsg) error).toString(), + sw.getStringId(), + errorRole); return RoleRecvStatus.UNSUPPORTED; } diff --git a/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/DriverAdapter.java b/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/DriverAdapter.java new file mode 100644 index 00000000..57becf94 --- /dev/null +++ b/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/DriverAdapter.java @@ -0,0 +1,104 @@ +/* + * 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.openflow; + +import java.util.Map; +import java.util.Set; + +import org.onosproject.net.driver.Behaviour; +import org.onosproject.net.driver.Driver; +import org.onosproject.net.driver.DriverData; +import org.onosproject.net.driver.DriverHandler; +import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; + +/** + * Created by ray on 11/4/15. + */ +public class DriverAdapter implements Driver { + @Override + public String name() { + return null; + } + + @Override + public Driver parent() { + return null; + } + + @Override + public String manufacturer() { + return null; + } + + @Override + public String hwVersion() { + return null; + } + + @Override + public String swVersion() { + return null; + } + + @Override + public Set> behaviours() { + return null; + } + + @Override + public Class implementation(Class behaviour) { + return null; + } + + @Override + public boolean hasBehaviour(Class behaviourClass) { + return true; + } + + @Override + public T createBehaviour(DriverData data, Class behaviourClass) { + return null; + } + + @SuppressWarnings("unchecked") + @Override + public T createBehaviour(DriverHandler handler, Class behaviourClass) { + if (behaviourClass == OpenFlowSwitchDriver.class) { + return (T) new OpenflowSwitchDriverAdapter(); + } + return null; + } + + @Override + public Map properties() { + return null; + } + + @Override + public Driver merge(Driver other) { + return null; + } + + @Override + public Set keys() { + return null; + } + + @Override + public String value(String key) { + return null; + } +} diff --git a/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/DriverServiceAdapter.java b/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/DriverServiceAdapter.java new file mode 100644 index 00000000..25596ada --- /dev/null +++ b/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/DriverServiceAdapter.java @@ -0,0 +1,59 @@ +/* + * 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.openflow; + +import java.util.Set; + +import org.onosproject.net.DeviceId; +import org.onosproject.net.driver.Behaviour; +import org.onosproject.net.driver.Driver; +import org.onosproject.net.driver.DriverHandler; +import org.onosproject.net.driver.DriverService; + +/** + * Created by ray on 11/4/15. + */ +public class DriverServiceAdapter implements DriverService { + @Override + public Set getDrivers() { + return null; + } + + @Override + public Set getDrivers(Class withBehaviour) { + return null; + } + + @Override + public Driver getDriver(String mfr, String hw, String sw) { + return null; + } + + @Override + public Driver getDriver(DeviceId deviceId) { + return null; + } + + @Override + public DriverHandler createHandler(DeviceId deviceId, String... credentials) { + return null; + } + + @Override + public Driver getDriver(String driverName) { + return null; + } +} diff --git a/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/OFDescStatsReplyAdapter.java b/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/OFDescStatsReplyAdapter.java new file mode 100644 index 00000000..1e866413 --- /dev/null +++ b/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/OFDescStatsReplyAdapter.java @@ -0,0 +1,97 @@ +/* + * 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.openflow; + +import java.util.Set; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.projectfloodlight.openflow.protocol.OFDescStatsReply; +import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; +import org.projectfloodlight.openflow.protocol.OFStatsType; +import org.projectfloodlight.openflow.protocol.OFType; +import org.projectfloodlight.openflow.protocol.OFVersion; + +import com.google.common.hash.PrimitiveSink; + +/** + * Created by ray on 11/4/15. + */ +public class OFDescStatsReplyAdapter implements OFDescStatsReply { + @Override + public OFVersion getVersion() { + return null; + } + + @Override + public OFType getType() { + return null; + } + + @Override + public long getXid() { + return 0; + } + + @Override + public OFStatsType getStatsType() { + return null; + } + + @Override + public Set getFlags() { + return null; + } + + @Override + public String getMfrDesc() { + return null; + } + + @Override + public String getHwDesc() { + return null; + } + + @Override + public String getSwDesc() { + return null; + } + + @Override + public String getSerialNum() { + return null; + } + + @Override + public String getDpDesc() { + return null; + } + + @Override + public void writeTo(ChannelBuffer channelBuffer) { + + } + + @Override + public Builder createBuilder() { + return null; + } + + @Override + public void putTo(PrimitiveSink sink) { + + } +} diff --git a/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/OpenflowSwitchDriverAdapter.java b/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/OpenflowSwitchDriverAdapter.java new file mode 100644 index 00000000..25ea6412 --- /dev/null +++ b/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/OpenflowSwitchDriverAdapter.java @@ -0,0 +1,299 @@ +/* + * 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.openflow; + +import java.util.List; + +import org.jboss.netty.channel.Channel; +import org.onosproject.net.Device; +import org.onosproject.net.driver.DriverData; +import org.onosproject.net.driver.DriverHandler; +import org.onosproject.openflow.controller.Dpid; +import org.onosproject.openflow.controller.RoleState; +import org.onosproject.openflow.controller.driver.OpenFlowAgent; +import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; +import org.onosproject.openflow.controller.driver.RoleHandler; +import org.onosproject.openflow.controller.driver.SwitchStateException; +import org.projectfloodlight.openflow.protocol.OFDescStatsReply; +import org.projectfloodlight.openflow.protocol.OFErrorMsg; +import org.projectfloodlight.openflow.protocol.OFFactories; +import org.projectfloodlight.openflow.protocol.OFFactory; +import org.projectfloodlight.openflow.protocol.OFFeaturesReply; +import org.projectfloodlight.openflow.protocol.OFMessage; +import org.projectfloodlight.openflow.protocol.OFPortDesc; +import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; +import org.projectfloodlight.openflow.protocol.OFVersion; + +/** + * Testing adapter for the OpenFlow switch driver class. + */ +public class OpenflowSwitchDriverAdapter implements OpenFlowSwitchDriver { + @Override + public void setAgent(OpenFlowAgent agent) { + + } + + @Override + public void setRoleHandler(RoleHandler roleHandler) { + + } + + @Override + public void reassertRole() { + + } + + @Override + public boolean handleRoleError(OFErrorMsg error) { + return false; + } + + @Override + public void handleNiciraRole(OFMessage m) throws SwitchStateException { + + } + + @Override + public void handleRole(OFMessage m) throws SwitchStateException { + + } + + @Override + public boolean connectSwitch() { + return false; + } + + @Override + public boolean activateMasterSwitch() { + return false; + } + + @Override + public boolean activateEqualSwitch() { + return false; + } + + @Override + public void transitionToEqualSwitch() { + + } + + @Override + public void transitionToMasterSwitch() { + + } + + @Override + public void removeConnectedSwitch() { + + } + + @Override + public void setPortDescReply(OFPortDescStatsReply portDescReply) { + + } + + @Override + public void setPortDescReplies(List portDescReplies) { + + } + + @Override + public void setFeaturesReply(OFFeaturesReply featuresReply) { + + } + + @Override + public void setSwitchDescription(OFDescStatsReply desc) { + + } + + @Override + public int getNextTransactionId() { + return 0; + } + + @Override + public void setOFVersion(OFVersion ofV) { + + } + + @Override + public void setTableFull(boolean full) { + + } + + @Override + public void setChannel(Channel channel) { + + } + + @Override + public void setConnected(boolean connected) { + + } + + @Override + public void init(Dpid dpid, OFDescStatsReply desc, OFVersion ofv) { + + } + + @Override + public Boolean supportNxRole() { + return true; + } + + @Override + public void startDriverHandshake() { + + } + + @Override + public boolean isDriverHandshakeComplete() { + return false; + } + + @Override + public void processDriverHandshakeMessage(OFMessage m) { + + } + + @Override + public void sendRoleRequest(OFMessage message) { + + } + + @Override + public void sendHandshakeMessage(OFMessage message) { + + } + + @Override + public DriverHandler handler() { + return null; + } + + @Override + public void setHandler(DriverHandler handler) { + + } + + @Override + public DriverData data() { + return null; + } + + @Override + public void setData(DriverData data) { + + } + + @Override + public void sendMsg(OFMessage msg) { + + } + + @Override + public void sendMsg(List msgs) { + + } + + @Override + public void handleMessage(OFMessage fromSwitch) { + + } + + @Override + public void setRole(RoleState role) { + + } + + @Override + public RoleState getRole() { + return null; + } + + @Override + public List getPorts() { + return null; + } + + @Override + public OFFactory factory() { + // return what-ever triggers requestPending = true + return OFFactories.getFactory(OFVersion.OF_10); + } + + @Override + public String getStringId() { + return "100"; + } + + @Override + public long getId() { + return 0; + } + + @Override + public String manufacturerDescription() { + return null; + } + + @Override + public String datapathDescription() { + return null; + } + + @Override + public String hardwareDescription() { + return null; + } + + @Override + public String softwareDescription() { + return null; + } + + @Override + public String serialNumber() { + return null; + } + + @Override + public boolean isConnected() { + return false; + } + + @Override + public void disconnectSwitch() { + + } + + @Override + public void returnRoleReply(RoleState requested, RoleState response) { + + } + + @Override + public Device.Type deviceType() { + return Device.Type.SWITCH; + } + + @Override + public String channelId() { + return null; + } +} diff --git a/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/controller/impl/ControllerTest.java b/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/controller/impl/ControllerTest.java new file mode 100644 index 00000000..3ff3bde5 --- /dev/null +++ b/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/controller/impl/ControllerTest.java @@ -0,0 +1,219 @@ +/* + * 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.openflow.controller.impl; + +import java.io.File; +import java.io.IOException; +import java.util.Dictionary; +import java.util.Hashtable; +import java.util.Map; +import java.util.stream.IntStream; + +import org.junit.Before; +import org.junit.Test; +import org.onlab.junit.TestTools; +import org.onlab.util.ItemNotFoundException; +import org.onosproject.net.DeviceId; +import org.onosproject.net.driver.Driver; +import org.onosproject.openflow.DriverAdapter; +import org.onosproject.openflow.DriverServiceAdapter; +import org.onosproject.openflow.OFDescStatsReplyAdapter; +import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; +import org.projectfloodlight.openflow.protocol.OFDescStatsReply; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.io.Files; + +import static com.google.common.io.ByteStreams.toByteArray; +import static com.google.common.io.Files.write; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThan; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; + +/** + * Unit tests for the OpenFlow controller class. + */ +public class ControllerTest { + + Controller controller; + protected static final Logger log = LoggerFactory.getLogger(ControllerTest.class); + + static final File TEST_DIR = Files.createTempDir(); + + /* + * Writes the necessary file for the tests in the temporary directory + */ + static File stageTestResource(String name) throws IOException { + File file = new File(TEST_DIR, name); + byte[] bytes = toByteArray(ControllerTest.class.getResourceAsStream(name)); + write(bytes, file); + return file; + } + + class MockDriverService extends DriverServiceAdapter { + static final int NO_SUCH_DRIVER_ID = 1; + static final int ITEM_NOT_FOUND_DRIVER_ID = 2; + static final int DRIVER_EXISTS_ID = 3; + + static final String BASE_DRIVER_NAME = "of:000000000000000"; + + static final String NO_SUCH_DRIVER = BASE_DRIVER_NAME + + NO_SUCH_DRIVER_ID; + static final String ITEM_NOT_FOUND_DRIVER = BASE_DRIVER_NAME + + ITEM_NOT_FOUND_DRIVER_ID; + static final String DRIVER_EXISTS = BASE_DRIVER_NAME + + DRIVER_EXISTS_ID; + + @Override + public Driver getDriver(DeviceId deviceId) { + switch (deviceId.toString()) { + case NO_SUCH_DRIVER: + return null; + case ITEM_NOT_FOUND_DRIVER: + throw new ItemNotFoundException(); + case DRIVER_EXISTS: + return new DriverAdapter(); + default: + throw new AssertionError(); + } + } + } + + /** + * Creates and initializes a new controller. + */ + @Before + public void setUp() { + controller = new Controller(); + Dictionary properties = new Hashtable<>(); + properties.put("openflowPorts", + Integer.toString(TestTools.findAvailablePort(0))); + controller.setConfigParams(properties); + } + + /** + * Tests fetching a driver that does not exist. + */ + @Test + public void switchInstanceNotFoundTest() { + controller.start(null, new MockDriverService()); + OpenFlowSwitchDriver driver = + controller.getOFSwitchInstance(MockDriverService.NO_SUCH_DRIVER_ID, + null, + null); + assertThat(driver, nullValue()); + controller.stop(); + } + + /** + * Tests fetching a driver that throws an ItemNotFoundException. + */ + @Test + public void switchItemNotFoundTest() { + controller.start(null, new MockDriverService()); + OFDescStatsReply stats = + new OFDescStatsReplyAdapter(); + OpenFlowSwitchDriver driver = + controller.getOFSwitchInstance(MockDriverService.ITEM_NOT_FOUND_DRIVER_ID, + stats, + null); + assertThat(driver, nullValue()); + controller.stop(); + } + + /** + * Tests fetching a driver that throws an ItemNotFoundException. + */ + @Test + public void driverExistsTest() { + controller.start(null, new MockDriverService()); + OFDescStatsReply stats = + new OFDescStatsReplyAdapter(); + OpenFlowSwitchDriver driver = + controller.getOFSwitchInstance(MockDriverService.DRIVER_EXISTS_ID, + stats, + null); + assertThat(driver, notNullValue()); + controller.stop(); + } + + /** + * Tests configuring the controller. + */ + @Test + public void testConfiguration() { + Dictionary properties = new Hashtable<>(); + properties.put("openflowPorts", "1,2,3,4,5"); + properties.put("workerThreads", "5"); + + controller.setConfigParams(properties); + IntStream.rangeClosed(1, 5) + .forEach(i -> assertThat(controller.openFlowPorts, hasItem(i))); + assertThat(controller.workerThreads, is(5)); + } + + /** + * Tests the SSL/TLS methods in the controller. + */ + @Test + public void testSsl() throws IOException { + File keystore = stageTestResource("ControllerTestKeystore.jks"); + String keystoreName = keystore.getAbsolutePath(); + + System.setProperty("enableOFTLS", Boolean.toString(Boolean.TRUE)); + System.setProperty("javax.net.ssl.keyStore", keystoreName); + System.setProperty("javax.net.ssl.trustStore", keystoreName); + System.setProperty("javax.net.ssl.keyStorePassword", "password"); + System.setProperty("javax.net.ssl.trustStorePassword", "password"); + Dictionary properties = new Hashtable<>(); + properties.put("openflowPorts", + Integer.toString(TestTools.findAvailablePort(0))); + properties.put("workerThreads", "0"); + + controller.setConfigParams(properties); + controller.start(null, new MockDriverService()); + + assertThat(controller.serverSSLEngine, notNullValue()); + + controller.stop(); + boolean removed = keystore.delete(); + if (!removed) { + log.warn("Could not remove temporary file"); + } + } + + /** + * Tests controll utility health methods. + */ + @Test + public void testHealth() { + Map memory = controller.getMemory(); + assertThat(memory.size(), is(2)); + assertThat(memory.get("total"), is(not(0))); + assertThat(memory.get("free"), is(not(0))); + + long startTime = controller.getSystemStartTime(); + assertThat(startTime, lessThan(System.currentTimeMillis())); + + long upTime = controller.getSystemUptime(); + assertThat(upTime, lessThan(30L * 1000)); + } +} diff --git a/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/controller/impl/RoleManagerTest.java b/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/controller/impl/RoleManagerTest.java index 0a71a40d..4b594383 100644 --- a/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/controller/impl/RoleManagerTest.java +++ b/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/controller/impl/RoleManagerTest.java @@ -15,35 +15,21 @@ */ package org.onosproject.openflow.controller.impl; -import org.jboss.netty.channel.Channel; +import java.io.IOException; + import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.onosproject.net.Device; -import org.onosproject.net.driver.DriverData; -import org.onosproject.net.driver.DriverHandler; -import org.onosproject.openflow.controller.Dpid; +import org.onosproject.openflow.OpenflowSwitchDriverAdapter; import org.onosproject.openflow.controller.RoleState; -import org.onosproject.openflow.controller.driver.OpenFlowAgent; import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; -import org.onosproject.openflow.controller.driver.RoleHandler; import org.onosproject.openflow.controller.driver.RoleRecvStatus; import org.onosproject.openflow.controller.driver.RoleReplyInfo; import org.onosproject.openflow.controller.driver.SwitchStateException; import org.projectfloodlight.openflow.protocol.OFDescStatsReply; -import org.projectfloodlight.openflow.protocol.OFErrorMsg; -import org.projectfloodlight.openflow.protocol.OFFactories; -import org.projectfloodlight.openflow.protocol.OFFactory; import org.projectfloodlight.openflow.protocol.OFFeaturesReply; -import org.projectfloodlight.openflow.protocol.OFMessage; -import org.projectfloodlight.openflow.protocol.OFPortDesc; -import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; -import org.projectfloodlight.openflow.protocol.OFVersion; import org.projectfloodlight.openflow.types.U64; -import java.io.IOException; -import java.util.List; - import static org.junit.Assert.assertEquals; import static org.onosproject.openflow.controller.RoleState.MASTER; import static org.onosproject.openflow.controller.RoleState.SLAVE; @@ -103,24 +89,11 @@ public class RoleManagerTest { } } - private class TestSwitchDriver implements OpenFlowSwitchDriver { + private class TestSwitchDriver extends OpenflowSwitchDriverAdapter { RoleState failed = null; RoleState current = null; - @Override - public void sendMsg(OFMessage msg) { - } - - @Override - public void sendMsg(List msgs) { - } - - - @Override - public void handleMessage(OFMessage fromSwitch) { - } - @Override public void setRole(RoleState role) { current = role; @@ -131,143 +104,6 @@ public class RoleManagerTest { return current; } - @Override - public List getPorts() { - return null; - } - - @Override - public OFFactory factory() { - // return what-ever triggers requestPending = true - return OFFactories.getFactory(OFVersion.OF_10); - } - - @Override - public String getStringId() { - return "100"; - } - - @Override - public long getId() { - return 0; - } - - @Override - public String manufacturerDescription() { - return null; - } - - @Override - public String datapathDescription() { - return null; - } - - @Override - public String hardwareDescription() { - return null; - } - - @Override - public String softwareDescription() { - return null; - } - - @Override - public String serialNumber() { - return null; - } - - @Override - public void disconnectSwitch() { - } - - @Override - public Device.Type deviceType() { - return Device.Type.SWITCH; - } - - @Override - public void setAgent(OpenFlowAgent agent) { - } - - @Override - public void setRoleHandler(RoleHandler roleHandler) { - } - - @Override - public void reassertRole() { - } - - @Override - public boolean handleRoleError(OFErrorMsg error) { - return false; - } - - @Override - public void handleNiciraRole(OFMessage m) throws SwitchStateException { - } - - @Override - public void handleRole(OFMessage m) throws SwitchStateException { - } - - @Override - public void startDriverHandshake() { - } - - @Override - public boolean isDriverHandshakeComplete() { - return false; - } - - @Override - public void processDriverHandshakeMessage(OFMessage m) { - } - - @Override - public void sendRoleRequest(OFMessage message) { - - } - - @Override - public void sendHandshakeMessage(OFMessage message) { - } - - @Override - public boolean connectSwitch() { - return false; - } - - @Override - public boolean activateMasterSwitch() { - return false; - } - - @Override - public boolean activateEqualSwitch() { - return false; - } - - @Override - public void transitionToEqualSwitch() { - } - - @Override - public void transitionToMasterSwitch() { - } - - @Override - public void removeConnectedSwitch() { - } - - @Override - public void setPortDescReply(OFPortDescStatsReply portDescReply) { - } - - @Override - public void setPortDescReplies(List portDescReplies) { - } - @Override public void setFeaturesReply(OFFeaturesReply featuresReply) { } @@ -281,37 +117,6 @@ public class RoleManagerTest { return (int) XID; } - @Override - public Boolean supportNxRole() { - return true; - } - - @Override - public void setOFVersion(OFVersion ofV) { - } - - @Override - public void setTableFull(boolean full) { - } - - @Override - public void setChannel(Channel channel) { - } - - @Override - public void setConnected(boolean connected) { - } - - @Override - public void init(Dpid dpid, OFDescStatsReply desc, OFVersion ofv) { - - } - - @Override - public boolean isConnected() { - return false; - } - @Override public void returnRoleReply(RoleState requested, RoleState response) { failed = requested; @@ -321,25 +126,5 @@ public class RoleManagerTest { public String channelId() { return "1.2.3.4:1"; } - - @Override - public DriverHandler handler() { - return null; - } - - @Override - public void setHandler(DriverHandler handler) { - - } - - @Override - public DriverData data() { - return null; - } - - @Override - public void setData(DriverData data) { - - } } } diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java index edd25ac6..65ff0245 100644 --- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java +++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbClientService.java @@ -204,7 +204,7 @@ public interface OvsdbClientService extends OvsdbRPC { String getControllerUuid(String controllerName, String controllerTarget); /** - * Gets the Ovs uuid. + * Gets the OVS uuid. * * @param dbName database name * @return ovs uuid, empty if no uuid is find @@ -212,7 +212,7 @@ public interface OvsdbClientService extends OvsdbRPC { String getOvsUuid(String dbName); /** - * Gets the ovsdb database schema. + * Gets the OVSDB database schema. * * @param dbName database name * @return database schema @@ -220,7 +220,7 @@ public interface OvsdbClientService extends OvsdbRPC { ListenableFuture getOvsdbSchema(String dbName); /** - * Gets the ovsdb table updates. + * Gets the OVSDB table updates. * * @param dbName database name * @param id random uuid @@ -229,7 +229,7 @@ public interface OvsdbClientService extends OvsdbRPC { ListenableFuture monitorTables(String dbName, String id); /** - * Gets the ovsdb config operation result. + * Gets the OVSDB config operation result. * * @param dbName database name * @param operations the list of operations @@ -239,7 +239,7 @@ public interface OvsdbClientService extends OvsdbRPC { List operations); /** - * Gets the ovsdb database schema from local. + * Gets the OVSDB database schema from local. * * @param dbName database name * @return database schema @@ -247,17 +247,17 @@ public interface OvsdbClientService extends OvsdbRPC { DatabaseSchema getDatabaseSchema(String dbName); /** - * Gets the ovsdb row from local ovsdb store. + * Gets the OVSDB row from local OVSDB store. * * @param dbName database name * @param tableName table name * @param uuid row uuid - * @return row ovsdb row + * @return row OVSDB row */ Row getRow(String dbName, String tableName, String uuid); /** - * Removes the ovsdb row from local ovsdb store. + * Removes the OVSDB row from local OVSDB store. * * @param dbName database name * @param tableName table name @@ -266,25 +266,25 @@ public interface OvsdbClientService extends OvsdbRPC { void removeRow(String dbName, String tableName, String uuid); /** - * Updates the local ovsdb store. + * Updates the local OVSDB store. * * @param dbName database name * @param tableName table name * @param uuid row uuid - * @param row ovsdb row + * @param row OVSDB row */ void updateOvsdbStore(String dbName, String tableName, String uuid, Row row); /** - * Gets ovsdb local ports. + * Gets OVSDB local ports. * * @param ifaceids the ifaceid that needed - * @return ovsdb ports + * @return OVSDB ports */ Set getLocalPorts(Iterable ifaceids); /** - * Disconnects the ovsdb server. + * Disconnects the OVSDB server. */ void disconnect(); } diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbNodeId.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbNodeId.java index d7a5f61a..60146c85 100644 --- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbNodeId.java +++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbNodeId.java @@ -22,7 +22,7 @@ import java.util.Objects; import org.onlab.packet.IpAddress; /** - * The class representing a OpenStack Compute or Network nodeId. + * The class representing a nodeId of node which using ovsdb connection. * This class is immutable. */ public final class OvsdbNodeId { diff --git a/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilder.java b/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilder.java index 7eca4920..010d7e7c 100644 --- a/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilder.java +++ b/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilder.java @@ -105,6 +105,7 @@ public abstract class FlowModBuilder { * @param flowRule the flow rule to transform into a flow mod * @param factory the OpenFlow factory to use to build the flow mod * @param xid the transaction ID + * @param driverService the device driver service * @return the new flow mod builder */ public static FlowModBuilder builder(FlowRule flowRule, @@ -127,6 +128,7 @@ public abstract class FlowModBuilder { * * @param flowRule the flow rule to transform into a flow mod * @param factory the OpenFlow factory to use to build the flow mod + * @param driverService the device driver service * @param xid the transaction ID */ protected FlowModBuilder(FlowRule flowRule, OFFactory factory, Optional xid, diff --git a/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer10.java b/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer10.java index 6c4ee4dc..bdea09da 100644 --- a/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer10.java +++ b/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer10.java @@ -69,6 +69,7 @@ public class FlowModBuilderVer10 extends FlowModBuilder { * @param flowRule the flow rule to transform into a flow mod * @param factory the OpenFlow factory to use to build the flow mod * @param xid the transaction ID + * @param driverService the device driver service */ protected FlowModBuilderVer10(FlowRule flowRule, OFFactory factory, Optional xid, diff --git a/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java b/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java index a99aa817..e2fc30da 100644 --- a/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java +++ b/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowModBuilderVer13.java @@ -103,6 +103,7 @@ public class FlowModBuilderVer13 extends FlowModBuilder { * @param flowRule the flow rule to transform into a flow mod * @param factory the OpenFlow factory to use to build the flow mod * @param xid the transaction ID + * @param driverService the device driver service */ protected FlowModBuilderVer13(FlowRule flowRule, OFFactory factory, Optional xid, Optional driverService) { diff --git a/framework/src/onos/utils/junit/src/main/java/org/onlab/junit/TestTools.java b/framework/src/onos/utils/junit/src/main/java/org/onlab/junit/TestTools.java index e2fcefce..40e8686c 100644 --- a/framework/src/onos/utils/junit/src/main/java/org/onlab/junit/TestTools.java +++ b/framework/src/onos/utils/junit/src/main/java/org/onlab/junit/TestTools.java @@ -20,6 +20,7 @@ import com.google.common.io.Files; import java.io.File; import java.io.IOException; +import java.net.ServerSocket; import java.util.List; import java.util.Random; @@ -207,4 +208,20 @@ public final class TestTools { } } + /* + * Finds an available port that a test can bind to. + */ + public static int findAvailablePort(int defaultPort) { + try { + ServerSocket socket = new ServerSocket(0); + socket.setReuseAddress(true); + int port = socket.getLocalPort(); + socket.close(); + return port; + } catch (IOException ex) { + return defaultPort; + } + } + + } diff --git a/framework/src/onos/utils/junit/src/main/resources/org/onosproject/openflow/controller/impl/ControllerTestKeystore.jks b/framework/src/onos/utils/junit/src/main/resources/org/onosproject/openflow/controller/impl/ControllerTestKeystore.jks new file mode 100644 index 00000000..ba750519 Binary files /dev/null and b/framework/src/onos/utils/junit/src/main/resources/org/onosproject/openflow/controller/impl/ControllerTestKeystore.jks differ -- cgit 1.2.3-korg