diff options
Diffstat (limited to 'framework/src/onos')
846 files changed, 14552 insertions, 64770 deletions
diff --git a/framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAA.java b/framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAA.java deleted file mode 100644 index 567944a6..00000000 --- a/framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAA.java +++ /dev/null @@ -1,563 +0,0 @@ -/* - * Copyright 2015 AT&T Foundry - * - * 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.aaa; - -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.InetAddress; -import java.nio.ByteBuffer; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - -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.onlab.packet.DeserializationException; -import org.onlab.packet.EAP; -import org.onlab.packet.EAPOL; -import org.onlab.packet.EthType; -import org.onlab.packet.Ethernet; -import org.onlab.packet.MacAddress; -import org.onlab.packet.RADIUS; -import org.onlab.packet.RADIUSAttribute; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.onosproject.net.PortNumber; -import org.onosproject.net.config.ConfigFactory; -import org.onosproject.net.config.NetworkConfigEvent; -import org.onosproject.net.config.NetworkConfigListener; -import org.onosproject.net.config.NetworkConfigRegistry; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.packet.DefaultOutboundPacket; -import org.onosproject.net.packet.InboundPacket; -import org.onosproject.net.packet.OutboundPacket; -import org.onosproject.net.packet.PacketContext; -import org.onosproject.net.packet.PacketProcessor; -import org.onosproject.net.packet.PacketService; -import org.onosproject.xosintegration.VoltTenantService; -import org.slf4j.Logger; - -import com.google.common.util.concurrent.ThreadFactoryBuilder; - -import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; -import static org.onosproject.net.packet.PacketPriority.CONTROL; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * AAA application for ONOS. - */ -@Component(immediate = true) -public class AAA { - - // for verbose output - private final Logger log = getLogger(getClass()); - - // a list of our dependencies : - // to register with ONOS as an application - described next - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - // to receive Packet-in events that we'll respond to - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected PacketService packetService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected VoltTenantService voltTenantService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected NetworkConfigRegistry netCfgService; - - // Parsed RADIUS server addresses - protected InetAddress radiusIpAddress; - protected String radiusMacAddress; - - // NAS IP address - protected InetAddress nasIpAddress; - protected String nasMacAddress; - - // RADIUS server secret - protected String radiusSecret; - - // ID of RADIUS switch - protected String radiusSwitch; - - // RADIUS port number - protected long radiusPort; - - // RADIUS server TCP port number - protected short radiusServerPort; - - // our application-specific event handler - private ReactivePacketProcessor processor = new ReactivePacketProcessor(); - - // our unique identifier - private ApplicationId appId; - - // Socket used for UDP communications with RADIUS server - private DatagramSocket radiusSocket; - - // Executor for RADIUS communication thread - private ExecutorService executor; - - // Configuration properties factory - private final ConfigFactory factory = - new ConfigFactory<ApplicationId, AAAConfig>(APP_SUBJECT_FACTORY, - AAAConfig.class, - "AAA") { - @Override - public AAAConfig createConfig() { - return new AAAConfig(); - } - }; - - // Listener for config changes - private final InternalConfigListener cfgListener = new InternalConfigListener(); - - /** - * Builds an EAPOL packet based on the given parameters. - * - * @param dstMac destination MAC address - * @param srcMac source MAC address - * @param vlan vlan identifier - * @param eapolType EAPOL type - * @param eap EAP payload - * @return Ethernet frame - */ - private static Ethernet buildEapolResponse(MacAddress dstMac, MacAddress srcMac, - short vlan, byte eapolType, EAP eap) { - - Ethernet eth = new Ethernet(); - eth.setDestinationMACAddress(dstMac.toBytes()); - eth.setSourceMACAddress(srcMac.toBytes()); - eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort()); - if (vlan != Ethernet.VLAN_UNTAGGED) { - eth.setVlanID(vlan); - } - //eapol header - EAPOL eapol = new EAPOL(); - eapol.setEapolType(eapolType); - eapol.setPacketLength(eap.getLength()); - - //eap part - eapol.setPayload(eap); - - eth.setPayload(eapol); - eth.setPad(true); - return eth; - } - - @Activate - public void activate() { - netCfgService.addListener(cfgListener); - netCfgService.registerConfigFactory(factory); - - // "org.onosproject.aaa" is the FQDN of our app - appId = coreService.registerApplication("org.onosproject.aaa"); - - cfgListener.reconfigureNetwork(netCfgService.getConfig(appId, AAAConfig.class)); - - // register our event handler - packetService.addProcessor(processor, PacketProcessor.director(2)); - requestIntercepts(); - - StateMachine.initializeMaps(); - - try { - radiusSocket = new DatagramSocket(radiusServerPort); - } catch (Exception ex) { - log.error("Can't open RADIUS socket", ex); - } - - executor = Executors.newSingleThreadExecutor( - new ThreadFactoryBuilder() - .setNameFormat("AAA-radius-%d").build()); - executor.execute(radiusListener); - } - - @Deactivate - public void deactivate() { - appId = coreService.registerApplication("org.onosproject.aaa"); - withdrawIntercepts(); - // de-register and null our handler - packetService.removeProcessor(processor); - processor = null; - StateMachine.destroyMaps(); - radiusSocket.close(); - executor.shutdownNow(); - } - - protected void sendRADIUSPacket(RADIUS radiusPacket) { - - try { - final byte[] data = radiusPacket.serialize(); - final DatagramSocket socket = radiusSocket; - - DatagramPacket packet = - new DatagramPacket(data, data.length, - radiusIpAddress, radiusServerPort); - - socket.send(packet); - } catch (IOException e) { - log.info("Cannot send packet to RADIUS server", e); - } - } - - /** - * Request packet in via PacketService. - */ - private void requestIntercepts() { - TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); - selector.matchEthType(EthType.EtherType.EAPOL.ethType().toShort()); - packetService.requestPackets(selector.build(), - CONTROL, appId); - } - - /** - * Cancel request for packet in via PacketService. - */ - private void withdrawIntercepts() { - TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); - selector.matchEthType(EthType.EtherType.EAPOL.ethType().toShort()); - packetService.cancelPackets(selector.build(), CONTROL, appId); - } - - /** - * Send the ethernet packet to the supplicant. - * - * @param ethernetPkt the ethernet packet - * @param connectPoint the connect point to send out - */ - private void sendPacketToSupplicant(Ethernet ethernetPkt, ConnectPoint connectPoint) { - TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(connectPoint.port()).build(); - OutboundPacket packet = new DefaultOutboundPacket(connectPoint.deviceId(), - treatment, ByteBuffer.wrap(ethernetPkt.serialize())); - packetService.emit(packet); - } - - // our handler defined as a private inner class - - /** - * Packet processor responsible for forwarding packets along their paths. - */ - private class ReactivePacketProcessor implements PacketProcessor { - @Override - public void process(PacketContext context) { - - // Extract the original Ethernet frame from the packet information - InboundPacket pkt = context.inPacket(); - Ethernet ethPkt = pkt.parsed(); - if (ethPkt == null) { - return; - } - try { - // identify if incoming packet comes from supplicant (EAP) or RADIUS - switch (EthType.EtherType.lookup(ethPkt.getEtherType())) { - case EAPOL: - handleSupplicantPacket(context.inPacket()); - break; - default: - log.trace("Skipping Ethernet packet type {}", - EthType.EtherType.lookup(ethPkt.getEtherType())); - } - } catch (StateMachineException e) { - log.warn("Unable to process RADIUS packet:", e); - } - } - - /** - * Creates and initializes common fields of a RADIUS packet. - * - * @param stateMachine state machine for the request - * @param eapPacket EAP packet - * @return RADIUS packet - */ - private RADIUS getRadiusPayload(StateMachine stateMachine, byte identifier, EAP eapPacket) { - RADIUS radiusPayload = - new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, - eapPacket.getIdentifier()); - - // set Request Authenticator in StateMachine - stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); - - radiusPayload.setIdentifier(identifier); - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, - stateMachine.username()); - - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP, - AAA.this.nasIpAddress.getAddress()); - - radiusPayload.encapsulateMessage(eapPacket); - - return radiusPayload; - } - - /** - * Handles PAE packets (supplicant). - * - * @param inPacket Ethernet packet coming from the supplicant - */ - private void handleSupplicantPacket(InboundPacket inPacket) throws StateMachineException { - Ethernet ethPkt = inPacket.parsed(); - // Where does it come from? - MacAddress srcMAC = ethPkt.getSourceMAC(); - - DeviceId deviceId = inPacket.receivedFrom().deviceId(); - PortNumber portNumber = inPacket.receivedFrom().port(); - String sessionId = deviceId.toString() + portNumber.toString(); - StateMachine stateMachine = StateMachine.lookupStateMachineBySessionId(sessionId); - if (stateMachine == null) { - stateMachine = new StateMachine(sessionId, voltTenantService); - } - - - EAPOL eapol = (EAPOL) ethPkt.getPayload(); - - switch (eapol.getEapolType()) { - case EAPOL.EAPOL_START: - stateMachine.start(); - stateMachine.setSupplicantConnectpoint(inPacket.receivedFrom()); - - //send an EAP Request/Identify to the supplicant - EAP eapPayload = new EAP(EAP.REQUEST, stateMachine.identifier(), EAP.ATTR_IDENTITY, null); - Ethernet eth = buildEapolResponse(srcMAC, MacAddress.valueOf(nasMacAddress), - ethPkt.getVlanID(), EAPOL.EAPOL_PACKET, - eapPayload); - stateMachine.setSupplicantAddress(srcMAC); - stateMachine.setVlanId(ethPkt.getVlanID()); - - sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); - - break; - case EAPOL.EAPOL_PACKET: - RADIUS radiusPayload; - // check if this is a Response/Identify or a Response/TLS - EAP eapPacket = (EAP) eapol.getPayload(); - - byte dataType = eapPacket.getDataType(); - switch (dataType) { - - case EAP.ATTR_IDENTITY: - // request id access to RADIUS - stateMachine.setUsername(eapPacket.getData()); - - radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket); - radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret); - - sendRADIUSPacket(radiusPayload); - - // change the state to "PENDING" - stateMachine.requestAccess(); - break; - case EAP.ATTR_MD5: - // verify if the EAP identifier corresponds to the - // challenge identifier from the client state - // machine. - if (eapPacket.getIdentifier() == stateMachine.challengeIdentifier()) { - //send the RADIUS challenge response - radiusPayload = - getRadiusPayload(stateMachine, - stateMachine.identifier(), - eapPacket); - - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, - stateMachine.challengeState()); - radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret); - sendRADIUSPacket(radiusPayload); - } - break; - case EAP.ATTR_TLS: - // request id access to RADIUS - radiusPayload = getRadiusPayload(stateMachine, stateMachine.identifier(), eapPacket); - - radiusPayload.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, - stateMachine.challengeState()); - stateMachine.setRequestAuthenticator(radiusPayload.generateAuthCode()); - - radiusPayload.addMessageAuthenticator(AAA.this.radiusSecret); - sendRADIUSPacket(radiusPayload); - - if (stateMachine.state() != StateMachine.STATE_PENDING) { - stateMachine.requestAccess(); - } - - break; - default: - return; - } - break; - default: - log.trace("Skipping EAPOL message {}", eapol.getEapolType()); - } - - } - } - - class RadiusListener implements Runnable { - - /** - * Handles RADIUS packets. - * - * @param radiusPacket RADIUS packet coming from the RADIUS server. - * @throws StateMachineException if an illegal state transition is triggered - */ - protected void handleRadiusPacket(RADIUS radiusPacket) throws StateMachineException { - StateMachine stateMachine = StateMachine.lookupStateMachineById(radiusPacket.getIdentifier()); - if (stateMachine == null) { - log.error("Invalid session identifier, exiting..."); - return; - } - - EAP eapPayload; - Ethernet eth; - switch (radiusPacket.getCode()) { - case RADIUS.RADIUS_CODE_ACCESS_CHALLENGE: - byte[] challengeState = - radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_STATE).getValue(); - eapPayload = radiusPacket.decapsulateMessage(); - stateMachine.setChallengeInfo(eapPayload.getIdentifier(), challengeState); - eth = buildEapolResponse(stateMachine.supplicantAddress(), - MacAddress.valueOf(nasMacAddress), - stateMachine.vlanId(), - EAPOL.EAPOL_PACKET, - eapPayload); - sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); - break; - case RADIUS.RADIUS_CODE_ACCESS_ACCEPT: - //send an EAPOL - Success to the supplicant. - byte[] eapMessage = - radiusPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE).getValue(); - eapPayload = new EAP(); - eapPayload = (EAP) eapPayload.deserialize(eapMessage, 0, eapMessage.length); - eth = buildEapolResponse(stateMachine.supplicantAddress(), - MacAddress.valueOf(nasMacAddress), - stateMachine.vlanId(), - EAPOL.EAPOL_PACKET, - eapPayload); - sendPacketToSupplicant(eth, stateMachine.supplicantConnectpoint()); - - stateMachine.authorizeAccess(); - break; - case RADIUS.RADIUS_CODE_ACCESS_REJECT: - stateMachine.denyAccess(); - break; - default: - log.warn("Unknown RADIUS message received with code: {}", radiusPacket.getCode()); - } - } - - - @Override - public void run() { - boolean done = false; - int packetNumber = 1; - - log.info("UDP listener thread starting up"); - RADIUS inboundRadiusPacket; - while (!done) { - try { - byte[] packetBuffer = new byte[RADIUS.RADIUS_MAX_LENGTH]; - DatagramPacket inboundBasePacket = - new DatagramPacket(packetBuffer, packetBuffer.length); - DatagramSocket socket = radiusSocket; - socket.receive(inboundBasePacket); - log.info("Packet #{} received", packetNumber++); - try { - inboundRadiusPacket = - RADIUS.deserializer() - .deserialize(inboundBasePacket.getData(), - 0, - inboundBasePacket.getLength()); - handleRadiusPacket(inboundRadiusPacket); - } catch (DeserializationException dex) { - log.error("Cannot deserialize packet", dex); - } catch (StateMachineException sme) { - log.error("Illegal state machine operation", sme); - } - - } catch (IOException e) { - log.info("Socket was closed, exiting listener thread"); - done = true; - } - } - } - } - - RadiusListener radiusListener = new RadiusListener(); - - private class InternalConfigListener implements NetworkConfigListener { - - /** - * Reconfigures the DHCP Server according to the configuration parameters passed. - * - * @param cfg configuration object - */ - private void reconfigureNetwork(AAAConfig cfg) { - AAAConfig newCfg; - if (cfg == null) { - newCfg = new AAAConfig(); - } else { - newCfg = cfg; - } - if (newCfg.nasIp() != null) { - nasIpAddress = newCfg.nasIp(); - } - if (newCfg.radiusIp() != null) { - radiusIpAddress = newCfg.radiusIp(); - } - if (newCfg.radiusMac() != null) { - radiusMacAddress = newCfg.radiusMac(); - } - if (newCfg.nasMac() != null) { - nasMacAddress = newCfg.nasMac(); - } - if (newCfg.radiusSecret() != null) { - radiusSecret = newCfg.radiusSecret(); - } - if (newCfg.radiusSwitch() != null) { - radiusSwitch = newCfg.radiusSwitch(); - } - if (newCfg.radiusPort() != -1) { - radiusPort = newCfg.radiusPort(); - } - if (newCfg.radiusServerUDPPort() != -1) { - radiusServerPort = newCfg.radiusServerUDPPort(); - } - } - - @Override - public void event(NetworkConfigEvent event) { - - if ((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || - event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED) && - event.configClass().equals(AAAConfig.class)) { - - AAAConfig cfg = netCfgService.getConfig(appId, AAAConfig.class); - reconfigureNetwork(cfg); - log.info("Reconfigured"); - } - } - } - - -} diff --git a/framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAAConfig.java b/framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAAConfig.java deleted file mode 100644 index 73be7691..00000000 --- a/framework/src/onos/apps/aaa/src/main/java/org/onosproject/aaa/AAAConfig.java +++ /dev/null @@ -1,239 +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.aaa; - -import java.net.InetAddress; -import java.net.UnknownHostException; - -import org.onosproject.core.ApplicationId; -import org.onosproject.net.config.Config; -import org.onosproject.net.config.basics.BasicElementConfig; - -/** - * Network config for the AAA app. - */ -public class AAAConfig extends Config<ApplicationId> { - - private static final String RADIUS_IP = "radiusIp"; - private static final String RADIUS_SERVER_PORT = "1812"; - private static final String RADIUS_MAC = "radiusMac"; - private static final String NAS_IP = "nasIp"; - private static final String NAS_MAC = "nasMac"; - private static final String RADIUS_SECRET = "radiusSecret"; - private static final String RADIUS_SWITCH = "radiusSwitch"; - private static final String RADIUS_PORT = "radiusPort"; - - // RADIUS server IP address - protected static final String DEFAULT_RADIUS_IP = "10.128.10.4"; - - // RADIUS MAC address - protected static final String DEFAULT_RADIUS_MAC = "00:00:00:00:01:10"; - - // NAS IP address - protected static final String DEFAULT_NAS_IP = "10.128.9.244"; - - // NAS MAC address - protected static final String DEFAULT_NAS_MAC = "00:00:00:00:10:01"; - - // RADIUS server shared secret - protected static final String DEFAULT_RADIUS_SECRET = "ONOSecret"; - - // Radius Switch Id - protected static final String DEFAULT_RADIUS_SWITCH = "of:90e2ba82f97791e9"; - - // Radius Port Number - protected static final String DEFAULT_RADIUS_PORT = "129"; - - // Radius Server UDP Port Number - protected static final String DEFAULT_RADIUS_SERVER_PORT = "1812"; - - /** - * Gets the value of a string property, protecting for an empty - * JSON object. - * - * @param name name of the property - * @param defaultValue default value if none has been specified - * @return String value if one os found, default value otherwise - */ - private String getStringProperty(String name, String defaultValue) { - if (object == null) { - return defaultValue; - } - return get(name, defaultValue); - } - - /** - * Returns the NAS ip. - * - * @return ip address or null if not set - */ - public InetAddress nasIp() { - try { - return InetAddress.getByName(getStringProperty(NAS_IP, DEFAULT_NAS_IP)); - } catch (UnknownHostException e) { - return null; - } - } - - /** - * Sets the NAS ip. - * - * @param ip new ip address; null to clear - * @return self - */ - public BasicElementConfig nasIp(String ip) { - return (BasicElementConfig) setOrClear(NAS_IP, ip); - } - - /** - * Returns the RADIUS server ip. - * - * @return ip address or null if not set - */ - public InetAddress radiusIp() { - try { - return InetAddress.getByName(getStringProperty(RADIUS_IP, DEFAULT_RADIUS_IP)); - } catch (UnknownHostException e) { - return null; - } - } - - /** - * Sets the RADIUS server ip. - * - * @param ip new ip address; null to clear - * @return self - */ - public BasicElementConfig radiusIp(String ip) { - return (BasicElementConfig) setOrClear(RADIUS_IP, ip); - } - - /** - * Returns the RADIUS MAC address. - * - * @return mac address or null if not set - */ - public String radiusMac() { - return getStringProperty(RADIUS_MAC, DEFAULT_RADIUS_MAC); - } - - /** - * Sets the RADIUS MAC address. - * - * @param mac new MAC address; null to clear - * @return self - */ - public BasicElementConfig radiusMac(String mac) { - return (BasicElementConfig) setOrClear(RADIUS_MAC, mac); - } - - /** - * Returns the RADIUS MAC address. - * - * @return mac address or null if not set - */ - public String nasMac() { - return getStringProperty(NAS_MAC, DEFAULT_NAS_MAC); - } - - /** - * Sets the RADIUS MAC address. - * - * @param mac new MAC address; null to clear - * @return self - */ - public BasicElementConfig nasMac(String mac) { - return (BasicElementConfig) setOrClear(NAS_MAC, mac); - } - - /** - * Returns the RADIUS secret. - * - * @return radius secret or null if not set - */ - public String radiusSecret() { - return getStringProperty(RADIUS_SECRET, DEFAULT_RADIUS_SECRET); - } - - /** - * Sets the RADIUS secret. - * - * @param secret new MAC address; null to clear - * @return self - */ - public BasicElementConfig radiusSecret(String secret) { - return (BasicElementConfig) setOrClear(RADIUS_SECRET, secret); - } - - /** - * Returns the ID of the RADIUS switch. - * - * @return radius switch ID or null if not set - */ - public String radiusSwitch() { - return getStringProperty(RADIUS_SWITCH, DEFAULT_RADIUS_SWITCH); - } - - /** - * Sets the ID of the RADIUS switch. - * - * @param switchId new RADIUS switch ID; null to clear - * @return self - */ - public BasicElementConfig radiusSwitch(String switchId) { - return (BasicElementConfig) setOrClear(RADIUS_SWITCH, switchId); - } - - /** - * Returns the RADIUS port. - * - * @return radius port or null if not set - */ - public long radiusPort() { - return Integer.parseInt(getStringProperty(RADIUS_PORT, DEFAULT_RADIUS_PORT)); - } - - /** - * Sets the RADIUS port. - * - * @param port new RADIUS port; null to clear - * @return self - */ - public BasicElementConfig radiusPort(long port) { - return (BasicElementConfig) setOrClear(RADIUS_PORT, port); - } - - /** - * Returns the RADIUS server UDP port. - * - * @return radius server UDP port. - */ - public short radiusServerUDPPort() { - return Short.parseShort(getStringProperty(RADIUS_SERVER_PORT, - DEFAULT_RADIUS_SERVER_PORT)); - } - - /** - * Sets the RADIUS port. - * - * @param port new RADIUS UDP port; -1 to clear - * @return self - */ - public BasicElementConfig radiusServerUDPPort(short port) { - return (BasicElementConfig) setOrClear(RADIUS_SERVER_PORT, (long) port); - } - -} diff --git a/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAAIntegrationTest.java b/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAAIntegrationTest.java deleted file mode 100644 index fb513ced..00000000 --- a/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAAIntegrationTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright 2014 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.aaa; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.onlab.packet.EAP; -import org.onlab.packet.EAPOL; -import org.onlab.packet.Ethernet; -import org.onosproject.core.CoreServiceAdapter; -import org.onosproject.net.config.Config; -import org.onosproject.net.config.NetworkConfigRegistryAdapter; - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; - -/** - * Set of tests of the ONOS application component. These use an existing RADIUS - * server and sends live packets over the network to it. - */ -@Ignore ("This should not be run as part of the standard build") -public class AAAIntegrationTest extends AAATestBase { - - private AAA aaa; - - /** - * Mocks the network config registry. - */ - @SuppressWarnings("unchecked") - static final class TestNetworkConfigRegistry - extends NetworkConfigRegistryAdapter { - @Override - public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { - return (C) new AAAConfig(); - } - } - - /** - * Sets up the services required by the AAA application. - */ - @Before - public void setUp() { - aaa = new AAA(); - aaa.netCfgService = new TestNetworkConfigRegistry(); - aaa.coreService = new CoreServiceAdapter(); - aaa.packetService = new MockPacketService(); - aaa.activate(); - } - - /** - * Fetches the sent packet at the given index. The requested packet - * must be the last packet on the list. - * - * @param index index into sent packets array - * @return packet - */ - private Ethernet fetchPacket(int index) { - for (int iteration = 0; iteration < 20; iteration++) { - if (savedPackets.size() > index) { - return (Ethernet) savedPackets.get(index); - } else { - try { - Thread.sleep(250); - } catch (Exception ex) { - return null; - } - } - } - return null; - } - - /** - * Tests the authentication path through the AAA application by sending - * packets to the RADIUS server and checking the state machine - * transitions. - * - * @throws Exception when an unhandled error occurs - */ - @Test - public void testAuthentication() throws Exception { - - // (1) Supplicant start up - - Ethernet startPacket = constructSupplicantStartPacket(); - sendPacket(startPacket); - - Ethernet responsePacket = fetchPacket(0); - assertThat(responsePacket, notNullValue()); - checkRadiusPacket(aaa, responsePacket, EAP.REQUEST); - - // (2) Supplicant identify - - Ethernet identifyPacket = constructSupplicantIdentifyPacket(null, EAP.ATTR_IDENTITY, (byte) 1, null); - sendPacket(identifyPacket); - - // State machine should have been created by now - - StateMachine stateMachine = - StateMachine.lookupStateMachineBySessionId(SESSION_ID); - assertThat(stateMachine, notNullValue()); - assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING)); - - // (3) RADIUS MD5 challenge - - Ethernet radiusChallengeMD5Packet = fetchPacket(1); - assertThat(radiusChallengeMD5Packet, notNullValue()); - checkRadiusPacket(aaa, radiusChallengeMD5Packet, EAP.REQUEST); - - - // (4) Supplicant MD5 response - - Ethernet md5RadiusPacket = - constructSupplicantIdentifyPacket(stateMachine, - EAP.ATTR_MD5, - stateMachine.challengeIdentifier(), - radiusChallengeMD5Packet); - sendPacket(md5RadiusPacket); - - - // (5) RADIUS Success - - Ethernet successRadiusPacket = fetchPacket(2); - assertThat(successRadiusPacket, notNullValue()); - EAPOL successEAPOL = (EAPOL) successRadiusPacket.getPayload(); - EAP successEAP = (EAP) successEAPOL.getPayload(); - assertThat(successEAP.getCode(), is(EAP.SUCCESS)); - - // State machine should be in authorized state - - assertThat(stateMachine, notNullValue()); - assertThat(stateMachine.state(), is(StateMachine.STATE_AUTHORIZED)); - - } - -} - diff --git a/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATest.java b/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATest.java deleted file mode 100644 index 860a7dbd..00000000 --- a/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATest.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * Copyright 2014 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.aaa; - -import java.net.InetAddress; -import java.net.UnknownHostException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onlab.packet.BasePacket; -import org.onlab.packet.DeserializationException; -import org.onlab.packet.EAP; -import org.onlab.packet.Ethernet; -import org.onlab.packet.IpAddress; -import org.onlab.packet.RADIUS; -import org.onlab.packet.RADIUSAttribute; -import org.onosproject.core.CoreServiceAdapter; -import org.onosproject.net.config.Config; -import org.onosproject.net.config.NetworkConfigRegistryAdapter; - -import com.google.common.base.Charsets; - -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; - -/** - * Set of tests of the ONOS application component. - */ -public class AAATest extends AAATestBase { - - static final String BAD_IP_ADDRESS = "198.51.100.0"; - - private AAA aaa; - - class AAAWithoutRadiusServer extends AAA { - protected void sendRADIUSPacket(RADIUS radiusPacket) { - savePacket(radiusPacket); - } - } - - /** - * Mocks the AAAConfig class to force usage of an unroutable address for the - * RADIUS server. - */ - static class MockAAAConfig extends AAAConfig { - @Override - public InetAddress radiusIp() { - try { - return InetAddress.getByName(BAD_IP_ADDRESS); - } catch (UnknownHostException ex) { - // can't happen - throw new IllegalStateException(ex); - } - } - } - - /** - * Mocks the network config registry. - */ - @SuppressWarnings("unchecked") - private static final class TestNetworkConfigRegistry - extends NetworkConfigRegistryAdapter { - @Override - public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) { - AAAConfig aaaConfig = new MockAAAConfig(); - return (C) aaaConfig; - } - } - - /** - * Constructs an Ethernet packet containing a RADIUS challenge - * packet. - * - * @param challengeCode code to use in challenge packet - * @param challengeType type to use in challenge packet - * @return Ethernet packet - */ - private RADIUS constructRADIUSCodeAccessChallengePacket(byte challengeCode, byte challengeType) { - - String challenge = "12345678901234567"; - - EAP eap = new EAP(challengeType, (byte) 1, challengeType, - challenge.getBytes(Charsets.US_ASCII)); - eap.setIdentifier((byte) 1); - - RADIUS radius = new RADIUS(); - radius.setCode(challengeCode); - - radius.setAttribute(RADIUSAttribute.RADIUS_ATTR_STATE, - challenge.getBytes(Charsets.US_ASCII)); - - radius.setPayload(eap); - radius.setAttribute(RADIUSAttribute.RADIUS_ATTR_EAP_MESSAGE, - eap.serialize()); - - return radius; - } - - /** - * Sets up the services required by the AAA application. - */ - @Before - public void setUp() { - aaa = new AAAWithoutRadiusServer(); - aaa.netCfgService = new TestNetworkConfigRegistry(); - aaa.coreService = new CoreServiceAdapter(); - aaa.packetService = new MockPacketService(); - aaa.activate(); - } - - /** - * Tears down the AAA application. - */ - @After - public void tearDown() { - aaa.deactivate(); - } - - /** - * Extracts the RADIUS packet from a packet sent by the supplicant. - * - * @param radius RADIUS packet sent by the supplicant - * @throws DeserializationException if deserialization of the packet contents - * fails. - */ - private void checkRADIUSPacketFromSupplicant(RADIUS radius) - throws DeserializationException { - assertThat(radius, notNullValue()); - - EAP eap = radius.decapsulateMessage(); - assertThat(eap, notNullValue()); - } - - /** - * Fetches the sent packet at the given index. The requested packet - * must be the last packet on the list. - * - * @param index index into sent packets array - * @return packet - */ - private BasePacket fetchPacket(int index) { - BasePacket packet = savedPackets.get(index); - assertThat(packet, notNullValue()); - return packet; - } - - /** - * Tests the authentication path through the AAA application. - * - * @throws DeserializationException if packed deserialization fails. - */ - @Test - public void testAuthentication() throws Exception { - - // (1) Supplicant start up - - Ethernet startPacket = constructSupplicantStartPacket(); - sendPacket(startPacket); - - Ethernet responsePacket = (Ethernet) fetchPacket(0); - checkRadiusPacket(aaa, responsePacket, EAP.ATTR_IDENTITY); - - // (2) Supplicant identify - - Ethernet identifyPacket = constructSupplicantIdentifyPacket(null, EAP.ATTR_IDENTITY, (byte) 1, null); - sendPacket(identifyPacket); - - RADIUS radiusIdentifyPacket = (RADIUS) fetchPacket(1); - - checkRADIUSPacketFromSupplicant(radiusIdentifyPacket); - - assertThat(radiusIdentifyPacket.getCode(), is(RADIUS.RADIUS_CODE_ACCESS_REQUEST)); - assertThat(new String(radiusIdentifyPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME).getValue()), - is("testuser")); - - IpAddress nasIp = - IpAddress.valueOf(IpAddress.Version.INET, - radiusIdentifyPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP) - .getValue()); - assertThat(nasIp.toString(), is(aaa.nasIpAddress.getHostAddress())); - - // State machine should have been created by now - - StateMachine stateMachine = - StateMachine.lookupStateMachineBySessionId(SESSION_ID); - assertThat(stateMachine, notNullValue()); - assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING)); - - // (3) RADIUS MD5 challenge - - RADIUS radiusCodeAccessChallengePacket = - constructRADIUSCodeAccessChallengePacket(RADIUS.RADIUS_CODE_ACCESS_CHALLENGE, EAP.ATTR_MD5); - aaa.radiusListener.handleRadiusPacket(radiusCodeAccessChallengePacket); - - Ethernet radiusChallengeMD5Packet = (Ethernet) fetchPacket(2); - checkRadiusPacket(aaa, radiusChallengeMD5Packet, EAP.ATTR_MD5); - - // (4) Supplicant MD5 response - - Ethernet md5RadiusPacket = - constructSupplicantIdentifyPacket(stateMachine, - EAP.ATTR_MD5, - stateMachine.challengeIdentifier(), - radiusChallengeMD5Packet); - sendPacket(md5RadiusPacket); - - RADIUS responseMd5RadiusPacket = (RADIUS) fetchPacket(3); - - checkRADIUSPacketFromSupplicant(responseMd5RadiusPacket); - assertThat(responseMd5RadiusPacket.getIdentifier(), is((byte) 0)); - assertThat(responseMd5RadiusPacket.getCode(), is(RADIUS.RADIUS_CODE_ACCESS_REQUEST)); - - // State machine should be in pending state - - assertThat(stateMachine, notNullValue()); - assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING)); - - // (5) RADIUS Success - - RADIUS successPacket = - constructRADIUSCodeAccessChallengePacket(RADIUS.RADIUS_CODE_ACCESS_ACCEPT, EAP.SUCCESS); - aaa.radiusListener.handleRadiusPacket((successPacket)); - Ethernet supplicantSuccessPacket = (Ethernet) fetchPacket(4); - - checkRadiusPacket(aaa, supplicantSuccessPacket, EAP.SUCCESS); - - // State machine should be in authorized state - - assertThat(stateMachine, notNullValue()); - assertThat(stateMachine.state(), is(StateMachine.STATE_AUTHORIZED)); - - } - - /** - * Tests the default configuration. - */ - @Test - public void testConfig() { - assertThat(aaa.nasIpAddress.getHostAddress(), is(AAAConfig.DEFAULT_NAS_IP)); - assertThat(aaa.nasMacAddress, is(AAAConfig.DEFAULT_NAS_MAC)); - assertThat(aaa.radiusIpAddress.getHostAddress(), is(BAD_IP_ADDRESS)); - assertThat(aaa.radiusMacAddress, is(AAAConfig.DEFAULT_RADIUS_MAC)); - } -} diff --git a/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATestBase.java b/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATestBase.java deleted file mode 100644 index dffcba2f..00000000 --- a/framework/src/onos/apps/aaa/src/test/java/org/onosproject/aaa/AAATestBase.java +++ /dev/null @@ -1,224 +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.aaa; - -import java.nio.ByteBuffer; -import java.security.MessageDigest; -import java.util.LinkedList; -import java.util.List; - -import org.onlab.packet.BasePacket; -import org.onlab.packet.EAP; -import org.onlab.packet.EAPOL; -import org.onlab.packet.EthType; -import org.onlab.packet.Ethernet; -import org.onlab.packet.MacAddress; -import org.onosproject.net.packet.DefaultInboundPacket; -import org.onosproject.net.packet.DefaultPacketContext; -import org.onosproject.net.packet.InboundPacket; -import org.onosproject.net.packet.OutboundPacket; -import org.onosproject.net.packet.PacketContext; -import org.onosproject.net.packet.PacketProcessor; -import org.onosproject.net.packet.PacketServiceAdapter; - -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; -import static org.onosproject.net.NetTestTools.connectPoint; - -/** - * Common methods for AAA app testing. - */ -public class AAATestBase { - - MacAddress clientMac = MacAddress.valueOf("1a:1a:1a:1a:1a:1a"); - MacAddress serverMac = MacAddress.valueOf("2a:2a:2a:2a:2a:2a"); - - // Our session id will be the device ID ("of:1") with the port ("1") concatenated - static final String SESSION_ID = "of:11"; - - List<BasePacket> savedPackets = new LinkedList<>(); - PacketProcessor packetProcessor; - - /** - * Saves the given packet onto the saved packets list. - * - * @param packet packet to save - */ - void savePacket(BasePacket packet) { - savedPackets.add(packet); - } - - /** - * Keeps a reference to the PacketProcessor and saves the OutboundPackets. - */ - class MockPacketService extends PacketServiceAdapter { - - @Override - public void addProcessor(PacketProcessor processor, int priority) { - packetProcessor = processor; - } - - @Override - public void emit(OutboundPacket packet) { - try { - Ethernet eth = Ethernet.deserializer().deserialize(packet.data().array(), - 0, packet.data().array().length); - savePacket(eth); - } catch (Exception e) { - fail(e.getMessage()); - } - } - } - - /** - * Mocks the DefaultPacketContext. - */ - final class TestPacketContext extends DefaultPacketContext { - - private TestPacketContext(long time, InboundPacket inPkt, - OutboundPacket outPkt, boolean block) { - super(time, inPkt, outPkt, block); - } - - @Override - public void send() { - // We don't send anything out. - } - } - - /** - * Sends an Ethernet packet to the process method of the Packet Processor. - * - * @param reply Ethernet packet - */ - void sendPacket(Ethernet reply) { - final ByteBuffer byteBuffer = ByteBuffer.wrap(reply.serialize()); - InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1), - reply, - byteBuffer); - - PacketContext context = new TestPacketContext(127L, inPacket, null, false); - packetProcessor.process(context); - } - - /** - * Constructs an Ethernet packet containing identification payload. - * - * @return Ethernet packet - */ - Ethernet constructSupplicantIdentifyPacket(StateMachine stateMachine, - byte type, - byte id, - Ethernet radiusChallenge) - throws Exception { - Ethernet eth = new Ethernet(); - eth.setDestinationMACAddress(clientMac.toBytes()); - eth.setSourceMACAddress(serverMac.toBytes()); - eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort()); - eth.setVlanID((short) 2); - - String username = "testuser"; - byte[] data = username.getBytes(); - - - if (type == EAP.ATTR_MD5) { - String password = "testpassword"; - EAPOL eapol = (EAPOL) radiusChallenge.getPayload(); - EAP eap = (EAP) eapol.getPayload(); - - byte[] identifier = new byte[password.length() + eap.getData().length]; - - identifier[0] = stateMachine.challengeIdentifier(); - System.arraycopy(password.getBytes(), 0, identifier, 1, password.length()); - System.arraycopy(eap.getData(), 1, identifier, 1 + password.length(), 16); - - MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] hash = md.digest(identifier); - data = new byte[17]; - data[0] = (byte) 16; - System.arraycopy(hash, 0, data, 1, 16); - } - EAP eap = new EAP(EAP.RESPONSE, (byte) 1, type, - data); - eap.setIdentifier(id); - - // eapol header - EAPOL eapol = new EAPOL(); - eapol.setEapolType(EAPOL.EAPOL_PACKET); - eapol.setPacketLength(eap.getLength()); - - // eap part - eapol.setPayload(eap); - - eth.setPayload(eapol); - eth.setPad(true); - return eth; - } - - /** - * Constructs an Ethernet packet containing a EAPOL_START Payload. - * - * @return Ethernet packet - */ - Ethernet constructSupplicantStartPacket() { - Ethernet eth = new Ethernet(); - eth.setDestinationMACAddress(clientMac.toBytes()); - eth.setSourceMACAddress(serverMac.toBytes()); - eth.setEtherType(EthType.EtherType.EAPOL.ethType().toShort()); - eth.setVlanID((short) 2); - - EAP eap = new EAP(EAPOL.EAPOL_START, (byte) 2, EAPOL.EAPOL_START, null); - - // eapol header - EAPOL eapol = new EAPOL(); - eapol.setEapolType(EAPOL.EAPOL_START); - eapol.setPacketLength(eap.getLength()); - - // eap part - eapol.setPayload(eap); - - eth.setPayload(eapol); - eth.setPad(true); - return eth; - } - - /** - * Checks the contents of a RADIUS packet being sent to the RADIUS server. - * - * @param radiusPacket packet to check - * @param code expected code - */ - void checkRadiusPacket(AAA aaa, Ethernet radiusPacket, byte code) { - - assertThat(radiusPacket.getSourceMAC(), - is(MacAddress.valueOf(aaa.nasMacAddress))); - assertThat(radiusPacket.getDestinationMAC(), is(serverMac)); - - assertThat(radiusPacket.getPayload(), instanceOf(EAPOL.class)); - EAPOL eapol = (EAPOL) radiusPacket.getPayload(); - assertThat(eapol, notNullValue()); - - assertThat(eapol.getEapolType(), is(EAPOL.EAPOL_PACKET)); - assertThat(eapol.getPayload(), instanceOf(EAP.class)); - EAP eap = (EAP) eapol.getPayload(); - assertThat(eap, notNullValue()); - - assertThat(eap.getCode(), is(code)); - } -} diff --git a/framework/src/onos/apps/acl/src/main/java/org/onosproject/acl/AclRule.java b/framework/src/onos/apps/acl/src/main/java/org/onosproject/acl/AclRule.java index 8c91da4c..cd85dea7 100644 --- a/framework/src/onos/apps/acl/src/main/java/org/onosproject/acl/AclRule.java +++ b/framework/src/onos/apps/acl/src/main/java/org/onosproject/acl/AclRule.java @@ -86,7 +86,7 @@ public final class AclRule { /** * Check if the first CIDR address is in (or the same as) the second CIDR address. */ - private boolean checkCIDRinCIDR(Ip4Prefix cidrAddr1, Ip4Prefix cidrAddr2) { + private boolean checkCidrInCidr(Ip4Prefix cidrAddr1, Ip4Prefix cidrAddr2) { if (cidrAddr2 == null) { return true; } else if (cidrAddr1 == null) { @@ -116,8 +116,8 @@ public final class AclRule { public boolean checkMatch(AclRule r) { return (this.dstTpPort == r.dstTpPort || r.dstTpPort == 0) && (this.ipProto == r.ipProto || r.ipProto == 0) - && (checkCIDRinCIDR(this.srcIp(), r.srcIp())) - && (checkCIDRinCIDR(this.dstIp(), r.dstIp())); + && (checkCidrInCidr(this.srcIp(), r.srcIp())) + && (checkCidrInCidr(this.dstIp(), r.dstIp())); } /** diff --git a/framework/src/onos/apps/acl/src/main/java/org/onosproject/acl/AclWebResource.java b/framework/src/onos/apps/acl/src/main/java/org/onosproject/acl/AclWebResource.java index 9ec4c883..bdbcc693 100644 --- a/framework/src/onos/apps/acl/src/main/java/org/onosproject/acl/AclWebResource.java +++ b/framework/src/onos/apps/acl/src/main/java/org/onosproject/acl/AclWebResource.java @@ -129,7 +129,7 @@ public class AclWebResource extends AbstractWebResource { * @return 200 OK */ @DELETE - public Response clearACL() { + public Response clearAcl() { get(AclService.class).clearAcl(); return Response.ok().build(); } @@ -189,4 +189,4 @@ public class AclWebResource extends AbstractWebResource { return rule.build(); } -}
\ No newline at end of file +} diff --git a/framework/src/onos/apps/acl/src/main/java/org/onosproject/acl/impl/AclManager.java b/framework/src/onos/apps/acl/src/main/java/org/onosproject/acl/impl/AclManager.java index f5c0c204..638f0799 100644 --- a/framework/src/onos/apps/acl/src/main/java/org/onosproject/acl/impl/AclManager.java +++ b/framework/src/onos/apps/acl/src/main/java/org/onosproject/acl/impl/AclManager.java @@ -90,7 +90,7 @@ public class AclManager implements AclService { /** * Checks if the given IP address is in the given CIDR address. */ - private boolean checkIpInCIDR(Ip4Address ip, Ip4Prefix cidr) { + private boolean checkIpInCidr(Ip4Address ip, Ip4Prefix cidr) { int offset = 32 - cidr.prefixLength(); int cidrPrefix = cidr.address().toInt(); int ipIntValue = ip.toInt(); @@ -111,17 +111,17 @@ public class AclManager implements AclService { DeviceId deviceId = event.subject().location().deviceId(); for (IpAddress address : event.subject().ipAddresses()) { if ((rule.srcIp() != null) ? - (checkIpInCIDR(address.getIp4Address(), rule.srcIp())) : - (checkIpInCIDR(address.getIp4Address(), rule.dstIp()))) { + (checkIpInCidr(address.getIp4Address(), rule.srcIp())) : + (checkIpInCidr(address.getIp4Address(), rule.dstIp()))) { if (!aclStore.checkIfRuleWorksInDevice(rule.id(), deviceId)) { List<RuleId> allowingRuleList = aclStore .getAllowingRuleByDenyingRule(rule.id()); if (allowingRuleList != null) { for (RuleId allowingRuleId : allowingRuleList) { - generateACLFlow(aclStore.getAclRule(allowingRuleId), deviceId); + generateAclFlow(aclStore.getAclRule(allowingRuleId), deviceId); } } - generateACLFlow(rule, deviceId); + generateAclFlow(rule, deviceId); } } } @@ -212,7 +212,7 @@ public class AclManager implements AclService { if (cidrAddr.prefixLength() != 32) { for (Host h : hosts) { for (IpAddress a : h.ipAddresses()) { - if (checkIpInCIDR(a.getIp4Address(), cidrAddr)) { + if (checkIpInCidr(a.getIp4Address(), cidrAddr)) { deviceIdSet.add(h.location().deviceId()); } } @@ -220,7 +220,7 @@ public class AclManager implements AclService { } else { for (Host h : hosts) { for (IpAddress a : h.ipAddresses()) { - if (checkIpInCIDR(a.getIp4Address(), cidrAddr)) { + if (checkIpInCidr(a.getIp4Address(), cidrAddr)) { deviceIdSet.add(h.location().deviceId()); return deviceIdSet; } @@ -245,10 +245,10 @@ public class AclManager implements AclService { List<RuleId> allowingRuleList = aclStore.getAllowingRuleByDenyingRule(rule.id()); if (allowingRuleList != null) { for (RuleId allowingRuleId : allowingRuleList) { - generateACLFlow(aclStore.getAclRule(allowingRuleId), deviceId); + generateAclFlow(aclStore.getAclRule(allowingRuleId), deviceId); } } - generateACLFlow(rule, deviceId); + generateAclFlow(rule, deviceId); } } @@ -256,7 +256,7 @@ public class AclManager implements AclService { * Generates ACL flow rule according to ACL rule * and install it into related device. */ - private void generateACLFlow(AclRule rule, DeviceId deviceId) { + private void generateAclFlow(AclRule rule, DeviceId deviceId) { if (rule == null || aclStore.checkIfRuleWorksInDevice(rule.id(), deviceId)) { return; } diff --git a/framework/src/onos/apps/bgprouter/src/main/java/org/onosproject/bgprouter/IcmpHandler.java b/framework/src/onos/apps/bgprouter/src/main/java/org/onosproject/bgprouter/IcmpHandler.java index 6130a2e2..be4499e9 100644 --- a/framework/src/onos/apps/bgprouter/src/main/java/org/onosproject/bgprouter/IcmpHandler.java +++ b/framework/src/onos/apps/bgprouter/src/main/java/org/onosproject/bgprouter/IcmpHandler.java @@ -83,11 +83,11 @@ public class IcmpHandler { if (((ICMP) ipv4.getPayload()).getIcmpType() == ICMP.TYPE_ECHO_REQUEST && ipMatches) { - sendICMPResponse(ethernet, connectPoint); + sendIcmpResponse(ethernet, connectPoint); } } - private void sendICMPResponse(Ethernet icmpRequest, ConnectPoint outport) { + private void sendIcmpResponse(Ethernet icmpRequest, ConnectPoint outport) { Ethernet icmpReplyEth = new Ethernet(); diff --git a/framework/src/onos/apps/bgprouter/src/main/java/org/onosproject/bgprouter/NextHopGroupKey.java b/framework/src/onos/apps/bgprouter/src/main/java/org/onosproject/bgprouter/NextHopGroupKey.java index 82a45a08..cd4c4e9a 100644 --- a/framework/src/onos/apps/bgprouter/src/main/java/org/onosproject/bgprouter/NextHopGroupKey.java +++ b/framework/src/onos/apps/bgprouter/src/main/java/org/onosproject/bgprouter/NextHopGroupKey.java @@ -61,7 +61,7 @@ public class NextHopGroupKey { @Override public int hashCode() { - return Objects.hash(address); + return address.hashCode(); } @Override diff --git a/framework/src/onos/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java b/framework/src/onos/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java index fa916865..690a3581 100644 --- a/framework/src/onos/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java +++ b/framework/src/onos/apps/cordfabric/src/main/java/org/onosproject/cordfabric/CordFabricManager.java @@ -268,7 +268,7 @@ public class CordFabricManager implements FabricService { removeVlan(vlan.vlan()); if (vlan.iptv()) { - provisionIPTV(); + provisionIpTv(); } vlan.ports().forEach(cp -> { @@ -283,7 +283,7 @@ public class CordFabricManager implements FabricService { } //FIXME: pass iptv vlan in here. - private void provisionIPTV() { + private void provisionIpTv() { TrafficSelector ipTvUp = DefaultTrafficSelector.builder() .matchVlanId(VlanId.vlanId((short) 7)) .matchInPort(PortNumber.portNumber(2)) diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtn.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtn.java index e15bc763..c3bf77c5 100644 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtn.java +++ b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtn.java @@ -15,7 +15,6 @@ */ package org.onosproject.cordvtn; -import com.google.common.collect.Collections2; import com.google.common.collect.Sets; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; @@ -32,6 +31,7 @@ import org.onosproject.net.DefaultAnnotations; import org.onosproject.net.Device; import org.onosproject.net.DeviceId; import org.onosproject.net.Host; +import org.onosproject.net.Port; import org.onosproject.net.behaviour.BridgeConfig; import org.onosproject.net.behaviour.BridgeName; import org.onosproject.net.behaviour.ControllerInfo; @@ -39,6 +39,7 @@ import org.onosproject.net.behaviour.DefaultTunnelDescription; import org.onosproject.net.behaviour.TunnelConfig; import org.onosproject.net.behaviour.TunnelDescription; import org.onosproject.net.behaviour.TunnelName; +import org.onosproject.net.device.DeviceAdminService; import org.onosproject.net.device.DeviceEvent; import org.onosproject.net.device.DeviceListener; import org.onosproject.net.device.DeviceService; @@ -54,7 +55,6 @@ import org.onosproject.store.serializers.KryoNamespaces; import org.onosproject.store.service.ConsistentMap; import org.onosproject.store.service.Serializer; import org.onosproject.store.service.StorageService; -import org.onosproject.store.service.Versioned; import org.slf4j.Logger; import java.util.ArrayList; @@ -84,7 +84,8 @@ public class CordVtn implements CordVtnService { private static final int NUM_THREADS = 1; private static final KryoNamespace.Builder NODE_SERIALIZER = KryoNamespace.newBuilder() .register(KryoNamespaces.API) - .register(DefaultOvsdbNode.class); + .register(CordVtnNode.class) + .register(NodeState.class); private static final String DEFAULT_BRIDGE_NAME = "br-int"; private static final String DEFAULT_TUNNEL = "vxlan"; private static final Map<String, String> DEFAULT_TUNNEL_OPTIONS = new HashMap<String, String>() { @@ -112,6 +113,9 @@ public class CordVtn implements CordVtnService { protected DriverService driverService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected DeviceAdminService adminService; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected OvsdbController controller; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) @@ -127,12 +131,55 @@ public class CordVtn implements CordVtnService { private final BridgeHandler bridgeHandler = new BridgeHandler(); private final VmHandler vmHandler = new VmHandler(); - private ConsistentMap<DeviceId, OvsdbNode> nodeStore; + private ConsistentMap<CordVtnNode, NodeState> nodeStore; + + private enum NodeState { + + INIT { + @Override + public void process(CordVtn cordVtn, CordVtnNode node) { + cordVtn.connect(node); + } + }, + OVSDB_CONNECTED { + @Override + public void process(CordVtn cordVtn, CordVtnNode node) { + if (!cordVtn.getOvsdbConnectionState(node)) { + cordVtn.connect(node); + } else { + cordVtn.createIntegrationBridge(node); + } + } + }, + BRIDGE_CREATED { + @Override + public void process(CordVtn cordVtn, CordVtnNode node) { + if (!cordVtn.getOvsdbConnectionState(node)) { + cordVtn.connect(node); + } else { + cordVtn.createTunnelInterface(node); + } + } + }, + COMPLETE { + @Override + public void process(CordVtn cordVtn, CordVtnNode node) { + cordVtn.postInit(node); + } + }, + INCOMPLETE { + @Override + public void process(CordVtn cordVtn, CordVtnNode node) { + } + }; + + public abstract void process(CordVtn cordVtn, CordVtnNode node); + } @Activate protected void activate() { ApplicationId appId = coreService.registerApplication("org.onosproject.cordvtn"); - nodeStore = storageService.<DeviceId, OvsdbNode>consistentMapBuilder() + nodeStore = storageService.<CordVtnNode, NodeState>consistentMapBuilder() .withSerializer(Serializer.using(NODE_SERIALIZER.build())) .withName("cordvtn-nodestore") .withApplicationId(appId) @@ -156,145 +203,272 @@ public class CordVtn implements CordVtnService { } @Override - public void addNode(OvsdbNode ovsdb) { - checkNotNull(ovsdb); + public void addNode(CordVtnNode node) { + checkNotNull(node); + + nodeStore.putIfAbsent(node, checkNodeState(node)); + initNode(node); + } - nodeStore.putIfAbsent(ovsdb.deviceId(), ovsdb); + @Override + public void deleteNode(CordVtnNode node) { + checkNotNull(node); - if (isNodeConnected(ovsdb)) { - init(ovsdb); - } else { - connect(ovsdb); + if (getOvsdbConnectionState(node)) { + disconnect(node); } + + nodeStore.remove(node); } @Override - public void deleteNode(OvsdbNode ovsdb) { - checkNotNull(ovsdb); + public int getNodeCount() { + return nodeStore.size(); + } - if (deviceService.getDevice(ovsdb.deviceId()) != null) { - if (deviceService.isAvailable(ovsdb.deviceId())) { - log.warn("Cannot delete connected node {}", ovsdb.host()); - return; - } - } - nodeStore.remove(ovsdb.deviceId()); + @Override + public List<CordVtnNode> getNodes() { + List<CordVtnNode> nodes = new ArrayList<>(); + nodes.addAll(nodeStore.keySet()); + return nodes; } @Override - public void connect(OvsdbNode ovsdb) { - checkNotNull(ovsdb); + public void initNode(CordVtnNode node) { + checkNotNull(node); - if (!nodeStore.containsKey(ovsdb.deviceId())) { - log.warn("Node {} does not exist", ovsdb.host()); + if (!nodeStore.containsKey(node)) { + log.warn("Node {} does not exist, add node first", node.hostname()); return; } - if (!isNodeConnected(ovsdb)) { - controller.connect(ovsdb.ip(), ovsdb.port()); + NodeState state = getNodeState(node); + if (state == null) { + return; + } else if (state.equals(NodeState.INCOMPLETE)) { + state = checkNodeState(node); } + + state.process(this, node); } @Override - public void disconnect(OvsdbNode ovsdb) { - checkNotNull(ovsdb); + public boolean getNodeInitState(CordVtnNode node) { + checkNotNull(node); - if (!nodeStore.containsKey(ovsdb.deviceId())) { - log.warn("Node {} does not exist", ovsdb.host()); - return; + NodeState state = getNodeState(node); + return state != null && state.equals(NodeState.COMPLETE); + } + + /** + * Returns state of a given cordvtn node. + * + * @param node cordvtn node + * @return node state, or null if no such node exists + */ + private NodeState getNodeState(CordVtnNode node) { + checkNotNull(node); + + try { + return nodeStore.get(node).value(); + } catch (NullPointerException e) { + log.error("Failed to get state of {}", node.hostname()); + return null; } + } - if (isNodeConnected(ovsdb)) { - OvsdbClientService ovsdbClient = getOvsdbClient(ovsdb); - ovsdbClient.disconnect(); + /** + * Sets a new state for a given cordvtn node. + * + * @param node cordvtn node + * @param newState new node state + */ + private void setNodeState(CordVtnNode node, NodeState newState) { + checkNotNull(node); + + log.info("Changed {} state: {}", node.hostname(), newState.toString()); + + nodeStore.put(node, newState); + newState.process(this, node); + } + + /** + * Checks current state of a given cordvtn node and returns it. + * + * @param node cordvtn node + * @return node state + */ + private NodeState checkNodeState(CordVtnNode node) { + checkNotNull(node); + + if (checkIntegrationBridge(node) && checkTunnelInterface(node)) { + return NodeState.COMPLETE; + } else if (checkIntegrationBridge(node)) { + return NodeState.BRIDGE_CREATED; + } else if (getOvsdbConnectionState(node)) { + return NodeState.OVSDB_CONNECTED; + } else { + return NodeState.INIT; } } - private void init(OvsdbNode ovsdb) { - checkNotNull(ovsdb); + /** + * Performs tasks after node initialization. + * + * @param node cordvtn node + */ + private void postInit(CordVtnNode node) { + disconnect(node); + } + + /** + * Returns connection state of OVSDB server for a given node. + * + * @param node cordvtn node + * @return true if it is connected, false otherwise + */ + private boolean getOvsdbConnectionState(CordVtnNode node) { + checkNotNull(node); + + OvsdbClientService ovsdbClient = getOvsdbClient(node); + return deviceService.isAvailable(node.ovsdbId()) && + ovsdbClient != null && ovsdbClient.isConnected(); + } + + /** + * Connects to OVSDB server for a given node. + * + * @param node cordvtn node + */ + private void connect(CordVtnNode node) { + checkNotNull(node); - if (!nodeStore.containsKey(ovsdb.deviceId())) { - log.warn("Node {} does not exist", ovsdb.host()); + if (!nodeStore.containsKey(node)) { + log.warn("Node {} does not exist", node.hostname()); return; } - if (!isNodeConnected(ovsdb)) { - log.warn("Node {} is not connected", ovsdb.host()); + if (!getOvsdbConnectionState(node)) { + // FIXME remove existing OVSDB device to work around OVSDB device re-connect issue + if (deviceService.getDevice(node.ovsdbId()) != null) { + adminService.removeDevice(node.ovsdbId()); + } + controller.connect(node.ovsdbIp(), node.ovsdbPort()); + } + } + + /** + * Disconnects OVSDB server for a given node. + * + * @param node cordvtn node + */ + private void disconnect(CordVtnNode node) { + checkNotNull(node); + + if (!nodeStore.containsKey(node)) { + log.warn("Node {} does not exist", node.hostname()); return; } - if (deviceService.getDevice(ovsdb.intBrId()) == null || - !deviceService.isAvailable(ovsdb.intBrId())) { - createIntegrationBridge(ovsdb); - } else if (!checkVxlanInterface(ovsdb)) { - createVxlanInterface(ovsdb); + if (getOvsdbConnectionState(node)) { + OvsdbClientService ovsdbClient = getOvsdbClient(node); + ovsdbClient.disconnect(); } - } - @Override - public int getNodeCount() { - return nodeStore.size(); + // FIXME remove existing OVSDB device to work around OVSDB device re-connect issue + if (deviceService.getDevice(node.ovsdbId()) != null) { + adminService.removeDevice(node.ovsdbId()); + } } - @Override - public OvsdbNode getNode(DeviceId deviceId) { - Versioned<OvsdbNode> ovsdb = nodeStore.get(deviceId); - if (ovsdb != null) { - return ovsdb.value(); - } else { + /** + * Returns cordvtn node associated with a given OVSDB device. + * + * @param ovsdbId OVSDB device id + * @return cordvtn node, null if it fails to find the node + */ + private CordVtnNode getNodeByOvsdbId(DeviceId ovsdbId) { + try { + return getNodes().stream() + .filter(node -> node.ovsdbId().equals(ovsdbId)) + .findFirst().get(); + } catch (NoSuchElementException e) { + log.debug("Couldn't find node information for {}", ovsdbId); return null; } } - @Override - public List<OvsdbNode> getNodes() { - List<OvsdbNode> ovsdbs = new ArrayList<>(); - ovsdbs.addAll(Collections2.transform(nodeStore.values(), Versioned::value)); - return ovsdbs; - } - - @Override - public boolean isNodeConnected(OvsdbNode ovsdb) { - checkNotNull(ovsdb); - - OvsdbClientService ovsdbClient = getOvsdbClient(ovsdb); - if (ovsdbClient == null) { - return false; - } else { - return ovsdbClient.isConnected(); + /** + * Returns cordvtn node associated with a given integration bridge. + * + * @param bridgeId device id of integration bridge + * @return cordvtn node, null if it fails to find the node + */ + private CordVtnNode getNodeByBridgeId(DeviceId bridgeId) { + try { + return getNodes().stream() + .filter(node -> node.intBrId().equals(bridgeId)) + .findFirst().get(); + } catch (NoSuchElementException e) { + log.debug("Couldn't find node information for {}", bridgeId); + return null; } } - private OvsdbClientService getOvsdbClient(OvsdbNode ovsdb) { - checkNotNull(ovsdb); + /** + * Returns OVSDB client for a given node. + * + * @param node cordvtn node + * @return OVSDB client, or null if it fails to get OVSDB client + */ + private OvsdbClientService getOvsdbClient(CordVtnNode node) { + checkNotNull(node); OvsdbClientService ovsdbClient = controller.getOvsdbClient( - new OvsdbNodeId(ovsdb.ip(), ovsdb.port().toInt())); + new OvsdbNodeId(node.ovsdbIp(), node.ovsdbPort().toInt())); if (ovsdbClient == null) { - log.debug("Couldn't find ovsdb client for {}", ovsdb.host()); + log.debug("Couldn't find OVSDB client for {}", node.hostname()); } return ovsdbClient; } - private void createIntegrationBridge(OvsdbNode ovsdb) { + /** + * Creates an integration bridge for a given node. + * + * @param node cordvtn node + */ + private void createIntegrationBridge(CordVtnNode node) { + if (checkIntegrationBridge(node)) { + return; + } + List<ControllerInfo> controllers = new ArrayList<>(); Sets.newHashSet(clusterService.getNodes()) .forEach(controller -> { ControllerInfo ctrlInfo = new ControllerInfo(controller.ip(), OFPORT, "tcp"); controllers.add(ctrlInfo); }); - String dpid = ovsdb.intBrId().toString().substring(DPID_BEGIN); + String dpid = node.intBrId().toString().substring(DPID_BEGIN); try { - DriverHandler handler = driverService.createHandler(ovsdb.deviceId()); + DriverHandler handler = driverService.createHandler(node.ovsdbId()); BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME), dpid, controllers); } catch (ItemNotFoundException e) { - log.warn("Failed to create integration bridge on {}", ovsdb.deviceId()); + log.warn("Failed to create integration bridge on {}", node.ovsdbId()); } } - private void createVxlanInterface(OvsdbNode ovsdb) { + /** + * Creates tunnel interface to the integration bridge for a given node. + * + * @param node cordvtn node + */ + private void createTunnelInterface(CordVtnNode node) { + if (checkTunnelInterface(node)) { + return; + } + DefaultAnnotations.Builder optionBuilder = DefaultAnnotations.builder(); for (String key : DEFAULT_TUNNEL_OPTIONS.keySet()) { optionBuilder.set(key, DEFAULT_TUNNEL_OPTIONS.get(key)); @@ -304,38 +478,63 @@ public class CordVtn implements CordVtnService { TunnelName.tunnelName(DEFAULT_TUNNEL), optionBuilder.build()); try { - DriverHandler handler = driverService.createHandler(ovsdb.deviceId()); + DriverHandler handler = driverService.createHandler(node.ovsdbId()); TunnelConfig tunnelConfig = handler.behaviour(TunnelConfig.class); tunnelConfig.createTunnelInterface(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME), description); } catch (ItemNotFoundException e) { - log.warn("Failed to create VXLAN interface on {}", ovsdb.deviceId()); + log.warn("Failed to create tunnel interface on {}", node.ovsdbId()); } } - private boolean checkVxlanInterface(OvsdbNode ovsdb) { + /** + * Checks if integration bridge exists and available. + * + * @param node cordvtn node + * @return true if the bridge is available, false otherwise + */ + private boolean checkIntegrationBridge(CordVtnNode node) { + return (deviceService.getDevice(node.intBrId()) != null + && deviceService.isAvailable(node.intBrId())); + } + + /** + * Checks if tunnel interface exists. + * + * @param node cordvtn node + * @return true if the interface exists, false otherwise + */ + private boolean checkTunnelInterface(CordVtnNode node) { try { - DriverHandler handler = driverService.createHandler(ovsdb.deviceId()); - BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); - bridgeConfig.getPorts().stream() - .filter(p -> p.annotations().value("portName").equals(DEFAULT_TUNNEL)) + deviceService.getPorts(node.intBrId()) + .stream() + .filter(p -> p.annotations().value("portName").contains(DEFAULT_TUNNEL) + && p.isEnabled()) .findAny().get(); - } catch (ItemNotFoundException | NoSuchElementException e) { + return true; + } catch (NoSuchElementException e) { return false; } - return true; } private class InternalDeviceListener implements DeviceListener { @Override public void event(DeviceEvent event) { + Device device = event.subject(); - ConnectionHandler handler = (device.type() == SWITCH ? bridgeHandler : ovsdbHandler); + ConnectionHandler<Device> handler = + (device.type().equals(SWITCH) ? bridgeHandler : ovsdbHandler); switch (event.type()) { - case DEVICE_ADDED: - eventExecutor.submit(() -> handler.connected(device)); + case PORT_ADDED: + eventExecutor.submit(() -> bridgeHandler.portAdded(event.port())); + break; + case PORT_UPDATED: + if (!event.port().isEnabled()) { + eventExecutor.submit(() -> bridgeHandler.portRemoved(event.port())); + } break; + case DEVICE_ADDED: case DEVICE_AVAILABILITY_CHANGED: if (deviceService.isAvailable(device.id())) { eventExecutor.submit(() -> handler.connected(device)); @@ -372,17 +571,15 @@ public class CordVtn implements CordVtnService { @Override public void connected(Device device) { - log.info("Ovsdb {} is connected", device.id()); - - OvsdbNode ovsdb = getNode(device.id()); - if (ovsdb != null) { - init(ovsdb); + CordVtnNode node = getNodeByOvsdbId(device.id()); + if (node != null) { + setNodeState(node, checkNodeState(node)); } } @Override public void disconnected(Device device) { - log.warn("Ovsdb {} is disconnected", device.id()); + log.info("OVSDB {} is disconnected", device.id()); } } @@ -390,26 +587,56 @@ public class CordVtn implements CordVtnService { @Override public void connected(Device device) { - log.info("Integration Bridge {} is detected", device.id()); - - OvsdbNode ovsdb; - try { - ovsdb = getNodes().stream() - .filter(node -> node.intBrId().equals(device.id())) - .findFirst().get(); - } catch (NoSuchElementException e) { - log.warn("Couldn't find OVSDB associated with {}", device.id()); + CordVtnNode node = getNodeByBridgeId(device.id()); + if (node != null) { + setNodeState(node, checkNodeState(node)); + } + } + + @Override + public void disconnected(Device device) { + CordVtnNode node = getNodeByBridgeId(device.id()); + if (node != null) { + log.info("Integration Bridge is disconnected from {}", node.hostname()); + setNodeState(node, NodeState.INCOMPLETE); + } + } + + /** + * Handles port added situation. + * If the added port is tunnel port, proceed remaining node initialization. + * Otherwise, do nothing. + * + * @param port port + */ + public void portAdded(Port port) { + if (!port.annotations().value("portName").contains(DEFAULT_TUNNEL)) { return; } - if (!checkVxlanInterface(ovsdb)) { - createVxlanInterface(ovsdb); + CordVtnNode node = getNodeByBridgeId((DeviceId) port.element().id()); + if (node != null) { + setNodeState(node, checkNodeState(node)); } } - @Override - public void disconnected(Device device) { - log.info("Integration Bridge {} is vanished", device.id()); + /** + * Handles port removed situation. + * If the removed port is tunnel port, proceed remaining node initialization. + * Others, do nothing. + * + * @param port port + */ + public void portRemoved(Port port) { + if (!port.annotations().value("portName").contains(DEFAULT_TUNNEL)) { + return; + } + + CordVtnNode node = getNodeByBridgeId((DeviceId) port.element().id()); + if (node != null) { + log.info("Tunnel interface is removed from {}", node.hostname()); + setNodeState(node, NodeState.INCOMPLETE); + } } } diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java index 550452ce..827ce052 100644 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java +++ b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfig.java @@ -32,77 +32,82 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class CordVtnConfig extends Config<ApplicationId> { - public static final String OVSDB_NODES = "ovsdbNodes"; - public static final String HOST = "host"; - public static final String IP = "ip"; - public static final String PORT = "port"; + public static final String CORDVTN_NODES = "nodes"; + public static final String HOSTNAME = "hostname"; + public static final String OVSDB_IP = "ovsdbIp"; + public static final String OVSDB_PORT = "ovsdbPort"; public static final String BRIDGE_ID = "bridgeId"; /** - * Returns the set of ovsdb nodes read from network config. + * Returns the set of nodes read from network config. * - * @return set of OvsdbNodeConfig or null + * @return set of CordVtnNodeConfig or null */ - public Set<OvsdbNodeConfig> ovsdbNodes() { - Set<OvsdbNodeConfig> ovsdbNodes = Sets.newHashSet(); + public Set<CordVtnNodeConfig> cordVtnNodes() { + Set<CordVtnNodeConfig> nodes = Sets.newHashSet(); - JsonNode nodes = object.get(OVSDB_NODES); - if (nodes == null) { + JsonNode jsonNodes = object.get(CORDVTN_NODES); + if (jsonNodes == null) { return null; } - nodes.forEach(jsonNode -> ovsdbNodes.add(new OvsdbNodeConfig( - jsonNode.path(HOST).asText(), - IpAddress.valueOf(jsonNode.path(IP).asText()), - TpPort.tpPort(jsonNode.path(PORT).asInt()), + jsonNodes.forEach(jsonNode -> nodes.add(new CordVtnNodeConfig( + jsonNode.path(HOSTNAME).asText(), + IpAddress.valueOf(jsonNode.path(OVSDB_IP).asText()), + TpPort.tpPort(jsonNode.path(OVSDB_PORT).asInt()), DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText())))); - return ovsdbNodes; + return nodes; } /** - * Configuration for an ovsdb node. + * Configuration for CordVtn node. */ - public static class OvsdbNodeConfig { + public static class CordVtnNodeConfig { - private final String host; - private final IpAddress ip; - private final TpPort port; + private final String hostname; + private final IpAddress ovsdbIp; + private final TpPort ovsdbPort; private final DeviceId bridgeId; - public OvsdbNodeConfig(String host, IpAddress ip, TpPort port, DeviceId bridgeId) { - this.host = checkNotNull(host); - this.ip = checkNotNull(ip); - this.port = checkNotNull(port); + public CordVtnNodeConfig(String hostname, IpAddress ovsdbIp, TpPort ovsdbPort, DeviceId bridgeId) { + this.hostname = checkNotNull(hostname); + this.ovsdbIp = checkNotNull(ovsdbIp); + this.ovsdbPort = checkNotNull(ovsdbPort); this.bridgeId = checkNotNull(bridgeId); } /** - * Returns host information of the node. + * Returns hostname of the node. * - * @return host + * @return hostname */ - public String host() { - return this.host; + public String hostname() { + return this.hostname; } /** - * Returns ip address to access ovsdb-server of the node. + * Returns OVSDB ip address of the node. * - * @return ip address + * @return OVSDB server IP address */ - public IpAddress ip() { - return this.ip; + public IpAddress ovsdbIp() { + return this.ovsdbIp; } /** - * Returns port number to access ovsdb-server of the node. + * Returns OVSDB port number of the node. * * @return port number */ - public TpPort port() { - return this.port; + public TpPort ovsdbPort() { + return this.ovsdbPort; } + /** + * Returns integration bridge id of the node. + * + * @return device id + */ public DeviceId bridgeId() { return this.bridgeId; } diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfigManager.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfigManager.java index 274ca9b4..f79b4460 100644 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfigManager.java +++ b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnConfigManager.java @@ -88,10 +88,10 @@ public class CordVtnConfigManager { return; } - config.ovsdbNodes().forEach(node -> { - DefaultOvsdbNode ovsdb = new DefaultOvsdbNode( - node.host(), node.ip(), node.port(), node.bridgeId()); - cordVtnService.addNode(ovsdb); + config.cordVtnNodes().forEach(node -> { + CordVtnNode cordVtnNode = new CordVtnNode( + node.hostname(), node.ovsdbIp(), node.ovsdbPort(), node.bridgeId()); + cordVtnService.addNode(cordVtnNode); }); } diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnService.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnService.java index 7e01a452..5ab7bafa 100644 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnService.java +++ b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/CordVtnService.java @@ -15,8 +15,6 @@ */ package org.onosproject.cordvtn; -import org.onosproject.net.DeviceId; - import java.util.List; /** @@ -28,30 +26,23 @@ public interface CordVtnService { /** * Adds a new node to the service. * - * @param ovsdb ovsdb node + * @param node cordvtn node */ - void addNode(OvsdbNode ovsdb); + void addNode(CordVtnNode node); /** * Deletes a node from the service. * - * @param ovsdb ovsdb node - */ - void deleteNode(OvsdbNode ovsdb); - - /** - * Connect to a node. - * - * @param ovsdb ovsdb node + * @param node cordvtn node */ - void connect(OvsdbNode ovsdb); + void deleteNode(CordVtnNode node); /** - * Disconnect a node. + * Initiates node to serve virtual tenant network. * - * @param ovsdb ovsdb node + * @param node cordvtn node */ - void disconnect(OvsdbNode ovsdb); + void initNode(CordVtnNode node); /** * Returns the number of the nodes known to the service. @@ -61,25 +52,17 @@ public interface CordVtnService { int getNodeCount(); /** - * Returns OvsdbNode with given device id. - * - * @param deviceId device id - * @return ovsdb node - */ - OvsdbNode getNode(DeviceId deviceId); - - /** - * Returns connection state of the node. + * Returns node initialization state. * - * @param ovsdb ovsdb node - * @return true if the node is connected, false otherwise + * @param node cordvtn node + * @return true if initial node setup is completed, otherwise false */ - boolean isNodeConnected(OvsdbNode ovsdb); + boolean getNodeInitState(CordVtnNode node); /** * Returns all nodes known to the service. * * @return list of nodes */ - List<OvsdbNode> getNodes(); + List<CordVtnNode> getNodes(); } diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/DefaultOvsdbNode.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/DefaultOvsdbNode.java deleted file mode 100644 index 46f6e29c..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/DefaultOvsdbNode.java +++ /dev/null @@ -1,99 +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.cordvtn; - -import com.google.common.base.MoreObjects; -import org.onlab.packet.IpAddress; -import org.onlab.packet.TpPort; -import org.onosproject.net.DeviceId; - -import java.util.Objects; - -/** - * OvsdbNode implementation. - */ -public class DefaultOvsdbNode implements OvsdbNode { - - private final String host; - private final IpAddress ip; - private final TpPort port; - private final DeviceId brId; - - public DefaultOvsdbNode(String host, IpAddress ip, TpPort port, DeviceId brId) { - this.host = host; - this.ip = ip; - this.port = port; - this.brId = brId; - } - - @Override - public IpAddress ip() { - return this.ip; - } - - @Override - public TpPort port() { - return this.port; - } - - @Override - public String host() { - return this.host; - } - - @Override - public DeviceId intBrId() { - return this.brId; - } - - @Override - public DeviceId deviceId() { - return DeviceId.deviceId("ovsdb:" + this.ip.toString()); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - - if (o instanceof DefaultOvsdbNode) { - DefaultOvsdbNode that = (DefaultOvsdbNode) o; - if (this.host.equals(that.host) && - this.ip.equals(that.ip) && - this.port.equals(that.port) && - this.brId.equals(that.brId)) { - return true; - } - } - return false; - } - - @Override - public int hashCode() { - return Objects.hash(host, ip, port); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("host", host) - .add("ip", ip) - .add("port", port) - .add("bridgeId", brId) - .toString(); - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/OvsdbNode.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/OvsdbNode.java deleted file mode 100644 index 7a9a06a6..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/OvsdbNode.java +++ /dev/null @@ -1,71 +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.cordvtn; - -import org.onlab.packet.IpAddress; -import org.onlab.packet.TpPort; -import org.onosproject.net.DeviceId; - -import java.util.Comparator; - -/** - * Representation of a node with ovsdb server. - */ -public interface OvsdbNode { - - Comparator<OvsdbNode> OVSDB_NODE_COMPARATOR = new Comparator<OvsdbNode>() { - @Override - public int compare(OvsdbNode ovsdb1, OvsdbNode ovsdb2) { - return ovsdb1.host().compareTo(ovsdb2.host()); - } - }; - - /** - * Returns the IP address of the ovsdb server. - * - * @return ip address - */ - IpAddress ip(); - - /** - * Returns the port number of the ovsdb server. - * - * @return port number - */ - TpPort port(); - - /** - * Returns the host information of the ovsdb server. - * It could be hostname or ip address. - * - * @return host - */ - String host(); - - /** - * Returns the device id of the ovsdb server. - * - * @return device id - */ - DeviceId deviceId(); - - /** - * Returns the device id of the integration bridge associated with the node. - * - * @return device id - */ - DeviceId intBrId(); -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeAddCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeAddCommand.java deleted file mode 100644 index 88d16341..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeAddCommand.java +++ /dev/null @@ -1,65 +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.cordvtn.cli; - -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.onlab.packet.IpAddress; -import org.onlab.packet.TpPort; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.cordvtn.CordVtnService; -import org.onosproject.cordvtn.DefaultOvsdbNode; -import org.onosproject.cordvtn.OvsdbNode; -import org.onosproject.net.DeviceId; - -import static com.google.common.base.Preconditions.checkArgument; - -/** - * Adds a new OVSDB nodes. - */ -@Command(scope = "onos", name = "ovsdb-add", - description = "Adds a new OVSDB node to cordvtn") -public class OvsdbNodeAddCommand extends AbstractShellCommand { - - @Argument(index = 0, name = "host", description = "Hostname or IP", - required = true, multiValued = false) - private String host = null; - - @Argument(index = 1, name = "address", - description = "OVSDB server listening address (ip:port)", - required = true, multiValued = false) - private String address = null; - - @Argument(index = 2, name = "bridgeId", - description = "Device ID of integration bridge", - required = true, multiValued = false) - private String bridgeId = null; - - @Override - protected void execute() { - checkArgument(address.contains(":"), "address should be ip:port format"); - checkArgument(bridgeId.startsWith("of:"), "bridgeId should be of:dpid format"); - - CordVtnService service = AbstractShellCommand.get(CordVtnService.class); - String[] ipPort = address.split(":"); - OvsdbNode ovsdb = new DefaultOvsdbNode(host, - IpAddress.valueOf(ipPort[0]), - TpPort.tpPort(Integer.parseInt(ipPort[1])), - DeviceId.deviceId(bridgeId)); - service.addNode(ovsdb); - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeConnectCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeConnectCommand.java deleted file mode 100644 index e4ca0f3c..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeConnectCommand.java +++ /dev/null @@ -1,60 +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.cordvtn.cli; - -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.cordvtn.CordVtnService; -import org.onosproject.cordvtn.OvsdbNode; - -import java.util.NoSuchElementException; - -/** - * Connects to OVSDBs. - */ -@Command(scope = "onos", name = "ovsdb-connect", - description = "Connects to OVSDBs") -public class OvsdbNodeConnectCommand extends AbstractShellCommand { - - @Argument(index = 0, name = "hosts", description = "Hostname(s) or IP(s)", - required = true, multiValued = true) - private String[] hosts = null; - - @Override - protected void execute() { - CordVtnService service = AbstractShellCommand.get(CordVtnService.class); - - for (String host : hosts) { - OvsdbNode ovsdb; - try { - ovsdb = service.getNodes().stream() - .filter(node -> node.host().equals(host)) - .findFirst().get(); - } catch (NoSuchElementException e) { - print("Unable to find %s", host); - continue; - } - - if (service.isNodeConnected(ovsdb)) { - print("OVSDB %s is already in connected state, do nothing", host); - } else { - service.connect(ovsdb); - } - } - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDeleteCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDeleteCommand.java deleted file mode 100644 index a500d0d8..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDeleteCommand.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.cordvtn.cli; - -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.cordvtn.CordVtnService; -import org.onosproject.cordvtn.OvsdbNode; - -import java.util.NoSuchElementException; - -/** - * Deletes OVSDB nodes from cordvtn. - */ -@Command(scope = "onos", name = "ovsdb-delete", - description = "Deletes OVSDB nodes from cordvtn") -public class OvsdbNodeDeleteCommand extends AbstractShellCommand { - - @Argument(index = 0, name = "hosts", description = "Hostname(s) or IP(s)", - required = true, multiValued = true) - private String[] hosts = null; - - @Override - protected void execute() { - CordVtnService service = AbstractShellCommand.get(CordVtnService.class); - - for (String host : hosts) { - OvsdbNode ovsdb; - try { - ovsdb = service.getNodes().stream() - .filter(node -> node.host().equals(host)) - .findFirst().get(); - - } catch (NoSuchElementException e) { - print("Unable to find %s", host); - continue; - } - - service.deleteNode(ovsdb); - } - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDisconnectCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDisconnectCommand.java deleted file mode 100644 index 14e44e08..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeDisconnectCommand.java +++ /dev/null @@ -1,60 +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.cordvtn.cli; - -import org.apache.karaf.shell.commands.Argument; -import org.apache.karaf.shell.commands.Command; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.cordvtn.CordVtnService; -import org.onosproject.cordvtn.OvsdbNode; - -import java.util.NoSuchElementException; - -/** - * Disconnects OVSDBs. - */ -@Command(scope = "onos", name = "ovsdb-disconnect", - description = "Disconnects OVSDBs") -public class OvsdbNodeDisconnectCommand extends AbstractShellCommand { - - @Argument(index = 0, name = "hosts", description = "Hostname(s) or IP(s)", - required = true, multiValued = true) - private String[] hosts = null; - - @Override - protected void execute() { - CordVtnService service = AbstractShellCommand.get(CordVtnService.class); - - for (String host : hosts) { - OvsdbNode ovsdb; - try { - ovsdb = service.getNodes().stream() - .filter(node -> node.host().equals(host)) - .findFirst().get(); - } catch (NoSuchElementException e) { - print("Unable to find %s", host); - continue; - } - - if (!service.isNodeConnected(ovsdb)) { - print("OVSDB %s is already in disconnected state, do nothing", host); - } else { - service.disconnect(ovsdb); - } - } - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeListCommand.java b/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeListCommand.java deleted file mode 100644 index 7d125ca6..00000000 --- a/framework/src/onos/apps/cordvtn/src/main/java/org/onosproject/cordvtn/cli/OvsdbNodeListCommand.java +++ /dev/null @@ -1,74 +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.cordvtn.cli; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import org.apache.karaf.shell.commands.Command; -import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.cordvtn.CordVtnService; -import org.onosproject.cordvtn.OvsdbNode; - -import java.util.Collections; -import java.util.List; - -/** - * Lists all OVSDB nodes. - */ -@Command(scope = "onos", name = "ovsdbs", - description = "Lists all OVSDB nodes registered in cordvtn application") -public class OvsdbNodeListCommand extends AbstractShellCommand { - - @Override - protected void execute() { - CordVtnService service = AbstractShellCommand.get(CordVtnService.class); - List<OvsdbNode> ovsdbs = service.getNodes(); - Collections.sort(ovsdbs, OvsdbNode.OVSDB_NODE_COMPARATOR); - - if (outputJson()) { - print("%s", json(service, ovsdbs)); - } else { - for (OvsdbNode ovsdb : ovsdbs) { - print("host=%s, address=%s, br-int=%s, state=%s", - ovsdb.host(), - ovsdb.ip().toString() + ":" + ovsdb.port().toString(), - ovsdb.intBrId().toString(), - getState(service, ovsdb)); - } - print("Total %s nodes", service.getNodeCount()); - } - } - - private JsonNode json(CordVtnService service, List<OvsdbNode> ovsdbs) { - ObjectMapper mapper = new ObjectMapper(); - ArrayNode result = mapper.createArrayNode(); - for (OvsdbNode ovsdb : ovsdbs) { - String ipPort = ovsdb.ip().toString() + ":" + ovsdb.port().toString(); - result.add(mapper.createObjectNode() - .put("host", ovsdb.host()) - .put("address", ipPort) - .put("brInt", ovsdb.intBrId().toString()) - .put("state", getState(service, ovsdb))); - } - return result; - } - - private String getState(CordVtnService service, OvsdbNode ovsdb) { - return service.isNodeConnected(ovsdb) ? "CONNECTED" : "DISCONNECTED"; - } -} diff --git a/framework/src/onos/apps/cordvtn/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/framework/src/onos/apps/cordvtn/src/main/resources/OSGI-INF/blueprint/shell-config.xml index 6e172387..ad28bc75 100644 --- a/framework/src/onos/apps/cordvtn/src/main/resources/OSGI-INF/blueprint/shell-config.xml +++ b/framework/src/onos/apps/cordvtn/src/main/resources/OSGI-INF/blueprint/shell-config.xml @@ -17,19 +17,16 @@ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0"> <command> - <action class="org.onosproject.cordvtn.cli.OvsdbNodeListCommand"/> + <action class="org.onosproject.cordvtn.cli.CordVtnNodeListCommand"/> </command> <command> - <action class="org.onosproject.cordvtn.cli.OvsdbNodeAddCommand"/> + <action class="org.onosproject.cordvtn.cli.CordVtnNodeAddCommand"/> </command> <command> - <action class="org.onosproject.cordvtn.cli.OvsdbNodeDeleteCommand"/> + <action class="org.onosproject.cordvtn.cli.CordVtnNodeDeleteCommand"/> </command> <command> - <action class="org.onosproject.cordvtn.cli.OvsdbNodeConnectCommand"/> - </command> - <command> - <action class="org.onosproject.cordvtn.cli.OvsdbNodeDisconnectCommand"/> + <action class="org.onosproject.cordvtn.cli.CordVtnNodeInitCommand"/> </command> </command-bundle> </blueprint> diff --git a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java index 7c2127f9..ae610239 100644 --- a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java +++ b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpService.java @@ -19,8 +19,10 @@ import org.onlab.packet.Ip4Address; import org.onlab.packet.MacAddress; import org.onosproject.net.HostId; +import java.util.List; import java.util.Map; + /** * DHCP Service Interface. */ @@ -56,12 +58,16 @@ public interface DhcpService { /** * Registers a static IP mapping with the DHCP Server. + * Supports rangeNotEnforced option * - * @param macID macID of the client + * @param macID macID of the client * @param ipAddress IP Address requested for the client - * @return true if the mapping was successfully registered, false otherwise + * @param rangeNotEnforced true if rangeNotEnforced was set and the mapping will be eternal + * @param addressList subnetMask, DHCP/Router/DNS IP Addresses if rangeNotEnforced was set + * @return true if the mapping was successfully added, false otherwise */ - boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress); + boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean rangeNotEnforced, + List<Ip4Address> addressList); /** * Removes a static IP mapping with the DHCP Server. @@ -77,5 +83,4 @@ public interface DhcpService { * @return list of available IPs */ Iterable<Ip4Address> getAvailableIPs(); - } diff --git a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java index e263b3a2..cdfadf7b 100644 --- a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java +++ b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/DhcpStore.java @@ -19,8 +19,10 @@ import org.onlab.packet.Ip4Address; import org.onlab.packet.MacAddress; import org.onosproject.net.HostId; +import java.util.List; import java.util.Map; + /** * DHCPStore Interface. */ @@ -43,15 +45,20 @@ public interface DhcpStore { */ Ip4Address suggestIP(HostId hostId, Ip4Address requestedIP); + /** * Assigns the requested IP to the Mac ID, in response to a DHCP REQUEST message. * * @param hostId Host Id of the client requesting an IP * @param ipAddr IP Address being requested * @param leaseTime Lease time offered by the server for this mapping + * @param rangeNotEnforced true if rangeNotEnforced was set + * @param addressList subnetMask, DHCP/Router/DNS IP Addresses if rangeNotEnforced was set * @return returns true if the assignment was successful, false otherwise */ - boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime); + boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean rangeNotEnforced, + List<Ip4Address> addressList); + /** * Sets the default time for which suggested IP mappings are valid. @@ -87,9 +94,11 @@ public interface DhcpStore { * * @param macID macID of the client * @param ipAddr IP Address requested for the client + * @param rangeNotEnforced true if rangeNotEnforced was set + * @param addressList subnetMask, DHCP/Router/DNS IP Addresses rangeNotEnforced was set * @return true if the mapping was successfully registered, false otherwise */ - boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr); + boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean rangeNotEnforced, List<Ip4Address> addressList); /** * Removes a static IP mapping associated with the given MAC ID from the DHCP Server. @@ -106,4 +115,11 @@ public interface DhcpStore { */ Iterable<Ip4Address> getAvailableIPs(); + /** + * + * + * @param hostId + * @return + */ + IpAssignment getIpAssignmentFromAllocationMap(HostId hostId); } diff --git a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java index 9b3aa686..5610fec8 100644 --- a/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java +++ b/framework/src/onos/apps/dhcp/api/src/main/java/org/onosproject/dhcp/IpAssignment.java @@ -33,6 +33,16 @@ public final class IpAssignment { private final long leasePeriod; + private final Ip4Address subnetMask; + + private final Ip4Address dhcpServer; + + private final Ip4Address routerAddress; + + private final Ip4Address domainServer; + + private final boolean rangeNotEnforced; + private final AssignmentStatus assignmentStatus; public enum AssignmentStatus { @@ -42,6 +52,10 @@ public final class IpAssignment { Option_Requested, /** + * IP Assignment has been requested by a OpenStack. + */ + Option_RangeNotEnforced, + /** * IP has been assigned to a host. */ Option_Assigned, @@ -58,16 +72,28 @@ public final class IpAssignment { * * @param ipAddress * @param leasePeriod + * @param timestamp * @param assignmentStatus + * @param subnetMask + * @param dhcpServer + * @param routerAddress + * @param domainServer + * @param rangeNotEnforced */ private IpAssignment(Ip4Address ipAddress, long leasePeriod, Date timestamp, - AssignmentStatus assignmentStatus) { + AssignmentStatus assignmentStatus, Ip4Address subnetMask, Ip4Address dhcpServer, + Ip4Address routerAddress, Ip4Address domainServer, boolean rangeNotEnforced) { this.ipAddress = ipAddress; this.leasePeriod = leasePeriod; this.timestamp = timestamp; this.assignmentStatus = assignmentStatus; + this.subnetMask = subnetMask; + this.dhcpServer = dhcpServer; + this.routerAddress = routerAddress; + this.domainServer = domainServer; + this.rangeNotEnforced = rangeNotEnforced; } /** @@ -115,6 +141,26 @@ public final class IpAssignment { return (int) this.leasePeriod * 1000; } + public Ip4Address subnetMask() { + return subnetMask; + } + + public Ip4Address dhcpServer() { + return dhcpServer; + } + + public Ip4Address routerAddress() { + return routerAddress; + } + + public Ip4Address domainServer() { + return domainServer; + } + + public boolean rangeNotEnforced() { + return rangeNotEnforced; + } + @Override public String toString() { return MoreObjects.toStringHelper(getClass()) @@ -122,6 +168,11 @@ public final class IpAssignment { .add("timestamp", timestamp) .add("lease", leasePeriod) .add("assignmentStatus", assignmentStatus) + .add("subnetMask", subnetMask) + .add("dhcpServer", dhcpServer) + .add("routerAddress", routerAddress) + .add("domainServer", domainServer) + .add("rangeNotEnforced", rangeNotEnforced) .toString(); } @@ -157,6 +208,16 @@ public final class IpAssignment { private AssignmentStatus assignmentStatus; + private Ip4Address subnetMask; + + private Ip4Address dhcpServer; + + private Ip4Address domainServer; + + private Ip4Address routerAddress; + + private boolean rangeNotEnforced = false; + private Builder() { } @@ -170,10 +231,8 @@ public final class IpAssignment { public IpAssignment build() { validateInputs(); - return new IpAssignment(ipAddress, - leasePeriod, - timeStamp, - assignmentStatus); + return new IpAssignment(ipAddress, leasePeriod, timeStamp, assignmentStatus, subnetMask, + dhcpServer, domainServer, routerAddress, rangeNotEnforced); } public Builder ipAddress(Ip4Address addr) { @@ -196,14 +255,48 @@ public final class IpAssignment { return this; } + public Builder subnetMask(Ip4Address subnetMask) { + this.subnetMask = subnetMask; + return this; + } + + public Builder dhcpServer(Ip4Address dhcpServer) { + this.dhcpServer = dhcpServer; + return this; + } + + public Builder domainServer(Ip4Address domainServer) { + this.domainServer = domainServer; + return this; + } + + public Builder routerAddress(Ip4Address routerAddress) { + this.routerAddress = routerAddress; + return this; + } + + public Builder rangeNotEnforced(boolean rangeNotEnforced) { + this.rangeNotEnforced = rangeNotEnforced; + return this; + } + + private void validateInputs() { checkNotNull(ipAddress, "IP Address must be specified"); checkNotNull(assignmentStatus, "Assignment Status must be specified"); checkNotNull(leasePeriod, "Lease Period must be specified"); checkNotNull(timeStamp, "Timestamp must be specified"); + if (rangeNotEnforced) { + checkNotNull(subnetMask, "subnetMask must be specified in case of rangeNotEnforced"); + checkNotNull(dhcpServer, "dhcpServer must be specified in case of rangeNotEnforced"); + checkNotNull(domainServer, "domainServer must be specified in case of rangeNotEnforced"); + checkNotNull(routerAddress, "routerAddress must be specified in case of rangeNotEnforced"); + } + switch (assignmentStatus) { case Option_Requested: + case Option_RangeNotEnforced: case Option_Assigned: case Option_Expired: break; diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/cli/DhcpSetStaticMapping.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/cli/DhcpSetStaticMapping.java index 9f4f6580..e1ce8904 100644 --- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/cli/DhcpSetStaticMapping.java +++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/cli/DhcpSetStaticMapping.java @@ -15,6 +15,7 @@ */ package org.onosproject.dhcp.cli; +import com.google.common.collect.Lists; import org.apache.karaf.shell.commands.Argument; import org.apache.karaf.shell.commands.Command; import org.onlab.packet.Ip4Address; @@ -48,7 +49,7 @@ public class DhcpSetStaticMapping extends AbstractShellCommand { try { MacAddress macID = MacAddress.valueOf(macAddr); Ip4Address ipAddress = Ip4Address.valueOf(ipAddr); - if (dhcpService.setStaticMapping(macID, ipAddress)) { + if (dhcpService.setStaticMapping(macID, ipAddress, false, Lists.newArrayList())) { print(DHCP_SUCCESS); } else { print(DHCP_FAILURE); diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java index 4353d623..1efdd082 100644 --- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java +++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpConfig.java @@ -21,6 +21,9 @@ import org.onosproject.core.ApplicationId; import org.onosproject.net.config.Config; import org.onosproject.net.config.basics.BasicElementConfig; +import static org.onosproject.net.config.Config.FieldPresence.MANDATORY; +import static org.onosproject.net.config.Config.FieldPresence.OPTIONAL; + /** * DHCP Config class. */ @@ -43,6 +46,20 @@ public class DhcpConfig extends Config<ApplicationId> { public static final int DEFAULT = -1; + @Override + public boolean isValid() { + // FIXME: Sweep through and revisit the validation assertions + // For now, this is just a demonstration of potential uses + return hasOnlyFields(MY_IP, MY_MAC, SUBNET_MASK, BROADCAST_ADDRESS, + ROUTER_ADDRESS, DOMAIN_SERVER, TTL, LEASE_TIME, + RENEW_TIME, REBIND_TIME, TIMER_DELAY, DEFAULT_TIMEOUT, + START_IP, END_IP) && + isIpAddress(MY_IP, MANDATORY) && isMacAddress(MY_MAC, MANDATORY) && + isIpAddress(START_IP, MANDATORY) && isIpAddress(END_IP, MANDATORY) && + isNumber(LEASE_TIME, OPTIONAL, 1) && isNumber(REBIND_TIME, OPTIONAL, 1) && + isNumber(DEFAULT_TIMEOUT, OPTIONAL, 1, 3600); + } + /** * Returns the dhcp server ip. * diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java index 96d94a2b..a1707e0b 100644 --- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java +++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DhcpManager.java @@ -16,6 +16,7 @@ package org.onosproject.dhcp.impl; import com.google.common.collect.ImmutableSet; +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; @@ -77,7 +78,6 @@ import java.util.Map; import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; - import static org.onlab.packet.MacAddress.valueOf; import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; @@ -109,7 +109,7 @@ public class DhcpManager implements DhcpService { @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected PacketService packetService; - private DHCPPacketProcessor processor = new DHCPPacketProcessor(); + private DhcpPacketProcessor processor = new DhcpPacketProcessor(); @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected CoreService coreService; @@ -168,7 +168,6 @@ public class DhcpManager implements DhcpService { cfgService.addListener(cfgListener); factories.forEach(cfgService::registerConfigFactory); cfgListener.reconfigureNetwork(cfgService.getConfig(appId, DhcpConfig.class)); - hostProviderService = hostProviderRegistry.register(hostProvider); packetService.addProcessor(processor, PacketProcessor.director(0)); requestPackets(); @@ -242,8 +241,12 @@ public class DhcpManager implements DhcpService { } @Override - public boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress) { - return dhcpStore.assignStaticIP(macID, ipAddress); + public boolean setStaticMapping(MacAddress macID, Ip4Address ipAddress, boolean rangeNotEnforced, + List<Ip4Address> addressList) { + log.debug("setStaticMapping is called with Mac: {}, Ip: {} addressList: {}", + macID.toString(), ipAddress.toString(), addressList.toString()); + + return dhcpStore.assignStaticIP(macID, ipAddress, rangeNotEnforced, addressList); } @Override @@ -256,7 +259,7 @@ public class DhcpManager implements DhcpService { return dhcpStore.getAvailableIPs(); } - private class DHCPPacketProcessor implements PacketProcessor { + private class DhcpPacketProcessor implements PacketProcessor { /** * Builds the DHCP Reply packet. @@ -268,6 +271,26 @@ public class DhcpManager implements DhcpService { */ private Ethernet buildReply(Ethernet packet, Ip4Address ipOffered, byte outgoingMessageType) { + Ip4Address subnetMaskReply; + Ip4Address dhcpServerReply; + Ip4Address routerAddressReply; + Ip4Address domainServerReply; + IpAssignment ipAssignment; + + ipAssignment = dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(packet.getSourceMAC())); + + if (ipAssignment != null && ipAssignment.rangeNotEnforced()) { + subnetMaskReply = ipAssignment.subnetMask(); + dhcpServerReply = ipAssignment.dhcpServer(); + domainServerReply = ipAssignment.domainServer(); + routerAddressReply = ipAssignment.routerAddress(); + } else { + subnetMaskReply = subnetMask; + dhcpServerReply = myIP; + routerAddressReply = routerAddress; + domainServerReply = domainServer; + } + // Ethernet Frame. Ethernet ethReply = new Ethernet(); ethReply.setSourceMACAddress(myMAC); @@ -278,7 +301,7 @@ public class DhcpManager implements DhcpService { // IP Packet IPv4 ipv4Packet = (IPv4) packet.getPayload(); IPv4 ipv4Reply = new IPv4(); - ipv4Reply.setSourceAddress(myIP.toInt()); + ipv4Reply.setSourceAddress(dhcpServerReply.toInt()); ipv4Reply.setDestinationAddress(ipOffered.toInt()); ipv4Reply.setTtl(packetTTL); @@ -299,7 +322,7 @@ public class DhcpManager implements DhcpService { if (outgoingMessageType != DHCPPacketType.DHCPNAK.getValue()) { dhcpReply.setYourIPAddress(ipOffered.toInt()); - dhcpReply.setServerIPAddress(myIP.toInt()); + dhcpReply.setServerIPAddress(dhcpServerReply.toInt()); if (dhcpPacket.getGatewayIPAddress() == 0) { ipv4Reply.setDestinationAddress(IP_BROADCAST.toInt()); } @@ -322,7 +345,7 @@ public class DhcpManager implements DhcpService { option = new DHCPOption(); option.setCode(DHCP.DHCPOptionCode.OptionCode_DHCPServerIp.getValue()); option.setLength((byte) 4); - option.setData(myIP.toOctets()); + option.setData(dhcpServerReply.toOctets()); optionList.add(option); if (outgoingMessageType != DHCPPacketType.DHCPNAK.getValue()) { @@ -352,7 +375,7 @@ public class DhcpManager implements DhcpService { option = new DHCPOption(); option.setCode(DHCP.DHCPOptionCode.OptionCode_SubnetMask.getValue()); option.setLength((byte) 4); - option.setData(subnetMask.toOctets()); + option.setData(subnetMaskReply.toOctets()); optionList.add(option); // Broadcast Address. @@ -366,14 +389,14 @@ public class DhcpManager implements DhcpService { option = new DHCPOption(); option.setCode(DHCP.DHCPOptionCode.OptionCode_RouterAddress.getValue()); option.setLength((byte) 4); - option.setData(routerAddress.toOctets()); + option.setData(routerAddressReply.toOctets()); optionList.add(option); // DNS Server Address. option = new DHCPOption(); option.setCode(DHCP.DHCPOptionCode.OptionCode_DomainServer.getValue()); option.setLength((byte) 4); - option.setData(domainServer.toOctets()); + option.setData(domainServerReply.toOctets()); optionList.add(option); } @@ -384,7 +407,6 @@ public class DhcpManager implements DhcpService { optionList.add(option); dhcpReply.setOptions(optionList); - udpReply.setPayload(dhcpReply); ipv4Reply.setPayload(udpReply); ethReply.setPayload(ipv4Reply); @@ -415,7 +437,7 @@ public class DhcpManager implements DhcpService { * @param context context of the incoming message * @param dhcpPayload the extracted DHCP payload */ - private void processDHCPPacket(PacketContext context, DHCP dhcpPayload) { + private void processDhcpPacket(PacketContext context, DHCP dhcpPayload) { Ethernet packet = context.inPacket().parsed(); boolean flagIfRequestedIP = false; boolean flagIfServerIP = false; @@ -442,38 +464,48 @@ public class DhcpManager implements DhcpService { } } DHCPPacketType outgoingPacketType; - MacAddress clientMAC = new MacAddress(dhcpPayload.getClientHardwareAddress()); + MacAddress clientMac = new MacAddress(dhcpPayload.getClientHardwareAddress()); VlanId vlanId = VlanId.vlanId(packet.getVlanID()); - HostId hostId = HostId.hostId(clientMAC, vlanId); + HostId hostId = HostId.hostId(clientMac, vlanId); if (incomingPacketType.getValue() == DHCPPacketType.DHCPDISCOVER.getValue()) { outgoingPacketType = DHCPPacketType.DHCPOFFER; - Ip4Address ipOffered = dhcpStore.suggestIP(hostId, requestedIP); + Ip4Address ipOffered = null; + ipOffered = dhcpStore.suggestIP(hostId, requestedIP); + if (ipOffered != null) { Ethernet ethReply = buildReply(packet, ipOffered, (byte) outgoingPacketType.getValue()); sendReply(context, ethReply); } - } else if (incomingPacketType.getValue() == DHCPPacketType.DHCPREQUEST.getValue()) { if (flagIfServerIP && flagIfRequestedIP) { // SELECTING state - if (myIP.equals(serverIP)) { - if (dhcpStore.assignIP(hostId, requestedIP, leaseTime)) { - outgoingPacketType = DHCPPacketType.DHCPACK; - discoverHost(context, requestedIP); - } else { - outgoingPacketType = DHCPPacketType.DHCPNAK; - } + + if (dhcpStore.getIpAssignmentFromAllocationMap(HostId.hostId(clientMac)) + .rangeNotEnforced()) { + outgoingPacketType = DHCPPacketType.DHCPACK; Ethernet ethReply = buildReply(packet, requestedIP, (byte) outgoingPacketType.getValue()); sendReply(context, ethReply); + } else { + if (myIP.equals(serverIP)) { + if (dhcpStore.assignIP(hostId, requestedIP, leaseTime, false, Lists.newArrayList())) { + outgoingPacketType = DHCPPacketType.DHCPACK; + discoverHost(context, requestedIP); + } else { + outgoingPacketType = DHCPPacketType.DHCPNAK; + } + Ethernet ethReply = buildReply(packet, requestedIP, + (byte) outgoingPacketType.getValue()); + sendReply(context, ethReply); + } } } else if (flagIfRequestedIP) { // INIT-REBOOT state - if (dhcpStore.assignIP(hostId, requestedIP, leaseTime)) { + if (dhcpStore.assignIP(hostId, requestedIP, leaseTime, false, Lists.newArrayList())) { outgoingPacketType = DHCPPacketType.DHCPACK; Ethernet ethReply = buildReply(packet, requestedIP, (byte) outgoingPacketType.getValue()); sendReply(context, ethReply); @@ -485,7 +517,7 @@ public class DhcpManager implements DhcpService { int ciaadr = dhcpPayload.getClientIPAddress(); if (ciaadr != 0) { Ip4Address clientIaddr = Ip4Address.valueOf(ciaadr); - if (dhcpStore.assignIP(hostId, clientIaddr, leaseTime)) { + if (dhcpStore.assignIP(hostId, clientIaddr, leaseTime, false, Lists.newArrayList())) { outgoingPacketType = DHCPPacketType.DHCPACK; discoverHost(context, clientIaddr); } else if (packet.getEtherType() == Ethernet.TYPE_IPV4 && @@ -513,7 +545,7 @@ public class DhcpManager implements DhcpService { * @param context context of the incoming message * @param packet the ethernet payload */ - private void processARPPacket(PacketContext context, Ethernet packet) { + private void processArpPacket(PacketContext context, Ethernet packet) { ARP arpPacket = (ARP) packet.getPayload(); @@ -574,7 +606,7 @@ public class DhcpManager implements DhcpService { // This is meant for the dhcp server so process the packet here. DHCP dhcpPayload = (DHCP) udpPacket.getPayload(); - processDHCPPacket(context, dhcpPayload); + processDhcpPacket(context, dhcpPayload); } } } else if (packet.getEtherType() == Ethernet.TYPE_ARP) { @@ -583,7 +615,7 @@ public class DhcpManager implements DhcpService { if ((arpPacket.getOpCode() == ARP.OP_REQUEST) && Objects.equals(myIP, Ip4Address.valueOf(arpPacket.getTargetProtocolAddress()))) { - processARPPacket(context, packet); + processArpPacket(context, packet); } } @@ -696,4 +728,4 @@ public class DhcpManager implements DhcpService { timeout = Timer.getTimer().newTimeout(new PurgeListTask(), timerDelay, TimeUnit.MINUTES); } } -}
\ No newline at end of file +} diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java index 63f69d40..ad4522cb 100644 --- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java +++ b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/impl/DistributedDhcpStore.java @@ -38,8 +38,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Date; -import java.util.HashMap; import java.util.Map; +import java.util.List; +import java.util.HashMap; import java.util.Objects; /** @@ -105,7 +106,9 @@ public class DistributedDhcpStore implements DhcpStore { IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus(); Ip4Address ipAddr = assignmentInfo.ipAddress(); - if (status == IpAssignment.AssignmentStatus.Option_Assigned || + if (assignmentInfo.rangeNotEnforced()) { + return assignmentInfo.ipAddress(); + } else if (status == IpAssignment.AssignmentStatus.Option_Assigned || status == IpAssignment.AssignmentStatus.Option_Requested) { // Client has a currently Active Binding. if (ipWithinRange(ipAddr)) { @@ -160,10 +163,15 @@ public class DistributedDhcpStore implements DhcpStore { } @Override - public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime) { + public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean rangeNotEnforced, + List<Ip4Address> addressList) { IpAssignment assignmentInfo; + + log.debug("Assign IP Called w/ Ip4Address: {}, HostId: {}", ipAddr.toString(), hostId.mac().toString()); + if (allocationMap.containsKey(hostId)) { + assignmentInfo = allocationMap.get(hostId).value(); IpAssignment.AssignmentStatus status = assignmentInfo.assignmentStatus(); @@ -207,6 +215,20 @@ public class DistributedDhcpStore implements DhcpStore { allocationMap.put(hostId, assignmentInfo); return true; } + } else if (rangeNotEnforced) { + assignmentInfo = IpAssignment.builder() + .ipAddress(ipAddr) + .timestamp(new Date()) + .leasePeriod(leaseTime) + .rangeNotEnforced(true) + .assignmentStatus(IpAssignment.AssignmentStatus.Option_RangeNotEnforced) + .subnetMask((Ip4Address) addressList.toArray()[0]) + .dhcpServer((Ip4Address) addressList.toArray()[1]) + .routerAddress((Ip4Address) addressList.toArray()[2]) + .domainServer((Ip4Address) addressList.toArray()[3]) + .build(); + allocationMap.put(hostId, assignmentInfo); + return true; } return false; } @@ -239,7 +261,8 @@ public class DistributedDhcpStore implements DhcpStore { IpAssignment assignment; for (Map.Entry<HostId, Versioned<IpAssignment>> entry: allocationMap.entrySet()) { assignment = entry.getValue().value(); - if (assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Assigned) { + if (assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_Assigned + || assignment.assignmentStatus() == IpAssignment.AssignmentStatus.Option_RangeNotEnforced) { validMapping.put(entry.getKey(), assignment); } } @@ -256,9 +279,10 @@ public class DistributedDhcpStore implements DhcpStore { } @Override - public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr) { + public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean rangeNotEnforced, + List<Ip4Address> addressList) { HostId host = HostId.hostId(macID); - return assignIP(host, ipAddr, -1); + return assignIP(host, ipAddr, -1, rangeNotEnforced, addressList); } @Override @@ -266,6 +290,12 @@ public class DistributedDhcpStore implements DhcpStore { HostId host = HostId.hostId(macID); if (allocationMap.containsKey(host)) { IpAssignment assignment = allocationMap.get(host).value(); + + if (assignment.rangeNotEnforced()) { + allocationMap.remove(host); + return true; + } + Ip4Address freeIP = assignment.ipAddress(); if (assignment.leasePeriod() < 0) { allocationMap.remove(host); @@ -299,6 +329,11 @@ public class DistributedDhcpStore implements DhcpStore { } } + @Override + public IpAssignment getIpAssignmentFromAllocationMap(HostId hostId) { + return allocationMap.get(hostId).value(); + } + /** * Fetches the next available IP from the free pool pf IPs. * @@ -326,3 +361,4 @@ public class DistributedDhcpStore implements DhcpStore { return false; } } + diff --git a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java b/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java deleted file mode 100644 index 646ab7ea..00000000 --- a/framework/src/onos/apps/dhcp/app/src/main/java/org/onosproject/dhcp/rest/DHCPWebResource.java +++ /dev/null @@ -1,164 +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.dhcp.rest; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.onlab.packet.Ip4Address; -import org.onlab.packet.MacAddress; -import org.onosproject.dhcp.DhcpService; -import org.onosproject.dhcp.IpAssignment; -import org.onosproject.net.HostId; -import org.onosproject.rest.AbstractWebResource; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.IOException; -import java.io.InputStream; -import java.util.Map; - -/** - * Manage DHCP address assignments. - */ -@Path("dhcp") -public class DHCPWebResource extends AbstractWebResource { - - final DhcpService service = get(DhcpService.class); - - /** - * Get DHCP server configuration data. - * Shows lease, renewal and rebinding times in seconds. - * - * @return 200 OK - */ - @GET - @Path("config") - public Response getConfigs() { - DhcpService service = get(DhcpService.class); - ObjectNode node = mapper().createObjectNode() - .put("leaseTime", service.getLeaseTime()) - .put("renewalTime", service.getRenewalTime()) - .put("rebindingTime", service.getRebindingTime()); - return ok(node.toString()).build(); - } - - /** - * Get all MAC/IP mappings. - * Shows all MAC/IP mappings held by the DHCP server. - * - * @return 200 OK - */ - @GET - @Path("mappings") - public Response listMappings() { - ObjectNode root = mapper().createObjectNode(); - - final Map<HostId, IpAssignment> intents = service.listMapping(); - ArrayNode arrayNode = root.putArray("mappings"); - intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode() - .put("host", i.getKey().toString()) - .put("ip", i.getValue().ipAddress().toString()))); - - return ok(root.toString()).build(); - } - - - - /** - * Get all available IPs. - * Shows all the IPs in the free pool of the DHCP Server. - * - * @return 200 OK - */ - @GET - @Path("available") - public Response listAvailableIPs() { - final Iterable<Ip4Address> availableIPList = service.getAvailableIPs(); - - final ObjectNode root = mapper().createObjectNode(); - ArrayNode arrayNode = root.putArray("availableIP"); - availableIPList.forEach(i -> arrayNode.add(i.toString())); - return ok(root.toString()).build(); - } - - /** - * Post a new static MAC/IP binding. - * Registers a static binding to the DHCP server, and displays the current set of bindings. - * - * @param stream JSON stream - * @return 200 OK - */ - @POST - @Path("mappings") - @Consumes(MediaType.APPLICATION_JSON) - public Response setMapping(InputStream stream) { - ObjectNode root = mapper().createObjectNode(); - - try { - ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); - JsonNode macID = jsonTree.get("mac"); - JsonNode ip = jsonTree.get("ip"); - if (macID != null && ip != null) { - - if (!service.setStaticMapping(MacAddress.valueOf(macID.asText()), - Ip4Address.valueOf(ip.asText()))) { - throw new IllegalArgumentException("Static Mapping Failed. The IP maybe unavailable."); - } - } - - final Map<HostId, IpAssignment> intents = service.listMapping(); - ArrayNode arrayNode = root.putArray("mappings"); - intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode() - .put("host", i.getKey().toString()) - .put("ip", i.getValue().ipAddress().toString()))); - } catch (IOException e) { - throw new IllegalArgumentException(e.getMessage()); - } - return ok(root.toString()).build(); - } - - /** - * Delete a static MAC/IP binding. - * Removes a static binding from the DHCP Server, and displays the current set of bindings. - * - * @param macID mac address identifier - * @return 200 OK - */ - @DELETE - @Path("mappings/{macID}") - public Response deleteMapping(@PathParam("macID") String macID) { - - ObjectNode root = mapper().createObjectNode(); - - if (!service.removeStaticMapping(MacAddress.valueOf(macID))) { - throw new IllegalArgumentException("Static Mapping Removal Failed."); - } - final Map<HostId, IpAssignment> intents = service.listMapping(); - ArrayNode arrayNode = root.putArray("mappings"); - intents.entrySet().forEach(i -> arrayNode.add(mapper().createObjectNode() - .put("host", i.getKey().toString()) - .put("ip", i.getValue().ipAddress().toString()))); - - return ok(root.toString()).build(); - } -} diff --git a/framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml b/framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml index 27504548..a53110ee 100644 --- a/framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml +++ b/framework/src/onos/apps/dhcp/app/src/main/webapp/WEB-INF/web.xml @@ -30,7 +30,7 @@ <init-param> <param-name>com.sun.jersey.config.property.classnames</param-name> <param-value> - org.onosproject.dhcp.rest.DHCPWebResource + org.onosproject.dhcp.rest.DhcpWebResource </param-value> </init-param> <load-on-startup>1</load-on-startup> diff --git a/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java b/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java index fd4701c6..e9b02608 100644 --- a/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java +++ b/framework/src/onos/apps/dhcp/app/src/test/java/org/onosproject/dhcp/impl/DhcpManagerTest.java @@ -106,7 +106,7 @@ public class DhcpManagerTest { */ @Test public void testDiscover() { - Ethernet reply = constructDHCPPacket(DHCPPacketType.DHCPDISCOVER); + Ethernet reply = constructDhcpPacket(DHCPPacketType.DHCPDISCOVER); sendPacket(reply); } @@ -115,7 +115,7 @@ public class DhcpManagerTest { */ @Test public void testRequest() { - Ethernet reply = constructDHCPPacket(DHCPPacketType.DHCPREQUEST); + Ethernet reply = constructDhcpPacket(DHCPPacketType.DHCPREQUEST); sendPacket(reply); } @@ -138,7 +138,7 @@ public class DhcpManagerTest { * @param packetType DHCP Message Type * @return Ethernet packet */ - private Ethernet constructDHCPPacket(DHCPPacketType packetType) { + private Ethernet constructDhcpPacket(DHCPPacketType packetType) { // Ethernet Frame. Ethernet ethReply = new Ethernet(); @@ -228,7 +228,8 @@ public class DhcpManagerTest { return Ip4Address.valueOf(EXPECTED_IP); } - public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime) { + public boolean assignIP(HostId hostId, Ip4Address ipAddr, int leaseTime, boolean fromOpenStack, + List<Ip4Address> addressList) { return true; } @@ -255,7 +256,8 @@ public class DhcpManagerTest { return map; } - public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr) { + public boolean assignStaticIP(MacAddress macID, Ip4Address ipAddr, boolean fromOpenStack, + List<Ip4Address> addressList) { return true; } @@ -268,6 +270,9 @@ public class DhcpManagerTest { ipList.add(Ip4Address.valueOf(EXPECTED_IP)); return ImmutableSet.copyOf(ipList); } + public IpAssignment getIpAssignmentFromAllocationMap(HostId hostId) { + return null; + } } /** diff --git a/framework/src/onos/apps/dhcp/pom.xml b/framework/src/onos/apps/dhcp/pom.xml index 7a10776e..473caea6 100644 --- a/framework/src/onos/apps/dhcp/pom.xml +++ b/framework/src/onos/apps/dhcp/pom.xml @@ -36,7 +36,4 @@ <module>app</module> </modules> - <dependencies> - </dependencies> - </project> diff --git a/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/AccessDeviceConfig.java b/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/AccessDeviceConfig.java index 90ed7403..07b73c84 100644 --- a/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/AccessDeviceConfig.java +++ b/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/AccessDeviceConfig.java @@ -16,11 +16,14 @@ package org.onosproject.olt; +import com.fasterxml.jackson.databind.JsonNode; import org.onlab.packet.VlanId; import org.onosproject.net.DeviceId; import org.onosproject.net.PortNumber; import org.onosproject.net.config.Config; +import java.util.Optional; + /** * Config object for access device data. */ @@ -28,6 +31,7 @@ public class AccessDeviceConfig extends Config<DeviceId> { private static final String UPLINK = "uplink"; private static final String VLAN = "vlan"; + private static final String DEFAULT_VLAN = "defaultVlan"; /** * Gets the access device configuration for this device. @@ -37,7 +41,15 @@ public class AccessDeviceConfig extends Config<DeviceId> { public AccessDeviceData getOlt() { PortNumber uplink = PortNumber.portNumber(node.path(UPLINK).asText()); VlanId vlan = VlanId.vlanId(Short.parseShort(node.path(VLAN).asText())); + JsonNode defaultVlanNode = node.path(DEFAULT_VLAN); + + Optional<VlanId> defaultVlan; + if (defaultVlanNode.isMissingNode()) { + defaultVlan = Optional.empty(); + } else { + defaultVlan = Optional.of(VlanId.vlanId(Short.parseShort(defaultVlanNode.asText()))); + } - return new AccessDeviceData(subject(), uplink, vlan); + return new AccessDeviceData(subject(), uplink, vlan, defaultVlan); } } diff --git a/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/AccessDeviceData.java b/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/AccessDeviceData.java index f7e40e30..18b5e99f 100644 --- a/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/AccessDeviceData.java +++ b/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/AccessDeviceData.java @@ -20,6 +20,8 @@ import org.onlab.packet.VlanId; import org.onosproject.net.DeviceId; import org.onosproject.net.PortNumber; +import java.util.Optional; + import static com.google.common.base.Preconditions.checkNotNull; /** @@ -33,6 +35,7 @@ public class AccessDeviceData { private final DeviceId deviceId; private final PortNumber uplink; private final VlanId vlan; + private final Optional<VlanId> defaultVlan; /** * Class constructor. @@ -41,10 +44,12 @@ public class AccessDeviceData { * @param uplink uplink port number * @param vlan device VLAN ID */ - public AccessDeviceData(DeviceId deviceId, PortNumber uplink, VlanId vlan) { + public AccessDeviceData(DeviceId deviceId, PortNumber uplink, VlanId vlan, + Optional<VlanId> defaultVlan) { this.deviceId = checkNotNull(deviceId, DEVICE_ID_MISSING); this.uplink = checkNotNull(uplink, UPLINK_MISSING); this.vlan = checkNotNull(vlan, VLAN_MISSING); + this.defaultVlan = checkNotNull(defaultVlan); } /** @@ -68,9 +73,18 @@ public class AccessDeviceData { /** * Retrieves the VLAN ID assigned to the device. * - * @return vlan ID + * @return VLAN ID */ public VlanId vlan() { return vlan; } + + /** + * Retrieves the default VLAN ID that will be used for this device. + * + * @return default VLAN ID + */ + public Optional<VlanId> defaultVlan() { + return defaultVlan; + } } diff --git a/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/OLT.java b/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/OLT.java deleted file mode 100644 index 9aa8865a..00000000 --- a/framework/src/onos/apps/olt/src/main/java/org/onosproject/olt/OLT.java +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Copyright 2014 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.olt; - -import com.google.common.base.Strings; -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.Modified; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.Service; -import org.onlab.packet.VlanId; -import org.onlab.util.Tools; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Port; -import org.onosproject.net.PortNumber; -import org.onosproject.net.config.ConfigFactory; -import org.onosproject.net.config.NetworkConfigEvent; -import org.onosproject.net.config.NetworkConfigListener; -import org.onosproject.net.config.NetworkConfigRegistry; -import org.onosproject.net.config.basics.SubjectFactories; -import org.onosproject.net.device.DeviceEvent; -import org.onosproject.net.device.DeviceListener; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.flowobjective.DefaultForwardingObjective; -import org.onosproject.net.flowobjective.FlowObjectiveService; -import org.onosproject.net.flowobjective.ForwardingObjective; -import org.osgi.service.component.ComponentContext; -import org.slf4j.Logger; - -import java.util.Dictionary; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import static org.slf4j.LoggerFactory.getLogger; - -/** - * Provisions rules on access devices. - */ -@Service -@Component(immediate = true) -public class OLT implements AccessDeviceService { - private final Logger log = getLogger(getClass()); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected FlowObjectiveService flowObjectiveService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceService deviceService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected NetworkConfigRegistry networkConfig; - - private final DeviceListener deviceListener = new InternalDeviceListener(); - - private ApplicationId appId; - - private static final VlanId DEFAULT_VLAN = VlanId.vlanId((short) 0); - public static final int OFFSET = 200; - - public static final int UPLINK_PORT = 129; - public static final int GFAST_UPLINK_PORT = 100; - - public static final String OLT_DEVICE = "of:90e2ba82f97791e9"; - public static final String GFAST_DEVICE = "of:0011223344551357"; - - @Property(name = "uplinkPort", intValue = UPLINK_PORT, - label = "The OLT's uplink port number") - private int uplinkPort = UPLINK_PORT; - - @Property(name = "gfastUplink", intValue = GFAST_UPLINK_PORT, - label = "The OLT's uplink port number") - private int gfastUplink = GFAST_UPLINK_PORT; - - //TODO: replace this with an annotation lookup - @Property(name = "oltDevice", value = OLT_DEVICE, - label = "The OLT device id") - private String oltDevice = OLT_DEVICE; - - @Property(name = "gfastDevice", value = GFAST_DEVICE, - label = "The gfast device id") - private String gfastDevice = GFAST_DEVICE; - - private Map<DeviceId, AccessDeviceData> oltData = new ConcurrentHashMap<>(); - - private InternalNetworkConfigListener configListener = - new InternalNetworkConfigListener(); - private static final Class<AccessDeviceConfig> CONFIG_CLASS = - AccessDeviceConfig.class; - - private ConfigFactory<DeviceId, AccessDeviceConfig> configFactory = - new ConfigFactory<DeviceId, AccessDeviceConfig>( - SubjectFactories.DEVICE_SUBJECT_FACTORY, CONFIG_CLASS, "accessDevice") { - @Override - public AccessDeviceConfig createConfig() { - return new AccessDeviceConfig(); - } - }; - - @Activate - public void activate() { - appId = coreService.registerApplication("org.onosproject.olt"); - - networkConfig.registerConfigFactory(configFactory); - networkConfig.addListener(configListener); - - networkConfig.getSubjects(DeviceId.class, AccessDeviceConfig.class).forEach( - subject -> { - AccessDeviceConfig config = networkConfig.getConfig(subject, AccessDeviceConfig.class); - if (config != null) { - AccessDeviceData data = config.getOlt(); - oltData.put(data.deviceId(), data); - } - } - ); - - /*deviceService.addListener(deviceListener); - - deviceService.getPorts(DeviceId.deviceId(oltDevice)).stream().forEach( - port -> { - if (!port.number().isLogical() && port.isEnabled()) { - short vlanId = fetchVlanId(port.number()); - if (vlanId > 0) { - provisionVlanOnPort(oltDevice, uplinkPort, port.number(), (short) 7); - provisionVlanOnPort(oltDevice, uplinkPort, port.number(), vlanId); - } - } - } - );*/ - - - deviceService.getPorts(DeviceId.deviceId(gfastDevice)).stream() - .filter(port -> !port.number().isLogical()) - .filter(Port::isEnabled) - .forEach(port -> { - short vlanId = (short) (fetchVlanId(port.number()) + OFFSET); - if (vlanId > 0) { - provisionVlanOnPort(gfastDevice, gfastUplink, port.number(), vlanId); - } - } - ); - log.info("Started with Application ID {}", appId.id()); - } - - @Deactivate - public void deactivate() { - networkConfig.removeListener(configListener); - networkConfig.unregisterConfigFactory(configFactory); - log.info("Stopped"); - } - - @Modified - public void modified(ComponentContext context) { - Dictionary<?, ?> properties = context.getProperties(); - - String s = Tools.get(properties, "uplinkPort"); - uplinkPort = Strings.isNullOrEmpty(s) ? UPLINK_PORT : Integer.parseInt(s); - - s = Tools.get(properties, "oltDevice"); - oltDevice = Strings.isNullOrEmpty(s) ? OLT_DEVICE : s; - } - - private short fetchVlanId(PortNumber port) { - long p = port.toLong() + OFFSET; - if (p > 4095) { - log.warn("Port Number {} exceeds vlan max", port); - return -1; - } - return (short) p; - } - - private void provisionVlanOnPort(String deviceId, int uplinkPort, PortNumber p, short vlanId) { - DeviceId did = DeviceId.deviceId(deviceId); - - TrafficSelector upstream = DefaultTrafficSelector.builder() - .matchVlanId(VlanId.vlanId(vlanId)) - .matchInPort(p) - .build(); - - TrafficSelector downStream = DefaultTrafficSelector.builder() - .matchVlanId(VlanId.vlanId(vlanId)) - .matchInPort(PortNumber.portNumber(uplinkPort)) - .build(); - - TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder() - .setOutput(PortNumber.portNumber(uplinkPort)) - .build(); - - TrafficTreatment downStreamTreatment = DefaultTrafficTreatment.builder() - .setOutput(p) - .build(); - - - ForwardingObjective upFwd = DefaultForwardingObjective.builder() - .withFlag(ForwardingObjective.Flag.VERSATILE) - .withPriority(1000) - .makePermanent() - .withSelector(upstream) - .fromApp(appId) - .withTreatment(upstreamTreatment) - .add(); - - ForwardingObjective downFwd = DefaultForwardingObjective.builder() - .withFlag(ForwardingObjective.Flag.VERSATILE) - .withPriority(1000) - .makePermanent() - .withSelector(downStream) - .fromApp(appId) - .withTreatment(downStreamTreatment) - .add(); - - flowObjectiveService.forward(did, upFwd); - flowObjectiveService.forward(did, downFwd); - } - - @Override - public void provisionSubscriber(ConnectPoint port, VlanId vlan) { - AccessDeviceData olt = oltData.get(port.deviceId()); - - if (olt == null) { - log.warn("No data found for OLT device {}", port.deviceId()); - return; - } - - provisionVlans(olt.deviceId(), olt.uplink(), port.port(), vlan, olt.vlan()); - } - - private void provisionVlans(DeviceId deviceId, PortNumber uplinkPort, - PortNumber subscriberPort, - VlanId subscriberVlan, VlanId deviceVlan) { - - TrafficSelector upstream = DefaultTrafficSelector.builder() - .matchVlanId(DEFAULT_VLAN) - .matchInPort(subscriberPort) - .build(); - - TrafficSelector downstream = DefaultTrafficSelector.builder() - .matchVlanId(deviceVlan) - .matchInPort(uplinkPort) - .build(); - - TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder() - .setVlanId(subscriberVlan) - .pushVlan() - .setVlanId(deviceVlan) - .setOutput(uplinkPort) - .build(); - - TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder() - .popVlan() - .setVlanId(DEFAULT_VLAN) - .setOutput(subscriberPort) - .build(); - - - ForwardingObjective upFwd = DefaultForwardingObjective.builder() - .withFlag(ForwardingObjective.Flag.VERSATILE) - .withPriority(1000) - .makePermanent() - .withSelector(upstream) - .fromApp(appId) - .withTreatment(upstreamTreatment) - .add(); - - ForwardingObjective downFwd = DefaultForwardingObjective.builder() - .withFlag(ForwardingObjective.Flag.VERSATILE) - .withPriority(1000) - .makePermanent() - .withSelector(downstream) - .fromApp(appId) - .withTreatment(downstreamTreatment) - .add(); - - flowObjectiveService.forward(deviceId, upFwd); - flowObjectiveService.forward(deviceId, downFwd); - } - - @Override - public void removeSubscriber(ConnectPoint port) { - throw new UnsupportedOperationException("Not yet implemented"); - } - - private class InternalDeviceListener implements DeviceListener { - @Override - public void event(DeviceEvent event) { - DeviceId devId = DeviceId.deviceId(oltDevice); - switch (event.type()) { - case PORT_ADDED: - case PORT_UPDATED: - if (devId.equals(event.subject().id()) && event.port().isEnabled()) { - short vlanId = fetchVlanId(event.port().number()); - provisionVlanOnPort(gfastDevice, uplinkPort, event.port().number(), vlanId); - } - break; - case DEVICE_ADDED: - case DEVICE_UPDATED: - case DEVICE_REMOVED: - case DEVICE_SUSPENDED: - case DEVICE_AVAILABILITY_CHANGED: - case PORT_REMOVED: - case PORT_STATS_UPDATED: - default: - return; - } - } - } - - private class InternalNetworkConfigListener implements NetworkConfigListener { - @Override - public void event(NetworkConfigEvent event) { - switch (event.type()) { - - case CONFIG_ADDED: - case CONFIG_UPDATED: - if (event.configClass().equals(CONFIG_CLASS)) { - AccessDeviceConfig config = - networkConfig.getConfig((DeviceId) event.subject(), CONFIG_CLASS); - if (config != null) { - oltData.put(config.getOlt().deviceId(), config.getOlt()); - } - } - break; - case CONFIG_UNREGISTERED: - case CONFIG_REMOVED: - default: - break; - } - } - } - -} diff --git a/framework/src/onos/apps/openstackswitching/pom.xml b/framework/src/onos/apps/openstackswitching/pom.xml index 245b9e80..52129b6f 100644 --- a/framework/src/onos/apps/openstackswitching/pom.xml +++ b/framework/src/onos/apps/openstackswitching/pom.xml @@ -80,6 +80,11 @@ <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-dhcp-api</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> <build> diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackArpHandler.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackArpHandler.java index afaf7a22..0c139d8d 100644 --- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackArpHandler.java +++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackArpHandler.java @@ -15,11 +15,20 @@ */ package org.onosproject.openstackswitching; +import org.onlab.packet.ARP; +import org.onlab.packet.Ethernet; +import org.onlab.packet.Ip4Address; +import org.onlab.packet.MacAddress; +import org.onosproject.net.flow.DefaultTrafficTreatment; +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.net.packet.PacketService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -import java.util.HashMap; +import java.nio.ByteBuffer; +import java.util.Map; /** * It handles ARP packet from VMs. @@ -28,16 +37,18 @@ public class OpenstackArpHandler { private static Logger log = LoggerFactory .getLogger(OpenstackArpHandler.class); - - HashMap<String, OpenstackPort> openstackPortHashMap; + private PacketService packetService; + private Map<String, OpenstackPort> openstackPortMap; /** - * Constructs an OpenstackArpHandler. + * Returns OpenstackArpHandler reference. * - * @param openstackPortMap port map + * @param openstackPortMap + * @param packetService */ - public OpenstackArpHandler(HashMap<String, OpenstackPort> openstackPortMap) { - this.openstackPortHashMap = openstackPortMap; + public OpenstackArpHandler(Map<String, OpenstackPort> openstackPortMap, PacketService packetService) { + this.openstackPortMap = openstackPortMap; + this.packetService = packetService; } /** @@ -46,6 +57,50 @@ public class OpenstackArpHandler { * @param pkt ARP request packet */ public void processPacketIn(InboundPacket pkt) { - log.warn("Received an ARP packet"); + Ethernet ethernet = pkt.parsed(); + ARP arp = (ARP) ethernet.getPayload(); + + if (arp.getOpCode() == ARP.OP_REQUEST) { + byte[] srcMacAddress = arp.getSenderHardwareAddress(); + byte[] srcIPAddress = arp.getSenderProtocolAddress(); + byte[] dstIPAddress = arp.getTargetProtocolAddress(); + + //Searches the Dst MAC Address based on openstackPortMap + MacAddress macAddress = null; + + OpenstackPort openstackPort = openstackPortMap.values().stream().filter(e -> e.fixedIps(). + containsValue(Ip4Address.valueOf(dstIPAddress))).findAny().orElse(null); + + if (openstackPort != null) { + macAddress = openstackPort.macAddress(); + log.debug("Found MACAddress: {}", macAddress.toString()); + } else { + return; + } + + //Creates a response packet + ARP arpReply = new ARP(); + arpReply.setOpCode(ARP.OP_REPLY) + .setHardwareAddressLength(arp.getHardwareAddressLength()) + .setHardwareType(arp.getHardwareType()) + .setProtocolAddressLength(arp.getProtocolAddressLength()) + .setProtocolType(arp.getProtocolType()) + .setSenderHardwareAddress(macAddress.toBytes()) + .setSenderProtocolAddress(dstIPAddress) + .setTargetHardwareAddress(srcMacAddress) + .setTargetProtocolAddress(srcIPAddress); + + //Sends a response packet + ethernet.setDestinationMACAddress(srcMacAddress) + .setSourceMACAddress(macAddress) + .setEtherType(Ethernet.TYPE_ARP) + .setPayload(arpReply); + + TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder(); + builder.setOutput(pkt.receivedFrom().port()); + OutboundPacket packet = new DefaultOutboundPacket(pkt.receivedFrom().deviceId(), + builder.build(), ByteBuffer.wrap(ethernet.serialize())); + packetService.emit(packet); + } } } diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackDhcpHandler.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackDhcpHandler.java deleted file mode 100644 index 9c3641c1..00000000 --- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackDhcpHandler.java +++ /dev/null @@ -1,45 +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.openstackswitching; - -import org.onosproject.net.packet.InboundPacket; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * It handles DHCP request packets. - */ -public class OpenstackDhcpHandler { - - private static Logger log = LoggerFactory - .getLogger(OpenstackDhcpHandler.class); - - /** - * Returns OpenstackDhcpHandler reference. - */ - public OpenstackDhcpHandler() { - - } - - /** - * Processes DHCP request packets. - * - * @param pkt DHCP request packet - */ - public void processPacketIn(InboundPacket pkt) { - log.warn("Received a DHCP packet"); - } -} diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java index dc7c0263..7bfdf290 100644 --- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java +++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackNetwork.java @@ -26,8 +26,18 @@ public final class OpenstackNetwork { private String name; private String tenantId; private String segmentId; - private String networkType; private String id; + private NetworkType networkType; + + public enum NetworkType { + /** + * Currently only VXLAN moded is supported. + */ + VXLAN, + VLAN, + STT, + LOCAL + } /** * Returns the builder object of the OpenstackNetwork class. @@ -39,12 +49,12 @@ public final class OpenstackNetwork { } private OpenstackNetwork(String name, String tenantId, String id, String sid, - String type) { + NetworkType type) { this.name = checkNotNull(name); this.tenantId = checkNotNull(tenantId); this.segmentId = checkNotNull(sid); this.id = checkNotNull(id); - this.networkType = checkNotNull(type); + this.networkType = type; } public String name() { @@ -63,7 +73,7 @@ public final class OpenstackNetwork { return this.segmentId; } - public String networkType() { + public NetworkType networkType() { return this.networkType; } @@ -72,7 +82,7 @@ public final class OpenstackNetwork { private String tenantId; private String id; private String sid; - private String networkType; + private NetworkType networkType; public Builder name(String name) { this.name = name; @@ -98,7 +108,7 @@ public final class OpenstackNetwork { return this; } - public Builder networkType(String type) { + public Builder networkType(NetworkType type) { this.networkType = type; return this; diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSubnet.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSubnet.java new file mode 100644 index 00000000..39d783e3 --- /dev/null +++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSubnet.java @@ -0,0 +1,159 @@ +/* + * 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.openstackswitching; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * Represents the subnet information given by Neutron. + * + */ +public final class OpenstackSubnet { + private String name; + private boolean enableHhcp; + private String networkId; + private String tenantId; + private String dnsNameservers; + private String gatewayIp; + private String cidr; + private String id; + + private OpenstackSubnet(String name, boolean enableHhcp, String networkId, + String tenantId, String dnsNameservers, String gatewayIp, + String cidr, String id) { + this.name = name; + this.enableHhcp = enableHhcp; + this.networkId = checkNotNull(networkId); + this.tenantId = checkNotNull(tenantId); + this.dnsNameservers = dnsNameservers; + this.gatewayIp = gatewayIp; + this.cidr = checkNotNull(cidr); + this.id = checkNotNull(id); + } + + /** + * Returns OpenstackSubnet builder object. + * + * @return OpenstackSubnet builder + */ + public static OpenstackSubnet.Builder builder() { + return new Builder(); + } + + public String name() { + return name; + } + + public boolean enableHhcp() { + return enableHhcp; + } + + public String networkId() { + return networkId; + } + + public String tenantId() { + return tenantId; + } + + public String dnsNameservers() { + return dnsNameservers; + } + + public String gatewayIp() { + return gatewayIp; + } + + public String cidr() { + return cidr; + } + + public String id() { + return id; + } + + // TODO : Implement the following functions when necessary + + /** + * OpenstackSubnet Builder class. + * + */ + public static final class Builder { + private String name; + private boolean enableDhcp; + private String networkId; + private String tenantId; + private String dnsNameservers; + private String gatewayIp; + private String cidr; + private String id; + + Builder() {} + + public Builder setName(String name) { + this.name = name; + + return this; + } + + public Builder setEnableDhcp(boolean enableDhcp) { + this.enableDhcp = enableDhcp; + + return this; + } + + public Builder setNetworkId(String networkId) { + this.networkId = networkId; + + return this; + } + + public Builder setTenantId(String tenantId) { + this.tenantId = tenantId; + + return this; + } + + public Builder setDnsNameservers(String dnsNameservers) { + this.dnsNameservers = dnsNameservers; + + return this; + } + + public Builder setGatewayIp(String gatewayIp) { + this.gatewayIp = gatewayIp; + + return this; + } + + public Builder setCidr(String cidr) { + this.cidr = cidr; + + return this; + } + + public Builder setId(String id) { + this.id = id; + + return this; + } + + public OpenstackSubnet build() { + return new OpenstackSubnet(name, enableDhcp, networkId, tenantId, + dnsNameservers, gatewayIp, cidr, id); + } + } +} diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingManager.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingManager.java index baae7f80..4be8a50d 100644 --- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingManager.java +++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingManager.java @@ -24,13 +24,12 @@ import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.ReferenceCardinality; import org.apache.felix.scr.annotations.Service; import org.onlab.packet.Ethernet; -import org.onlab.packet.IPv4; import org.onlab.packet.Ip4Address; import org.onlab.packet.Ip4Prefix; import org.onlab.packet.MacAddress; -import org.onlab.packet.UDP; import org.onosproject.core.ApplicationId; import org.onosproject.core.CoreService; +import org.onosproject.dhcp.DhcpService; import org.onosproject.net.Device; import org.onosproject.net.DeviceId; import org.onosproject.net.Port; @@ -45,8 +44,8 @@ import org.onosproject.net.packet.PacketService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -73,12 +72,14 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected FlowObjectiveService flowObjectiveService; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected DhcpService dhcpService; public static final int DHCP_PORT = 67; private ApplicationId appId; private OpenstackArpHandler arpHandler; - private OpenstackDhcpHandler dhcpHandler = new OpenstackDhcpHandler(); + private OpenstackSwitchingRulePopulator rulePopulator; private ExecutorService deviceEventExcutorService = Executors.newFixedThreadPool(10); @@ -86,12 +87,14 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { private InternalDeviceListener internalDeviceListener = new InternalDeviceListener(); // Map <port_id, OpenstackPort> - private HashMap<String, OpenstackPort> openstackPortMap; + private Map<String, OpenstackPort> openstackPortMap; // Map <network_id, OpenstackNetwork> - private HashMap<String, OpenstackNetwork> openstackNetworkMap; + private Map<String, OpenstackNetwork> openstackNetworkMap; + // Map <subnet_id, OpenstackSubner> + private Map<String, OpenstackSubnet> openstackSubnetMap; // Map <vni, List <Entry <portName, host ip>> - private HashMap<String, List<PortInfo>> vniPortMap; - private HashMap<Ip4Address, Port> tunnelPortMap; + private Map<String, List<PortInfo>> vniPortMap; + private Map<Ip4Address, Port> tunnelPortMap; @Activate @@ -104,11 +107,11 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { openstackPortMap = Maps.newHashMap(); openstackNetworkMap = Maps.newHashMap(); + openstackSubnetMap = Maps.newHashMap(); + vniPortMap = Maps.newHashMap(); tunnelPortMap = Maps.newHashMap(); - - arpHandler = new OpenstackArpHandler(openstackPortMap); - + arpHandler = new OpenstackArpHandler(openstackPortMap, packetService); log.info("Started"); } @@ -124,9 +127,43 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { @Override public void createPorts(OpenstackPort openstackPort) { + //For DHCP purpose + //registerDhcpInfo(openstackPort); openstackPortMap.put(openstackPort.id(), openstackPort); } + /* + private void registerDhcpInfo(OpenstackPort openstackPort) { + Ip4Address ip4Address; + Ip4Address subnetMask; + Ip4Address dhcpServer; + Ip4Address gatewayIPAddress; + Ip4Address domainServer; + OpenstackSubnet openstackSubnet; + + ip4Address = (Ip4Address) openstackPort.fixedIps().values().toArray()[0]; + + openstackSubnet = openstackSubnetMap.values().stream() + .filter(n -> n.networkId().equals(openstackPort.networkId())) + .findFirst().get(); + + int prefix; + String[] parts = openstackSubnet.cidr().split("/"); + prefix = Integer.parseInt(parts[1]); + int mask = 0xffffffff << (32 - prefix); + byte[] bytes = new byte[]{(byte) (mask >>> 24), + (byte) (mask >> 16 & 0xff), (byte) (mask >> 8 & 0xff), (byte) (mask & 0xff)}; + + subnetMask = Ip4Address.valueOf(bytes); + gatewayIPAddress = Ip4Address.valueOf(openstackSubnet.gatewayIp()); + dhcpServer = gatewayIPAddress; + domainServer = Ip4Address.valueOf("8.8.8.8"); + + dhcpService.setStaticMappingOpenstack(openstackPort.macAddress(), + ip4Address, subnetMask, dhcpServer, gatewayIPAddress, domainServer); + } + */ + @Override public void deletePorts() { @@ -142,8 +179,15 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { openstackNetworkMap.put(openstackNetwork.id(), openstackNetwork); } + + @Override + public void createSubnet(OpenstackSubnet openstackSubnet) { + openstackSubnetMap.put(openstackSubnet.id(), openstackSubnet); + log.debug("Added Subnet Info {}", openstackNetworkMap.get(openstackSubnet.id())); + } + private void processDeviceAdded(Device device) { - log.warn("device {} is added", device.id()); + log.debug("device {} is added", device.id()); rulePopulator.populateDefaultRules(device.id()); } @@ -152,7 +196,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { // TODO: Make it stateless // TODO: All the logics need to be processed inside of the rulePopulator class synchronized (vniPortMap) { - log.warn("port {} is updated", port.toString()); + log.debug("port {} is updated", port.toString()); updatePortMaps(device, port); if (!port.annotations().value("portName").equals("vxlan")) { @@ -163,7 +207,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { } private void processPortRemoved(Device device, Port port) { - log.warn("port {} is removed", port.toString()); + log.debug("port {} is removed", port.toString()); // TODO: need to update the vniPortMap } @@ -182,7 +226,7 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { // TODO: Avoid duplicate flow rule set up for VMs in other Cnode // (possibly avoided by flowrule subsystem?) if (tunnelPortMap.get(hostIpAddress) == null) { - log.warn("There is no tunnel port information"); + log.debug("There is no tunnel port information"); return; } String vni = getVniForPort(portName); @@ -251,20 +295,19 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { .filter(p -> p.id().startsWith(uuid)) .findFirst().get(); if (port == null) { - log.warn("No port information for port {}", portName); + log.debug("No port information for port {}", portName); return null; } - //OpenstackSubnet subnet = openstackSubnetMap.values().stream() - // .filter(s -> s.networkId().equals(port.networkId())) - // .findFirst().get(); - //if (subnet == null) { - // log.warn("No subnet information for network {}", subnet.id()); - // return null; - //} + OpenstackSubnet subnet = openstackSubnetMap.values().stream() + .filter(s -> s.networkId().equals(port.networkId())) + .findFirst().get(); + if (subnet == null) { + log.debug("No subnet information for network {}", subnet.id()); + return null; + } - //return Ip4Prefix.valueOf(subnet.cidr()); - return null; + return Ip4Prefix.valueOf(subnet.cidr()); } /** @@ -280,14 +323,14 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { .filter(p -> p.id().startsWith(uuid)) .findFirst().get(); if (port == null) { - log.warn("No port information for port {}", portName); + log.debug("No port information for port {}", portName); return null; } OpenstackNetwork network = openstackNetworkMap.values().stream() .filter(n -> n.id().equals(port.networkId())) .findFirst().get(); if (network == null) { - log.warn("No VNI information for network {}", network.id()); + log.debug("No VNI information for network {}", network.id()); return null; } @@ -357,15 +400,6 @@ public class OpenstackSwitchingManager implements OpenstackSwitchingService { if (ethernet.getEtherType() == Ethernet.TYPE_ARP) { arpHandler.processPacketIn(pkt); - } else if (ethernet.getEtherType() == Ethernet.TYPE_IPV4) { - IPv4 ipPacket = (IPv4) ethernet.getPayload(); - - if (ipPacket.getProtocol() == IPv4.PROTOCOL_UDP) { - UDP udpPacket = (UDP) ipPacket.getPayload(); - if (udpPacket.getDestinationPort() == DHCP_PORT) { - dhcpHandler.processPacketIn(pkt); - } - } } } } diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java index 9ead05f0..f6e98060 100644 --- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java +++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingRulePopulator.java @@ -87,7 +87,6 @@ public class OpenstackSwitchingRulePopulator { */ public void populateDefaultRules(DeviceId id) { - //setFlowRuleForDHCP(id); setFlowRuleForArp(id); log.warn("Default rule has been set"); @@ -121,7 +120,7 @@ public class OpenstackSwitchingRulePopulator { * * @param id device ID to set the rules */ - private void setFlowRuleForDHCP(DeviceId id) { + private void setFlowRuleForDhcp(DeviceId id) { TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder(); TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingService.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingService.java index d97b39c8..3d40d51d 100644 --- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingService.java +++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/OpenstackSwitchingService.java @@ -46,4 +46,10 @@ public interface OpenstackSwitchingService { */ void createNetwork(OpenstackNetwork openstackNetwork); + /** + * Store the subnet information created by openstack. + * + * @param openstackSubnet subnet information + */ + void createSubnet(OpenstackSubnet openstackSubnet); } diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java index 43bd1583..fc1509d4 100644 --- a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java +++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackNetworkCodec.java @@ -54,6 +54,8 @@ public class OpenstackNetworkCodec extends JsonCodec<OpenstackNetwork> { .id(id); if (!networkInfo.path(NETWORK_TYPE).isMissingNode()) { + onb.networkType(OpenstackNetwork.NetworkType.valueOf(networkInfo.path(NETWORK_TYPE). + asText().toUpperCase())); onb.name(networkInfo.path(NETWORK_TYPE).asText()); onb.segmentId(networkInfo.path(SEGMENTATION_ID).asText()); } diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetCodec.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetCodec.java new file mode 100644 index 00000000..a643057a --- /dev/null +++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetCodec.java @@ -0,0 +1,72 @@ +/* + * 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.openstackswitching.web; + +import com.fasterxml.jackson.databind.JsonNode; + + +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.openstackswitching.OpenstackSubnet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * It encodes and decodes the OpenstackSubnet. + */ + +public class OpenstackSubnetCodec extends JsonCodec<OpenstackSubnet> { + private static Logger log = LoggerFactory + .getLogger(OpenstackSubnetCodec.class); + + // JSON Field names + private static final String SUBNET = "subnet"; + private static final String NAME = "name"; + private static final String ENABLE_DHCP = "enable_dhcp"; + private static final String NETWORK_ID = "network_id"; + private static final String TENANT_ID = "tenant_id"; + private static final String DNS_NAMESERVERS = "dns_nameservers"; + private static final String GATEWAY_IP = "gateway_ip"; + private static final String CIDR = "cidr"; + private static final String ID = "id"; + + @Override + public OpenstackSubnet decode(ObjectNode json, CodecContext context) { + JsonNode subnetInfo = json.get(SUBNET); + + String name = subnetInfo.path(NAME).asText(); + boolean enableDhcp = subnetInfo.path(ENABLE_DHCP).asBoolean(); + String networkId = subnetInfo.path(NETWORK_ID).asText(); + String tenantId = subnetInfo.path(TENANT_ID).asText(); + String dnsNameservsers = subnetInfo.path(DNS_NAMESERVERS).asText(); + String gatewayIp = subnetInfo.path(GATEWAY_IP).asText(); + String cidr = subnetInfo.path(CIDR).asText(); + String id = subnetInfo.path(ID).asText(); + + OpenstackSubnet openstackSubnet = OpenstackSubnet.builder() + .setName(name) + .setEnableDhcp(enableDhcp) + .setNetworkId(networkId) + .setTenantId(tenantId) + .setDnsNameservers(dnsNameservsers) + .setGatewayIp(gatewayIp) + .setCidr(cidr) + .setId(id) + .build(); + return openstackSubnet; + } +} diff --git a/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetWebResource.java b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetWebResource.java new file mode 100644 index 00000000..af1ae9dd --- /dev/null +++ b/framework/src/onos/apps/openstackswitching/src/main/java/org/onosproject/openstackswitching/web/OpenstackSubnetWebResource.java @@ -0,0 +1,64 @@ +/* + * 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.openstackswitching.web; + + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.onosproject.openstackswitching.OpenstackSubnet; +import org.onosproject.openstackswitching.OpenstackSwitchingService; +import org.onosproject.rest.AbstractWebResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.InputStream; + +@Path("subnets") +public class OpenstackSubnetWebResource extends AbstractWebResource { + protected static final Logger log = LoggerFactory + .getLogger(OpenstackSubnetWebResource.class); + + private static final OpenstackSubnetCodec SUBNET_CODEC = new OpenstackSubnetCodec(); + + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response createSubnet(InputStream input) { + try { + ObjectMapper mapper = new ObjectMapper(); + ObjectNode subnetNode = (ObjectNode) mapper.readTree(input); + + OpenstackSubnet openstackSubnet = SUBNET_CODEC.decode(subnetNode, this); + + OpenstackSwitchingService switchingService = get(OpenstackSwitchingService.class); + switchingService.createSubnet(openstackSubnet); + log.info("REST API subnets is called with {}", subnetNode.toString()); + return Response.status(Response.Status.OK).build(); + } catch (Exception e) { + log.error("Creates VirtualSubnet failed because of exception {}", + e.toString()); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.toString()) + .build(); + } + } + +} diff --git a/framework/src/onos/apps/openstackswitching/src/main/webapp/WEB-INF/web.xml b/framework/src/onos/apps/openstackswitching/src/main/webapp/WEB-INF/web.xml index 53b0e2e9..4f50ef72 100644 --- a/framework/src/onos/apps/openstackswitching/src/main/webapp/WEB-INF/web.xml +++ b/framework/src/onos/apps/openstackswitching/src/main/webapp/WEB-INF/web.xml @@ -31,7 +31,8 @@ <param-name>com.sun.jersey.config.property.classnames</param-name> <param-value> org.onosproject.openstackswitching.web.OpenstackPortWebResource, - org.onosproject.openstackswitching.web.OpenstackNetworkWebResource + org.onosproject.openstackswitching.web.OpenstackNetworkWebResource, + org.onosproject.openstackswitching.web.OpenstackSubnetWebResource </param-value> </init-param> <load-on-startup>1</load-on-startup> diff --git a/framework/src/onos/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java b/framework/src/onos/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java index e0545023..3890bb4a 100644 --- a/framework/src/onos/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java +++ b/framework/src/onos/apps/optical/src/main/java/org/onosproject/optical/OpticalPathProvisioner.java @@ -343,6 +343,7 @@ public class OpticalPathProvisioner { return getIntents(crossConnectPoints); } + log.warn("Unable to find multi-layer path."); return Collections.emptyList(); } @@ -392,20 +393,41 @@ public class OpticalPathProvisioner { } /** - * Verifies if given link is cross-connect between packet and optical layer. + * Verifies if given device type is in packet layer, i.e., ROADM, OTN or ROADM_OTN device. + * + * @param type device type + * @return true if in packet layer, false otherwise + */ + private boolean isPacketLayer(Device.Type type) { + return type == Device.Type.SWITCH || type == Device.Type.ROUTER; + } + + /** + * Verifies if given device type is in packet layer, i.e., switch or router device. + * + * @param type device type + * @return true if in packet layer, false otherwise + */ + private boolean isTransportLayer(Device.Type type) { + return type == Device.Type.ROADM || type == Device.Type.OTN || type == Device.Type.ROADM_OTN; + } + + /** + * Verifies if given link forms a cross-connection between packet and optical layer. * * @param link the link - * @return true if the link is a cross-connect link + * @return true if the link is a cross-connect link, false otherwise */ - public static boolean isCrossConnectLink(Link link) { + private boolean isCrossConnectLink(Link link) { if (link.type() != Link.Type.OPTICAL) { return false; } - checkNotNull(link.annotations()); - checkNotNull(link.annotations().value("optical.type")); + Device.Type src = deviceService.getDevice(link.src().deviceId()).type(); + Device.Type dst = deviceService.getDevice(link.dst().deviceId()).type(); - return link.annotations().value("optical.type").equals("cross-connect"); + return src != dst && + ((isPacketLayer(src) && isTransportLayer(dst)) || (isPacketLayer(dst) && isTransportLayer(src))); } } diff --git a/framework/src/onos/apps/optical/src/main/java/org/onosproject/optical/testapp/MPLSForwarding.java b/framework/src/onos/apps/optical/src/main/java/org/onosproject/optical/testapp/MplsForwarding.java index c784c82f..b9a4b0ca 100644 --- a/framework/src/onos/apps/optical/src/main/java/org/onosproject/optical/testapp/MPLSForwarding.java +++ b/framework/src/onos/apps/optical/src/main/java/org/onosproject/optical/testapp/MplsForwarding.java @@ -15,15 +15,12 @@ */ package org.onosproject.optical.testapp; -import static org.slf4j.LoggerFactory.getLogger; - -import java.util.HashMap; -import java.util.Map; - import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.ReferenceCardinality; +import org.onlab.packet.Ethernet; +import org.onlab.packet.MplsLabel; import org.onosproject.core.ApplicationId; import org.onosproject.core.CoreService; import org.onosproject.net.Device; @@ -39,15 +36,18 @@ import org.onosproject.net.flow.FlowRule; import org.onosproject.net.flow.FlowRuleService; import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficTreatment; -import org.onlab.packet.Ethernet; -import org.onlab.packet.MplsLabel; import org.slf4j.Logger; +import java.util.HashMap; +import java.util.Map; + +import static org.slf4j.LoggerFactory.getLogger; + /** * Sample reactive forwarding application. */ //@Component(immediate = true) -public class MPLSForwarding { +public class MplsForwarding { private final Logger log = getLogger(getClass()); diff --git a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/cli/PIMShowCommand.java b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/cli/PIMShowCommand.java index 0ef7e389..6bd563b6 100644 --- a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/cli/PIMShowCommand.java +++ b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/cli/PIMShowCommand.java @@ -18,30 +18,30 @@ package org.onosproject.pim.cli; import com.fasterxml.jackson.databind.JsonNode; import org.apache.karaf.shell.commands.Command; import org.onosproject.cli.AbstractShellCommand; -import org.onosproject.net.ConnectPoint; -import org.onosproject.pim.impl.PIMNeighbors; -import org.onosproject.pim.impl.PIMNeighborsCodec; +import org.onosproject.pim.impl.PIMInterface; +import org.onosproject.pim.impl.PIMInterfaces; +import org.onosproject.pim.impl.PIMInterfacesCodec; -import java.util.HashMap; +import java.util.Collection; -@Command(scope = "onos", name = "pim-neighbors", description = "Displays the pim neighbors") +@Command(scope = "onos", name = "pim-interfaces", description = "Displays the pim interfaces") public class PIMShowCommand extends AbstractShellCommand { // prints either the json or cli version of the hash map connect point - // neighbors from the PIMNeighbors class. + // neighbors from the PIMInterfaces class. @Override protected void execute() { // grab connect point neighbors hash map to send in to json encoder. - HashMap<ConnectPoint, PIMNeighbors> pimNbrs = PIMNeighbors.getConnectPointNeighbors(); + Collection<PIMInterface> pimIntfs = PIMInterfaces.getInstance().getInterfaces(); if (outputJson()) { - print("%s", json(pimNbrs)); + print("%s", json(pimIntfs)); } else { - print(PIMNeighbors.printPimNeighbors()); + print(PIMInterfaces.getInstance().printInterfaces()); } } - private JsonNode json(HashMap<ConnectPoint, PIMNeighbors> pimNbrs) { - return new PIMNeighborsCodec().encode(pimNbrs, this); + private JsonNode json(Collection<PIMInterface> pimIntfs) { + return new PIMInterfacesCodec().encode(pimIntfs, this); } }
\ No newline at end of file diff --git a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMComponent.java b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMComponent.java index bd5e1486..1a2d6f54 100644 --- a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMComponent.java +++ b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMComponent.java @@ -22,132 +22,61 @@ 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.onlab.packet.Ethernet; -import org.onlab.packet.IPv4; -import org.onlab.packet.Ip4Address; -import org.onlab.packet.IpAddress; -import org.onlab.packet.IpPrefix; -import org.onlab.packet.PIM; import org.onosproject.core.ApplicationId; import org.onosproject.core.CoreService; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.packet.InboundPacket; -import org.onosproject.net.packet.PacketContext; -import org.onosproject.net.packet.PacketPriority; -import org.onosproject.net.packet.PacketProcessor; +import org.onosproject.incubator.net.intf.InterfaceService; +import org.onosproject.net.config.NetworkConfigService; import org.onosproject.net.packet.PacketService; import org.slf4j.Logger; /** - * Protocol Independent Multicast Emulation. + * Protocol Independent Multicast (PIM) Emulation. This component is responsible + * for reference the services this PIM module is going to need, then initializing + * the corresponding utility classes. */ @Component(immediate = true) public class PIMComponent { private final Logger log = getLogger(getClass()); + // Register to receive PIM packets, used to send packets as well @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected PacketService packetService; + // Get the appId @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected CoreService coreService; - private PIMPacketProcessor processor = new PIMPacketProcessor(); + // Get the network configuration updates + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected NetworkConfigService configService; + + // Access defined network (IP) interfaces + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected InterfaceService interfaceService; + private static ApplicationId appId; + private PIMInterfaces pimInterfaces; + private PIMPacketHandler pimPacketHandler; + @Activate public void activate() { appId = coreService.registerApplication("org.onosproject.pim"); - packetService.addProcessor(processor, PacketProcessor.director(1)); + // Initialize the Packet Handler class + pimPacketHandler = PIMPacketHandler.getInstance(); + pimPacketHandler.initialize(packetService, appId); - // Build a traffic selector for all multicast traffic - TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); - selector.matchEthType(Ethernet.TYPE_IPV4); - selector.matchIPProtocol(IPv4.PROTOCOL_PIM); - packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId); + // Initialize the Interface class + pimInterfaces = PIMInterfaces.getInstance(); + pimInterfaces.initialize(configService, interfaceService); log.info("Started"); } @Deactivate public void deactivate() { - packetService.removeProcessor(processor); - processor = null; + PIMPacketHandler.getInstance().stop(); log.info("Stopped"); } - - /** - * Packet processor responsible for handling IGMP packets. - */ - private class PIMPacketProcessor implements PacketProcessor { - - @Override - public void process(PacketContext context) { - // Stop processing if the packet has been handled, since we - // can't do any more to it. - if (context.isHandled()) { - return; - } - - InboundPacket pkt = context.inPacket(); - if (pkt == null) { - return; - } - - Ethernet ethPkt = pkt.parsed(); - if (ethPkt == null) { - return; - } - - /* - * IPv6 MLD packets are handled by ICMP6. We'll only deal - * with IPv4. - */ - if (ethPkt.getEtherType() != Ethernet.TYPE_IPV4) { - return; - } - - IPv4 ip = (IPv4) ethPkt.getPayload(); - IpAddress gaddr = IpAddress.valueOf(ip.getDestinationAddress()); - IpAddress saddr = Ip4Address.valueOf(ip.getSourceAddress()); - log.debug("Packet (" + saddr.toString() + ", " + gaddr.toString() + - "\tingress port: " + context.inPacket().receivedFrom().toString()); - - if (ip.getProtocol() != IPv4.PROTOCOL_PIM) { - log.debug("PIM Picked up a non PIM packet: IP protocol: " + ip.getProtocol()); - return; - } - - // TODO: check incoming to be PIM.PIM_ADDRESS or "Our" address. - IpPrefix spfx = IpPrefix.valueOf(saddr, 32); - IpPrefix gpfx = IpPrefix.valueOf(gaddr, 32); - - PIM pim = (PIM) ip.getPayload(); - switch (pim.getPimMsgType()) { - - case PIM.TYPE_HELLO: - PIMNeighbors.processHello(ethPkt, context.inPacket().receivedFrom()); - break; - - case PIM.TYPE_JOIN_PRUNE_REQUEST: - // Create the function - break; - - case PIM.TYPE_ASSERT: - case PIM.TYPE_BOOTSTRAP: - case PIM.TYPE_CANDIDATE_RP_ADV: - case PIM.TYPE_GRAFT: - case PIM.TYPE_GRAFT_ACK: - case PIM.TYPE_REGISTER: - case PIM.TYPE_REGISTER_STOP: - log.debug("Unsupported PIM message type: " + pim.getPimMsgType()); - break; - - default: - log.debug("Unkown PIM message type: " + pim.getPimMsgType()); - break; - } - } - } } 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 new file mode 100644 index 00000000..5da5c2b3 --- /dev/null +++ b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterface.java @@ -0,0 +1,341 @@ +/* + * 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.pim.impl; + +import org.onlab.packet.Ethernet; +import org.onlab.packet.IPv4; +import org.onlab.packet.Ip4Address; +import org.onlab.packet.IpAddress; +import org.onlab.packet.MacAddress; +import org.onlab.packet.PIM; +import org.onlab.packet.pim.PIMHello; +import org.onlab.packet.pim.PIMHelloOption; +import org.onosproject.incubator.net.intf.Interface; +import org.onosproject.net.ConnectPoint; +import org.onosproject.net.host.InterfaceIpAddress; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * The PIM Interface is a wrapper around a ConnectPoint and used to provide + * hello options values when "talking" with PIM other PIM routers. + */ +public class PIMInterface { + private static Logger log = LoggerFactory.getLogger("PIMInterfaces"); + + // Interface from the interface subsystem + private Interface theInterface; + + // The list of PIM neighbors adjacent to this interface + private Map<IpAddress, PIMNeighbor> neighbors = new HashMap<>(); + + // The designatedRouter for this LAN + private PIMNeighbor designatedRouter; + + // The priority we use on this ConnectPoint. + private int priority = PIMHelloOption.DEFAULT_PRIORITY; + + // The holdtime we are sending out. + private int holdtime = PIMHelloOption.DEFAULT_HOLDTIME; + + // Then generation ID we are sending out. 0 means we need to generate a new random ID + private int genid = PIMHelloOption.DEFAULT_GENID; + + // Our default prune delay + private int prunedelay = PIMHelloOption.DEFAULT_PRUNEDELAY; + + /** + * Create a PIMInterface. + * + * @param intf the network interface configuration + */ + public PIMInterface(Interface intf) { + + log.debug("Adding an interface: " + intf.toString() + "\n"); + this.theInterface = intf; + + // Send a hello to let our neighbors know we are alive + sendHello(); + } + + /** + * Get the PIM Interface. + * + * @return the PIM Interface + */ + public Interface getInterface() { + return theInterface; + } + + /** + * Getter for our IP address. + * + * @return our IP address. + */ + public IpAddress getIpAddress() { + if (theInterface.ipAddresses().isEmpty()) { + return null; + } + + // We will just assume the first interface on the list + IpAddress ipaddr = null; + for (InterfaceIpAddress ifipaddr : theInterface.ipAddresses()) { + ipaddr = ifipaddr.ipAddress(); + break; + } + return ipaddr; + } + + /** + * Get our priority. + * + * @return our priority. + */ + public int getPriority() { + return this.priority; + } + + /** + * Get the designated router on this connection. + * + * @return the PIMNeighbor representing the DR + */ + public PIMNeighbor getDesignatedRouter() { + return designatedRouter; + } + + /** + * Are we the DR on this CP? + * + * @return true if we are, false if not + */ + public boolean areWeDr() { + return (designatedRouter != null && + designatedRouter.getPrimaryAddr().equals(this.getIpAddress())); + } + + /** + * Return a collection of PIM Neighbors. + * + * @return the collection of PIM Neighbors + */ + public Collection<PIMNeighbor> getNeighbors() { + return this.neighbors.values(); + } + + /** + * Find the neighbor with the given IP address on this CP. + * + * @param ipaddr the IP address of the neighbor we are interested in + * @return the pim neighbor if it exists + */ + public PIMNeighbor findNeighbor(IpAddress ipaddr) { + PIMNeighbor nbr = neighbors.get(ipaddr); + return nbr; + } + + /** + * Add a new PIM neighbor to this list. + * + * @param nbr the neighbor to be added. + */ + public void addNeighbor(PIMNeighbor nbr) { + if (neighbors.containsKey(nbr.getPrimaryAddr())) { + + log.debug("We are adding a neighbor that already exists: {}", nbr.toString()); + neighbors.remove(nbr.getPrimaryAddr()); + } + neighbors.put(nbr.getPrimaryAddr(), nbr); + } + + /** + * Remove the neighbor from our neighbor list. + * + * @param ipaddr the IP address of the neighbor to remove + */ + public void removeNeighbor(IpAddress ipaddr) { + + if (neighbors.containsKey(ipaddr)) { + neighbors.remove(ipaddr); + } + this.electDR(); + } + + /** + * Remove the given neighbor from the neighbor list. + * + * @param nbr the nbr to be removed. + */ + public void removeNeighbor(PIMNeighbor nbr) { + + neighbors.remove(nbr.getPrimaryAddr(), nbr); + this.electDR(); + } + + /** + * Elect a new DR on this ConnectPoint. + * + * @return the PIM Neighbor that wins + */ + public PIMNeighbor electDR() { + + for (PIMNeighbor nbr : this.neighbors.values()) { + if (this.designatedRouter == null) { + this.designatedRouter = nbr; + continue; + } + + if (nbr.getPriority() > this.designatedRouter.getPriority()) { + this.designatedRouter = nbr; + continue; + } + + // We could sort in ascending order + if (this.designatedRouter.getPrimaryAddr().compareTo(nbr.getPrimaryAddr()) > 0) { + this.designatedRouter = nbr; + continue; + } + } + + return this.designatedRouter; + } + + /** + * Elect a new DR given the new neighbor. + * + * @param nbr the new neighbor to use in DR election. + * @return the PIM Neighbor that wins DR election + */ + public PIMNeighbor electDR(PIMNeighbor nbr) { + + // Make sure I have + if (this.designatedRouter == null || + this.designatedRouter.getPriority() < nbr.getPriority() || + this.designatedRouter.getPrimaryAddr().compareTo(nbr.getPrimaryAddr()) > 0) { + this.designatedRouter = nbr; + } + return this.designatedRouter; + } + + /** + * Find or create a pim neighbor with a given ip address and connect point. + * + * @param ipaddr of the pim neighbor + * @param mac The mac address of our sending neighbor + * @return an existing or new PIM neighbor + */ + public PIMNeighbor findOrCreate(IpAddress ipaddr, MacAddress mac) { + PIMNeighbor nbr = this.findNeighbor(ipaddr); + if (nbr == null) { + nbr = new PIMNeighbor(ipaddr, mac, this); + this.addNeighbor(nbr); + this.electDR(nbr); + } + return nbr; + } + + /** + * Process a hello packet received on this Interface. + * + * @param ethPkt the ethernet packet containing the hello message + * @param cp the ConnectPoint of this interface + */ + public void processHello(Ethernet ethPkt, ConnectPoint cp) { + checkNotNull(ethPkt); + checkNotNull(cp); + + MacAddress srcmac = ethPkt.getSourceMAC(); + IPv4 ip = (IPv4) ethPkt.getPayload(); + Ip4Address srcip = Ip4Address.valueOf(ip.getSourceAddress()); + + PIM pim = (PIM) ip.getPayload(); + checkNotNull(pim); + + PIMHello hello = (PIMHello) pim.getPayload(); + checkNotNull(hello); + + PIMNeighbor nbr = this.findOrCreate(srcip, srcmac); + if (nbr == null) { + log.error("Could not create a neighbor for: {1}", srcip.toString()); + return; + } + + ConnectPoint icp = theInterface.connectPoint(); + checkNotNull(icp); + if (!cp.equals(icp)) { + log.error("PIM Hello message received from {} on incorrect interface {}", + nbr.getPrimaryAddr(), this.toString()); + return; + } + nbr.refresh(hello); + } + + /** + * Send a hello packet from this interface. + */ + public void sendHello() { + PIM pim = new PIM(); + PIMHello hello = new PIMHello(); + + // Create a PIM Hello + pim = new PIM(); + pim.setVersion((byte) 2); + pim.setPIMType((byte) PIM.TYPE_HELLO); + pim.setChecksum((short) 0); + + hello = new PIMHello(); + hello.createDefaultOptions(); + pim.setPayload(hello); + hello.setParent(pim); + + log.debug("Sending hello: \n"); + PIMPacketHandler.getInstance().sendPacket(pim, this); + } + + /** + * prints the connectPointNeighbors list with each neighbor list. + * + * @return string of neighbors. + */ + public String printNeighbors() { + String out = "PIM Neighbors Table: \n"; + for (PIMNeighbor nbr : this.neighbors.values()) { + out += "\t" + nbr.toString(); + } + return out; + } + + @Override + public String toString() { + IpAddress ipaddr = this.getIpAddress(); + String out = "PIM Neighbors: "; + if (ipaddr != null) { + out += "IP: " + ipaddr.toString(); + } else { + out += "IP: *Null*"; + } + out += "\tPR: " + String.valueOf(this.priority) + "\n"; + return out; + } + +} + diff --git a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterfaces.java b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterfaces.java new file mode 100644 index 00000000..e33d5aa1 --- /dev/null +++ b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterfaces.java @@ -0,0 +1,260 @@ +/* + * 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.pim.impl; + +import org.jboss.netty.util.Timeout; +import org.jboss.netty.util.TimerTask; +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.incubator.net.intf.InterfaceService; +import org.onosproject.net.ConnectPoint; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import org.onosproject.net.config.NetworkConfigEvent; +import org.onosproject.net.config.NetworkConfigListener; +import org.onosproject.net.config.NetworkConfigService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * PIMInterfaces is a collection of all neighbors we have received + * PIM hello messages from. The main structure is a HashMap indexed + * by ConnectPoint with another HashMap indexed on the PIM neighbors + * IPAddress, it contains all PIM neighbors attached on that ConnectPoint. + */ +public final class PIMInterfaces { + + private Logger log = LoggerFactory.getLogger("PIMInterfaces"); + + private static PIMInterfaces instance = null; + + // Used to listen to network configuration changes + private NetworkConfigService configService; + + // Used to access IP Interface definitions for our segment + private InterfaceService interfaceService; + + // Internal class used to listen for network configuration changes + private InternalConfigListener configListener = new InternalConfigListener(); + + // This is the global container for all PIM Interfaces indexed by ConnectPoints. + private Map<ConnectPoint, PIMInterface> interfaces = new HashMap<>(); + + // Default hello message interval + private int helloMessageInterval = 60; + + // Timer used to send hello messages on this interface + private Timeout helloTimer; + + // Required by a utility class + private PIMInterfaces() {} + + /** + * Get the instance of PIMInterfaces. Create the instance if needed. + * + * @return PIMInterface instance + */ + public static PIMInterfaces getInstance() { + if (null == instance) { + instance = new PIMInterfaces(); + } + return instance; + } + + // Initialize the services + public void initialize(NetworkConfigService cs, InterfaceService is) { + configService = cs; + interfaceService = is; + + // Initialize interfaces if they already exist + initInterfaces(); + + // Listen for network config changes + configService.addListener(configListener); + } + + /** + * Listener for network config events. + */ + private class InternalConfigListener implements NetworkConfigListener { + + private void updateInterfaces(InterfaceConfig config) { + Set<Interface> intfs; + try { + intfs = config.getInterfaces(); + } catch (ConfigException e) { + log.error(e.toString()); + return; + } + for (Interface intf : intfs) { + addInterface(intf); + } + } + + /** + * Remove the PIMInterface represented by the ConnectPoint. If the + * PIMInterface does not exist this function is a no-op. + * + * @param cp The connectPoint representing the PIMInterface to be removed. + */ + private void removeInterface(ConnectPoint cp) { + removeInterface(cp); + } + + @Override + public void event(NetworkConfigEvent event) { + switch (event.type()) { + case CONFIG_ADDED: + case CONFIG_UPDATED: + log.debug("Config updated: " + event.toString() + "\n"); + if (event.configClass() == InterfaceConfig.class) { + InterfaceConfig config = + configService.getConfig((ConnectPoint) event.subject(), InterfaceConfig.class); + updateInterfaces(config); + } + break; + case CONFIG_REMOVED: + if (event.configClass() == InterfaceConfig.class) { + removeInterface((ConnectPoint) event.subject()); + } + break; + case CONFIG_REGISTERED: + case CONFIG_UNREGISTERED: + default: + break; + } + } + } + + // Configure interfaces if they already exist. + private void initInterfaces() { + Set<Interface> intfs = interfaceService.getInterfaces(); + for (Interface intf : intfs) { + log.debug("Adding interface: " + intf.toString() + "\n"); + addInterface(intf); + } + } + + /** + * Create a PIM Interface and add to our interfaces list. + * + * @param intf the interface to add + * @return the PIMInterface + */ + public PIMInterface addInterface(Interface intf) { + PIMInterface pif = new PIMInterface(intf); + interfaces.put(intf.connectPoint(), pif); + + // If we have added our first interface start the hello timer. + if (interfaces.size() == 1) { + startHelloTimer(); + } + + // Return this interface + return pif; + } + + /** + * Remove the PIMInterface from the given ConnectPoint. + * + * @param cp the ConnectPoint indexing the PIMInterface to be removed. + */ + public void removeInterface(ConnectPoint cp) { + if (interfaces.containsKey(cp)) { + interfaces.remove(cp); + } + + if (interfaces.size() == 0) { + PIMTimer.stop(); + } + } + + /** + * Return a collection of PIMInterfaces for use by the PIM Interface codec. + * + * @return the collection of PIMInterfaces + */ + public Collection<PIMInterface> getInterfaces() { + return interfaces.values(); + } + + /** + * Get the PIM Interface indexed by the given ConnectPoint. + * + * @param cp the connect point + * @return the PIMInterface if it exists, NULL if not + */ + public PIMInterface getInterface(ConnectPoint cp) { + return interfaces.get(cp); + } + + /** + * Return a string of PIMInterfaces for the cli command. + * + * @return a string representing PIM interfaces + */ + public String printInterfaces() { + String str = ""; + for (PIMInterface pi : interfaces.values()) { + str += pi.toString(); + } + return str; + } + + /* ---------------------------------- PIM Hello Timer ----------------------------------- */ + + /** + * Start a new hello timer for this interface. + */ + private void startHelloTimer() { + helloTimer = PIMTimer.getTimer().newTimeout( + new HelloTimer(), + helloMessageInterval, + TimeUnit.SECONDS); + + log.debug("Started Hello Timer"); + } + + /** + * This inner class handles transmitting a PIM hello message on this ConnectPoint. + */ + private final class HelloTimer implements TimerTask { + + HelloTimer() { + } + + @Override + public void run(Timeout timeout) throws Exception { + + log.debug("Running Hello Timer\n"); + // Technically we should not send all hello's in synch.. + for (PIMInterface pi : interfaces.values()) { + pi.sendHello(); + } + + // restart the hello timer + if (interfaces.size() > 0) { + startHelloTimer(); + } + } + } +}
\ No newline at end of file diff --git a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMNeighborsCodec.java b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterfacesCodec.java index ee62eb79..ddd7a597 100644 --- a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMNeighborsCodec.java +++ b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMInterfacesCodec.java @@ -19,16 +19,15 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import org.onosproject.codec.CodecContext; import org.onosproject.codec.JsonCodec; -import org.onosproject.net.ConnectPoint; -import java.util.HashMap; +import java.util.Collection; import static com.google.common.base.Preconditions.checkNotNull; /** * PIM neighbors Codec. */ -public class PIMNeighborsCodec extends JsonCodec<HashMap<ConnectPoint, PIMNeighbors>> { +public class PIMInterfacesCodec extends JsonCodec<Collection<PIMInterface>> { // JSON field names //Return Name private static final String CPNBRLIST = "connect_point_list"; @@ -53,22 +52,22 @@ public class PIMNeighborsCodec extends JsonCodec<HashMap<ConnectPoint, PIMNeighb * @return Encoded neighbors used by CLI and REST */ @Override - public ObjectNode encode(HashMap<ConnectPoint, PIMNeighbors> cpn, CodecContext context) { + public ObjectNode encode(Collection<PIMInterface> cpn, CodecContext context) { checkNotNull(cpn, "Pim Neighbors cannot be null"); ObjectNode pimNbrJsonCodec = context.mapper().createObjectNode(); ArrayNode cpnList = context.mapper().createArrayNode(); - for (PIMNeighbors pn: cpn.values()) { + for (PIMInterface pn: cpn) { // get the PimNeighbors Obj, contains Neighbors list // create the json object for a single Entry in the Neighbors list ObjectNode cp = context.mapper().createObjectNode(); - cp.put(IP, pn.getOurIpAddress().toString()); - cp.put(PRIORITY, String.valueOf(pn.getOurPriority())); + cp.put(IP, pn.getIpAddress().toString()); + cp.put(PRIORITY, String.valueOf(pn.getPriority())); // create the array for the neighbors list ArrayNode nbrsList = context.mapper().createArrayNode(); - for (PIMNeighbor nbr : pn.getOurNeighborsList().values()) { + for (PIMNeighbor nbr : pn.getNeighbors()) { nbrsList.add(neighbor(nbr, context)); } // adds pim neighbor to list diff --git a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMNeighbor.java b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMNeighbor.java index 1a96138f..73d1598a 100644 --- a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMNeighbor.java +++ b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMNeighbor.java @@ -60,22 +60,20 @@ public class PIMNeighbor { // Timeout for this neighbor private volatile Timeout timeout; - private boolean reelect = false; - // A back pointer the neighbors list this neighbor belongs to. - private PIMNeighbors neighbors; + private PIMInterface pimInterface; /** * Construct this neighbor from the address and connect point. * * @param ipaddr IP Address of neighbor * @param macaddr MAC Address of the neighbor - * @param cp The ConnectPoint of this neighbor + * @param pimInterface The PIMInterface of this neighbor */ - public PIMNeighbor(IpAddress ipaddr, MacAddress macaddr, ConnectPoint cp) { + public PIMNeighbor(IpAddress ipaddr, MacAddress macaddr, PIMInterface pimInterface) { this.macAddress = macaddr; this.primaryAddr = ipaddr; - this.connectPoint = cp; + this.pimInterface = pimInterface; this.resetTimeout(); } @@ -174,30 +172,12 @@ public class PIMNeighbor { * * @return the ConnectPoint */ - public ConnectPoint getConnectPoint() { - return connectPoint; - } - - /** - * Set the ConnectPoint this router is connected to. - * - * @param connectPoint the ConnectPoint this router is connected to. - */ - public void setConnectPoint(ConnectPoint connectPoint) { - this.connectPoint = connectPoint; + public PIMInterface getPimInterface() { + return pimInterface; } /** - * Set a back pointer to the neighbors list this neighbor is a member of. - * - * @param neighbors the neighbor list this neighbor belongs to - */ - public void setNeighbors(PIMNeighbors neighbors) { - this.neighbors = neighbors; - } - - /** - * We have received a fresh hello from a neighbor, now we need to process it. + * We have received a fresh hello from this neighbor, now we need to process it. * Depending on the values received in the the hello options may force a * re-election process. * @@ -208,17 +188,19 @@ public class PIMNeighbor { public void refresh(PIMHello hello) { checkNotNull(hello); + boolean reelect = false; for (PIMHelloOption opt : hello.getOptions().values()) { int len = opt.getOptLength(); - byte [] value = new byte[len]; - ByteBuffer bb = ByteBuffer.wrap(value); + ByteBuffer bb = ByteBuffer.wrap(opt.getValue()); switch (opt.getOptType()) { case PIMHelloOption.OPT_GENID: int newid = bb.getInt(); if (this.genId != newid) { - // TODO: we have a newly rebooted neighbor. Send them our joins. + + // We have a newly rebooted neighbor, this is where we would + // send them our joins. this.genId = newid; } break; @@ -228,7 +210,7 @@ public class PIMNeighbor { if (this.priority != newpri) { // The priorities have changed. We may need to re-elect a new DR? - if (this.isDr || this.neighbors.getDesignatedRouter().getPriority() < priority) { + if (this.isDr || pimInterface.getDesignatedRouter().getPriority() < priority) { reelect = true; } this.priority = newpri; @@ -242,7 +224,6 @@ public class PIMNeighbor { if (holdtime == 0) { // We have a neighbor going down. We can remove all joins // we have learned from them. - // TODO: What else do we need to do when a neighbor goes down? log.debug("PIM Neighbor has timed out: {}", this.primaryAddr.toString()); return; @@ -261,7 +242,7 @@ public class PIMNeighbor { } if (reelect) { - this.neighbors.electDR(this); + pimInterface.electDR(this); } // Reset the next timeout timer @@ -307,9 +288,8 @@ public class PIMNeighbor { @Override public void run(Timeout timeout) throws Exception { - // TODO: log.debug; - PIMNeighbors neighbors = nbr.neighbors; - neighbors.removeNeighbor(nbr.getPrimaryAddr()); + log.debug("PIM Neighbor {} has timed out: ", nbr.toString()); + nbr.pimInterface.removeNeighbor(nbr); } } diff --git a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMNeighbors.java b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMNeighbors.java deleted file mode 100644 index cad90768..00000000 --- a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMNeighbors.java +++ /dev/null @@ -1,395 +0,0 @@ - -package org.onosproject.pim.impl; - -import org.jboss.netty.util.Timeout; -import org.jboss.netty.util.TimerTask; -import org.onlab.packet.Ethernet; -import org.onlab.packet.IPv4; -import org.onlab.packet.Ip4Address; -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onlab.packet.PIM; -import org.onlab.packet.pim.PIMHello; -import org.onosproject.net.ConnectPoint; -import java.util.HashMap; -import java.util.concurrent.TimeUnit; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static com.google.common.base.Preconditions.checkNotNull; - -/** - * PIMNeighbors is a collection of all neighbors we have received - * PIM hello messages from. The main structure is a HashMap indexed - * by ConnectPoint with another HashMap indexed on the PIM neighbors - * IPAddress, it contains all PIM neighbors attached on that ConnectPoint. - */ -public final class PIMNeighbors { - - private static Logger log = LoggerFactory.getLogger("PIMNeighbors"); - - /** - * This is the global container for all PIM neighbors indexed by ConnectPoints. - * - * NOTE: We'll have a problem if the same neighbor can show up on two interfaces - * but that should never happen. - */ - private static HashMap<ConnectPoint, PIMNeighbors> connectPointNeighbors = new HashMap<>(); - - // The connect point these neighbors are connected to. - private ConnectPoint connectPoint; - - // Pointer to the current designated router on this ConnectPoint. - private PIMNeighbor designatedRouter; - - // The list of neighbors we have learned on this ConnectPoint. - private HashMap<IpAddress, PIMNeighbor> neighbors = new HashMap<>(); - - /* - * TODO: turn ourIpAddress, ourPriority and OurHoldTime into config options. - */ - // The IP address we are using to source our PIM hello messages on this connect Point. - private IpAddress ourIpAddress; - - // The priority we use on this ConnectPoint. - private int ourPriority = 1; - - // The holdtime we are sending out. - private int ourHoldtime = 105; - - // Then generation ID we are sending out. 0 means we need to generate a new random ID - private int ourGenid = 0; - - // Hello Timer for sending hello messages per ConnectPoint with neighbors. - private volatile Timeout helloTimer; - - // The period of which we will be sending out PIM hello messages. - private final int defaultPimHelloInterval = 30; // seconds - - /** - * Create PIMNeighbors object per ConnectPoint. - * - * @param cp the ConnectPoint. - * @return PIMNeighbors structure - */ - public static PIMNeighbors getConnectPointNeighbors(ConnectPoint cp) { - return connectPointNeighbors.get(cp); - } - - /** - * Process incoming hello message, we will need the Macaddress and IP address of the sender. - * - * @param ethPkt the ethernet header - * @param receivedFrom the connect point we recieved this message from - */ - public static void processHello(Ethernet ethPkt, ConnectPoint receivedFrom) { - checkNotNull(ethPkt); - checkNotNull(ethPkt); - - MacAddress srcmac = ethPkt.getSourceMAC(); - IPv4 ip = (IPv4) ethPkt.getPayload(); - Ip4Address srcip = Ip4Address.valueOf(ip.getSourceAddress()); - - PIM pim = (PIM) ip.getPayload(); - checkNotNull(pim); - - PIMHello hello = (PIMHello) pim.getPayload(); - checkNotNull(hello); - - PIMNeighbor nbr = PIMNeighbors.findOrCreate(srcip, srcmac, receivedFrom); - if (nbr == null) { - log.error("Could not create a neighbor for: {1}", srcip.toString()); - return; - } - - nbr.setConnectPoint(receivedFrom); - nbr.refresh(hello); - } - - /** - * Create a PIM Neighbor. - * - * @param cp The ConnectPoint this neighbor was found on - */ - public PIMNeighbors(ConnectPoint cp) { - this.connectPoint = cp; - - // TODO: use network config to assign address. - this.ourIpAddress = IpAddress.valueOf("10.2.2.2"); - this.addIpAddress(this.ourIpAddress); - } - - /** - * Create a PIM neighbor. - * - * @param cp the ConnectPoint this neighbor was found on - * @param ourIp the IP address of this neighbor - */ - public PIMNeighbors(ConnectPoint cp, IpAddress ourIp) { - this.connectPoint = cp; - this.addIpAddress(ourIp); - } - - /** - * Start the hello timer when we have been given an IP address. - * - * @param ourIp our IP address. - */ - public void addIpAddress(IpAddress ourIp) { - this.startHelloTimer(); - - // Kick off the first pim hello packet - this.sendHelloPacket(); - } - - /** - * Getter for our IP address. - * - * @return our IP address. - */ - public IpAddress getOurIpAddress() { - return this.ourIpAddress; - } - - /** - * Get our priority. - * - * @return our priority. - */ - public int getOurPriority() { - return this.ourPriority; - } - - /** - * Get the neighbor list for this specific connectPoint. - * - * @return PIM neighbors on this ConnectPoint - */ - public HashMap<IpAddress, PIMNeighbor> getOurNeighborsList() { - return this.neighbors; - } - - /** - * Get the designated router on this connection. - * - * @return the PIMNeighbor representing the DR - */ - public PIMNeighbor getDesignatedRouter() { - return designatedRouter; - } - - /** - * Are we the DR on this CP? - * - * @return true if we are, false if not - */ - public boolean weAreTheDr() { - return (designatedRouter != null && - designatedRouter.getPrimaryAddr().equals(ourIpAddress)); - } - - /** - * Find the neighbor with the given IP address on this CP. - * - * @param ipaddr the IP address of the neighbor we are interested in - * @return the pim neighbor if it exists - */ - public PIMNeighbor findNeighbor(IpAddress ipaddr) { - PIMNeighbor nbr = neighbors.get(ipaddr); - return nbr; - } - - /** - * Add a new PIM neighbor to this list. - * - * @param nbr the neighbor to be added. - */ - public void addNeighbor(PIMNeighbor nbr) { - if (neighbors.containsKey(nbr.getPrimaryAddr())) { - - // TODO: Hmmm, how should this be handled? - log.debug("We are adding a neighbor that already exists: {}", nbr.toString()); - neighbors.remove(nbr.getPrimaryAddr(), nbr); - } - nbr.setNeighbors(this); - neighbors.put(nbr.getPrimaryAddr(), nbr); - } - - /** - * Remove the neighbor from our neighbor list. - * - * @param ipaddr the IP address of the neighbor to remove - */ - public void removeNeighbor(IpAddress ipaddr) { - - boolean reelect = (designatedRouter == null || designatedRouter.getPrimaryAddr().equals(ipaddr)); - if (neighbors.containsKey(ipaddr)) { - neighbors.remove(ipaddr); - } - this.electDR(); - } - - /** - * Remove the given neighbor from the neighbor list. - * - * @param nbr the nbr to be removed. - */ - public void removeNeighbor(PIMNeighbor nbr) { - - boolean reelect = (designatedRouter == null || nbr.isDr()); - neighbors.remove(nbr.getPrimaryAddr(), nbr); - this.electDR(); - } - - /** - * Elect a new DR on this ConnectPoint. - * - * @return the PIM Neighbor that wins - */ - public PIMNeighbor electDR() { - - for (PIMNeighbor nbr : this.neighbors.values()) { - if (this.designatedRouter == null) { - this.designatedRouter = nbr; - continue; - } - - if (nbr.getPriority() > this.designatedRouter.getPriority()) { - this.designatedRouter = nbr; - continue; - } - - // We could sort in ascending order - if (this.designatedRouter.getPrimaryAddr().compareTo(nbr.getPrimaryAddr()) > 0) { - this.designatedRouter = nbr; - continue; - } - } - - return this.designatedRouter; - } - - /** - * Elect a new DR given the new neighbor. - * - * @param nbr the new neighbor to use in DR election. - * @return the PIM Neighbor that wins DR election - */ - public PIMNeighbor electDR(PIMNeighbor nbr) { - - // Make sure I have - if (this.designatedRouter == null || - this.designatedRouter.getPriority() < nbr.getPriority() || - this.designatedRouter.getPrimaryAddr().compareTo(nbr.getPrimaryAddr()) > 0) { - this.designatedRouter = nbr; - } - return this.designatedRouter; - } - - /** - * Find or create a pim neighbor with a given ip address and connect point. - * - * @param ipaddr of the pim neighbor - * @param mac The mac address of our sending neighbor - * @param cp the connect point the neighbor was learned from - * @return an existing or new PIM neighbor - */ - public static PIMNeighbor findOrCreate(IpAddress ipaddr, MacAddress mac, ConnectPoint cp) { - PIMNeighbors neighbors = connectPointNeighbors.get(cp); - if (neighbors == null) { - neighbors = new PIMNeighbors(cp); - connectPointNeighbors.put(cp, neighbors); - } - - PIMNeighbor nbr = neighbors.findNeighbor(ipaddr); - if (nbr == null) { - nbr = new PIMNeighbor(ipaddr, mac, cp); - neighbors.addNeighbor(nbr); - neighbors.electDR(nbr); - } - return nbr; - } - - // Returns the connect point neighbors hash map - public static HashMap<ConnectPoint, PIMNeighbors> getConnectPointNeighbors() { - return connectPointNeighbors; - } - - /* ---------------------------------- PIM Hello Timer ----------------------------------- */ - - /** - * Start a new hello timer for this ConnectPoint. - */ - private void startHelloTimer() { - this.helloTimer = PIMTimer.getTimer().newTimeout( - new HelloTimer(this), - this.defaultPimHelloInterval, - TimeUnit.SECONDS); - - log.trace("Started Hello Timer: " + this.ourIpAddress.toString()); - } - - /** - * This inner class handles transmitting a PIM hello message on this ConnectPoint. - */ - private final class HelloTimer implements TimerTask { - PIMNeighbors neighbors; - - HelloTimer(PIMNeighbors neighbors) { - this.neighbors = neighbors; - } - - @Override - public void run(Timeout timeout) throws Exception { - - // Send off a hello packet - sendHelloPacket(); - - // restart the hello timer - neighbors.startHelloTimer(); - } - } - - private void sendHelloPacket() { - PIMHello hello = new PIMHello(); - - // TODO: we will need to implement the network config service to assign ip addresses & options - /* - hello.createDefaultOptions(); - - Ethernet eth = hello.createPIMHello(this.ourIpAddress); - hello.sendPacket(this.connectPoint); - */ - } - - /** - * prints the connectPointNeighbors list with each neighbor list. - * - * @return string of neighbors. - */ - public static String printPimNeighbors() { - String out = "PIM Neighbors Table: \n"; - - for (PIMNeighbors pn: connectPointNeighbors.values()) { - - out += "CP:\n " + pn.toString(); - for (PIMNeighbor nbr : pn.neighbors.values()) { - out += "\t" + nbr.toString(); - } - } - return out; - } - - @Override - public String toString() { - String out = "PIM Neighbors: "; - if (this.ourIpAddress != null) { - out += "IP: " + this.ourIpAddress.toString(); - } else { - out += "IP: *Null*"; - } - out += "\tPR: " + String.valueOf(this.ourPriority) + "\n"; - return out; - } -}
\ No newline at end of file diff --git a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMPacketHandler.java b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMPacketHandler.java new file mode 100644 index 00000000..c1ad2cfe --- /dev/null +++ b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMPacketHandler.java @@ -0,0 +1,229 @@ +/* + * 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.pim.impl; + +import org.onlab.packet.Ethernet; +import org.onlab.packet.IPv4; +import org.onlab.packet.Ip4Address; +import org.onlab.packet.IpAddress; +import org.onlab.packet.IpPrefix; +import org.onlab.packet.MacAddress; +import org.onlab.packet.PIM; +import org.onlab.packet.VlanId; +import org.onosproject.core.ApplicationId; +import org.onosproject.incubator.net.intf.Interface; +import org.onosproject.net.ConnectPoint; +import org.onosproject.net.flow.DefaultTrafficSelector; +import org.onosproject.net.flow.DefaultTrafficTreatment; +import org.onosproject.net.flow.TrafficSelector; +import org.onosproject.net.flow.TrafficTreatment; +import org.onosproject.net.packet.DefaultOutboundPacket; +import org.onosproject.net.packet.InboundPacket; +import org.onosproject.net.packet.OutboundPacket; +import org.onosproject.net.packet.PacketContext; +import org.onosproject.net.packet.PacketPriority; +import org.onosproject.net.packet.PacketProcessor; +import org.onosproject.net.packet.PacketService; +import org.slf4j.Logger; + +import java.nio.ByteBuffer; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + +/** + * Handing Incoming and outgoing PIM packets. + */ +public final class PIMPacketHandler { + private final Logger log = getLogger(getClass()); + + private static PIMPacketHandler instance = null; + + private PacketService packetService; + private PIMPacketProcessor processor = new PIMPacketProcessor(); + private MacAddress pimDestinationMac = MacAddress.valueOf("01:00:5E:00:00:0d"); + + // Utility class + private PIMPacketHandler() {} + + public static PIMPacketHandler getInstance() { + if (null == instance) { + instance = new PIMPacketHandler(); + } + return instance; + } + + /** + * Initialize the packet handling service. + * + * @param ps the packetService + * @param appId our application ID + */ + public void initialize(PacketService ps, ApplicationId appId) { + packetService = ps; + + // Build a traffic selector for all multicast traffic + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); + selector.matchEthType(Ethernet.TYPE_IPV4); + selector.matchIPProtocol(IPv4.PROTOCOL_PIM); + packetService.requestPackets(selector.build(), PacketPriority.REACTIVE, appId); + + packetService.addProcessor(processor, PacketProcessor.director(1)); + } + + /** + * Shutdown the packet handling service. + */ + public void stop() { + packetService.removeProcessor(processor); + processor = null; + } + + /** + * Packet processor responsible for handling IGMP packets. + */ + public class PIMPacketProcessor implements PacketProcessor { + private final Logger log = getLogger(getClass()); + + @Override + public void process(PacketContext context) { + // Stop processing if the packet has been handled, since we + // can't do any more to it. + if (context.isHandled()) { + return; + } + + InboundPacket pkt = context.inPacket(); + if (pkt == null) { + return; + } + + Ethernet ethPkt = pkt.parsed(); + if (ethPkt == null) { + return; + } + + /* + * IPv6 MLD packets are handled by ICMP6. We'll only deal + * with IPv4. + */ + if (ethPkt.getEtherType() != Ethernet.TYPE_IPV4) { + return; + } + + IPv4 ip = (IPv4) ethPkt.getPayload(); + IpAddress gaddr = IpAddress.valueOf(ip.getDestinationAddress()); + IpAddress saddr = Ip4Address.valueOf(ip.getSourceAddress()); + log.debug("Packet (" + saddr.toString() + ", " + gaddr.toString() + + "\tingress port: " + context.inPacket().receivedFrom().toString()); + + if (ip.getProtocol() != IPv4.PROTOCOL_PIM) { + log.debug("PIM Picked up a non PIM packet: IP protocol: " + ip.getProtocol()); + return; + } + + // TODO: check incoming to be PIM.PIM_ADDRESS or "Our" address. + IpPrefix spfx = IpPrefix.valueOf(saddr, 32); + IpPrefix gpfx = IpPrefix.valueOf(gaddr, 32); + + PIM pim = (PIM) ip.getPayload(); + switch (pim.getPimMsgType()) { + + case PIM.TYPE_HELLO: + processHello(ethPkt, context.inPacket().receivedFrom()); + break; + + case PIM.TYPE_JOIN_PRUNE_REQUEST: + // Create the function + break; + + case PIM.TYPE_ASSERT: + case PIM.TYPE_BOOTSTRAP: + case PIM.TYPE_CANDIDATE_RP_ADV: + case PIM.TYPE_GRAFT: + case PIM.TYPE_GRAFT_ACK: + case PIM.TYPE_REGISTER: + case PIM.TYPE_REGISTER_STOP: + log.debug("Unsupported PIM message type: " + pim.getPimMsgType()); + break; + + default: + log.debug("Unkown PIM message type: " + pim.getPimMsgType()); + break; + } + } + + /** + * Process incoming hello message, we will need the Macaddress and IP address of the sender. + * + * @param ethPkt the ethernet header + * @param receivedFrom the connect point we recieved this message from + */ + private void processHello(Ethernet ethPkt, ConnectPoint receivedFrom) { + checkNotNull(ethPkt); + checkNotNull(receivedFrom); + + // It is a problem if we don't have the + PIMInterfaces pintfs = PIMInterfaces.getInstance(); + PIMInterface intf = pintfs.getInterface(receivedFrom); + if (intf == null) { + log.error("We received a PIM message on an interface we were not supposed to"); + return; + } + intf.processHello(ethPkt, receivedFrom); + } + } + + // Create an ethernet header and serialize then send + public void sendPacket(PIM pim, PIMInterface pimIntf) { + + Interface theInterface = pimIntf.getInterface(); + + // Create the ethernet packet + Ethernet eth = new Ethernet(); + eth.setDestinationMACAddress(pimDestinationMac); + eth.setSourceMACAddress(theInterface.mac()); + eth.setEtherType(Ethernet.TYPE_IPV4); + if (theInterface.vlan() != VlanId.NONE) { + eth.setVlanID(theInterface.vlan().toShort()); + } + + // Create the IP Packet + IPv4 ip = new IPv4(); + ip.setVersion((byte) 4); + ip.setTtl((byte) 20); + ip.setProtocol(IPv4.PROTOCOL_PIM); + ip.setChecksum((short) 0); + ip.setSourceAddress(checkNotNull(pimIntf.getIpAddress()).getIp4Address().toInt()); + ip.setDestinationAddress(PIM.PIM_ADDRESS.getIp4Address().toInt()); + eth.setPayload(ip); + ip.setParent(eth); + + // Now set pim + ip.setPayload(pim); + pim.setParent(ip); + + ConnectPoint cp = theInterface.connectPoint(); + checkNotNull(cp); + + TrafficTreatment treat = DefaultTrafficTreatment.builder().setOutput(cp.port()).build(); + ByteBuffer bb = ByteBuffer.wrap(eth.serialize()); + OutboundPacket packet = new DefaultOutboundPacket(cp.deviceId(), treat, bb); + checkNotNull(packet); + + packetService.emit(packet); + } +} diff --git a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMTimer.java b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMTimer.java index c131a53b..c2a33033 100644 --- a/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMTimer.java +++ b/framework/src/onos/apps/pim/src/main/java/org/onosproject/pim/impl/PIMTimer.java @@ -17,6 +17,8 @@ package org.onosproject.pim.impl; import org.jboss.netty.util.HashedWheelTimer; +import static com.google.common.base.Preconditions.checkNotNull; + /** * PIM Timer used for PIM Neighbors. */ @@ -50,4 +52,21 @@ public final class PIMTimer { PIMTimer.timer = hwTimer; } } + + public static void start() { + if (PIMTimer.timer == null) { + getTimer(); + } + checkNotNull(timer); + timer.start(); + } + + public static void stop() { + if (PIMTimer.timer == null) { + // No need to stop + return; + } + checkNotNull(timer); + timer.stop(); + } } diff --git a/framework/src/onos/apps/routing-api/pom.xml b/framework/src/onos/apps/routing-api/pom.xml index 48fc2920..4c2d7d37 100644 --- a/framework/src/onos/apps/routing-api/pom.xml +++ b/framework/src/onos/apps/routing-api/pom.xml @@ -53,6 +53,21 @@ <dependency> <groupId>org.onosproject</groupId> + <artifactId>onos-cli</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-api</artifactId> + <version>${project.version}</version> + <scope>test</scope> + <classifier>tests</classifier> + </dependency> + + <dependency> + <groupId>org.onosproject</groupId> <artifactId>onlab-junit</artifactId> <scope>test</scope> </dependency> diff --git a/framework/src/onos/apps/routing-api/src/main/java/org/onosproject/routing/config/BgpConfig.java b/framework/src/onos/apps/routing-api/src/main/java/org/onosproject/routing/config/BgpConfig.java index 2f1ede79..6085c60a 100644 --- a/framework/src/onos/apps/routing-api/src/main/java/org/onosproject/routing/config/BgpConfig.java +++ b/framework/src/onos/apps/routing-api/src/main/java/org/onosproject/routing/config/BgpConfig.java @@ -17,12 +17,16 @@ package org.onosproject.routing.config; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.collect.Sets; import org.onlab.packet.IpAddress; import org.onosproject.core.ApplicationId; import org.onosproject.net.ConnectPoint; import org.onosproject.net.config.Config; +import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -49,6 +53,11 @@ public class BgpConfig extends Config<ApplicationId> { Set<BgpSpeakerConfig> speakers = Sets.newHashSet(); JsonNode speakersNode = object.get(SPEAKERS); + + if (speakersNode == null) { + return speakers; + } + speakersNode.forEach(jsonNode -> { Set<IpAddress> listenAddresses = Sets.newHashSet(); jsonNode.path(PEERS).forEach(addressNode -> @@ -71,6 +80,130 @@ public class BgpConfig extends Config<ApplicationId> { } /** + * Examines whether a name of BGP speaker exists in configuration. + * + * @param name name of BGP speaker being search + * @return speaker + */ + public BgpSpeakerConfig getSpeakerWithName(String name) { + for (BgpConfig.BgpSpeakerConfig speaker : bgpSpeakers()) { + if (speaker.name().isPresent() && speaker.name().get().equals(name)) { + return speaker; + } + } + return null; + } + + /** + * Adds BGP speaker to configuration. + * + * @param speaker BGP speaker configuration entry + */ + public void addSpeaker(BgpSpeakerConfig speaker) { + ObjectNode speakerNode = JsonNodeFactory.instance.objectNode(); + + speakerNode.put(NAME, speaker.name().get()); + + speakerNode.put(CONNECT_POINT, speaker.connectPoint().elementId().toString() + + "/" + speaker.connectPoint().port().toString()); + + ArrayNode peersNode = speakerNode.putArray(PEERS); + for (IpAddress peerAddress: speaker.peers()) { + peersNode.add(peerAddress.toString()); + } + + ArrayNode speakersArray = bgpSpeakers().isEmpty() ? + initBgpConfiguration() : (ArrayNode) object.get(SPEAKERS); + speakersArray.add(speakerNode); + } + + /** + * Removes BGP speaker from configuration. + * + * @param speakerName BGP speaker name + */ + public void removeSpeaker(String speakerName) { + ArrayNode speakersArray = (ArrayNode) object.get(SPEAKERS); + + for (int i = 0; i < speakersArray.size(); i++) { + if (speakersArray.get(i).hasNonNull(NAME) && + speakersArray.get(i).get(NAME).asText().equals(speakerName)) { + speakersArray.remove(i); + return; + } + } + } + + /** + * Adds peering address to BGP speaker. + * + * @param speakerName name of BGP speaker + * @param peerAddress peering address to be added + */ + public void addPeerToSpeaker(String speakerName, IpAddress peerAddress) { + JsonNode speakersNode = object.get(SPEAKERS); + speakersNode.forEach(jsonNode -> { + if (jsonNode.hasNonNull(NAME) && + jsonNode.get(NAME).asText().equals(speakerName)) { + ArrayNode peersNode = (ArrayNode) jsonNode.get(PEERS); + for (int i = 0; i < peersNode.size(); i++) { + if (peersNode.get(i).asText().equals(peerAddress.toString())) { + return; // Peer already exists. + } + } + peersNode.add(peerAddress.toString()); + } + }); + } + + /** + * Finds BGP speaker peering with a given external peer. + * + * @param peerAddress peering address to be removed + * @return speaker + */ + public BgpSpeakerConfig getSpeakerFromPeer(IpAddress peerAddress) { + for (BgpConfig.BgpSpeakerConfig speaker : bgpSpeakers()) { + if (speaker.peers().contains(peerAddress)) { + return speaker; + } + } + return null; + } + + /** + * Removes peering address from BGP speaker. + * + * @param speaker BGP speaker configuration entries + * @param peerAddress peering address to be removed + */ + public void removePeerFromSpeaker(BgpSpeakerConfig speaker, IpAddress peerAddress) { + JsonNode speakersNode = object.get(SPEAKERS); + speakersNode.forEach(jsonNode -> { + if (jsonNode.hasNonNull(NAME) && + jsonNode.get(NAME).asText().equals(speaker.name().get())) { + ArrayNode peersNode = (ArrayNode) jsonNode.get(PEERS); + for (int i = 0; i < peersNode.size(); i++) { + if (peersNode.get(i).asText().equals(peerAddress.toString())) { + peersNode.remove(i); + return; + } + } + } + }); + } + + /** + * Creates empty configuration for BGP speakers. + * + * @return empty array of BGP speakers + */ + private ArrayNode initBgpConfiguration() { + return object.putArray(SPEAKERS); + } + + + /** * Configuration for a BGP speaker. */ public static class BgpSpeakerConfig { @@ -97,5 +230,39 @@ public class BgpConfig extends Config<ApplicationId> { public Set<IpAddress> peers() { return peers; } + + /** + * Examines if BGP peer is connected. + * + * @param peer IP address of peer + * @return result of search + */ + public boolean isConnectedToPeer(IpAddress peer) { + for (final IpAddress entry : peers()) { + if (entry.equals(peer)) { + return true; + } + } + return false; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof BgpSpeakerConfig) { + final BgpSpeakerConfig that = (BgpSpeakerConfig) obj; + return Objects.equals(this.name, that.name) && + Objects.equals(this.connectPoint, that.connectPoint) && + Objects.equals(this.peers, that.peers); + } + return false; + } + + @Override + public int hashCode() { + return Objects.hash(name, connectPoint, peers); + } } } diff --git a/framework/src/onos/apps/routing-api/src/test/java/org/onosproject/routing/config/BgpConfigTest.java b/framework/src/onos/apps/routing-api/src/test/java/org/onosproject/routing/config/BgpConfigTest.java new file mode 100644 index 00000000..28f52b79 --- /dev/null +++ b/framework/src/onos/apps/routing-api/src/test/java/org/onosproject/routing/config/BgpConfigTest.java @@ -0,0 +1,244 @@ +/* + * 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.routing.config; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.Before; +import org.junit.Test; +import org.onlab.packet.IpAddress; +import org.onosproject.TestApplicationId; +import org.onosproject.core.ApplicationId; +import org.onosproject.net.ConnectPoint; +import org.onosproject.net.config.Config; +import org.onosproject.net.config.ConfigApplyDelegate; +import org.onosproject.routing.RoutingService; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Optional; +import java.util.Set; + +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertNull; +import static junit.framework.TestCase.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class BgpConfigTest { + + private static final ApplicationId APP_ID = + new TestApplicationId(RoutingService.ROUTER_APP_ID); + + private static final IpAddress IP1 = IpAddress.valueOf("10.0.1.1"); + private static final IpAddress IP2 = IpAddress.valueOf("10.0.2.1"); + private static final IpAddress IP3 = IpAddress.valueOf("10.0.3.1"); + private static final IpAddress IP4 = IpAddress.valueOf("10.0.101.1"); + private static final IpAddress IP5 = IpAddress.valueOf("10.0.201.1"); + public static final IpAddress IP_NON_EXIST = IpAddress.valueOf("10.101.1.1"); + + public static final ConnectPoint CONNECT_POINT1 = ConnectPoint. + deviceConnectPoint("of:0000000000000001/1"); + public static final ConnectPoint CONNECT_POINT2 = ConnectPoint. + deviceConnectPoint("of:00000000000000a3/1"); + + private static final String JSON_TREE = "{\"" + BgpConfig.SPEAKERS + + "\" : [{\"" + BgpConfig.NAME + "\" : \"bgp1\"," + + "\"" + BgpConfig.CONNECT_POINT + + "\" : \"of:0000000000000001/1\"," + + "\"" + BgpConfig.PEERS + "\" : [" + + "\"10.0.1.1\",\"10.0.2.1\",\"10.0.3.1\"]}]}"; + private static final String EMPTY_JSON_TREE = "{}"; + + private final ObjectMapper mapper = new ObjectMapper(); + private final ConfigApplyDelegate delegate = new MockCfgDelegate(); + private final BgpConfig.BgpSpeakerConfig initialSpeaker = createInitialSpeaker(); + + private Set<BgpConfig.BgpSpeakerConfig> speakers = new HashSet<>(); + private BgpConfig bgpConfig = new BgpConfig(); + private BgpConfig emptyBgpConfig = new BgpConfig(); + + @Before + public void setUp() throws Exception { + JsonNode tree = new ObjectMapper().readTree(JSON_TREE); + bgpConfig.init(APP_ID, "bgp-test", tree, mapper, delegate); + JsonNode emptyTree = new ObjectMapper().readTree(EMPTY_JSON_TREE); + emptyBgpConfig.init(APP_ID, "bgp-test", emptyTree, mapper, delegate); + speakers.add(initialSpeaker); + } + + /** + * Tests if speakers can be retrieved from JSON. + */ + @Test + public void testBgpSpeakers() throws Exception { + assertEquals(speakers, bgpConfig.bgpSpeakers()); + } + + /** + * Tests if speakers can be retrieved from empty JSON. + */ + @Test + public void testEmptyBgpSpeakers() throws Exception { + assertTrue(emptyBgpConfig.bgpSpeakers().isEmpty()); + } + + /** + * Tests if speaker can be found by name. + */ + @Test + public void testGetSpeakerWithName() throws Exception { + assertNotNull(bgpConfig.getSpeakerWithName("bgp1")); + assertNull(bgpConfig.getSpeakerWithName("bgp2")); + } + + /** + * Tests addition of new speaker. + */ + @Test + public void testAddSpeaker() throws Exception { + int initialSize = bgpConfig.bgpSpeakers().size(); + BgpConfig.BgpSpeakerConfig newSpeaker = createNewSpeaker(); + bgpConfig.addSpeaker(newSpeaker); + assertEquals(initialSize + 1, bgpConfig.bgpSpeakers().size()); + speakers.add(newSpeaker); + assertEquals(speakers, bgpConfig.bgpSpeakers()); + } + + /** + * Tests addition of new speaker to empty configuration. + */ + @Test + public void testAddSpeakerToEmpty() throws Exception { + BgpConfig.BgpSpeakerConfig newSpeaker = createNewSpeaker(); + emptyBgpConfig.addSpeaker(newSpeaker); + + assertFalse(emptyBgpConfig.bgpSpeakers().isEmpty()); + } + + /** + * Tests removal of existing speaker. + */ + @Test + public void testRemoveExistingSpeaker() throws Exception { + int initialSize = bgpConfig.bgpSpeakers().size(); + bgpConfig.removeSpeaker("bgp1"); + + assertEquals(initialSize - 1, bgpConfig.bgpSpeakers().size()); + } + + /** + * Tests removal of non-existing speaker. + */ + @Test + public void testRemoveInexistingSpeaker() throws Exception { + int initialSize = bgpConfig.bgpSpeakers().size(); + bgpConfig.removeSpeaker("bgp2"); + + assertEquals(initialSize, bgpConfig.bgpSpeakers().size()); + } + + /** + * Tests addition of new speaker. + */ + @Test + public void testAddPeerToSpeaker() throws Exception { + int initialSize = bgpConfig.getSpeakerWithName("bgp1").peers().size(); + bgpConfig.addPeerToSpeaker("bgp1", IP4); + + assertEquals(initialSize + 1, bgpConfig.getSpeakerWithName("bgp1").peers().size()); + } + + /** + * Tests addition of new speaker when peer already exists. + */ + @Test + public void testAddExistingPeerToSpeaker() throws Exception { + int initialSize = bgpConfig.getSpeakerWithName("bgp1").peers().size(); + bgpConfig.addPeerToSpeaker("bgp1", IP1); + + assertEquals(initialSize, bgpConfig.getSpeakerWithName("bgp1").peers().size()); + } + + /** + * Tests retrieval of speaker based on peering address. + */ + @Test + public void testGetSpeakerFromPeer() throws Exception { + assertNotNull(bgpConfig.getSpeakerFromPeer(IP1)); + assertNull(bgpConfig.getSpeakerFromPeer(IP_NON_EXIST)); + } + + /** + * Tests removal of peer. + */ + @Test + public void testRemoveExistingPeerFromSpeaker() throws Exception { + int initialSize = bgpConfig.getSpeakerWithName("bgp1").peers().size(); + bgpConfig.removePeerFromSpeaker(initialSpeaker, IP1); + + assertEquals(initialSize - 1, bgpConfig.getSpeakerWithName("bgp1").peers().size()); + } + + /** + * Tests peer removal when peer does not exist. + */ + @Test + public void testRemoveNonExistingPeerFromSpeaker() throws Exception { + int initialSize = bgpConfig.getSpeakerWithName("bgp1").peers().size(); + bgpConfig.removePeerFromSpeaker(initialSpeaker, IP_NON_EXIST); + + assertEquals(initialSize, bgpConfig.getSpeakerWithName("bgp1").peers().size()); + } + + /** + * Tests if connections to peers are found. + */ + @Test + public void testIsConnectedToPeer() { + BgpConfig.BgpSpeakerConfig speaker = createNewSpeaker(); + + assertTrue(speaker.isConnectedToPeer(IP4)); + assertFalse(speaker.isConnectedToPeer(IP_NON_EXIST)); + } + + private class MockCfgDelegate implements ConfigApplyDelegate { + + @Override + public void onApply(@SuppressWarnings("rawtypes") Config config) { + config.apply(); + } + + } + + private BgpConfig.BgpSpeakerConfig createInitialSpeaker() { + Optional<String> speakerName = Optional.of("bgp1"); + ConnectPoint connectPoint = CONNECT_POINT1; + Set<IpAddress> connectedPeers = new HashSet<>(Arrays.asList(IP1, IP2, IP3)); + + return new BgpConfig.BgpSpeakerConfig(speakerName, connectPoint, connectedPeers); + } + + private BgpConfig.BgpSpeakerConfig createNewSpeaker() { + Optional<String> speakerName = Optional.of("newSpeaker"); + ConnectPoint connectPoint = CONNECT_POINT2; + Set<IpAddress> connectedPeers = new HashSet<>( + Arrays.asList(IP4, IP5)); + + return new BgpConfig.BgpSpeakerConfig(speakerName, connectPoint, connectedPeers); + } +} diff --git a/framework/src/onos/apps/routing/pom.xml b/framework/src/onos/apps/routing/pom.xml index c461ef3f..2882f52e 100644 --- a/framework/src/onos/apps/routing/pom.xml +++ b/framework/src/onos/apps/routing/pom.xml @@ -43,7 +43,7 @@ <version>${project.version}</version> </dependency> - <dependency> + <dependency> <groupId>org.onosproject</groupId> <artifactId>onlab-thirdparty</artifactId> </dependency> diff --git a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpOpen.java b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpOpen.java index 5b5a259e..1ccb6b6b 100644 --- a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpOpen.java +++ b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpOpen.java @@ -309,94 +309,104 @@ final class BgpOpen { case BgpConstants.Open.Capabilities.TYPE: // Optional Parameter Type: Capabilities if (paramLen < BgpConstants.Open.Capabilities.MIN_LENGTH) { - // ERROR: Malformed Capability - String errorMsg = "Malformed Capability Type " + paramType; + // ERROR: Malformed Param Type + String errorMsg = "Malformed Capabilities Optional " + + "Parameter Type " + paramType; throw new BgpMessage.BgpParseException(errorMsg); } - int capabEnd = message.readerIndex() + paramLen; - int capabCode = message.readUnsignedByte(); - int capabLen = message.readUnsignedByte(); - if (message.readerIndex() + capabLen > capabEnd) { - // ERROR: Malformed Capability - String errorMsg = "Malformed Capability Type " + paramType; - throw new BgpMessage.BgpParseException(errorMsg); - } - - switch (capabCode) { - case BgpConstants.Open.Capabilities.MultiprotocolExtensions.CODE: - // Multiprotocol Extensions Capabilities (RFC 4760) - if (capabLen != BgpConstants.Open.Capabilities.MultiprotocolExtensions.LENGTH) { - // ERROR: Multiprotocol Extension Length Error - String errorMsg = "Multiprotocol Extension Length Error"; + int paramEnd = message.readerIndex() + paramLen; + // Parse Capabilities + while (message.readerIndex() < paramEnd) { + if (paramEnd - message.readerIndex() < + BgpConstants.Open.Capabilities.MIN_LENGTH) { + String errorMsg = "Malformed Capabilities"; throw new BgpMessage.BgpParseException(errorMsg); } - // Decode the AFI (2 octets) and SAFI (1 octet) - int afi = message.readUnsignedShort(); - int reserved = message.readUnsignedByte(); - int safi = message.readUnsignedByte(); - log.debug("BGP RX OPEN Capability: AFI = {} SAFI = {}", - afi, safi); - // - // Setup the AFI/SAFI in the BgpSession - // - // NOTE: For now we just copy the remote AFI/SAFI setting - // to the local configuration. - // - if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4 && - safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST) { - bgpSession.remoteInfo().setIpv4Unicast(); - bgpSession.localInfo().setIpv4Unicast(); - } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4 && - safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_MULTICAST) { - bgpSession.remoteInfo().setIpv4Multicast(); - bgpSession.localInfo().setIpv4Multicast(); - } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6 && - safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST) { - bgpSession.remoteInfo().setIpv6Unicast(); - bgpSession.localInfo().setIpv6Unicast(); - } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6 && - safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_MULTICAST) { - bgpSession.remoteInfo().setIpv6Multicast(); - bgpSession.localInfo().setIpv6Multicast(); - } else { - log.debug("BGP RX OPEN Capability: Unknown AFI = {} SAFI = {}", - afi, safi); + int capabCode = message.readUnsignedByte(); + int capabLen = message.readUnsignedByte(); + if (message.readerIndex() + capabLen > paramEnd) { + // ERROR: Malformed Capability + String errorMsg = "Malformed Capability instance with " + + "code " + capabCode; + throw new BgpMessage.BgpParseException(errorMsg); } - break; - case BgpConstants.Open.Capabilities.As4Octet.CODE: - // Support for 4-octet AS Number Capabilities (RFC 6793) - if (capabLen != BgpConstants.Open.Capabilities.As4Octet.LENGTH) { - // ERROR: 4-octet AS Number Capability Length Error - String errorMsg = "4-octet AS Number Capability Length Error"; - throw new BgpMessage.BgpParseException(errorMsg); + switch (capabCode) { + case BgpConstants.Open.Capabilities.MultiprotocolExtensions.CODE: + // Multiprotocol Extensions Capabilities (RFC 4760) + if (capabLen != BgpConstants.Open.Capabilities.MultiprotocolExtensions.LENGTH) { + // ERROR: Multiprotocol Extension Length Error + String errorMsg = "Multiprotocol Extension Length Error"; + throw new BgpMessage.BgpParseException(errorMsg); + } + // Decode the AFI (2 octets) and SAFI (1 octet) + int afi = message.readUnsignedShort(); + int reserved = message.readUnsignedByte(); + int safi = message.readUnsignedByte(); + log.debug("BGP RX OPEN Capability: AFI = {} SAFI = {}", + afi, safi); + // + // Setup the AFI/SAFI in the BgpSession + // + // NOTE: For now we just copy the remote AFI/SAFI setting + // to the local configuration. + // + if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4 && + safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST) { + bgpSession.remoteInfo().setIpv4Unicast(); + bgpSession.localInfo().setIpv4Unicast(); + } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV4 && + safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_MULTICAST) { + bgpSession.remoteInfo().setIpv4Multicast(); + bgpSession.localInfo().setIpv4Multicast(); + } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6 && + safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_UNICAST) { + bgpSession.remoteInfo().setIpv6Unicast(); + bgpSession.localInfo().setIpv6Unicast(); + } else if (afi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.AFI_IPV6 && + safi == BgpConstants.Open.Capabilities.MultiprotocolExtensions.SAFI_MULTICAST) { + bgpSession.remoteInfo().setIpv6Multicast(); + bgpSession.localInfo().setIpv6Multicast(); + } else { + log.debug("BGP RX OPEN Capability: Unknown AFI = {} SAFI = {}", + afi, safi); + } + break; + + case BgpConstants.Open.Capabilities.As4Octet.CODE: + // Support for 4-octet AS Number Capabilities (RFC 6793) + if (capabLen != BgpConstants.Open.Capabilities.As4Octet.LENGTH) { + // ERROR: 4-octet AS Number Capability Length Error + String errorMsg = "4-octet AS Number Capability Length Error"; + throw new BgpMessage.BgpParseException(errorMsg); + } + long as4Number = message.readUnsignedInt(); + + bgpSession.remoteInfo().setAs4OctetCapability(); + bgpSession.remoteInfo().setAs4Number(as4Number); + + // + // Copy remote 4-octet AS Number Capabilities and AS + // Number. This is a temporary setting until local AS + // number configuration is supported. + // + bgpSession.localInfo().setAs4OctetCapability(); + bgpSession.localInfo().setAs4Number(as4Number); + log.debug("BGP RX OPEN Capability: AS4 Number = {}", + as4Number); + break; + + default: + // Unknown Capability: ignore it + log.debug("BGP RX OPEN Capability Code = {} Length = {}", + capabCode, capabLen); + message.readBytes(capabLen); + break; } - long as4Number = message.readUnsignedInt(); - - bgpSession.remoteInfo().setAs4OctetCapability(); - bgpSession.remoteInfo().setAs4Number(as4Number); - - // - // Copy remote 4-octet AS Number Capabilities and AS - // Number. This is a temporary setting until local AS - // number configuration is supported. - // - bgpSession.localInfo().setAs4OctetCapability(); - bgpSession.localInfo().setAs4Number(as4Number); - log.debug("BGP RX OPEN Capability: AS4 Number = {}", - as4Number); - break; - - default: - // Unknown Capability: ignore it - log.debug("BGP RX OPEN Capability Code = {} Length = {}", - capabCode, capabLen); - message.readBytes(capabLen); - break; - } - break; + } + break; default: // Unknown Parameter Type: ignore it log.debug("BGP RX OPEN Parameter Type = {} Length = {}", diff --git a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpRouteEntry.java b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpRouteEntry.java index 974da808..24d1a8da 100644 --- a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpRouteEntry.java +++ b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/bgp/BgpRouteEntry.java @@ -421,7 +421,7 @@ public class BgpRouteEntry extends RouteEntry { @Override public int hashCode() { - return Objects.hash(pathSegments); + return pathSegments.hashCode(); } @Override diff --git a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/BgpSpeakersListCommand.java b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/BgpSpeakersListCommand.java index 23d7086c..064080fd 100644 --- a/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/BgpSpeakersListCommand.java +++ b/framework/src/onos/apps/routing/src/main/java/org/onosproject/routing/cli/BgpSpeakersListCommand.java @@ -50,13 +50,17 @@ public class BgpSpeakersListCommand extends AbstractShellCommand { ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID); BgpConfig config = configService.getConfig(appId, BgpConfig.class); + if (config == null) { + print("No speakers configured"); + return; + } List<BgpConfig.BgpSpeakerConfig> bgpSpeakers = Lists.newArrayList(config.bgpSpeakers()); Collections.sort(bgpSpeakers, SPEAKERS_COMPARATOR); - if (config == null || config.bgpSpeakers().isEmpty()) { + if (config.bgpSpeakers().isEmpty()) { print("No speakers configured"); } else { bgpSpeakers.forEach( diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java index eaabed33..2eb5d0f3 100644 --- a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentSynchronizer.java @@ -15,24 +15,25 @@ */ package org.onosproject.sdnip; -import org.onosproject.core.ApplicationId; -import org.onosproject.net.intent.Intent; -import org.onosproject.net.intent.IntentService; -import org.onosproject.net.intent.IntentState; -import org.onosproject.net.intent.Key; -import org.onosproject.routing.IntentSynchronizationService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static java.util.concurrent.Executors.newSingleThreadExecutor; +import static org.onlab.util.Tools.groupedThreads; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; -import static java.util.concurrent.Executors.newSingleThreadExecutor; -import static org.onlab.util.Tools.groupedThreads; +import org.onosproject.core.ApplicationId; +import org.onosproject.net.intent.Intent; +import org.onosproject.net.intent.IntentService; +import org.onosproject.net.intent.IntentState; +import org.onosproject.net.intent.Key; +import org.onosproject.routing.IntentSynchronizationService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Synchronizes intents between the in-memory intent store and the @@ -49,9 +50,9 @@ public class IntentSynchronizer implements IntentSynchronizationService { private final Map<Key, Intent> intents; // - // State to deal with SDN-IP Leader election and pushing Intents + // State to deal with the Leader election and pushing Intents // - private final ExecutorService bgpIntentsSynchronizerExecutor; + private final ExecutorService intentsSynchronizerExecutor; private volatile boolean isElectedLeader = false; private volatile boolean isActivatedLeader = false; @@ -61,9 +62,9 @@ public class IntentSynchronizer implements IntentSynchronizationService { * @param appId the Application ID * @param intentService the intent service */ - IntentSynchronizer(ApplicationId appId, IntentService intentService) { + public IntentSynchronizer(ApplicationId appId, IntentService intentService) { this(appId, intentService, - newSingleThreadExecutor(groupedThreads("onos/sdnip", "sync"))); + newSingleThreadExecutor(groupedThreads("onos/" + appId, "sync"))); } /** @@ -73,14 +74,14 @@ public class IntentSynchronizer implements IntentSynchronizationService { * @param intentService the intent service * @param executorService executor service for synchronization thread */ - IntentSynchronizer(ApplicationId appId, IntentService intentService, + public IntentSynchronizer(ApplicationId appId, IntentService intentService, ExecutorService executorService) { this.appId = appId; this.intentService = intentService; intents = new ConcurrentHashMap<>(); - bgpIntentsSynchronizerExecutor = executorService; + intentsSynchronizerExecutor = executorService; } /** @@ -96,56 +97,31 @@ public class IntentSynchronizer implements IntentSynchronizationService { public void stop() { synchronized (this) { // Stop the thread(s) - bgpIntentsSynchronizerExecutor.shutdownNow(); + intentsSynchronizerExecutor.shutdownNow(); + log.info("Intents Synchronizer Executor shutdown completed"); - // - // Withdraw all SDN-IP intents - // - if (!isElectedLeader) { - return; // Nothing to do: not the leader anymore - } + } + } - // - // NOTE: We don't withdraw the intents during shutdown, because - // it creates flux in the data plane during switchover. - // - - /* - // - // Build a batch operation to withdraw all intents from this - // application. - // - log.debug("SDN-IP Intent Synchronizer shutdown: " + - "withdrawing all intents..."); - IntentOperations.Builder builder = IntentOperations.builder(appId); - for (Intent intent : intentService.getIntents()) { - // Skip the intents from other applications - if (!intent.appId().equals(appId)) { - continue; - } + /** + * Withdraws all intents. + */ + public void removeIntents() { + if (!isElectedLeader) { + // only leader will withdraw intents + return; + } - // Skip the intents that are already withdrawn - IntentState intentState = - intentService.getIntentState(intent.id()); - if ((intentState == null) || - intentState.equals(IntentState.WITHDRAWING) || - intentState.equals(IntentState.WITHDRAWN)) { - continue; - } + log.debug("Intent Synchronizer shutdown: withdrawing all intents..."); - log.trace("SDN-IP Intent Synchronizer withdrawing intent: {}", - intent); - builder.addWithdrawOperation(intent.id()); - } - IntentOperations intentOperations = builder.build(); - intentService.execute(intentOperations); - leaderChanged(false); - - peerIntents.clear(); - routeIntents.clear(); - log.debug("SDN-IP Intent Synchronizer shutdown completed"); - */ + for (Entry<Key, Intent> entry : intents.entrySet()) { + intentService.withdraw(entry.getValue()); + log.debug("Intent Synchronizer withdrawing intent: {}", + entry.getValue()); } + + intents.clear(); + log.info("Tried to clean all intents"); } @Override @@ -153,7 +129,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { synchronized (this) { intents.put(intent.key(), intent); if (isElectedLeader && isActivatedLeader) { - log.trace("SDN-IP Submitting intent: {}", intent); + log.trace("Submitting intent: {}", intent); intentService.submit(intent); } } @@ -164,19 +140,19 @@ public class IntentSynchronizer implements IntentSynchronizationService { synchronized (this) { intents.remove(intent.key(), intent); if (isElectedLeader && isActivatedLeader) { - log.trace("SDN-IP Withdrawing intent: {}", intent); + log.trace("Withdrawing intent: {}", intent); intentService.withdraw(intent); } } } /** - * Signals the synchronizer that the SDN-IP leadership has changed. + * Signals the synchronizer that the leadership has changed. * * @param isLeader true if this instance is now the leader, otherwise false */ public void leaderChanged(boolean isLeader) { - log.debug("SDN-IP Leader changed: {}", isLeader); + log.debug("Leader changed: {}", isLeader); if (!isLeader) { this.isElectedLeader = false; @@ -187,7 +163,7 @@ public class IntentSynchronizer implements IntentSynchronizationService { this.isElectedLeader = true; // Run the synchronization method off-thread - bgpIntentsSynchronizerExecutor.execute(this::synchronizeIntents); + intentsSynchronizerExecutor.execute(this::synchronizeIntents); } private void synchronizeIntents() { @@ -225,17 +201,17 @@ public class IntentSynchronizer implements IntentSynchronizationService { } } - log.debug("SDN-IP Intent Synchronizer: submitting {}, withdrawing {}", + log.debug("Intent Synchronizer: submitting {}, withdrawing {}", intentsToAdd.size(), intentsToRemove.size()); // Withdraw Intents for (Intent intent : intentsToRemove) { intentService.withdraw(intent); - log.trace("SDN-IP Intent Synchronizer: withdrawing intent: {}", + log.trace("Intent Synchronizer: withdrawing intent: {}", intent); } if (!isElectedLeader) { - log.debug("SDN-IP Intent Synchronizer: cannot withdraw intents: " + + log.debug("Intent Synchronizer: cannot withdraw intents: " + "not elected leader anymore"); isActivatedLeader = false; return; @@ -244,11 +220,11 @@ public class IntentSynchronizer implements IntentSynchronizationService { // Add Intents for (Intent intent : intentsToAdd) { intentService.submit(intent); - log.trace("SDN-IP Intent Synchronizer: submitting intent: {}", + log.trace("Intent Synchronizer: submitting intent: {}", intent); } if (!isElectedLeader) { - log.debug("SDN-IP Intent Synchronizer: cannot submit intents: " + + log.debug("Intent Synchronizer: cannot submit intents: " + "not elected leader anymore"); isActivatedLeader = false; return; @@ -259,7 +235,6 @@ public class IntentSynchronizer implements IntentSynchronizationService { } else { isActivatedLeader = false; } - log.debug("SDN-IP intent synchronization completed"); + log.debug("Intent synchronization completed"); } - } diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentUtils.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentUtils.java index 8e2a3df3..863de12a 100644 --- a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentUtils.java +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/IntentUtils.java @@ -19,13 +19,12 @@ package org.onosproject.sdnip; import org.onosproject.net.intent.Intent; import org.onosproject.net.intent.MultiPointToSinglePointIntent; import org.onosproject.net.intent.PointToPointIntent; +import org.onosproject.net.intent.SinglePointToMultiPointIntent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Objects; -import static com.google.common.base.Preconditions.checkArgument; - /** * Utilities for dealing with intents. */ @@ -49,15 +48,24 @@ public final class IntentUtils { * @return true if the two intents represent the same value, otherwise false */ public static boolean equals(Intent one, Intent two) { - checkArgument(one.getClass() == two.getClass(), - "Intents are not the same type"); + if (one.getClass() != two.getClass()) { + return false; + } if (!(Objects.equals(one.appId(), two.appId()) && Objects.equals(one.key(), two.key()))) { return false; } - if (one instanceof MultiPointToSinglePointIntent) { + if (one instanceof SinglePointToMultiPointIntent) { + SinglePointToMultiPointIntent intent1 = (SinglePointToMultiPointIntent) one; + SinglePointToMultiPointIntent intent2 = (SinglePointToMultiPointIntent) two; + + return Objects.equals(intent1.selector(), intent2.selector()) && + Objects.equals(intent1.treatment(), intent2.treatment()) && + Objects.equals(intent1.ingressPoint(), intent2.ingressPoint()) && + Objects.equals(intent1.egressPoints(), intent2.egressPoints()); + } else if (one instanceof MultiPointToSinglePointIntent) { MultiPointToSinglePointIntent intent1 = (MultiPointToSinglePointIntent) one; MultiPointToSinglePointIntent intent2 = (MultiPointToSinglePointIntent) two; diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java index a27baaf9..fb008aad 100644 --- a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/PeerConnectivityManager.java @@ -340,15 +340,15 @@ public class PeerConnectivityManager { private TrafficSelector buildSelector(byte ipProto, IpAddress srcIp, IpAddress dstIp, Short srcTcpPort, Short dstTcpPort) { - TrafficSelector.Builder builder = DefaultTrafficSelector.builder() - .matchEthType(Ethernet.TYPE_IPV4) - .matchIPProtocol(ipProto); + TrafficSelector.Builder builder = DefaultTrafficSelector.builder().matchIPProtocol(ipProto); if (dstIp.isIp4()) { - builder.matchIPSrc(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET_MASK_LENGTH)) + builder.matchEthType(Ethernet.TYPE_IPV4) + .matchIPSrc(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET_MASK_LENGTH)) .matchIPDst(IpPrefix.valueOf(dstIp, IpPrefix.MAX_INET_MASK_LENGTH)); } else { - builder.matchIPv6Src(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET6_MASK_LENGTH)) + builder.matchEthType(Ethernet.TYPE_IPV6) + .matchIPv6Src(IpPrefix.valueOf(srcIp, IpPrefix.MAX_INET6_MASK_LENGTH)) .matchIPv6Dst(IpPrefix.valueOf(dstIp, IpPrefix.MAX_INET6_MASK_LENGTH)); } diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java index 1b3eda9d..ace888d1 100644 --- a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/SdnIp.java @@ -15,12 +15,17 @@ */ package org.onosproject.sdnip; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.Objects; + 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.app.ApplicationService; import org.onosproject.cluster.ClusterService; import org.onosproject.cluster.ControllerNode; import org.onosproject.cluster.LeadershipEvent; @@ -28,8 +33,8 @@ import org.onosproject.cluster.LeadershipEventListener; import org.onosproject.cluster.LeadershipService; import org.onosproject.core.ApplicationId; import org.onosproject.core.CoreService; -import org.onosproject.net.config.NetworkConfigService; import org.onosproject.incubator.net.intf.InterfaceService; +import org.onosproject.net.config.NetworkConfigService; import org.onosproject.net.host.HostService; import org.onosproject.net.intent.IntentService; import org.onosproject.routing.IntentSynchronizationService; @@ -38,10 +43,6 @@ import org.onosproject.routing.SdnIpService; import org.onosproject.routing.config.RoutingConfigurationService; import org.slf4j.Logger; -import java.util.Objects; - -import static org.slf4j.LoggerFactory.getLogger; - /** * Component for the SDN-IP peering application. */ @@ -59,6 +60,9 @@ public class SdnIp implements SdnIpService { protected IntentService intentService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected ApplicationService applicationService; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected HostService hostService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) @@ -84,7 +88,7 @@ public class SdnIp implements SdnIpService { private SdnIpFib fib; private LeadershipEventListener leadershipEventListener = - new InnerLeadershipEventListener(); + new InnerLeadershipEventListener(); private ApplicationId appId; private ControllerNode localControllerNode; @@ -113,6 +117,10 @@ public class SdnIp implements SdnIpService { leadershipService.addListener(leadershipEventListener); leadershipService.runForLeadership(appId.name()); + + applicationService.registerDeactivateHook(appId, + intentSynchronizer::removeIntents); + } @Deactivate diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/cli/AddPeerCommand.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/cli/AddPeerCommand.java new file mode 100644 index 00000000..81231ab9 --- /dev/null +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/cli/AddPeerCommand.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.sdnip.cli; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.onlab.packet.IpAddress; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.core.ApplicationId; +import org.onosproject.core.CoreService; +import org.onosproject.incubator.net.intf.InterfaceService; +import org.onosproject.net.config.NetworkConfigService; +import org.onosproject.routing.RoutingService; +import org.onosproject.routing.config.BgpConfig; + +/** + * Command to add new BGP peer to existing internal speaker. + */ +@Command(scope = "onos", name = "add-bgp-peer", + description = "Adds an external BGP router as peer to an existing BGP speaker") +public class AddPeerCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "name", + description = "Name of the internal BGP speaker", + required = true, multiValued = false) + String name = null; + + @Argument(index = 1, name = "ip", + description = "IP address of the BGP peer", + required = true, multiValued = false) + String ip = null; + + private static final String PEER_ADD_SUCCESS = "Peer Successfully Added."; + private static final String NO_CONFIGURATION = "No speakers configured"; + private static final String SPEAKER_NOT_FOUND = + "Speaker with name \'%s\' not found"; + private static final String NO_INTERFACE = + "No matching interface found for IP \'%s\'"; + + private IpAddress peerAddress = null; + + @Override + protected void execute() { + peerAddress = IpAddress.valueOf(ip); + + NetworkConfigService configService = get(NetworkConfigService.class); + CoreService coreService = get(CoreService.class); + ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID); + + BgpConfig config = configService.getConfig(appId, BgpConfig.class); + if (config == null || config.bgpSpeakers().isEmpty()) { + print(NO_CONFIGURATION); + return; + } + + BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name); + if (speaker == null) { + print(SPEAKER_NOT_FOUND, name); + return; + } else { + if (speaker.isConnectedToPeer(peerAddress)) { + return; // Peering already exists. + } + } + + InterfaceService interfaceService = get(InterfaceService.class); + if (interfaceService.getMatchingInterface(peerAddress) == null) { + print(NO_INTERFACE, ip); + return; + } + + addPeerToSpeakerConf(config); + configService.applyConfig(appId, BgpConfig.class, config.node()); + + print(PEER_ADD_SUCCESS); + } + + private void addPeerToSpeakerConf(BgpConfig config) { + log.debug("Creating BGP configuration for new peer: {}", ip); + config.addPeerToSpeaker(name, peerAddress); + } +} diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/cli/AddSpeakerCommand.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/cli/AddSpeakerCommand.java new file mode 100644 index 00000000..84353852 --- /dev/null +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/cli/AddSpeakerCommand.java @@ -0,0 +1,90 @@ +/* + * 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.sdnip.cli; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.onlab.packet.IpAddress; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.core.ApplicationId; +import org.onosproject.core.CoreService; +import org.onosproject.net.ConnectPoint; +import org.onosproject.net.config.NetworkConfigService; +import org.onosproject.routing.RoutingService; +import org.onosproject.routing.config.BgpConfig; + +import java.util.HashSet; +import java.util.Optional; + +/** + * Command to add a new internal BGP speaker. + */ +@Command(scope = "onos", name = "add-bgp-speaker", + description = "Adds an internal BGP speaker") +public class AddSpeakerCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "name", + description = "Name of the internal BGP speaker", + required = true, multiValued = false) + String name = null; + + @Argument(index = 1, name = "connectionPoint", + description = "Interface to the BGP speaker", + required = true, multiValued = false) + String connectionPoint = null; + + private static final String SPEAKER_ADD_SUCCESS = "Speaker Successfully Added."; + + @Override + protected void execute() { + NetworkConfigService configService = get(NetworkConfigService.class); + CoreService coreService = get(CoreService.class); + ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID); + + BgpConfig config = configService.addConfig(appId, BgpConfig.class); + + BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name); + if (speaker != null) { + log.debug("Speaker already exists: {}", name); + return; + } + + addSpeakerToConf(config); + configService.applyConfig(appId, BgpConfig.class, config.node()); + + print(SPEAKER_ADD_SUCCESS); + } + + /** + * Adds the speaker to the BgpConfig service. + * + * @param config the BGP configuration + */ + private void addSpeakerToConf(BgpConfig config) { + log.debug("Adding new speaker to configuration: {}", name); + BgpConfig.BgpSpeakerConfig speaker = getSpeaker(); + + config.addSpeaker(speaker); + } + + private BgpConfig.BgpSpeakerConfig getSpeaker() { + ConnectPoint connectPoint = ConnectPoint. + deviceConnectPoint(connectionPoint); + return new BgpConfig.BgpSpeakerConfig(Optional.ofNullable(name), + connectPoint, new HashSet<IpAddress>()); + } +} diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/cli/RemovePeerCommand.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/cli/RemovePeerCommand.java new file mode 100644 index 00000000..bfc6fb7b --- /dev/null +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/cli/RemovePeerCommand.java @@ -0,0 +1,81 @@ +/* + * 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.sdnip.cli; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.onlab.packet.IpAddress; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.core.ApplicationId; +import org.onosproject.core.CoreService; +import org.onosproject.net.config.NetworkConfigService; +import org.onosproject.routing.RoutingService; +import org.onosproject.routing.config.BgpConfig; + +/** + * Command to remove existing BGP peer. + */ +@Command(scope = "onos", name = "remove-bgp-peer", + description = "Removes a BGP peer") +public class RemovePeerCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "ip", + description = "IP address of the BGP peer", + required = true, multiValued = false) + String ip = null; + + private static final String PEER_REMOVE_SUCCESS = "Peer Successfully Removed."; + private static final String NO_CONFIGURATION = "No speakers configured"; + private static final String PEER_NOT_FOUND = + "Peer with IP \'%s\' not found"; + + private IpAddress peerAddress = null; + + @Override + protected void execute() { + peerAddress = IpAddress.valueOf(ip); + + NetworkConfigService configService = get(NetworkConfigService.class); + CoreService coreService = get(CoreService.class); + ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID); + + BgpConfig config = configService.getConfig(appId, BgpConfig.class); + if (config == null || config.bgpSpeakers().isEmpty()) { + print(NO_CONFIGURATION); + return; + } + + peerAddress = IpAddress.valueOf(ip); + + BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerFromPeer(peerAddress); + if (speaker == null) { + print(PEER_NOT_FOUND, ip); + return; + } + + removePeerFromSpeakerConf(speaker, config); + configService.applyConfig(appId, BgpConfig.class, config.node()); + + print(PEER_REMOVE_SUCCESS); + } + + private void removePeerFromSpeakerConf(BgpConfig.BgpSpeakerConfig speaker, + BgpConfig config) { + log.debug("Removing BGP configuration for peer: {}", ip); + config.removePeerFromSpeaker(speaker, peerAddress); + } +} diff --git a/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/cli/RemoveSpeakerCommand.java b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/cli/RemoveSpeakerCommand.java new file mode 100644 index 00000000..6a51b42f --- /dev/null +++ b/framework/src/onos/apps/sdnip/src/main/java/org/onosproject/sdnip/cli/RemoveSpeakerCommand.java @@ -0,0 +1,87 @@ +/* + * 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.sdnip.cli; + +import org.apache.karaf.shell.commands.Argument; +import org.apache.karaf.shell.commands.Command; +import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.core.ApplicationId; +import org.onosproject.core.CoreService; +import org.onosproject.net.config.NetworkConfigService; +import org.onosproject.routing.RoutingService; +import org.onosproject.routing.config.BgpConfig; + +/** + * Command to remove a internal BGP speaker. + */ +@Command(scope = "onos", name = "remove-bgp-speaker", + description = "Removes an internal BGP speaker") +public class RemoveSpeakerCommand extends AbstractShellCommand { + + @Argument(index = 0, name = "name", + description = "Name of the internal BGP speaker", + required = true, multiValued = false) + String name = null; + + private static final String SPEAKER_REMOVE_SUCCESS = "Speaker Successfully Removed."; + private static final String NO_CONFIGURATION = "No speakers configured"; + private static final String PEERS_EXIST = + "Speaker with name \'%s\' has peer connections"; + private static final String SPEAKER_NOT_FOUND = + "Speaker with name \'%s\' not found"; + + @Override + protected void execute() { + NetworkConfigService configService = get(NetworkConfigService.class); + CoreService coreService = get(CoreService.class); + ApplicationId appId = coreService.getAppId(RoutingService.ROUTER_APP_ID); + + BgpConfig config = configService.getConfig(appId, BgpConfig.class); + if (config == null || config.bgpSpeakers().isEmpty()) { + print(NO_CONFIGURATION); + return; + } + + BgpConfig.BgpSpeakerConfig speaker = config.getSpeakerWithName(name); + if (speaker == null) { + print(SPEAKER_NOT_FOUND, name); + return; + } else { + if (!speaker.peers().isEmpty()) { + // Removal not allowed when peer connections exist. + print(PEERS_EXIST, name); + return; + } + } + + removeSpeakerFromConf(config); + configService.applyConfig(appId, BgpConfig.class, config.node()); + + print(SPEAKER_REMOVE_SUCCESS); + } + + /** + * Removes the speaker from the BgpConfig service. + * + * @param bgpConfig the BGP configuration + */ + private void removeSpeakerFromConf(BgpConfig bgpConfig) { + log.debug("Removing speaker from configuration: {}", name); + + bgpConfig.removeSpeaker(name); + } +} diff --git a/framework/src/onos/apps/sdnip/src/main/resources/OSGI-INF/blueprint/shell-config.xml b/framework/src/onos/apps/sdnip/src/main/resources/OSGI-INF/blueprint/shell-config.xml index 3be1c79a..97b2f09f 100644 --- a/framework/src/onos/apps/sdnip/src/main/resources/OSGI-INF/blueprint/shell-config.xml +++ b/framework/src/onos/apps/sdnip/src/main/resources/OSGI-INF/blueprint/shell-config.xml @@ -19,5 +19,17 @@ <command> <action class="org.onosproject.sdnip.cli.PrimaryChangeCommand"/> </command> + <command> + <action class="org.onosproject.sdnip.cli.AddSpeakerCommand"/> + </command> + <command> + <action class="org.onosproject.sdnip.cli.RemoveSpeakerCommand"/> + </command> + <command> + <action class="org.onosproject.sdnip.cli.AddPeerCommand"/> + </command> + <command> + <action class="org.onosproject.sdnip.cli.RemovePeerCommand"/> + </command> </command-bundle> </blueprint> 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..2c6412cf 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 @@ -20,10 +20,10 @@ import org.onlab.packet.Ethernet; import org.onlab.packet.Ip4Address; import org.onlab.packet.IpAddress; import org.onlab.packet.MacAddress; +import org.onlab.packet.VlanId; import org.onosproject.net.ConnectPoint; import org.onosproject.net.DeviceId; import org.onosproject.net.Host; -import org.onosproject.net.Port; import org.onosproject.net.PortNumber; import org.onosproject.net.flow.DefaultTrafficTreatment; import org.onosproject.net.flow.TrafficTreatment; @@ -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; @@ -58,12 +60,21 @@ public class ArpHandler { /** * Processes incoming ARP packets. + * * If it is an ARP request to router itself or known hosts, * then it sends ARP response. * If it is an ARP request to unknown hosts in its own subnet, * then it flood the ARP request to the ports. * If it is an ARP response, then set a flow rule for the host * and forward any IP packets to the host in the packet buffer to the host. + * <p> + * Note: We handles all ARP packet in, even for those ARP packets between + * hosts in the same subnet. + * For an ARP packet with broadcast destination MAC, + * some switches pipelines will send it to the controller due to table miss, + * other swithches will flood the packets directly in the data plane without + * packet in. + * We can deal with both cases. * * @param pkt incoming packet */ @@ -84,29 +95,56 @@ public class ArpHandler { if (arp.getOpCode() == ARP.OP_REQUEST) { handleArpRequest(deviceId, connectPoint, ethernet); } else { - srManager.ipHandler.forwardPackets(deviceId, hostIpAddress); + handleArpReply(deviceId, connectPoint, ethernet); } } private void handleArpRequest(DeviceId deviceId, ConnectPoint inPort, Ethernet payload) { ARP arpRequest = (ARP) payload.getPayload(); + VlanId vlanId = VlanId.vlanId(payload.getVlanID()); HostId targetHostId = HostId.hostId(MacAddress.valueOf( - arpRequest.getTargetHardwareAddress())); + arpRequest.getTargetHardwareAddress()), + vlanId); - // ARP request for router + // ARP request for router. Send ARP reply. if (isArpReqForRouter(deviceId, arpRequest)) { Ip4Address targetAddress = Ip4Address.valueOf(arpRequest.getTargetProtocolAddress()); - - sendArpResponse(arpRequest, config.getRouterMacForAGatewayIp(targetAddress)); + sendArpResponse(arpRequest, config.getRouterMacForAGatewayIp(targetAddress), vlanId); } else { Host targetHost = srManager.hostService.getHost(targetHostId); - // ARP request for known hosts + // ARP request for known hosts. Send proxy ARP reply on behalf of the target. if (targetHost != null) { - sendArpResponse(arpRequest, targetHost.mac()); + removeVlanAndForward(payload, targetHost.location()); + // ARP request for unknown host in the subnet. Flood in the subnet. + } else { + removeVlanAndFlood(payload, inPort); + } + } + } + + private void handleArpReply(DeviceId deviceId, ConnectPoint inPort, Ethernet payload) { + ARP arpReply = (ARP) payload.getPayload(); + VlanId vlanId = VlanId.vlanId(payload.getVlanID()); + HostId targetHostId = HostId.hostId(MacAddress.valueOf( + arpReply.getTargetHardwareAddress()), + vlanId); - // ARP request for unknown host in the subnet - } else if (isArpReqForSubnet(deviceId, arpRequest)) { - flood(payload, inPort); + // ARP reply for router. Process all pending IP packets. + if (isArpReqForRouter(deviceId, arpReply)) { + Ip4Address hostIpAddress = Ip4Address.valueOf(arpReply.getSenderProtocolAddress()); + srManager.ipHandler.forwardPackets(deviceId, hostIpAddress); + } else { + Host targetHost = srManager.hostService.getHost(targetHostId); + // ARP reply for known hosts. Forward to the host. + if (targetHost != null) { + removeVlanAndForward(payload, targetHost.location()); + // ARP reply for unknown host, Flood in the subnet. + } else { + // Don't flood to non-edge ports + if (vlanId.equals(VlanId.vlanId(srManager.ASSIGNED_VLAN_NO_SUBNET))) { + return; + } + removeVlanAndFlood(payload, inPort); } } } @@ -124,14 +162,6 @@ public class ArpHandler { return false; } - private boolean isArpReqForSubnet(DeviceId deviceId, ARP arpRequest) { - return config.getSubnets(deviceId).stream() - .anyMatch((prefix)-> - prefix.contains(Ip4Address. - valueOf(arpRequest. - getTargetProtocolAddress()))); - } - /** * Sends an APR request for the target IP address to all ports except in-port. * @@ -140,9 +170,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) @@ -161,11 +198,10 @@ public class ArpHandler { .setSourceMACAddress(senderMacAddress) .setEtherType(Ethernet.TYPE_ARP).setPayload(arpRequest); - flood(eth, inPort); + removeVlanAndFlood(eth, inPort); } - private void sendArpResponse(ARP arpRequest, MacAddress targetMac) { - + private void sendArpResponse(ARP arpRequest, MacAddress targetMac, VlanId vlanId) { ARP arpReply = new ARP(); arpReply.setHardwareType(ARP.HW_TYPE_ETHERNET) .setProtocolType(ARP.PROTO_TYPE_IP) @@ -184,8 +220,9 @@ public class ArpHandler { .setEtherType(Ethernet.TYPE_ARP).setPayload(arpReply); - HostId dstId = HostId.hostId(MacAddress.valueOf( - arpReply.getTargetHardwareAddress())); + HostId dstId = HostId.hostId( + MacAddress.valueOf(arpReply.getTargetHardwareAddress()), + vlanId); Host dst = srManager.hostService.getHost(dstId); if (dst == null) { log.warn("Cannot send ARP response to unknown device"); @@ -200,19 +237,51 @@ public class ArpHandler { srManager.packetService.emit(packet); } - private void flood(Ethernet request, ConnectPoint inPort) { - TrafficTreatment.Builder builder; - ByteBuffer buf = ByteBuffer.wrap(request.serialize()); - - for (Port port: srManager.deviceService.getPorts(inPort.deviceId())) { - if (!port.number().equals(inPort.port()) && - port.number().toLong() > 0) { - builder = DefaultTrafficTreatment.builder(); - builder.setOutput(port.number()); - srManager.packetService.emit(new DefaultOutboundPacket(inPort.deviceId(), - builder.build(), buf)); + /** + * Remove VLAN tag and flood to all ports in the same subnet. + * + * @param packet packet to be flooded + * @param inPort where the packet comes from + */ + private void removeVlanAndFlood(Ethernet packet, ConnectPoint inPort) { + Ip4Address targetProtocolAddress = Ip4Address.valueOf( + ((ARP) packet.getPayload()).getTargetProtocolAddress() + ); + + srManager.deviceConfiguration.getSubnetPortsMap(inPort.deviceId()).forEach((subnet, ports) -> { + if (subnet.contains(targetProtocolAddress)) { + ports.stream() + .filter(port -> port != inPort.port()) + .forEach(port -> { + removeVlanAndForward(packet, new ConnectPoint(inPort.deviceId(), port)); + }); } - } + }); } + /** + * Remove VLAN tag and packet out to given port. + * + * Note: In current implementation, we expect all communication with + * end hosts within a subnet to be untagged. + * <p> + * For those pipelines that internally assigns a VLAN, the VLAN tag will be + * removed before egress. + * <p> + * For those pipelines that do not assign internal VLAN, the packet remains + * untagged. + * + * @param packet packet to be forwarded + * @param outPort where the packet should be forwarded + */ + private void removeVlanAndForward(Ethernet packet, ConnectPoint outPort) { + packet.setEtherType(Ethernet.TYPE_ARP); + packet.setVlanID(Ethernet.VLAN_UNTAGGED); + ByteBuffer buf = ByteBuffer.wrap(packet.serialize()); + + TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); + tbuilder.setOutput(outPort.port()); + srManager.packetService.emit(new DefaultOutboundPacket(outPort.deviceId(), + tbuilder.build(), buf)); + } } 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<Ip4Prefix> 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/DefaultTunnel.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DefaultTunnel.java index 8c6fbe8d..70161432 100644 --- a/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DefaultTunnel.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/DefaultTunnel.java @@ -17,8 +17,6 @@ package org.onosproject.segmentrouting; import java.util.List; -import java.util.Objects; - import static com.google.common.base.Preconditions.checkNotNull; /** @@ -96,7 +94,7 @@ public class DefaultTunnel implements Tunnel { @Override public int hashCode() { - return Objects.hash(labelIds); + return labelIds.hashCode(); } @Override 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..eb3b3fd5 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<Ip4Address> 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(); @@ -97,8 +105,17 @@ public class IcmpHandler { } } + /** + * Sends an ICMP reply message. + * + * Note: we assume that packets sending from the edge switches to the hosts + * have untagged VLAN. + * @param icmpRequest the original ICMP request + * @param outport the output port where the ICMP reply should be sent to + */ private void sendICMPResponse(Ethernet icmpRequest, ConnectPoint outport) { - + // Note: We assume that packets arrive at the edge switches have + // untagged VLAN. Ethernet icmpReplyEth = new Ethernet(); IPv4 icmpRequestIpv4 = (IPv4) icmpRequest.getPayload(); @@ -121,7 +138,6 @@ public class IcmpHandler { icmpReplyEth.setEtherType(Ethernet.TYPE_IPV4); icmpReplyEth.setDestinationMACAddress(icmpRequest.getSourceMACAddress()); icmpReplyEth.setSourceMACAddress(icmpRequest.getDestinationMACAddress()); - icmpReplyEth.setVlanID(icmpRequest.getVlanID()); Ip4Address destIpAddress = Ip4Address.valueOf(icmpReplyIpv4.getDestinationAddress()); Ip4Address destRouterAddress = config.getRouterIpAddressForASubnetHost(destIpAddress); 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..bc3ce8c6 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; @@ -53,7 +55,6 @@ import java.util.concurrent.atomic.AtomicLong; import static com.google.common.base.Preconditions.checkNotNull; public class RoutingRulePopulator { - private static final Logger log = LoggerFactory .getLogger(RoutingRulePopulator.class); @@ -103,6 +104,46 @@ public class RoutingRulePopulator { */ public void populateIpRuleForHost(DeviceId deviceId, Ip4Address hostIp, MacAddress hostMac, PortNumber outPort) { + log.debug("Populate IP table entry for host {} at {}:{}", + hostIp, deviceId, outPort); + ForwardingObjective.Builder fwdBuilder; + try { + fwdBuilder = getForwardingObjectiveBuilder( + deviceId, hostIp, hostMac, outPort); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting populateIpRuleForHost."); + return; + } + srManager.flowObjectiveService. + forward(deviceId, fwdBuilder.add(new SRObjectiveContext(deviceId, + SRObjectiveContext.ObjectiveType.FORWARDING))); + rulePopulationCounter.incrementAndGet(); + } + + public void revokeIpRuleForHost(DeviceId deviceId, Ip4Address hostIp, + MacAddress hostMac, PortNumber outPort) { + log.debug("Revoke IP table entry for host {} at {}:{}", + hostIp, deviceId, outPort); + ForwardingObjective.Builder fwdBuilder; + try { + fwdBuilder = getForwardingObjectiveBuilder( + deviceId, hostIp, hostMac, outPort); + } catch (DeviceConfigNotFoundException e) { + log.warn(e.getMessage() + " Aborting revokeIpRuleForHost."); + return; + } + srManager.flowObjectiveService. + forward(deviceId, fwdBuilder.remove(new SRObjectiveContext(deviceId, + SRObjectiveContext.ObjectiveType.FORWARDING))); + } + + private ForwardingObjective.Builder getForwardingObjectiveBuilder( + DeviceId deviceId, Ip4Address hostIp, + MacAddress hostMac, PortNumber outPort) + throws DeviceConfigNotFoundException { + MacAddress deviceMac; + deviceMac = config.getDeviceMac(deviceId); + TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); @@ -111,25 +152,16 @@ public class RoutingRulePopulator { tbuilder.deferred() .setEthDst(hostMac) - .setEthSrc(config.getDeviceMac(deviceId)) + .setEthSrc(deviceMac) .setOutput(outPort); TrafficTreatment treatment = tbuilder.build(); TrafficSelector selector = sbuilder.build(); - ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective - .builder().fromApp(srManager.appId).makePermanent() + return DefaultForwardingObjective.builder() + .fromApp(srManager.appId).makePermanent() .withSelector(selector).withTreatment(treatment) .withPriority(100).withFlag(ForwardingObjective.Flag.SPECIFIC); - - log.debug("Installing IPv4 forwarding objective " - + "for host {} in switch {}", hostIp, deviceId); - srManager.flowObjectiveService. - forward(deviceId, - fwdBuilder. - add(new SRObjectiveContext(deviceId, - SRObjectiveContext.ObjectiveType.FORWARDING))); - rulePopulationCounter.incrementAndGet(); } /** @@ -167,28 +199,34 @@ public class RoutingRulePopulator { public boolean populateIpRuleForRouter(DeviceId deviceId, IpPrefix ipPrefix, DeviceId destSw, Set<DeviceId> 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(); - sbuilder.matchIPDst(ipPrefix); sbuilder.matchEthType(Ethernet.TYPE_IPV4); + TrafficSelector selector = sbuilder.build(); - NeighborSet ns = null; + TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); + NeighborSet ns; + TrafficTreatment treatment; // If the next hop is the same as the final destination, then MPLS label // is not set. if (nextHops.size() == 1 && nextHops.toArray()[0].equals(destSw)) { - tbuilder.deferred().decNwTtl(); + tbuilder.immediate().decNwTtl(); ns = new NeighborSet(nextHops); + treatment = tbuilder.build(); } else { - tbuilder.deferred().copyTtlOut(); - ns = new NeighborSet(nextHops, config.getSegmentId(destSw)); + ns = new NeighborSet(nextHops, segmentId); + treatment = null; } - TrafficTreatment treatment = tbuilder.build(); - TrafficSelector selector = sbuilder.build(); - if (srManager.getNextObjectiveId(deviceId, ns) <= 0) { log.warn("No next objective in {} for ns: {}", deviceId, ns); return false; @@ -199,10 +237,12 @@ public class RoutingRulePopulator { .fromApp(srManager.appId) .makePermanent() .nextStep(srManager.getNextObjectiveId(deviceId, ns)) - .withTreatment(treatment) .withSelector(selector) .withPriority(100) .withFlag(ForwardingObjective.Flag.SPECIFIC); + if (treatment != null) { + fwdBuilder.withTreatment(treatment); + } log.debug("Installing IPv4 forwarding objective " + "for router IP/subnet {} in switch {}", ipPrefix, @@ -227,19 +267,26 @@ public class RoutingRulePopulator { */ public boolean populateMplsRule(DeviceId deviceId, DeviceId destSwId, Set<DeviceId> 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<ForwardingObjective.Builder> 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 +311,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 +357,21 @@ public class RoutingRulePopulator { Set<DeviceId> 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 +388,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 +430,25 @@ 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 +473,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,16 +488,16 @@ public class RoutingRulePopulator { } ForwardingObjective.Builder puntIp = DefaultForwardingObjective.builder(); Set<Ip4Address> allIps = new HashSet<Ip4Address>(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(); - selector.matchEthType(Ethernet.TYPE_IPV4); - selector.matchIPDst(IpPrefix.valueOf(ipaddr, + TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); + TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); + sbuilder.matchEthType(Ethernet.TYPE_IPV4); + sbuilder.matchIPDst(IpPrefix.valueOf(ipaddr, IpPrefix.MAX_INET_MASK_LENGTH)); - treatment.setOutput(PortNumber.CONTROLLER); - puntIp.withSelector(selector.build()); - puntIp.withTreatment(treatment.build()); + tbuilder.setOutput(PortNumber.CONTROLLER); + puntIp.withSelector(sbuilder.build()); + puntIp.withTreatment(tbuilder.build()); puntIp.withFlag(Flag.VERSATILE) .withPriority(HIGHEST_PRIORITY) .makePermanent() @@ -434,6 +510,48 @@ public class RoutingRulePopulator { } } + /** + * Populates a forwarding objective to send packets that miss other high + * priority Bridging Table entries to a group that contains all ports of + * its subnet. + * + * Note: We assume that packets sending from the edge switches to the hosts + * have untagged VLAN. + * The VLAN tag will be popped later in the flooding group. + * + * @param deviceId switch ID to set the rules + */ + public void populateSubnetBroadcastRule(DeviceId deviceId) { + config.getSubnets(deviceId).forEach(subnet -> { + int nextId = srManager.getSubnetNextObjectiveId(deviceId, subnet); + VlanId vlanId = srManager.getSubnetAssignedVlanId(deviceId, subnet); + + /* Driver should treat objective with MacAddress.NONE as the + * subnet broadcast rule + */ + TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); + sbuilder.matchVlanId(vlanId); + sbuilder.matchEthDst(MacAddress.NONE); + + ForwardingObjective.Builder fob = DefaultForwardingObjective.builder(); + fob.withFlag(Flag.SPECIFIC) + .withSelector(sbuilder.build()) + .nextStep(nextId) + .withPriority(5) + .fromApp(srManager.appId) + .makePermanent(); + + srManager.flowObjectiveService.forward( + deviceId, + fob.add(new SRObjectiveContext( + deviceId, + SRObjectiveContext.ObjectiveType.FORWARDING) + ) + ); + }); + } + + private PortNumber selectOnePort(DeviceId srcId, Set<DeviceId> destIds) { Set<Link> links = srManager.linkService.getDeviceLinks(srcId); 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 9d60b279..84fe5168 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 @@ -22,6 +22,7 @@ import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.ReferenceCardinality; import org.apache.felix.scr.annotations.Service; import org.onlab.packet.Ethernet; +import org.onlab.packet.MacAddress; import org.onlab.packet.VlanId; import org.onlab.packet.IPv4; import org.onlab.packet.Ip4Address; @@ -33,11 +34,25 @@ import org.onosproject.core.ApplicationId; import org.onosproject.core.CoreService; import org.onosproject.event.Event; import org.onosproject.net.ConnectPoint; +import org.onosproject.net.PortNumber; import org.onosproject.net.config.ConfigFactory; 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.net.flow.DefaultTrafficSelector; +import org.onosproject.net.flow.DefaultTrafficTreatment; +import org.onosproject.net.flow.TrafficSelector; +import org.onosproject.net.flow.TrafficTreatment; +import org.onosproject.net.flowobjective.DefaultForwardingObjective; +import org.onosproject.net.flowobjective.ForwardingObjective; +import org.onosproject.net.flowobjective.Objective; +import org.onosproject.net.flowobjective.ObjectiveContext; +import org.onosproject.net.flowobjective.ObjectiveError; +import org.onosproject.net.host.HostEvent; +import org.onosproject.net.host.HostListener; +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; @@ -137,11 +152,13 @@ public class SegmentRoutingManager implements SegmentRoutingService { private static ScheduledFuture<?> eventHandlerFuture = null; private ConcurrentLinkedQueue<Event> eventQueue = new ConcurrentLinkedQueue<Event>(); - private Map<DeviceId, DefaultGroupHandler> groupHandlerMap = new ConcurrentHashMap<DeviceId, DefaultGroupHandler>(); + private Map<DeviceId, DefaultGroupHandler> groupHandlerMap = + new ConcurrentHashMap<DeviceId, DefaultGroupHandler>(); // Per device next objective ID store with (device id + neighbor set) as key - private EventuallyConsistentMap<NeighborSetNextObjectiveStoreKey, - Integer> nsNextObjStore = null; - private EventuallyConsistentMap<SubnetNextObjectiveStoreKey, Integer> subnetNextObjStore = null; + private EventuallyConsistentMap<NeighborSetNextObjectiveStoreKey, Integer> + nsNextObjStore = null; + private EventuallyConsistentMap<SubnetNextObjectiveStoreKey, Integer> + subnetNextObjStore = null; private EventuallyConsistentMap<String, Tunnel> tunnelStore = null; private EventuallyConsistentMap<String, Policy> policyStore = null; // Per device, per-subnet assigned-vlans store, with (device id + subnet @@ -168,6 +185,8 @@ public class SegmentRoutingManager implements SegmentRoutingService { } }; + private final HostListener hostListener = new InternalHostListener(); + private Object threadSchedulerLock = new Object(); private static int numOfEventsQueued = 0; private static int numOfEventsExecuted = 0; @@ -257,6 +276,8 @@ public class SegmentRoutingManager implements SegmentRoutingService { cfgService.addListener(cfgListener); cfgService.registerConfigFactory(cfgFactory); + hostService.addListener(hostListener); + processor = new InternalPacketProcessor(); linkListener = new InternalLinkListener(); deviceListener = new InternalDeviceListener(); @@ -553,7 +574,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,30 +620,43 @@ public class SegmentRoutingManager implements SegmentRoutingService { private void processDeviceAdded(Device device) { log.debug("A new device with ID {} was added", device.id()); + if (deviceConfiguration == null || !deviceConfiguration.isConfigured(device.id())) { + log.warn("Device configuration uploading. Device {} will be " + + "processed after config completes.", device.id()); + return; + } // Irrespective of whether the local is a MASTER or not for this device, // we need to create a SR-group-handler instance. This is because in a // multi-instance setup, any instance can initiate forwarding/next-objectives // for any switch (even if this instance is a SLAVE or not even connected // to the switch). To handle this, a default-group-handler instance is necessary // per switch. - DefaultGroupHandler groupHandler = DefaultGroupHandler. - createGroupHandler(device.id(), - appId, - deviceConfiguration, - linkService, - flowObjectiveService, - nsNextObjStore, - subnetNextObjStore); - 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 - // port addressing rules to the driver as well irrespective of whether - // this instance is the master or not. - defaultRoutingHandler.populatePortAddressingRules(device.id()); - + if (groupHandlerMap.get(device.id()) == null) { + 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 + // port addressing rules to the driver as well irrespective of whether + // this instance is the master or not. + defaultRoutingHandler.populatePortAddressingRules(device.id()); + } if (mastershipService.isLocalMaster(device.id())) { + DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id()); groupHandler.createGroupsFromSubnetConfig(); + routingRulePopulator.populateSubnetBroadcastRule(device.id()); } } @@ -660,22 +697,33 @@ public class SegmentRoutingManager implements SegmentRoutingService { // for any switch (even if this instance is a SLAVE or not even connected // to the switch). To handle this, a default-group-handler instance is necessary // per switch. - DefaultGroupHandler groupHandler = DefaultGroupHandler - .createGroupHandler(device.id(), appId, - deviceConfiguration, linkService, - flowObjectiveService, - nsNextObjStore, - subnetNextObjStore); - 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 - // port addressing rules to the driver as well, irrespective of whether - // this instance is the master or not. - defaultRoutingHandler.populatePortAddressingRules(device.id()); + if (groupHandlerMap.get(device.id()) == null) { + 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 + // information to process rules (eg. Router IP/MAC); and so, we send + // port addressing rules to the driver as well, irrespective of whether + // this instance is the master or not. + defaultRoutingHandler.populatePortAddressingRules(device.id()); + } if (mastershipService.isLocalMaster(device.id())) { + DefaultGroupHandler groupHandler = groupHandlerMap.get(device.id()); groupHandler.createGroupsFromSubnetConfig(); + routingRulePopulator.populateSubnetBroadcastRule(device.id()); } } @@ -696,4 +744,205 @@ public class SegmentRoutingManager implements SegmentRoutingService { } } } + + private class InternalHostListener implements HostListener { + private ForwardingObjective.Builder getForwardingObjectiveBuilder( + MacAddress mac, VlanId vlanId, PortNumber port) { + TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder(); + sbuilder.matchEthDst(mac); + sbuilder.matchVlanId(vlanId); + + TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder(); + // TODO Move popVlan from flow action to group action + tbuilder.immediate().popVlan(); + tbuilder.immediate().setOutput(port); + + return DefaultForwardingObjective.builder() + .withFlag(ForwardingObjective.Flag.SPECIFIC) + .withSelector(sbuilder.build()) + .withTreatment(tbuilder.build()) + .withPriority(100) + .fromApp(appId) + .makePermanent(); + } + + private void processHostAddedEvent(HostEvent event) { + MacAddress mac = event.subject().mac(); + VlanId vlanId = event.subject().vlan(); + DeviceId deviceId = event.subject().location().deviceId(); + PortNumber port = event.subject().location().port(); + Set<IpAddress> ips = event.subject().ipAddresses(); + log.debug("Host {}/{} is added at {}:{}", mac, vlanId, deviceId, port); + + // TODO Move bridging table population to a separate class + // Populate bridging table entry + ForwardingObjective.Builder fob = + getForwardingObjectiveBuilder(mac, vlanId, port); + flowObjectiveService.forward(deviceId, fob.add( + new BridgingTableObjectiveContext(mac, vlanId) + )); + + // Populate IP table entry + ips.forEach(ip -> { + if (ip.isIp4()) { + routingRulePopulator.populateIpRuleForHost( + deviceId, ip.getIp4Address(), mac, port); + } + }); + } + + private void processHostRemoveEvent(HostEvent event) { + MacAddress mac = event.subject().mac(); + VlanId vlanId = event.subject().vlan(); + DeviceId deviceId = event.subject().location().deviceId(); + PortNumber port = event.subject().location().port(); + Set<IpAddress> ips = event.subject().ipAddresses(); + log.debug("Host {}/{} is removed from {}:{}", mac, vlanId, deviceId, port); + + // Revoke bridging table entry + ForwardingObjective.Builder fob = + getForwardingObjectiveBuilder(mac, vlanId, port); + flowObjectiveService.forward(deviceId, fob.remove( + new BridgingTableObjectiveContext(mac, vlanId) + )); + + // Revoke IP table entry + ips.forEach(ip -> { + if (ip.isIp4()) { + routingRulePopulator.revokeIpRuleForHost( + deviceId, ip.getIp4Address(), mac, port); + } + }); + } + + private void processHostMovedEvent(HostEvent event) { + MacAddress mac = event.subject().mac(); + VlanId vlanId = event.subject().vlan(); + DeviceId prevDeviceId = event.prevSubject().location().deviceId(); + PortNumber prevPort = event.prevSubject().location().port(); + Set<IpAddress> prevIps = event.prevSubject().ipAddresses(); + DeviceId newDeviceId = event.subject().location().deviceId(); + PortNumber newPort = event.subject().location().port(); + Set<IpAddress> newIps = event.subject().ipAddresses(); + log.debug("Host {}/{} is moved from {}:{} to {}:{}", + mac, vlanId, prevDeviceId, prevPort, newDeviceId, newPort); + + // Revoke previous bridging table entry + ForwardingObjective.Builder prevFob = + getForwardingObjectiveBuilder(mac, vlanId, prevPort); + flowObjectiveService.forward(prevDeviceId, prevFob.remove( + new BridgingTableObjectiveContext(mac, vlanId) + )); + + // Revoke previous IP table entry + prevIps.forEach(ip -> { + if (ip.isIp4()) { + routingRulePopulator.revokeIpRuleForHost( + prevDeviceId, ip.getIp4Address(), mac, prevPort); + } + }); + + // Populate new bridging table entry + ForwardingObjective.Builder newFob = + getForwardingObjectiveBuilder(mac, vlanId, prevPort); + flowObjectiveService.forward(newDeviceId, newFob.add( + new BridgingTableObjectiveContext(mac, vlanId) + )); + + // Populate new IP table entry + newIps.forEach(ip -> { + if (ip.isIp4()) { + routingRulePopulator.populateIpRuleForHost( + newDeviceId, ip.getIp4Address(), mac, newPort); + } + }); + } + + private void processHostUpdatedEvent(HostEvent event) { + MacAddress mac = event.subject().mac(); + VlanId vlanId = event.subject().vlan(); + DeviceId prevDeviceId = event.prevSubject().location().deviceId(); + PortNumber prevPort = event.prevSubject().location().port(); + Set<IpAddress> prevIps = event.prevSubject().ipAddresses(); + DeviceId newDeviceId = event.subject().location().deviceId(); + PortNumber newPort = event.subject().location().port(); + Set<IpAddress> newIps = event.subject().ipAddresses(); + log.debug("Host {}/{} is updated", mac, vlanId); + + // Revoke previous IP table entry + prevIps.forEach(ip -> { + if (ip.isIp4()) { + routingRulePopulator.revokeIpRuleForHost( + prevDeviceId, ip.getIp4Address(), mac, prevPort); + } + }); + + // Populate new IP table entry + newIps.forEach(ip -> { + if (ip.isIp4()) { + routingRulePopulator.populateIpRuleForHost( + newDeviceId, ip.getIp4Address(), mac, newPort); + } + }); + } + + @Override + public void event(HostEvent event) { + // Do not proceed without mastership + DeviceId deviceId = event.subject().location().deviceId(); + if (!mastershipService.isLocalMaster(deviceId)) { + return; + } + + switch (event.type()) { + case HOST_ADDED: + processHostAddedEvent(event); + break; + case HOST_MOVED: + processHostMovedEvent(event); + break; + case HOST_REMOVED: + processHostRemoveEvent(event); + break; + case HOST_UPDATED: + processHostUpdatedEvent(event); + break; + default: + log.warn("Unsupported host event type: {}", event.type()); + break; + } + } + } + + private static class BridgingTableObjectiveContext implements ObjectiveContext { + final MacAddress mac; + final VlanId vlanId; + + BridgingTableObjectiveContext(MacAddress mac, VlanId vlanId) { + this.mac = mac; + this.vlanId = vlanId; + } + + @Override + public void onSuccess(Objective objective) { + if (objective.op() == Objective.Operation.ADD) { + log.debug("Successfully populate bridging table entry for {}/{}", + mac, vlanId); + } else { + log.debug("Successfully revoke bridging table entry for {}/{}", + mac, vlanId); + } + } + + @Override + public void onError(Objective objective, ObjectiveError error) { + if (objective.op() == Objective.Operation.ADD) { + log.debug("Fail to populate bridging table entry for {}/{}. {}", + mac, vlanId, error); + } else { + log.debug("Fail to revoke bridging table entry for {}/{}. {}", + mac, vlanId, error); + } + } + } } 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/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowEventListener.java b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfigNotFoundException.java index 5deccf5e..ae156e60 100644 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowEventListener.java +++ b/framework/src/onos/apps/segmentrouting/src/main/java/org/onosproject/segmentrouting/config/DeviceConfigNotFoundException.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 Open Networking Laboratory + * 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. @@ -13,21 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.openflow.controller; - -import org.projectfloodlight.openflow.protocol.OFMessage; +package org.onosproject.segmentrouting.config; /** - * Notifies providers about openflow msg events. + * Signals that an error occurred during reading device configuration. */ -public interface OpenFlowEventListener { +public class DeviceConfigNotFoundException extends Exception { /** - * Handles the message event. + * Creates a new ConfigNotFoundException with the given message. * - * @param dpid switch data path identifier - * @param msg the message + * @param message exception message */ - void handleMessage(Dpid dpid, OFMessage msg); + public DeviceConfigNotFoundException(String message) { + super(message); + } } 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/config/DeviceConfiguration.java index 828c51ce..0ad00679 100644 --- 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/config/DeviceConfiguration.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.segmentrouting; +package org.onosproject.segmentrouting.config; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; @@ -26,9 +26,7 @@ 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; @@ -126,23 +124,20 @@ public class DeviceConfiguration implements DeviceProperties { }); } - /** - * Returns the Node segment id of a segment router. - * - * @param deviceId device identifier - * @return segment id - */ @Override - public int getSegmentId(DeviceId deviceId) { + 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 { - log.warn("getSegmentId for device {} " - + "throwing IllegalStateException " - + "because device does not exist in config", deviceId); - throw new IllegalStateException(); + String message = "getSegmentId fails for device: " + deviceId + "."; + throw new DeviceConfigNotFoundException(message); } } @@ -180,71 +175,42 @@ public class DeviceConfiguration implements DeviceProperties { return -1; } - /** - * Returns the router mac of a segment router. - * - * @param deviceId device identifier - * @return router mac address - */ @Override - public MacAddress getDeviceMac(DeviceId deviceId) { + 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 { - log.warn("getDeviceMac for device {} " - + "throwing IllegalStateException " - + "because device does not exist in config", deviceId); - throw new IllegalStateException(); + String message = "getDeviceMac fails for device: " + deviceId + "."; + throw new DeviceConfigNotFoundException(message); } } - /** - * Returns the router ip address of a segment router. - * - * @param deviceId device identifier - * @return router ip address - */ - public Ip4Address getRouterIp(DeviceId deviceId) { + @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 { - log.warn("getRouterIp for device {} " - + "throwing IllegalStateException " - + "because device does not exist in config", deviceId); - throw new IllegalStateException(); + String message = "getRouterIp fails for device: " + deviceId + "."; + throw new DeviceConfigNotFoundException(message); } } - /** - * 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) { + 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 { - log.warn("isEdgeDevice for device {} " - + "throwing IllegalStateException " - + "because device does not exist in config", deviceId); - throw new IllegalStateException(); + String message = "isEdgeDevice fails for device: " + deviceId + "."; + throw new DeviceConfigNotFoundException(message); } } - /** - * Returns the node segment ids of all configured segment routers. - * - * @return list of node segment ids - */ @Override public List<Integer> getAllDeviceSegmentIds() { return allSegmentIds; 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/config/DeviceProperties.java index d28d38d5..a39c9567 100644 --- 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/config/DeviceProperties.java @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.segmentrouting.grouphandler; +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; @@ -30,28 +31,48 @@ import org.onosproject.net.PortNumber; */ 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); + 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); + 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); + boolean isEdgeDevice(DeviceId deviceId) throws DeviceConfigNotFoundException; /** * Returns all segment IDs to be considered in building auto 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..b394db5e 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<Integer> 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<SubnetNextObjectiveStoreKey, - Integer> 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,13 +220,12 @@ 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() - .setMpls(MplsLabel. - mplsLabel(ns.getEdgeLabel())); + .copyTtlOut() + .setMpls(MplsLabel.mplsLabel(ns.getEdgeLabel())); } Integer nextId = nsNextObjStore. @@ -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<NeighborSet> nsSet = computeImpactedNeighborsetForPortEvent(portDeviceMap @@ -263,11 +289,12 @@ 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())); + tBuilder.pushMpls() + .copyTtlOut() + .setMpls(MplsLabel.mplsLabel(ns.getEdgeLabel())); } Integer nextId = nsNextObjStore. @@ -432,7 +459,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<Integer> getSegmentIdsTobePairedWithNeighborSet(Set<DeviceId> neighbors) { @@ -487,15 +522,24 @@ 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 - .getEdgeLabel())); + tBuilder.pushMpls() + .copyTtlOut() + .setMpls(MplsLabel.mplsLabel(ns.getEdgeLabel())); } nextObjBuilder.addTreatment(tBuilder.build()); } @@ -535,6 +579,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/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<GroupBucket> 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/test/demo/src/main/java/org/onosproject/demo/DemoAPI.java b/framework/src/onos/apps/test/demo/src/main/java/org/onosproject/demo/DemoApi.java index 00956763..1e594157 100644 --- a/framework/src/onos/apps/test/demo/src/main/java/org/onosproject/demo/DemoAPI.java +++ b/framework/src/onos/apps/test/demo/src/main/java/org/onosproject/demo/DemoApi.java @@ -22,7 +22,7 @@ import java.util.Optional; /** * Simple demo api interface. */ -public interface DemoAPI { +public interface DemoApi { enum InstallType { MESH, RANDOM } diff --git a/framework/src/onos/apps/test/demo/src/main/java/org/onosproject/demo/DemoInstaller.java b/framework/src/onos/apps/test/demo/src/main/java/org/onosproject/demo/DemoInstaller.java index a408e695..0bddc083 100644 --- a/framework/src/onos/apps/test/demo/src/main/java/org/onosproject/demo/DemoInstaller.java +++ b/framework/src/onos/apps/test/demo/src/main/java/org/onosproject/demo/DemoInstaller.java @@ -87,7 +87,7 @@ import static org.slf4j.LoggerFactory.getLogger; */ @Component(immediate = true) @Service -public class DemoInstaller implements DemoAPI { +public class DemoInstaller implements DemoApi { private final Logger log = getLogger(getClass()); diff --git a/framework/src/onos/apps/test/demo/src/main/java/org/onosproject/demo/DemoResource.java b/framework/src/onos/apps/test/demo/src/main/java/org/onosproject/demo/DemoResource.java index e0c97dd8..e3a5a2d8 100644 --- a/framework/src/onos/apps/test/demo/src/main/java/org/onosproject/demo/DemoResource.java +++ b/framework/src/onos/apps/test/demo/src/main/java/org/onosproject/demo/DemoResource.java @@ -51,7 +51,7 @@ public class DemoResource extends BaseResource { public Response flowTest(InputStream input) throws IOException { ObjectMapper mapper = new ObjectMapper(); JsonNode cfg = mapper.readTree(input); - DemoAPI demo = get(DemoAPI.class); + DemoApi demo = get(DemoApi.class); return Response.ok(demo.flowTest(Optional.ofNullable(cfg)).toString()).build(); } @@ -75,9 +75,9 @@ public class DemoResource extends BaseResource { } - DemoAPI.InstallType type = DemoAPI.InstallType.valueOf( + DemoApi.InstallType type = DemoApi.InstallType.valueOf( cfg.get("type").asText().toUpperCase()); - DemoAPI demo = get(DemoAPI.class); + DemoApi demo = get(DemoApi.class); demo.setup(type, Optional.ofNullable(cfg.get("runParams"))); return Response.ok(mapper.createObjectNode().toString()).build(); @@ -93,7 +93,7 @@ public class DemoResource extends BaseResource { @Produces(MediaType.APPLICATION_JSON) public Response tearDown() { ObjectMapper mapper = new ObjectMapper(); - DemoAPI demo = get(DemoAPI.class); + DemoApi demo = get(DemoApi.class); demo.tearDown(); return Response.ok(mapper.createObjectNode().toString()).build(); } diff --git a/framework/src/onos/apps/vtn/app/pom.xml b/framework/src/onos/apps/vtn/app/pom.xml index 4ed66172..5a877363 100644 --- a/framework/src/onos/apps/vtn/app/pom.xml +++ b/framework/src/onos/apps/vtn/app/pom.xml @@ -1,44 +1,44 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- ~ Copyright 2014 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. --> +<!-- ~ Copyright 2014 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. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> + <parent> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn</artifactId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> - <artifactId>onos-app-vtn-onosfw</artifactId> - <packaging>pom</packaging> + <artifactId>onos-app-vtn-onosfw</artifactId> + <packaging>pom</packaging> - <description>ONOS framework applications</description> + <description>ONOS framework applications</description> - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn-rsc</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn-web</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn-mgr</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn-rsc</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn-web</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn-mgr</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> </project> diff --git a/framework/src/onos/apps/vtn/pom.xml b/framework/src/onos/apps/vtn/pom.xml index e91b0c9b..a42f91a0 100644 --- a/framework/src/onos/apps/vtn/pom.xml +++ b/framework/src/onos/apps/vtn/pom.xml @@ -32,6 +32,7 @@ <description>ONOS framework applications</description> <modules> + <module>sfcmgr</module> <module>vtnrsc</module> <module>vtnmgr</module> <module>vtnweb</module> @@ -53,5 +54,25 @@ <artifactId>easymock</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onlab-osgi</artifactId> + <classifier>tests</classifier> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.sun.jersey</groupId> + <artifactId>jersey-servlet</artifactId> + </dependency> + <dependency> + <groupId>com.sun.jersey.jersey-test-framework</groupId> + <artifactId>jersey-test-framework-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.sun.jersey.jersey-test-framework</groupId> + <artifactId>jersey-test-framework-grizzly2</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/SfcService.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/SfcService.java deleted file mode 100644 index a2748f5e..00000000 --- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/SfcService.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.sfc; - -import org.onosproject.vtnrsc.PortChain; - -/** - * SFC application that applies flows to the device. - */ -public interface SfcService { - /** - * Applies flow classification to OVS. - * - * @param portChain Port-Chain. - */ - void InstallFlowClassification(PortChain portChain); - - - /** - * Remove flow classification from OVS. - * - * @param portChain Port-Chain. - */ - void UnInstallFlowClassification(PortChain portChain); - - /** - * Applies Service Function chain to OVS. - * - * @param portChain Port-Chain. - */ - void InstallServiceFunctionChain(PortChain portChain); - - /** - * Remove Service Function chain from OVS. - * - * @param portChain Port-Chain. - */ - void UnInstallServiceFunctionChain(PortChain portChain); -} diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/SfcManager.java b/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/SfcManager.java deleted file mode 100644 index 1872295f..00000000 --- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/SfcManager.java +++ /dev/null @@ -1,69 +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.sfc.impl; - -import static org.slf4j.LoggerFactory.getLogger; - -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.Service; -import org.onosproject.vtnrsc.sfc.PortChain; -import org.slf4j.Logger; - -/** - * Provides implementation of SFC Service. - */ -@Component(immediate = true) -@Service -public class SfcManager implements SfcService { - - private final Logger log = getLogger(SfcManager.class); - - @Activate - public void activate() { - log.info("Started"); - } - - @Deactivate - public void deactivate() { - log.info("Stopped"); - } - - @Override - public void InstallFlowClassification(PortChain portChain) { - log.debug("InstallFlowClassification"); - //TODO: Installation of flow classification into OVS. - } - - @Override - public void UnInstallFlowClassification(PortChain portChain) { - log.debug("UnInstallFlowClassification"); - //TODO: Un-installation flow classification from OVS - } - - @Override - public void InstallServiceFunctionChain(PortChain portChain) { - log.debug("InstallServiceFunctionChain"); - //TODO: Installation of Service Function chain into OVS. - } - - @Override - public void UnInstallServiceFunctionChain(PortChain portChain) { - log.debug("UnInstallServiceFunctionChain"); - //TODO: Un-installation of Service Function chain from OVS. - } -} diff --git a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/VTNService.java b/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/VTNService.java deleted file mode 100644 index a20f852b..00000000 --- a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/VTNService.java +++ /dev/null @@ -1,68 +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.vtn; - -import org.onosproject.net.Device; -import org.onosproject.net.Host; - -/** - * VTN application that applies configuration and flows to the device. - */ -public interface VTNService { - - /** - * Creates a vxlan tunnel and creates the ovs when a ovs controller node is detected. - * - * @param device controller-type device - */ - void onServerDetected(Device device); - - /** - * Drops a vxlan tunnel and drops the ovs when a ovs controller node is vanished. - * - * @param device controller-type device - */ - void onServerVanished(Device device); - - /** - * Applies default forwarding flows when a ovs is detected. - * - * @param device switch-type device - */ - void onOvsDetected(Device device); - - /** - * Remove default forwarding flows when a ovs is vanished. - * - * @param device switch-type device - */ - void onOvsVanished(Device device); - - /** - * Applies multicast flows and tunnel flows when a VM is detected. - * - * @param host a VM - */ - void onHostDetected(Host host); - - /** - * Remove multicast flows and tunnel flows when a VM is vanished. - * - * @param host a VM - */ - void onHostVanished(Host host); - -} diff --git a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/VTNManager.java b/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/VTNManager.java deleted file mode 100644 index 090ef0f1..00000000 --- a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/VTNManager.java +++ /dev/null @@ -1,672 +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.vtn.impl; - -import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; -import static org.onlab.util.Tools.groupedThreads; -import static org.slf4j.LoggerFactory.getLogger; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ScheduledExecutorService; -import java.util.stream.Collectors; - -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.onlab.osgi.DefaultServiceDirectory; -import org.onlab.osgi.ServiceDirectory; -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onlab.util.KryoNamespace; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Host; -import org.onosproject.net.HostId; -import org.onosproject.net.Port; -import org.onosproject.net.PortNumber; -import org.onosproject.net.behaviour.BridgeConfig; -import org.onosproject.net.behaviour.BridgeDescription; -import org.onosproject.net.behaviour.BridgeName; -import org.onosproject.net.behaviour.DefaultTunnelDescription; -import org.onosproject.net.behaviour.IpTunnelEndPoint; -import org.onosproject.net.behaviour.Pipeliner; -import org.onosproject.net.behaviour.PipelinerContext; -import org.onosproject.net.behaviour.TunnelConfig; -import org.onosproject.net.behaviour.TunnelDescription; -import org.onosproject.net.behaviour.TunnelEndPoint; -import org.onosproject.net.device.DeviceEvent; -import org.onosproject.net.device.DeviceListener; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.driver.DefaultDriverData; -import org.onosproject.net.driver.Driver; -import org.onosproject.net.driver.DriverHandler; -import org.onosproject.net.driver.DriverService; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.FlowRuleService; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.flow.criteria.Criteria; -import org.onosproject.net.flow.instructions.Instructions; -import org.onosproject.net.flowobjective.DefaultForwardingObjective; -import org.onosproject.net.flowobjective.FlowObjectiveService; -import org.onosproject.net.flowobjective.FlowObjectiveStore; -import org.onosproject.net.flowobjective.ForwardingObjective; -import org.onosproject.net.flowobjective.ForwardingObjective.Flag; -import org.onosproject.net.flowobjective.Objective; -import org.onosproject.net.host.HostEvent; -import org.onosproject.net.host.HostListener; -import org.onosproject.net.host.HostService; -import org.onosproject.store.serializers.KryoNamespaces; -import org.onosproject.store.service.EventuallyConsistentMap; -import org.onosproject.store.service.StorageService; -import org.onosproject.store.service.WallClockTimestamp; -import org.onosproject.vtn.VTNService; -import org.onosproject.vtnrsc.SegmentationId; -import org.onosproject.vtnrsc.TenantNetwork; -import org.onosproject.vtnrsc.VirtualPort; -import org.onosproject.vtnrsc.VirtualPortId; -import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService; -import org.onosproject.vtnrsc.virtualport.VirtualPortService; -import org.slf4j.Logger; - -import com.google.common.collect.Sets; - -/** - * Provides implementation of VTNService. - */ -@Component(immediate = true) -@Service -public class VTNManager implements VTNService { - private final Logger log = getLogger(getClass()); - - private static final String APP_ID = "org.onosproject.app.vtn"; - private ScheduledExecutorService backgroundService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceService deviceService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected HostService hostService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected FlowRuleService flowRuleService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected StorageService storageService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected TenantNetworkService tenantNetworkService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected VirtualPortService virtualPortService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DriverService driverService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected FlowObjectiveService flowObjectiveService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected FlowObjectiveStore flowObjectiveStore; - protected ServiceDirectory serviceDirectory = new DefaultServiceDirectory(); - private EventuallyConsistentMap<HostId, SegmentationId> binding; - private ApplicationId appId; - private HostListener hostListener = new InnerHostListener(); - private DeviceListener deviceListener = new InnerDeviceListener(); - private static final String IFACEID = "ifaceid"; - private static final String PORT_HEAD = "vxlan"; - private static final String DEFAULT_BRIDGE_NAME = "br-int"; - private static final String CONTROLLER_IP_KEY = "ipaddress"; - private static final int DEFAULT_MAC_PRIORITY = 0x0000; - private static final int MAC_PRIORITY = 0xffff; - private static final int DEFAULT_PORT_PRIORITY = 0x0000; - private static final int PORT_PRIORITY = 0xffff; - private static final String SWITCH_CHANNEL_ID = "channelId"; - private static final String DRIVER_NAME = "onosfw"; - - @Activate - public void activate() { - KryoNamespace.Builder serializer = KryoNamespace.newBuilder() - .register(KryoNamespaces.API); - appId = coreService.registerApplication(APP_ID); - deviceService.addListener(deviceListener); - hostService.addListener(hostListener); - backgroundService = newSingleThreadScheduledExecutor(groupedThreads("onos-apps/vtn", - "manager-background")); - binding = storageService - .<HostId, SegmentationId>eventuallyConsistentMapBuilder() - .withName("all_tunnel").withSerializer(serializer) - .withTimestampProvider((k, v) -> new WallClockTimestamp()) - .build(); - log.info("Started"); - } - - @Deactivate - public void deactivate() { - backgroundService.shutdown(); - binding.destroy(); - log.info("Stopped"); - } - - @Override - public void onServerDetected(Device device) { - Iterable<Device> devices = deviceService.getAvailableDevices(); - DriverHandler handler = driverService.createHandler(device.id()); - BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); - bridgeConfig.addBridge(BridgeName.bridgeName(DEFAULT_BRIDGE_NAME)); - String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); - IpAddress ip = IpAddress.valueOf(ipAddress); - Sets.newHashSet(devices).stream() - .filter(d -> Device.Type.CONTROLLER == d.type()) - .filter(d -> !device.id().equals(d.id())).forEach(d -> { - String ipAddress1 = d.annotations() - .value(CONTROLLER_IP_KEY); - IpAddress ip1 = IpAddress.valueOf(ipAddress1); - applyTunnelConfig(ip, ip1, handler); - DriverHandler handler1 = driverService - .createHandler(d.id()); - applyTunnelConfig(ip1, ip, handler1); - - }); - } - - @Override - public void onServerVanished(Device device) { - Iterable<Device> devices = deviceService.getAvailableDevices(); - String ipAddress = device.annotations().value(CONTROLLER_IP_KEY); - IpAddress dst = IpAddress.valueOf(ipAddress); - Sets.newHashSet(devices).stream() - .filter(d -> d.type() == Device.Type.CONTROLLER) - .filter(d -> !device.id().equals(d.id())).forEach(d -> { - String ipAddress1 = d.annotations() - .value(CONTROLLER_IP_KEY); - DriverHandler handler = driverService.createHandler(d.id()); - IpAddress src = IpAddress.valueOf(ipAddress1); - removeTunnelConfig(src, dst, handler); - }); - } - - private void applyTunnelConfig(IpAddress src, IpAddress dst, - DriverHandler handler) { - TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(src); - TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dst); - TunnelDescription tunnel = new DefaultTunnelDescription( - tunnelAsSrc, - tunnelAsDst, - TunnelDescription.Type.VXLAN, - null); - TunnelConfig config = handler.behaviour(TunnelConfig.class); - config.createTunnel(tunnel); - } - - private void removeTunnelConfig(IpAddress src, IpAddress dst, - DriverHandler handler) { - TunnelEndPoint tunnelAsSrc = IpTunnelEndPoint.ipTunnelPoint(src); - TunnelEndPoint tunnelAsDst = IpTunnelEndPoint.ipTunnelPoint(dst); - TunnelDescription tunnel = new DefaultTunnelDescription( - tunnelAsSrc, - tunnelAsDst, - TunnelDescription.Type.VXLAN, - null); - TunnelConfig config = handler.behaviour(TunnelConfig.class); - config.removeTunnel(tunnel); - } - - @Override - public void onOvsDetected(Device device) { - programMacDefaultRules(device.id(), appId, Objective.Operation.ADD); - programPortDefaultRules(device.id(), appId, Objective.Operation.ADD); - } - - @Override - public void onOvsVanished(Device device) { - programMacDefaultRules(device.id(), appId, Objective.Operation.REMOVE); - programPortDefaultRules(device.id(), appId, Objective.Operation.REMOVE); - } - - @Override - public void onHostDetected(Host host) { - String ifaceId = host.annotations().value(IFACEID); - DeviceId deviceId = host.location().deviceId(); - String currentControllerIp = getControllerIpOfSwitch(deviceId); - Iterable<Device> devices = deviceService.getAvailableDevices(); - VirtualPortId portId = VirtualPortId.portId(ifaceId); - VirtualPort port = virtualPortService.getPort(portId); - TenantNetwork network = tenantNetworkService - .getNetwork(port.networkId()); - String tunnelName = "vxlan-" + currentControllerIp; - binding.put(host.id(), network.segmentationId()); - List<Port> allPorts = deviceService.getPorts(deviceId); - PortNumber inPort = host.location().port(); - List<PortNumber> localVmPorts = getLocalPorts(deviceId, ifaceId); - List<PortNumber> localTunnelPorts = new ArrayList<>(); - Sets.newHashSet(allPorts.iterator()).stream() - .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { - if (p.annotations().value("portName").startsWith(PORT_HEAD)) { - localTunnelPorts.add(p.number()); - } - }); - - localVmPorts.forEach(lp -> programLocalBcastRules(deviceId, network.segmentationId(), lp, localVmPorts, - localTunnelPorts, appId, Objective.Operation.ADD)); - programLocalOut(deviceId, network.segmentationId(), inPort, host.mac(), - appId, Objective.Operation.ADD); - localTunnelPorts - .forEach(tp -> programTunnelFloodOut(deviceId, - network.segmentationId(), - tp, localVmPorts, - appId, - Objective.Operation.ADD)); - Sets.newHashSet(devices).stream() - .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> { - DriverHandler handler = driverService.createHandler(d.id()); - BridgeConfig bridgeConfig = handler - .behaviour(BridgeConfig.class); - Collection<BridgeDescription> bridgeDescriptions = bridgeConfig - .getBridges(); - - Iterator<BridgeDescription> it = bridgeDescriptions - .iterator(); - if (it.hasNext()) { - BridgeDescription sw = it.next(); - Set<PortNumber> ports = bridgeConfig.getPortNumbers(); - ports.stream() - .filter(p -> p.name() - .equalsIgnoreCase(tunnelName)) - .forEach(p -> programTunnelOut(sw.deviceId(), - network.segmentationId(), p, - host.mac(), appId, - Objective.Operation.ADD)); - } - }); - programLocalIn(deviceId, network.segmentationId(), inPort, host.mac(), - appId, Objective.Operation.ADD); - localTunnelPorts - .forEach(tp -> programTunnelIn(deviceId, - network.segmentationId(), - tp, inPort, host.mac(), - appId, Objective.Operation.ADD)); - - } - - @Override - public void onHostVanished(Host host) { - String ifaceId = host.annotations().value(IFACEID); - SegmentationId segId = binding.remove(host.id()); - DeviceId deviceId = host.location().deviceId(); - String currentControllerIp = getControllerIpOfSwitch(deviceId); - Iterable<Device> devices = deviceService.getAvailableDevices(); - - String tunnelName = "vxlan-" + currentControllerIp; - List<Port> allPorts = deviceService.getPorts(deviceId); - PortNumber inPort = host.location().port(); - - List<PortNumber> localTunnelPorts = new ArrayList<>(); - Sets.newHashSet(allPorts.iterator()).stream() - .filter(p -> !p.number().equals(PortNumber.LOCAL)).forEach(p -> { - if (p.annotations().value("portName").startsWith(PORT_HEAD)) { - localTunnelPorts.add(p.number()); - } - }); - - List<PortNumber> localVmPorts = getLocalPorts(deviceId, ifaceId); - localVmPorts.add(inPort); - localVmPorts.forEach(lp -> programLocalBcastRules(deviceId, segId, lp, localVmPorts, - localTunnelPorts, appId, Objective.Operation.REMOVE)); - programLocalOut(deviceId, segId, inPort, host.mac(), - appId, Objective.Operation.REMOVE); - localTunnelPorts - .forEach(tp -> programTunnelFloodOut(deviceId, - segId, - tp, localVmPorts, - appId, - Objective.Operation.REMOVE)); - Sets.newHashSet(devices).stream() - .filter(d -> d.type() == Device.Type.CONTROLLER).forEach(d -> { - DriverHandler handler = driverService.createHandler(d.id()); - BridgeConfig bridgeConfig = handler - .behaviour(BridgeConfig.class); - Collection<BridgeDescription> bridgeDescriptions = bridgeConfig - .getBridges(); - - Iterator<BridgeDescription> it = bridgeDescriptions - .iterator(); - if (it.hasNext()) { - BridgeDescription sw = it.next(); - Set<PortNumber> ports = bridgeConfig.getPortNumbers(); - ports.stream() - .filter(p -> p.name() - .equalsIgnoreCase(tunnelName)) - .forEach(p -> programTunnelOut(sw.deviceId(), - segId, p, - host.mac(), appId, - Objective.Operation.REMOVE)); - } - }); - programLocalIn(deviceId, segId, inPort, host.mac(), - appId, Objective.Operation.REMOVE); - localTunnelPorts - .forEach(tp -> programTunnelIn(deviceId, - segId, - tp, inPort, host.mac(), - appId, Objective.Operation.REMOVE)); - } - - private class InnerDeviceListener implements DeviceListener { - - @Override - public void event(DeviceEvent event) { - Device device = event.subject(); - if (Device.Type.CONTROLLER == device.type() - && DeviceEvent.Type.DEVICE_ADDED == event.type()) { - backgroundService.execute(() -> onServerDetected(device)); - } else if (Device.Type.CONTROLLER == device.type() - && DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED == event - .type()) { - backgroundService.execute(() -> onServerVanished(device)); - } else if (Device.Type.SWITCH == device.type() - && DeviceEvent.Type.DEVICE_ADDED == event.type()) { - backgroundService.execute(() -> onOvsDetected(device)); - } else if (Device.Type.SWITCH == device.type() - && DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED == event - .type()) { - backgroundService.execute(() -> onOvsVanished(device)); - } else { - log.info("Do nothing for this device type"); - } - } - - } - - private class InnerHostListener implements HostListener { - - @Override - public void event(HostEvent event) { - Host host = event.subject(); - if (HostEvent.Type.HOST_ADDED == event.type()) { - backgroundService.execute(() -> onHostDetected(host)); - } else if (HostEvent.Type.HOST_REMOVED == event.type()) { - backgroundService.execute(() -> onHostVanished(host)); - } else if (HostEvent.Type.HOST_UPDATED == event.type()) { - backgroundService.execute(() -> { - onHostVanished(host); - onHostDetected(host); - }); - } - } - - } - - // Used to forward the flows to the local VM. - private void programLocalOut(DeviceId dpid, SegmentationId segmentationId, - PortNumber outPort, MacAddress sourceMac, - ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder() - .matchTunnelId(Long.parseLong(segmentationId.toString())) - .matchEthDst(sourceMac).build(); - TrafficTreatment treatment = DefaultTrafficTreatment.builder() - .setOutput(outPort).build(); - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment).withSelector(selector) - .fromApp(appId).withFlag(Flag.SPECIFIC) - .withPriority(MAC_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(dpid, objective.add()); - } else { - flowServiceForward(dpid, objective.remove()); - } - - } - - // Used to forward the flows into the VXLAN tunnel. - private void programTunnelOut(DeviceId dpid, SegmentationId segmentationId, - PortNumber tunnelOutPort, MacAddress dstMac, - ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder() - .matchEthDst(dstMac).add(Criteria.matchTunnelId(Long - .parseLong(segmentationId.toString()))) - .build(); - TrafficTreatment treatment = DefaultTrafficTreatment.builder() - - .setOutput(tunnelOutPort).build(); - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment).withSelector(selector) - .fromApp(appId).withFlag(Flag.SPECIFIC) - .withPriority(MAC_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(dpid, objective.add()); - } else { - flowServiceForward(dpid, objective.remove()); - } - - } - - // Used to forward multicast flows to remote VMs of the same tenant via - // VXLAN tunnel. - private void programTunnelFloodOut(DeviceId deviceId, - SegmentationId segmentationId, - PortNumber ofPortOut, - List<PortNumber> localVmPorts, - ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder() - .matchInPort(ofPortOut) - - .add(Criteria.matchTunnelId(Long.parseLong(segmentationId - .toString()))).matchEthDst(MacAddress.BROADCAST) - .build(); - TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); - - for (PortNumber outPort : localVmPorts) { - treatment.setOutput(outPort); - } - - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment.build()) - .withSelector(selector).fromApp(appId).makePermanent() - .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(deviceId, objective.add()); - } else { - flowServiceForward(deviceId, objective.remove()); - } - } - - // Applies default flows to mac table. - private void programMacDefaultRules(DeviceId dpid, ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder().build(); - TrafficTreatment treatment = DefaultTrafficTreatment.builder().drop() - .build(); - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment).withSelector(selector) - .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) - .withPriority(DEFAULT_MAC_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(dpid, objective.add()); - } else { - flowServiceForward(dpid, objective.remove()); - } - } - - // Used to forward the flows to the local VMs with the same tenant. - private void programLocalBcastRules(DeviceId deviceId, - SegmentationId segmentationId, - PortNumber inPort, - List<PortNumber> localVmPorts, - List<PortNumber> localTunnelPorts, - ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder() - .matchInPort(inPort).matchEthDst(MacAddress.BROADCAST) - .add(Criteria.matchTunnelId(Long - .parseLong(segmentationId.toString()))) - .build(); - TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); - for (PortNumber outPort : localVmPorts) { - if (inPort != outPort) { - treatment.setOutput(outPort); - } - } - for (PortNumber outport : localTunnelPorts) { - treatment.setOutput(outport); - } - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment.build()) - .withSelector(selector).fromApp(appId).makePermanent() - .withFlag(Flag.SPECIFIC).withPriority(MAC_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(deviceId, objective.add()); - } else { - flowServiceForward(deviceId, objective.remove()); - } - } - - // Used to apply local entry flow. - private void programLocalIn(DeviceId dpid, SegmentationId segmentationId, - PortNumber inPort, MacAddress srcMac, - ApplicationId appid, Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder() - .matchInPort(inPort).matchEthSrc(srcMac).build(); - TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); - treatment.add(Instructions.modTunnelId(Long.parseLong(segmentationId - .toString()))); - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment.build()) - .withSelector(selector).fromApp(appId).makePermanent() - .withFlag(Flag.SPECIFIC).withPriority(PORT_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(dpid, objective.add()); - } else { - flowServiceForward(dpid, objective.remove()); - } - } - - // Used to forward the flows from the egress tunnel to the VM. - private void programTunnelIn(DeviceId dpid, SegmentationId segmentationId, - PortNumber tunnelInPort, PortNumber outPort, - MacAddress sourceMac, ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder() - .matchInPort(tunnelInPort).add(Criteria.matchTunnelId(Long - .parseLong(segmentationId.toString()))) - .build(); - TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); - - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment).withSelector(selector) - .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) - .withPriority(PORT_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(dpid, objective.add()); - } else { - flowServiceForward(dpid, objective.remove()); - } - } - - // Applies the default flows to port table. - private void programPortDefaultRules(DeviceId dpid, ApplicationId appid, - Objective.Operation type) { - TrafficSelector selector = DefaultTrafficSelector.builder().build(); - TrafficTreatment treatment = DefaultTrafficTreatment.builder().build(); - ForwardingObjective.Builder objective = DefaultForwardingObjective - .builder().withTreatment(treatment).withSelector(selector) - .fromApp(appId).makePermanent().withFlag(Flag.SPECIFIC) - .withPriority(DEFAULT_PORT_PRIORITY); - if (type.equals(Objective.Operation.ADD)) { - flowServiceForward(dpid, objective.add()); - } else { - flowServiceForward(dpid, objective.remove()); - } - } - - // Used to get channelId from the device annotations. - private String getControllerIpOfSwitch(DeviceId deviceId) { - Device device = deviceService.getDevice(deviceId); - String url = device.annotations().value(SWITCH_CHANNEL_ID); - return url.substring(0, url.lastIndexOf(":")); - } - - private Iterable<String> getIfaceIds(String ifaceId) { - VirtualPortId portId = VirtualPortId.portId(ifaceId); - VirtualPort port = virtualPortService.getPort(portId); - if (port == null) { - return Collections.emptyList(); - } - - TenantNetwork network = tenantNetworkService - .getNetwork(port.networkId()); - if (network == null) { - return Collections.emptyList(); - } - - Collection<VirtualPort> ports = virtualPortService - .getPorts(network.id()); - return ports.stream().map(p -> p.portId().portId()) - .collect(Collectors.toSet()); - } - - private List<PortNumber> getLocalPorts(DeviceId deviceId, String ifaceId) { - DriverHandler handler = driverService - .createHandler(getController(deviceId)); - BridgeConfig bridgeConfig = handler.behaviour(BridgeConfig.class); - Iterable<String> ifaceIds = getIfaceIds(ifaceId); - return bridgeConfig.getLocalPorts(ifaceIds); - } - - private DeviceId getController(DeviceId deviceId) { - Iterable<Device> devices = deviceService.getAvailableDevices(); - for (Device device : devices) { - if (device.type() == Device.Type.CONTROLLER && device.id() - .toString().contains(getControllerIpOfSwitch(deviceId))) { - return device.id(); - } - } - log.info("Can not find controller for device : {}", deviceId); - return null; - } - - //Used to apply flowRule - private void flowServiceForward(DeviceId deviceId, ForwardingObjective forwardingObjective) { - Driver driver = driverService.getDriver(DRIVER_NAME); - Pipeliner pipeLiner = driver.createBehaviour(new DefaultDriverData(driver, deviceId), Pipeliner.class); - if (pipeLiner != null) { - final PipelinerContext context = new InnerPipelineContext(); - pipeLiner.init(deviceId, context); - pipeLiner.forward(forwardingObjective); - } - } - - // Processing context for initializing pipeline driver behaviours. - private class InnerPipelineContext implements PipelinerContext { - @Override - public ServiceDirectory directory() { - return serviceDirectory; - } - - @Override - public FlowObjectiveStore store() { - return flowObjectiveStore; - } - } - -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/pom.xml b/framework/src/onos/apps/vtn/vtnrsc/pom.xml index 8696295c..816624cb 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/pom.xml +++ b/framework/src/onos/apps/vtn/vtnrsc/pom.xml @@ -15,42 +15,42 @@ ~ limitations under the License. --> <project - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" - xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-vtn</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-vtn</artifactId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> - <artifactId>onos-app-vtn-rsc</artifactId> - <packaging>bundle</packaging> + <artifactId>onos-app-vtn-rsc</artifactId> + <packaging>bundle</packaging> - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-api</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-cli</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - <dependency> - <groupId>org.apache.karaf.shell</groupId> - <artifactId>org.apache.karaf.shell.console</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-core-serializers</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-api</artifactId> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-cli</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr.annotations</artifactId> + </dependency> + <dependency> + <groupId>org.apache.karaf.shell</groupId> + <artifactId>org.apache.karaf.shell.console</artifactId> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-core-serializers</artifactId> + <version>${project.version}</version> + </dependency> + </dependencies> </project> diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java index c715d08a..7dca32de 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/BindingHostId.java @@ -49,7 +49,7 @@ public final class BindingHostId { @Override public int hashCode() { - return Objects.hash(bindingHostId); + return bindingHostId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java index 39df2cff..7915ce08 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/DefaultFlowClassifier.java @@ -43,6 +43,8 @@ public final class DefaultFlowClassifier implements FlowClassifier { private static final int NULL_PORT = 0; private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "FlowClassifier id can not be null."; private static final String TENANT_ID_NOT_NULL = "Tenant id can not be null."; + private static final String NAME_NOT_NULL = "Name can not be null."; + private static final String ETHER_TYPE_NOT_NULL = "Ether Type can not be null."; /** * Constructor to create default flow classifier. @@ -160,11 +162,9 @@ public final class DefaultFlowClassifier implements FlowClassifier { private FlowClassifierId flowClassifierId; private TenantId tenantId; private String name; - private boolean isFlowClassifierNameSet = false; private String description; private boolean isFlowClassifierDescriptionSet = false; private String etherType; - private boolean isEtherTypeSet = false; private String protocol; private boolean isProtocolSet = false; private int minSrcPortRange; @@ -189,9 +189,9 @@ public final class DefaultFlowClassifier implements FlowClassifier { checkNotNull(flowClassifierId, FLOW_CLASSIFIER_ID_NOT_NULL); checkNotNull(tenantId, TENANT_ID_NOT_NULL); - String name = null; + checkNotNull(name, NAME_NOT_NULL); + checkNotNull(etherType, ETHER_TYPE_NOT_NULL); String description = null; - String etherType = null; String protocol = null; int minSrcPortRange = NULL_PORT; int maxSrcPortRange = NULL_PORT; @@ -202,15 +202,9 @@ public final class DefaultFlowClassifier implements FlowClassifier { VirtualPortId srcPort = null; VirtualPortId dstPort = null; - if (isFlowClassifierNameSet) { - name = this.name; - } if (isFlowClassifierDescriptionSet) { description = this.description; } - if (isEtherTypeSet) { - etherType = this.etherType; - } if (isProtocolSet) { protocol = this.protocol; } @@ -259,7 +253,6 @@ public final class DefaultFlowClassifier implements FlowClassifier { @Override public Builder setName(String name) { this.name = name; - this.isFlowClassifierNameSet = true; return this; } @@ -273,7 +266,6 @@ public final class DefaultFlowClassifier implements FlowClassifier { @Override public Builder setEtherType(String etherType) { this.etherType = etherType; - this.isEtherTypeSet = true; return this; } diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifierId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifierId.java index b789abe3..df180ebe 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifierId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/FlowClassifierId.java @@ -15,6 +15,8 @@ */ package org.onosproject.vtnrsc; +import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.base.MoreObjects; import java.util.UUID; @@ -33,6 +35,7 @@ public final class FlowClassifierId { * @param flowClassifierId flow classifier id. */ private FlowClassifierId(final UUID flowClassifierId) { + checkNotNull(flowClassifierId, "Flow classifier id can not be null"); this.flowClassifierId = flowClassifierId; } @@ -42,7 +45,7 @@ public final class FlowClassifierId { * @param flowClassifierId flow classifier id * @return new flow classifier id */ - public static FlowClassifierId flowClassifierId(final UUID flowClassifierId) { + public static FlowClassifierId of(final UUID flowClassifierId) { return new FlowClassifierId(flowClassifierId); } @@ -52,7 +55,7 @@ public final class FlowClassifierId { * @param flowClassifierId flow classifier id * @return new flow classifier id */ - public static FlowClassifierId flowClassifierId(final String flowClassifierId) { + public static FlowClassifierId of(final String flowClassifierId) { return new FlowClassifierId(UUID.fromString(flowClassifierId)); } diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java index e96e666a..30631d28 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PhysicalNetwork.java @@ -53,7 +53,7 @@ public final class PhysicalNetwork { @Override public int hashCode() { - return Objects.hash(physicalNetwork); + return physicalNetwork.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChainId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChainId.java index 66edbdcc..a42a700f 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChainId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortChainId.java @@ -19,8 +19,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; import static com.google.common.base.Preconditions.checkNotNull; import java.util.UUID; - -import com.google.common.base.Objects; +import java.util.Objects; /** * Representation of a Port Chain ID. @@ -40,22 +39,22 @@ public final class PortChainId { } /** - * Constructor to create port chain id from UUID. + * Returns newly created port chain id object. * * @param id UUID of port chain * @return object of port chain id */ - public static PortChainId portChainId(UUID id) { + public static PortChainId of(UUID id) { return new PortChainId(id); } /** - * Constructor to create port chain id from string. + * Returns newly created port chain id object. * * @param id port chain id in string * @return object of port chain id */ - public static PortChainId portChainId(String id) { + public static PortChainId of(String id) { return new PortChainId(UUID.fromString(id)); } @@ -73,10 +72,9 @@ public final class PortChainId { if (this == obj) { return true; } - - if (obj.getClass() == this.getClass()) { - PortChainId that = (PortChainId) obj; - return Objects.equal(this.portChainId, that.portChainId); + if (obj instanceof PortChainId) { + final PortChainId other = (PortChainId) obj; + return Objects.equals(this.portChainId, other.portChainId); } return false; } @@ -88,8 +86,6 @@ public final class PortChainId { @Override public String toString() { - return toStringHelper(this) - .add("portChainId", portChainId.toString()) - .toString(); + return toStringHelper(this).add("portChainId", portChainId).toString(); } } diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroupId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroupId.java index 0474901c..a52a2bb3 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroupId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairGroupId.java @@ -19,8 +19,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; import static com.google.common.base.Preconditions.checkNotNull; import java.util.UUID; - -import com.google.common.base.Objects; +import java.util.Objects; /** * Representation of a Port Pair Group ID. @@ -40,22 +39,22 @@ public final class PortPairGroupId { } /** - * Constructor to create port pair group id from UUID. + * Returns newly created port pair group id object. * - * @param id UUID of port pair group id + * @param id port pair group id in UUID * @return object of port pair group id */ - public static PortPairGroupId portPairGroupId(UUID id) { + public static PortPairGroupId of(UUID id) { return new PortPairGroupId(id); } /** - * Constructor to create port pair group id from string. + * Returns newly created port pair group id object. * * @param id port pair group id in string * @return object of port pair group id */ - public static PortPairGroupId portPairGroupId(String id) { + public static PortPairGroupId of(String id) { return new PortPairGroupId(UUID.fromString(id)); } @@ -73,10 +72,9 @@ public final class PortPairGroupId { if (this == obj) { return true; } - - if (obj.getClass() == this.getClass()) { - PortPairGroupId that = (PortPairGroupId) obj; - return Objects.equal(this.portPairGroupId, that.portPairGroupId); + if (obj instanceof PortPairGroupId) { + final PortPairGroupId other = (PortPairGroupId) obj; + return Objects.equals(this.portPairGroupId, other.portPairGroupId); } return false; } @@ -88,8 +86,7 @@ public final class PortPairGroupId { @Override public String toString() { - return toStringHelper(this) - .add("portPairGroupId", portPairGroupId.toString()) + return toStringHelper(this).add("portPairGroupId", portPairGroupId) .toString(); } } diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairId.java index 05c31aac..1f45e80e 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/PortPairId.java @@ -19,8 +19,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; import static com.google.common.base.Preconditions.checkNotNull; import java.util.UUID; - -import com.google.common.base.Objects; +import java.util.Objects; /** * Representation of a Port Pair ID. @@ -40,22 +39,22 @@ public final class PortPairId { } /** - * Constructor to create port pair id from UUID. + * Returns newly created port pair id object. * * @param id UUID of port pair id * @return object of port pair id */ - public static PortPairId portPairId(UUID id) { + public static PortPairId of(UUID id) { return new PortPairId(id); } /** - * Constructor to create port pair id from string. + * Returns newly created port pair id object. * * @param id port pair id in string * @return object of port pair id */ - public static PortPairId portPairId(String id) { + public static PortPairId of(String id) { return new PortPairId(UUID.fromString(id)); } @@ -73,10 +72,9 @@ public final class PortPairId { if (this == obj) { return true; } - - if (obj.getClass() == this.getClass()) { - PortPairId that = (PortPairId) obj; - return Objects.equal(this.portPairId, that.portPairId); + if (obj instanceof PortPairId) { + final PortPairId other = (PortPairId) obj; + return Objects.equals(this.portPairId, other.portPairId); } return false; } @@ -89,7 +87,7 @@ public final class PortPairId { @Override public String toString() { return toStringHelper(this) - .add("portPairId", portPairId.toString()) + .add("portPairId", portPairId) .toString(); } } diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Router.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Router.java new file mode 100644 index 00000000..e853ec2f --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/Router.java @@ -0,0 +1,102 @@ +/*
+ * 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.vtnrsc;
+
+import java.util.List;
+
+/**
+ * Representation of a Router.
+ */
+public interface Router {
+
+ /**
+ * Coarse classification of the type of the Router.
+ */
+ public enum Status {
+ /**
+ * Signifies that a router is currently active.
+ */
+ ACTIVE,
+ /**
+ * Signifies that a router is currently inactive.
+ */
+ INACTIVE
+ }
+
+ /**
+ * Returns the router identifier.
+ *
+ * @return identifier
+ */
+ RouterId id();
+
+ /**
+ * Returns the router Name.
+ *
+ * @return routerName
+ */
+ String name();
+
+ /**
+ * Returns the router admin state.
+ *
+ * @return true or false
+ */
+ boolean adminStateUp();
+
+ /**
+ * Returns the status of router.
+ *
+ * @return RouterStatus
+ */
+ Status status();
+
+ /**
+ * Returns the distributed status of this router.
+ * If true, indicates a distributed router.
+ *
+ * @return true or false
+ */
+ boolean distributed();
+
+ /**
+ * Returns the RouterGateway of router.
+ *
+ * @return routerGateway
+ */
+ RouterGateway externalGatewayInfo();
+
+ /**
+ * Returns the gatewayPortid of router.
+ *
+ * @return virtualPortId
+ */
+ VirtualPortId gatewayPortid();
+
+ /**
+ * Returns the owner(tenant) of this router.
+ *
+ * @return tenantId
+ */
+ TenantId tenantId();
+
+ /**
+ * Returns the router list of router.
+ *
+ * @return routes
+ */
+ List<String> routes();
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterGateway.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterGateway.java new file mode 100644 index 00000000..9a755561 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterGateway.java @@ -0,0 +1,108 @@ +/*
+ * 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.vtnrsc;
+
+import static com.google.common.base.MoreObjects.toStringHelper;
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Collection;
+import java.util.Objects;
+
+/**
+ * Representation of a Router gateway.
+ */
+public final class RouterGateway {
+
+ private final TenantNetworkId networkId;
+ private final boolean enableSnat;
+ private final Collection<FixedIp> externalFixedIps;
+
+ // Public construction is prohibited
+ private RouterGateway(TenantNetworkId networkId, boolean enableSnat,
+ Collection<FixedIp> externalFixedIps) {
+ this.networkId = checkNotNull(networkId, "networkId cannot be null");
+ this.enableSnat = checkNotNull(enableSnat, "enableSnat cannot be null");
+ this.externalFixedIps = checkNotNull(externalFixedIps, "externalFixedIps cannot be null");
+ }
+
+ /**
+ * Creates router gateway object.
+ *
+ * @param networkId network identifier
+ * @param enableSnat SNAT enable or not
+ * @param externalFixedIps external fixed IP
+ * @return RouterGateway
+ */
+ public static RouterGateway routerGateway(TenantNetworkId networkId, boolean enableSnat,
+ Collection<FixedIp> externalFixedIps) {
+ return new RouterGateway(networkId, enableSnat, externalFixedIps);
+ }
+
+ /**
+ * Returns network identifier.
+ *
+ * @return networkId
+ */
+ public TenantNetworkId networkId() {
+ return networkId;
+ }
+
+ /**
+ * Return SNAT enable or not.
+ *
+ * @return enableSnat
+ */
+ public boolean enableSnat() {
+ return enableSnat;
+ }
+
+ /**
+ * Return external fixed Ip.
+ *
+ * @return externalFixedIps
+ */
+ public Collection<FixedIp> externalFixedIps() {
+ return externalFixedIps;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(networkId, enableSnat, externalFixedIps);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof RouterGateway) {
+ final RouterGateway that = (RouterGateway) obj;
+ return Objects.equals(this.networkId, that.networkId)
+ && Objects.equals(this.enableSnat, that.enableSnat)
+ && Objects.equals(this.externalFixedIps, that.externalFixedIps);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return toStringHelper(this)
+ .add("networkId", networkId)
+ .add("enableSnat", enableSnat)
+ .add("externalFixedIps", externalFixedIps)
+ .toString();
+ }
+}
diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterId.java new file mode 100644 index 00000000..d396c0d1 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/RouterId.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.vtnrsc; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; + +/** + * Immutable representation of a router identifier. + */ +public final class RouterId { + + private final String routerId; + + // Public construction is prohibited + private RouterId(String routerId) { + checkNotNull(routerId, "routerId cannot be null"); + this.routerId = routerId; + } + + /** + * Creates a router identifier. + * + * @param routerId the router identifier + * @return the router identifier + */ + public static RouterId valueOf(String routerId) { + return new RouterId(routerId); + } + + /** + * Returns the router identifier. + * + * @return the router identifier + */ + public String routerId() { + return routerId; + } + + @Override + public int hashCode() { + return routerId.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof RouterId) { + final RouterId that = (RouterId) obj; + return Objects.equals(this.routerId, that.routerId); + } + return false; + } + + @Override + public String toString() { + return toStringHelper(this).add("routerId", routerId).toString(); + } +} + diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java index 9ec1dc63..33ddcbfe 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SecurityGroup.java @@ -52,7 +52,7 @@ public final class SecurityGroup { @Override public int hashCode() { - return Objects.hash(securityGroup); + return securityGroup.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java index a076265f..651ebd89 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SegmentationId.java @@ -53,7 +53,7 @@ public final class SegmentationId { @Override public int hashCode() { - return Objects.hash(segmentationId); + return segmentationId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java index 4bcc3329..eb93d153 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/SubnetId.java @@ -53,7 +53,7 @@ public final class SubnetId { @Override public int hashCode() { - return Objects.hash(subnetId); + return subnetId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java index c4d99e49..0e7c9417 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantId.java @@ -53,7 +53,7 @@ public final class TenantId { @Override public int hashCode() { - return Objects.hash(tenantId); + return tenantId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java index fbb9e480..8680d28f 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/TenantNetworkId.java @@ -52,7 +52,7 @@ public final class TenantNetworkId { @Override public int hashCode() { - return Objects.hash(networkId); + return networkId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java index 3038bdff..a3863483 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/VirtualPortId.java @@ -46,7 +46,7 @@ public final class VirtualPortId { @Override public int hashCode() { - return Objects.hash(portId); + return portId.hashCode(); } @Override diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/FlowClassifierService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierService.java index e379be81..c160d221 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/FlowClassifierService.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierService.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.vtnrsc.flowClassifier; +package org.onosproject.vtnrsc.flowclassifier; import org.onosproject.vtnrsc.FlowClassifier; import org.onosproject.vtnrsc.FlowClassifierId; @@ -69,4 +69,4 @@ public interface FlowClassifierService { * @return true if Flow Classifier removal is success otherwise return false. */ boolean removeFlowClassifier(FlowClassifierId id); -}
\ No newline at end of file +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/FlowClassifierManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/FlowClassifierManager.java index 7238558a..ee5873d6 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/FlowClassifierManager.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/FlowClassifierManager.java @@ -13,23 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.vtnrsc.flowClassifier.impl; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; +package org.onosproject.vtnrsc.flowclassifier.impl; 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.onlab.util.KryoNamespace; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.EventuallyConsistentMap; +import org.onosproject.store.service.MultiValuedTimestamp; +import org.onosproject.store.service.StorageService; +import org.onosproject.store.service.WallClockTimestamp; import org.onosproject.vtnrsc.FlowClassifierId; import org.onosproject.vtnrsc.FlowClassifier; -import org.onosproject.vtnrsc.flowClassifier.FlowClassifierService; - +import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; import org.slf4j.Logger; -import static org.slf4j.LoggerFactory.getLogger; +import static org.slf4j.LoggerFactory.getLogger; import static com.google.common.base.Preconditions.checkNotNull; + import com.google.common.collect.ImmutableList; /** @@ -44,16 +49,26 @@ public class FlowClassifierManager implements FlowClassifierService { private static final String FLOW_CLASSIFIER_NOT_NULL = "Flow Classifier cannot be null"; private static final String FLOW_CLASSIFIER_ID_NOT_NULL = "Flow Classifier Id cannot be null"; - private ConcurrentMap<FlowClassifierId, FlowClassifier> flowClassifierStore - = new ConcurrentHashMap<FlowClassifierId, FlowClassifier>(); + private EventuallyConsistentMap<FlowClassifierId, FlowClassifier> flowClassifierStore; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; @Activate private void activate() { + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() + .register(KryoNamespaces.API) + .register(MultiValuedTimestamp.class) + .register(FlowClassifier.class); + flowClassifierStore = storageService + .<FlowClassifierId, FlowClassifier>eventuallyConsistentMapBuilder() + .withName("flowclassifierstore").withSerializer(serializer) + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); log.info("Flow Classifier service activated"); } @Deactivate private void deactivate() { + flowClassifierStore.destroy(); log.info("Flow Classifier service deactivated"); } @@ -92,7 +107,8 @@ public class FlowClassifierManager implements FlowClassifierService { public boolean updateFlowClassifier(FlowClassifier flowClassifier) { checkNotNull(flowClassifier, FLOW_CLASSIFIER_NOT_NULL); FlowClassifierId id = flowClassifier.flowClassifierId(); - return flowClassifierStore.replace(id, flowClassifierStore.get(id), flowClassifier); + flowClassifierStore.put(id, flowClassifier); + return true; } @Override @@ -105,4 +121,4 @@ public class FlowClassifierManager implements FlowClassifierService { } return true; } -}
\ No newline at end of file +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/package-info.java index 4ea050b3..62b5603d 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/impl/package-info.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/impl/package-info.java @@ -17,4 +17,4 @@ /** * Provides implementation of the flow Classifier service. */ -package org.onosproject.vtnrsc.flowClassifier.impl; +package org.onosproject.vtnrsc.flowclassifier.impl; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/package-info.java index 07584170..c8c75bf3 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowClassifier/package-info.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/flowclassifier/package-info.java @@ -17,4 +17,4 @@ /** * Service for interacting with flow Classifier of SFC. */ -package org.onosproject.vtnrsc.flowClassifier; +package org.onosproject.vtnrsc.flowclassifier; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/PortChainManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/PortChainManager.java new file mode 100644 index 00000000..5201a2ca --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/PortChainManager.java @@ -0,0 +1,146 @@ +/* + * 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.vtnrsc.portchain.impl; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.Collections; + +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.onlab.util.KryoNamespace; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.EventuallyConsistentMap; +import org.onosproject.store.service.MultiValuedTimestamp; +import org.onosproject.store.service.StorageService; +import org.onosproject.store.service.WallClockTimestamp; +import org.onosproject.vtnrsc.PortChain; +import org.onosproject.vtnrsc.PortChainId; +import org.onosproject.vtnrsc.portchain.PortChainService; +import org.slf4j.Logger; + +/** + * Provides implementation of the portChainService. + */ +@Component(immediate = true) +@Service +public class PortChainManager implements PortChainService { + + private final Logger log = getLogger(getClass()); + + private static final String PORT_CHAIN_ID_NULL = "PortChain ID cannot be null"; + private static final String PORT_CHAIN_NULL = "PortChain cannot be null"; + + private EventuallyConsistentMap<PortChainId, PortChain> portChainStore; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; + + @Activate + public void activate() { + + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() + .register(KryoNamespaces.API) + .register(MultiValuedTimestamp.class) + .register(PortChain.class); + + portChainStore = storageService + .<PortChainId, PortChain>eventuallyConsistentMapBuilder() + .withName("portchainstore").withSerializer(serializer) + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); + + log.info("Started"); + } + + @Deactivate + public void deactivate() { + portChainStore.destroy(); + log.info("Stopped"); + } + + @Override + public boolean exists(PortChainId portChainId) { + checkNotNull(portChainId, PORT_CHAIN_ID_NULL); + return portChainStore.containsKey(portChainId); + } + + @Override + public int getPortChainCount() { + return portChainStore.size(); + } + + @Override + public Iterable<PortChain> getPortChains() { + return Collections.unmodifiableCollection(portChainStore.values()); + } + + @Override + public PortChain getPortChain(PortChainId portChainId) { + checkNotNull(portChainId, PORT_CHAIN_ID_NULL); + return portChainStore.get(portChainId); + } + + @Override + public boolean createPortChain(PortChain portChain) { + checkNotNull(portChain, PORT_CHAIN_NULL); + + portChainStore.put(portChain.portChainId(), portChain); + if (!portChainStore.containsKey(portChain.portChainId())) { + log.debug("The portChain is created failed which identifier was {}", portChain.portChainId() + .toString()); + return false; + } + return true; + } + + @Override + public boolean updatePortChain(PortChain portChain) { + checkNotNull(portChain, PORT_CHAIN_NULL); + + if (!portChainStore.containsKey(portChain.portChainId())) { + log.debug("The portChain is not exist whose identifier was {} ", + portChain.portChainId().toString()); + return false; + } + + portChainStore.put(portChain.portChainId(), portChain); + + if (!portChain.equals(portChainStore.get(portChain.portChainId()))) { + log.debug("The portChain is updated failed whose identifier was {} ", + portChain.portChainId().toString()); + return false; + } + return true; + } + + @Override + public boolean removePortChain(PortChainId portChainId) { + checkNotNull(portChainId, PORT_CHAIN_NULL); + + portChainStore.remove(portChainId); + if (portChainStore.containsKey(portChainId)) { + log.debug("The portChain is removed failed whose identifier was {}", + portChainId.toString()); + return false; + } + return true; + } +} diff --git a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/package-info.java index 371466c3..424d54ab 100644 --- a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/package-info.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchain/impl/package-info.java @@ -15,6 +15,6 @@ */ /** - * VTN application that applies configuration and flows to the device. + * Implementation of service for interacting with the inventory of port chains. */ -package org.onosproject.vtn; +package org.onosproject.vtnrsc.portchain.impl; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/PortPairService.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/PortPairService.java new file mode 100644 index 00000000..f99cc2cf --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/PortPairService.java @@ -0,0 +1,80 @@ +/* + * 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.vtnrsc.portpair; + +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.PortPairId; + +/** + * Service for interacting with the inventory of port pairs. + */ +public interface PortPairService { + + /** + * Returns if the port pair is existed. + * + * @param portPairId port pair identifier + * @return true or false if one with the given identifier exists. + */ + boolean exists(PortPairId portPairId); + + /** + * Returns the number of port pairs known to the system. + * + * @return number of port pairs. + */ + int getPortPairCount(); + + /** + * Returns an iterable collection of the currently known port pairs. + * + * @return collection of port pairs. + */ + Iterable<PortPair> getPortPairs(); + + /** + * Returns the portPair with the given identifier. + * + * @param portPairId port pair identifier + * @return PortPair or null if port pair with the given identifier is not + * known. + */ + PortPair getPortPair(PortPairId portPairId); + + /** + * Creates a PortPair in the store. + * + * @param portPair the port pair to create + * @return true if given port pair is created successfully. + */ + boolean createPortPair(PortPair portPair); + + /** + * Updates the portPair in the store. + * + * @param portPair the port pair to update + * @return true if given port pair is updated successfully. + */ + boolean updatePortPair(PortPair portPair); + + /** + * Deletes portPair by given portPairId. + * + * @param portPairId id of port pair to remove + * @return true if the give port pair is deleted successfully. + */ + boolean removePortPair(PortPairId portPairId); +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/PortPairManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/PortPairManager.java new file mode 100644 index 00000000..93c8782a --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/PortPairManager.java @@ -0,0 +1,146 @@ +/* + * 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.vtnrsc.portpair.impl; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.Collections; + +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.onlab.util.KryoNamespace; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.EventuallyConsistentMap; +import org.onosproject.store.service.MultiValuedTimestamp; +import org.onosproject.store.service.StorageService; +import org.onosproject.store.service.WallClockTimestamp; +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.portpair.PortPairService; +import org.slf4j.Logger; + +/** + * Provides implementation of the portPairService. + */ +@Component(immediate = true) +@Service +public class PortPairManager implements PortPairService { + + private final Logger log = getLogger(getClass()); + + private static final String PORT_PAIR_ID_NULL = "PortPair ID cannot be null"; + private static final String PORT_PAIR_NULL = "PortPair cannot be null"; + + private EventuallyConsistentMap<PortPairId, PortPair> portPairStore; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; + + @Activate + public void activate() { + + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() + .register(KryoNamespaces.API) + .register(MultiValuedTimestamp.class) + .register(PortPair.class); + + portPairStore = storageService + .<PortPairId, PortPair>eventuallyConsistentMapBuilder() + .withName("portpairstore").withSerializer(serializer) + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); + + log.info("Started"); + } + + @Deactivate + public void deactivate() { + portPairStore.destroy(); + log.info("Stopped"); + } + + @Override + public boolean exists(PortPairId portPairId) { + checkNotNull(portPairId, PORT_PAIR_ID_NULL); + return portPairStore.containsKey(portPairId); + } + + @Override + public int getPortPairCount() { + return portPairStore.size(); + } + + @Override + public Iterable<PortPair> getPortPairs() { + return Collections.unmodifiableCollection(portPairStore.values()); + } + + @Override + public PortPair getPortPair(PortPairId portPairId) { + checkNotNull(portPairId, PORT_PAIR_ID_NULL); + return portPairStore.get(portPairId); + } + + @Override + public boolean createPortPair(PortPair portPair) { + checkNotNull(portPair, PORT_PAIR_NULL); + + portPairStore.put(portPair.portPairId(), portPair); + if (!portPairStore.containsKey(portPair.portPairId())) { + log.debug("The portPair is created failed which identifier was {}", portPair.portPairId() + .toString()); + return false; + } + return true; + } + + @Override + public boolean updatePortPair(PortPair portPair) { + checkNotNull(portPair, PORT_PAIR_NULL); + + if (!portPairStore.containsKey(portPair.portPairId())) { + log.debug("The portPair is not exist whose identifier was {} ", + portPair.portPairId().toString()); + return false; + } + + portPairStore.put(portPair.portPairId(), portPair); + + if (!portPair.equals(portPairStore.get(portPair.portPairId()))) { + log.debug("The portPair is updated failed whose identifier was {} ", + portPair.portPairId().toString()); + return false; + } + return true; + } + + @Override + public boolean removePortPair(PortPairId portPairId) { + checkNotNull(portPairId, PORT_PAIR_NULL); + + portPairStore.remove(portPairId); + if (portPairStore.containsKey(portPairId)) { + log.debug("The portPair is removed failed whose identifier was {}", + portPairId.toString()); + return false; + } + return true; + } +} diff --git a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/package-info.java index f18dbf8a..625fbdd4 100644 --- a/framework/src/onos/apps/vtn/vtnmgr/src/main/java/org/onosproject/vtn/impl/package-info.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/impl/package-info.java @@ -15,6 +15,6 @@ */ /** - * VTN application that applies configuration and flows to the device. + * Implementation of service for interacting with the inventory of port pairs. */ -package org.onosproject.vtn.impl; +package org.onosproject.vtnrsc.portpair.impl; diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/package-info.java index 1dcb9929..e2c61531 100644 --- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/package-info.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpair/package-info.java @@ -15,6 +15,6 @@ */ /** - * Service for interacting with SFC. + * Service for interacting with the inventory of port pairs. */ -package org.onosproject.sfc; +package org.onosproject.vtnrsc.portpair; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java new file mode 100644 index 00000000..55fb4e43 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/PortPairGroupManager.java @@ -0,0 +1,146 @@ +/* + * 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.vtnrsc.portpairgroup.impl; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.Collections; + +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.onlab.util.KryoNamespace; +import org.onosproject.store.serializers.KryoNamespaces; +import org.onosproject.store.service.EventuallyConsistentMap; +import org.onosproject.store.service.MultiValuedTimestamp; +import org.onosproject.store.service.StorageService; +import org.onosproject.store.service.WallClockTimestamp; +import org.onosproject.vtnrsc.PortPairGroup; +import org.onosproject.vtnrsc.PortPairGroupId; +import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; +import org.slf4j.Logger; + +/** + * Provides implementation of the portPairGroupService. + */ +@Component(immediate = true) +@Service +public class PortPairGroupManager implements PortPairGroupService { + + private final Logger log = getLogger(getClass()); + + private static final String PORT_PAIR_GROUP_ID_NULL = "PortPairGroup ID cannot be null"; + private static final String PORT_PAIR_GROUP_NULL = "PortPairGroup cannot be null"; + + private EventuallyConsistentMap<PortPairGroupId, PortPairGroup> portPairGroupStore; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected StorageService storageService; + + @Activate + public void activate() { + + KryoNamespace.Builder serializer = KryoNamespace.newBuilder() + .register(KryoNamespaces.API) + .register(MultiValuedTimestamp.class) + .register(PortPairGroup.class); + + portPairGroupStore = storageService + .<PortPairGroupId, PortPairGroup>eventuallyConsistentMapBuilder() + .withName("portpairgroupstore").withSerializer(serializer) + .withTimestampProvider((k, v) -> new WallClockTimestamp()).build(); + + log.info("Started"); + } + + @Deactivate + public void deactivate() { + portPairGroupStore.destroy(); + log.info("Stopped"); + } + + @Override + public boolean exists(PortPairGroupId portPairGroupId) { + checkNotNull(portPairGroupId, PORT_PAIR_GROUP_ID_NULL); + return portPairGroupStore.containsKey(portPairGroupId); + } + + @Override + public int getPortPairGroupCount() { + return portPairGroupStore.size(); + } + + @Override + public Iterable<PortPairGroup> getPortPairGroups() { + return Collections.unmodifiableCollection(portPairGroupStore.values()); + } + + @Override + public PortPairGroup getPortPairGroup(PortPairGroupId portPairGroupId) { + checkNotNull(portPairGroupId, PORT_PAIR_GROUP_ID_NULL); + return portPairGroupStore.get(portPairGroupId); + } + + @Override + public boolean createPortPairGroup(PortPairGroup portPairGroup) { + checkNotNull(portPairGroup, PORT_PAIR_GROUP_NULL); + + portPairGroupStore.put(portPairGroup.portPairGroupId(), portPairGroup); + if (!portPairGroupStore.containsKey(portPairGroup.portPairGroupId())) { + log.debug("The portPairGroup is created failed which identifier was {}", portPairGroup.portPairGroupId() + .toString()); + return false; + } + return true; + } + + @Override + public boolean updatePortPairGroup(PortPairGroup portPairGroup) { + checkNotNull(portPairGroup, PORT_PAIR_GROUP_NULL); + + if (!portPairGroupStore.containsKey(portPairGroup.portPairGroupId())) { + log.debug("The portPairGroup is not exist whose identifier was {} ", + portPairGroup.portPairGroupId().toString()); + return false; + } + + portPairGroupStore.put(portPairGroup.portPairGroupId(), portPairGroup); + + if (!portPairGroup.equals(portPairGroupStore.get(portPairGroup.portPairGroupId()))) { + log.debug("The portPairGroup is updated failed whose identifier was {} ", + portPairGroup.portPairGroupId().toString()); + return false; + } + return true; + } + + @Override + public boolean removePortPairGroup(PortPairGroupId portPairGroupId) { + checkNotNull(portPairGroupId, PORT_PAIR_GROUP_NULL); + + portPairGroupStore.remove(portPairGroupId); + if (portPairGroupStore.containsKey(portPairGroupId)) { + log.debug("The portPairGroup is removed failed whose identifier was {}", + portPairGroupId.toString()); + return false; + } + return true; + } +} diff --git a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/package-info.java index 0dba868c..68c186bc 100644 --- a/framework/src/onos/apps/vtn/sfcmgr/src/main/java/org/onosproject/sfc/impl/package-info.java +++ b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portpairgroup/impl/package-info.java @@ -15,6 +15,6 @@ */ /** - * SFC Service manager for interacting with SFC. + * Implementation of service for interacting with the inventory of port pair groups. */ -package org.onosproject.sfc.impl; +package org.onosproject.vtnrsc.portpairgroup.impl; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/package-info.java b/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/package-info.java deleted file mode 100644 index 34636a9f..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/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. - */ - -/** - * Codecs for virtual tenant objects. - */ -package org.onosproject.vtnrsc.web; diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java deleted file mode 100644 index b2fed347..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/flowclassifier/FlowClassifierIdTest.java +++ /dev/null @@ -1,68 +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.vtnrsc.flowclassifier; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.FlowClassifierId; - -import com.google.common.testing.EqualsTester; -import java.util.UUID; - -/** - * Unit tests for FlowClassifierId class. - */ -public class FlowClassifierIdTest { - - final FlowClassifierId flowClassifierId1 = FlowClassifierId - .flowClassifierId("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); - final FlowClassifierId sameAsFlowClassifierId1 = FlowClassifierId - .flowClassifierId("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); - final FlowClassifierId flowClassifierId2 = FlowClassifierId - .flowClassifierId("dace4513-24fc-4fae-af4b-321c5e2eb3d1"); - - /** - * Checks that the FlowClassifierId class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(FlowClassifierId.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(flowClassifierId1, sameAsFlowClassifierId1) - .addEqualityGroup(flowClassifierId2).testEquals(); - } - - /** - * Checks the construction of a FlowClassifierId object. - */ - @Test - public void testConstruction() { - final String flowClassifierIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1"; - final FlowClassifierId flowClassifierId = FlowClassifierId.flowClassifierId(flowClassifierIdValue); - assertThat(flowClassifierId, is(notNullValue())); - assertThat(flowClassifierId.value(), is(UUID.fromString(flowClassifierIdValue))); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java deleted file mode 100644 index 4ce4def2..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultAllocationPoolTest.java +++ /dev/null @@ -1,68 +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.vtnrsc.subnet; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onosproject.vtnrsc.AllocationPool; -import org.onosproject.vtnrsc.DefaultAllocationPool; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for DefaultAllocationPool class. - */ -public class DefaultAllocationPoolTest { - - final IpAddress startIP1 = IpAddress.valueOf("192.168.1.1"); - final IpAddress startIP2 = IpAddress.valueOf("192.168.1.2"); - final IpAddress endIP1 = IpAddress.valueOf("192.168.1.1"); - final IpAddress endIP2 = IpAddress.valueOf("192.168.1.2"); - - /** - * Checks that the DefaultAllocationPool class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(DefaultAllocationPool.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - AllocationPool pool1 = new DefaultAllocationPool(startIP1, endIP1); - AllocationPool pool2 = new DefaultAllocationPool(startIP1, endIP1); - AllocationPool pool3 = new DefaultAllocationPool(startIP2, endIP2); - new EqualsTester().addEqualityGroup(pool1, pool2) - .addEqualityGroup(pool3).testEquals(); - } - - /** - * Checks the construction of a DefaultAllocationPool object. - */ - @Test - public void testConstruction() { - final AllocationPool apool = new DefaultAllocationPool(startIP1, endIP1); - assertThat(startIP1, is(apool.startIp())); - assertThat(endIP1, is(apool.endIp())); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java deleted file mode 100644 index 2f751742..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/DefaultHostRouteTest.java +++ /dev/null @@ -1,68 +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.vtnrsc.subnet; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onlab.packet.IpPrefix; -import org.onosproject.vtnrsc.DefaultHostRoute; -import org.onosproject.vtnrsc.HostRoute; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for DefaultHostRoute class. - */ -public class DefaultHostRouteTest { - final IpAddress nexthop1 = IpAddress.valueOf("192.168.1.1"); - final IpAddress nexthop2 = IpAddress.valueOf("192.168.1.2"); - final IpPrefix destination1 = IpPrefix.valueOf("1.1.1.1/1"); - final IpPrefix destination2 = IpPrefix.valueOf("1.1.1.1/2"); - - /** - * Checks that the DefaultHostRoute class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(DefaultHostRoute.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - HostRoute route1 = new DefaultHostRoute(nexthop1, destination1); - HostRoute route2 = new DefaultHostRoute(nexthop1, destination1); - HostRoute route3 = new DefaultHostRoute(nexthop2, destination2); - new EqualsTester().addEqualityGroup(route1, route2) - .addEqualityGroup(route3).testEquals(); - } - - /** - * Checks the construction of a DefaultHostRoute object. - */ - @Test - public void testConstruction() { - final HostRoute host = new DefaultHostRoute(nexthop1, destination1); - assertThat(nexthop1, is(host.nexthop())); - assertThat(destination1, is(host.destination())); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.java deleted file mode 100644 index d18dd41a..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/subnet/SubnetIdTest.java +++ /dev/null @@ -1,64 +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.vtnrsc.subnet; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.SubnetId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for SubnetId class. - */ -public class SubnetIdTest { - - final SubnetId subnetId1 = SubnetId.subnetId("1"); - final SubnetId sameAsSubnetId1 = SubnetId.subnetId("1"); - final SubnetId subnetId2 = SubnetId.subnetId("2"); - - /** - * Checks that the SubnetId class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(SubnetId.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(subnetId1, sameAsSubnetId1).addEqualityGroup(subnetId2) - .testEquals(); - } - - /** - * Checks the construction of a SubnetId object. - */ - @Test - public void testConstruction() { - final String subnetIdValue = "s"; - final SubnetId subnetId = SubnetId.subnetId(subnetIdValue); - assertThat(subnetId, is(notNullValue())); - assertThat(subnetId.subnetId(), is(subnetIdValue)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java deleted file mode 100644 index 742d5933..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/DefaultNeutronNetworkTest.java +++ /dev/null @@ -1,83 +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.vtnrsc.tenantnetwork; - -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.DefaultTenantNetwork; -import org.onosproject.vtnrsc.PhysicalNetwork; -import org.onosproject.vtnrsc.SegmentationId; -import org.onosproject.vtnrsc.TenantId; -import org.onosproject.vtnrsc.TenantNetwork; -import org.onosproject.vtnrsc.TenantNetworkId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for DefaultNeutronNetwork class. - */ -public class DefaultNeutronNetworkTest { - - private String networkIdStr1 = "123"; - private String networkIdStr2 = "234"; - private String physicalNetworkStr = "1234"; - private String tenantIdStr = "345"; - private String segmentationIdStr = "1"; - private String name = "456"; - - /** - * Checks that the DefaultNeutronNetwork class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(DefaultTenantNetwork.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquality() { - TenantNetworkId networkid1 = TenantNetworkId.networkId(networkIdStr1); - TenantNetworkId networkid2 = TenantNetworkId.networkId(networkIdStr2); - PhysicalNetwork physicalNetwork = PhysicalNetwork - .physicalNetwork(physicalNetworkStr); - TenantId tenantId = TenantId.tenantId(tenantIdStr); - SegmentationId segmentationID = SegmentationId - .segmentationId(segmentationIdStr); - TenantNetwork p1 = new DefaultTenantNetwork(networkid1, name, false, - TenantNetwork.State.ACTIVE, - false, tenantId, false, - TenantNetwork.Type.LOCAL, - physicalNetwork, - segmentationID); - TenantNetwork p2 = new DefaultTenantNetwork(networkid1, name, false, - TenantNetwork.State.ACTIVE, - false, tenantId, false, - TenantNetwork.Type.LOCAL, - physicalNetwork, - segmentationID); - TenantNetwork p3 = new DefaultTenantNetwork(networkid2, name, false, - TenantNetwork.State.ACTIVE, - false, tenantId, false, - TenantNetwork.Type.LOCAL, - physicalNetwork, - segmentationID); - new EqualsTester().addEqualityGroup(p1, p2).addEqualityGroup(p3) - .testEquals(); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java deleted file mode 100644 index e101795e..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/PhysicalNetworkTest.java +++ /dev/null @@ -1,65 +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.vtnrsc.tenantnetwork; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.PhysicalNetwork; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for PhysicalNetwork class. - */ -public class PhysicalNetworkTest { - - final PhysicalNetwork physicalNetwork1 = PhysicalNetwork.physicalNetwork("1"); - final PhysicalNetwork sameAsPhysicalNetwork1 = PhysicalNetwork.physicalNetwork("1"); - final PhysicalNetwork physicalNetwork2 = PhysicalNetwork.physicalNetwork("2"); - - /** - * Checks that the PhysicalNetwork class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(PhysicalNetwork.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(physicalNetwork1, sameAsPhysicalNetwork1) - .addEqualityGroup(physicalNetwork2).testEquals(); - } - - /** - * Checks the construction of a PhysicalNetwork object. - */ - @Test - public void testConstruction() { - final String physicalNetworkValue = "s"; - final PhysicalNetwork physicalNetwork = PhysicalNetwork - .physicalNetwork(physicalNetworkValue); - assertThat(physicalNetwork, is(notNullValue())); - assertThat(physicalNetwork.physicalNetwork(), is(physicalNetworkValue)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.java deleted file mode 100644 index dea7baf6..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/SegmentationIdTest.java +++ /dev/null @@ -1,64 +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.vtnrsc.tenantnetwork; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.SegmentationId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for SegmentationId class. - */ -public class SegmentationIdTest { - - final SegmentationId segmentationID1 = SegmentationId.segmentationId("1"); - final SegmentationId sameAsSegmentationID1 = SegmentationId.segmentationId("1"); - final SegmentationId segmentationID2 = SegmentationId.segmentationId("2"); - - /** - * Checks that the SegmentationId class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(SegmentationId.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(segmentationID1, sameAsSegmentationID1) - .addEqualityGroup(segmentationID2).testEquals(); - } - - /** - * Checks the construction of a segmentationId object. - */ - @Test - public void testConstruction() { - final String segmentationIdValue = "s"; - final SegmentationId segmentationId = SegmentationId.segmentationId(segmentationIdValue); - assertThat(segmentationId, is(notNullValue())); - assertThat(segmentationId.segmentationId(), is(segmentationIdValue)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.java deleted file mode 100644 index e9216383..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantIdTest.java +++ /dev/null @@ -1,64 +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.vtnrsc.tenantnetwork; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.TenantId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for TenantId class. - */ -public class TenantIdTest { - - final TenantId tenantId1 = TenantId.tenantId("1"); - final TenantId sameAsTenantId1 = TenantId.tenantId("1"); - final TenantId tenantId2 = TenantId.tenantId("2"); - - /** - * Checks that the TenantId class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(TenantId.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(tenantId1, sameAsTenantId1).addEqualityGroup(tenantId2) - .testEquals(); - } - - /** - * Checks the construction of a TenantId object. - */ - @Test - public void testConstruction() { - final String tenantIdValue = "s"; - final TenantId tenantId = TenantId.tenantId(tenantIdValue); - assertThat(tenantId, is(notNullValue())); - assertThat(tenantId.tenantId(), is(tenantIdValue)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.java deleted file mode 100644 index 8271b51c..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/tenantnetwork/TenantNetworkIdTest.java +++ /dev/null @@ -1,64 +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.vtnrsc.tenantnetwork; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.TenantNetworkId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for TenantNetworkId class. - */ -public class TenantNetworkIdTest { - - final TenantNetworkId networkId1 = TenantNetworkId.networkId("1"); - final TenantNetworkId sameAsnetworkId1 = TenantNetworkId.networkId("1"); - final TenantNetworkId networkId2 = TenantNetworkId.networkId("2"); - - /** - * Checks that the TenantNetworkId class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(TenantNetworkId.class); - } - - /** - * Checks the operation of equals() methods. - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(networkId1, sameAsnetworkId1) - .addEqualityGroup(networkId2).testEquals(); - } - - /** - * Checks the construction of a TenantNetworkId object. - */ - @Test - public void testConstruction() { - final String networkIdValue = "s"; - final TenantNetworkId networkId = TenantNetworkId.networkId(networkIdValue); - assertThat(networkId, is(notNullValue())); - assertThat(networkId.networkId(), is(networkIdValue)); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.java deleted file mode 100644 index dabe5896..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/AllowedAddressPairTest.java +++ /dev/null @@ -1,76 +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.vtnrsc.virtualport; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onosproject.vtnrsc.AllowedAddressPair; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for AllowedAddressPair class. - */ -public class AllowedAddressPairTest { - - final IpAddress ip1 = IpAddress.valueOf("192.168.0.1"); - final IpAddress ip2 = IpAddress.valueOf("192.168.0.2"); - final MacAddress mac1 = MacAddress.valueOf("fa:16:3e:76:83:88"); - final MacAddress mac2 = MacAddress.valueOf("aa:16:3e:76:83:88"); - - /** - * Checks that the AllowedAddressPair class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(AllowedAddressPair.class); - } - - /** - * Checks the operation of equals(). - */ - @Test - public void testEquals() { - AllowedAddressPair p1 = AllowedAddressPair - .allowedAddressPair(ip1, mac1); - AllowedAddressPair p2 = AllowedAddressPair - .allowedAddressPair(ip1, mac1); - AllowedAddressPair p3 = AllowedAddressPair - .allowedAddressPair(ip2, mac2); - new EqualsTester().addEqualityGroup(p1, p2).addEqualityGroup(p3) - .testEquals(); - } - - /** - * Checks the construction of a AllowedAddressPair object. - */ - @Test - public void testConstruction() { - AllowedAddressPair allowedAddressPair = AllowedAddressPair - .allowedAddressPair(ip1, mac1); - assertThat(ip1, is(notNullValue())); - assertThat(ip1, is(allowedAddressPair.ip())); - assertThat(mac1, is(notNullValue())); - assertThat(mac1, is(allowedAddressPair.mac())); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java deleted file mode 100644 index 8a0c8004..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/DefaultVirtualPortTest.java +++ /dev/null @@ -1,142 +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.vtnrsc.virtualport; - -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import java.util.Map; -import java.util.Set; - -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onlab.packet.MacAddress; -import org.onosproject.net.DeviceId; -import org.onosproject.vtnrsc.AllowedAddressPair; -import org.onosproject.vtnrsc.BindingHostId; -import org.onosproject.vtnrsc.DefaultVirtualPort; -import org.onosproject.vtnrsc.FixedIp; -import org.onosproject.vtnrsc.SecurityGroup; -import org.onosproject.vtnrsc.SubnetId; -import org.onosproject.vtnrsc.TenantId; -import org.onosproject.vtnrsc.TenantNetworkId; -import org.onosproject.vtnrsc.VirtualPort; -import org.onosproject.vtnrsc.VirtualPortId; - -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for DefaultVirtualPort class. - */ -public class DefaultVirtualPortTest { - - private Set<FixedIp> fixedIps; - private Map<String, String> propertyMap; - private Set<AllowedAddressPair> allowedAddressPairs; - private Set<SecurityGroup> securityGroups; - private VirtualPortId id1; - private VirtualPortId id2; - private String macAddressStr = "fa:12:3e:56:ee:a2"; - private String ipAddress = "10.1.1.1"; - private String deviceStr = "of:000000000000001"; - private String tenantIdStr = "123"; - private String portId1 = "1241"; - private String portId2 = "1242"; - private String tenantNetworkId = "1234567"; - private String subnet = "1212"; - private String hostIdStr = "fa:e2:3e:56:ee:a2"; - - private void initVirtualPortId() { - id1 = VirtualPortId.portId(portId1); - id2 = VirtualPortId.portId(portId2); - } - - private void initFixedIpSet() { - FixedIp fixedIp = FixedIp.fixedIp(SubnetId.subnetId(subnet), - IpAddress.valueOf(ipAddress)); - fixedIps = Sets.newHashSet(); - fixedIps.add(fixedIp); - } - - private void initPropertyMap() { - String deviceOwner = "james"; - propertyMap = Maps.newHashMap(); - propertyMap.putIfAbsent("deviceOwner", deviceOwner); - } - - private void initAddressPairSet() { - allowedAddressPairs = Sets.newHashSet(); - AllowedAddressPair allowedAddressPair = AllowedAddressPair - .allowedAddressPair(IpAddress.valueOf(ipAddress), - MacAddress.valueOf(macAddressStr)); - allowedAddressPairs.add(allowedAddressPair); - } - - private void initSecurityGroupSet() { - securityGroups = Sets.newHashSet(); - } - - /** - * Checks that the DefaultVirtualPort class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(SecurityGroup.class); - } - - /** - * Checks the operation of equals(). - */ - @Test - public void testEquals() { - initVirtualPortId(); - initFixedIpSet(); - initPropertyMap(); - initAddressPairSet(); - initSecurityGroupSet(); - TenantNetworkId networkId = TenantNetworkId.networkId(tenantNetworkId); - MacAddress macAddress = MacAddress.valueOf(macAddressStr); - TenantId tenantId = TenantId.tenantId(tenantIdStr); - DeviceId deviceId = DeviceId.deviceId(deviceStr); - BindingHostId bindingHostId = BindingHostId.bindingHostId(hostIdStr); - - VirtualPort d1 = new DefaultVirtualPort(id1, networkId, true, - propertyMap, - VirtualPort.State.ACTIVE, - macAddress, tenantId, deviceId, - fixedIps, bindingHostId, - allowedAddressPairs, - securityGroups); - VirtualPort d2 = new DefaultVirtualPort(id1, networkId, true, - propertyMap, - VirtualPort.State.ACTIVE, - macAddress, tenantId, deviceId, - fixedIps, bindingHostId, - allowedAddressPairs, - securityGroups); - VirtualPort d3 = new DefaultVirtualPort(id2, networkId, true, - propertyMap, - VirtualPort.State.ACTIVE, - macAddress, tenantId, deviceId, - fixedIps, bindingHostId, - allowedAddressPairs, - securityGroups); - new EqualsTester().addEqualityGroup(d1, d2).addEqualityGroup(d3) - .testEquals(); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.java deleted file mode 100644 index 1e33da09..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/FixedIpTest.java +++ /dev/null @@ -1,72 +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.vtnrsc.virtualport; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onlab.packet.IpAddress; -import org.onosproject.vtnrsc.FixedIp; -import org.onosproject.vtnrsc.SubnetId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for FixedIp class. - */ -public class FixedIpTest { - - final SubnetId subnetId1 = SubnetId.subnetId("lef11-95w-4er-9c9c"); - final SubnetId subnetId2 = SubnetId.subnetId("lefaa-95w-4er-9c9c"); - final IpAddress ip1 = IpAddress.valueOf("192.168.0.1"); - final IpAddress ip2 = IpAddress.valueOf("192.168.1.1"); - - /** - * Checks that the FixedIp class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(FixedIp.class); - } - - /** - * Checks the operation of equals(). - */ - @Test - public void testEquals() { - FixedIp fixedIp1 = FixedIp.fixedIp(subnetId1, ip1); - FixedIp fixedIp2 = FixedIp.fixedIp(subnetId1, ip1); - FixedIp fixedIp3 = FixedIp.fixedIp(subnetId2, ip2); - new EqualsTester().addEqualityGroup(fixedIp1, fixedIp2) - .addEqualityGroup(fixedIp3).testEquals(); - } - - /** - * Checks the construction of a FixedIp object. - */ - @Test - public void testConstruction() { - FixedIp fixedIp = FixedIp.fixedIp(subnetId1, ip1); - assertThat(ip1, is(notNullValue())); - assertThat(ip1, is(fixedIp.ip())); - assertThat(subnetId1, is(notNullValue())); - assertThat(subnetId1, is(fixedIp.subnetId())); - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java deleted file mode 100644 index 8c04e499..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/SecurityGroupTest.java +++ /dev/null @@ -1,66 +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.vtnrsc.virtualport; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.SecurityGroup; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for SecurityGroup class. - */ -public class SecurityGroupTest { - - final SecurityGroup securityGroup1 = SecurityGroup.securityGroup("1"); - final SecurityGroup sameAssecurityGroup = SecurityGroup.securityGroup("1"); - final SecurityGroup securityGroup2 = SecurityGroup.securityGroup("2"); - - /** - * Checks that the SecurityGroup class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(SecurityGroup.class); - } - - /** - * Checks the operation of equals(). - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(securityGroup1, sameAssecurityGroup) - .addEqualityGroup(securityGroup2).testEquals(); - } - - /** - * Checks the construction of a SecurityGroup object. - */ - @Test - public void testConstruction() { - final String securityGroupValue = "1"; - final SecurityGroup securityGroup = SecurityGroup.securityGroup(securityGroupValue); - assertThat(securityGroup, is(notNullValue())); - assertThat(securityGroup.securityGroup(), is(securityGroupValue)); - - } -} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java b/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java deleted file mode 100644 index 2d63e91c..00000000 --- a/framework/src/onos/apps/vtn/vtnrsc/src/test/java/org/onosproject/vtnrsc/virtualport/VirtualPortIdTest.java +++ /dev/null @@ -1,66 +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.vtnrsc.virtualport; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; - -import org.junit.Test; -import org.onosproject.vtnrsc.VirtualPortId; - -import com.google.common.testing.EqualsTester; - -/** - * Unit tests for VirtualPortId class. - */ -public class VirtualPortIdTest { - - final VirtualPortId virtualPortId1 = VirtualPortId.portId("1"); - final VirtualPortId sameAsVirtualPortId1 = VirtualPortId.portId("1"); - final VirtualPortId virtualPortId2 = VirtualPortId.portId("2"); - - /** - * Checks that the VirtualPortId class is immutable. - */ - @Test - public void testImmutability() { - assertThatClassIsImmutable(VirtualPortId.class); - } - - /** - * Checks the operation of equals(). - */ - @Test - public void testEquals() { - new EqualsTester().addEqualityGroup(virtualPortId1, sameAsVirtualPortId1) - .addEqualityGroup(virtualPortId2).testEquals(); - } - - /** - * Checks the construction of a VirtualPortId object. - */ - @Test - public void testConstruction() { - final String vPortIdValue = "aaa"; - final VirtualPortId virtualPortId = VirtualPortId.portId(vPortIdValue); - assertThat(virtualPortId, is(notNullValue())); - assertThat(virtualPortId.portId(), is(vPortIdValue)); - - } -} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java index 1450e4ef..b0e2f38d 100644 --- a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/FlowClassifierWebResource.java @@ -15,15 +15,12 @@ */ package org.onosproject.vtnweb.resources; -import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; -import static org.onlab.util.Tools.nullIsNotFound; import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.onlab.util.Tools.nullIsNotFound; import java.io.IOException; import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.UUID; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -36,13 +33,17 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.onosproject.rest.AbstractWebResource; import org.onosproject.vtnrsc.FlowClassifier; import org.onosproject.vtnrsc.FlowClassifierId; -import org.onosproject.rest.AbstractWebResource; -import org.onosproject.vtnrsc.flowClassifier.FlowClassifierService; -import org.onosproject.vtnrsc.web.FlowClassifierCodec; +import org.onosproject.vtnrsc.flowclassifier.FlowClassifierService; +import org.onosproject.vtnweb.web.FlowClassifierCodec; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; /** @@ -51,73 +52,51 @@ import com.fasterxml.jackson.databind.node.ObjectNode; @Path("flow_classifiers") public class FlowClassifierWebResource extends AbstractWebResource { + private final Logger log = LoggerFactory.getLogger(FlowClassifierWebResource.class); + final FlowClassifierService service = get(FlowClassifierService.class); - final ObjectNode root = mapper().createObjectNode(); public static final String FLOW_CLASSIFIER_NOT_FOUND = "Flow classifier not found"; /** - * Get all flow classifiers created. Returns list of all flow classifiers - * created. + * Get all flow classifiers created. * * @return 200 OK */ @GET @Produces(MediaType.APPLICATION_JSON) public Response getFlowClassifiers() { - Iterable<FlowClassifier> flowClassifiers = service.getFlowClassifiers(); + final Iterable<FlowClassifier> flowClassifiers = service.getFlowClassifiers(); ObjectNode result = new ObjectMapper().createObjectNode(); - result.set("flow_classifiers", new FlowClassifierCodec().encode(flowClassifiers, this)); + ArrayNode flowClassifierEntry = result.putArray("flow_classifiers"); + if (flowClassifiers != null) { + for (final FlowClassifier flowClassifier : flowClassifiers) { + flowClassifierEntry.add(new FlowClassifierCodec().encode(flowClassifier, this)); + } + } return ok(result.toString()).build(); } /** - * Get details of a flow classifier. Returns details of a specified flow - * classifier id. + * Get details of a flow classifier. * * @param id flow classifier id - * @return 200 OK + * @return 200 OK , 404 if given identifier does not exist */ @GET @Path("{flow_id}") @Produces(MediaType.APPLICATION_JSON) public Response getFlowClassifier(@PathParam("flow_id") String id) { - if (!service.hasFlowClassifier(FlowClassifierId.flowClassifierId(UUID.fromString(id)))) { + if (!service.hasFlowClassifier(FlowClassifierId.of(id))) { return Response.status(NOT_FOUND).entity(FLOW_CLASSIFIER_NOT_FOUND).build(); } - FlowClassifier flowClassifier = nullIsNotFound( - service.getFlowClassifier(FlowClassifierId.flowClassifierId(UUID.fromString(id))), + FlowClassifier flowClassifier = nullIsNotFound(service.getFlowClassifier(FlowClassifierId.of(id)), FLOW_CLASSIFIER_NOT_FOUND); ObjectNode result = new ObjectMapper().createObjectNode(); result.set("flow_classifier", new FlowClassifierCodec().encode(flowClassifier, this)); - return ok(result.toString()).build(); - } - /** - * Creates and stores a new flow classifier. - * - * @param flowClassifierId flow classifier identifier - * @param stream flow classifier from JSON - * @return status of the request - CREATED if the JSON is correct, - * BAD_REQUEST if the JSON is invalid - */ - @POST - @Path("{flow_id}") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public Response createFlowClassifier(@PathParam("flow_id") String flowClassifierId, InputStream stream) { - URI location; - try { - ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); - - FlowClassifier flowClassifier = codec(FlowClassifier.class).decode(jsonTree, this); - service.createFlowClassifier(flowClassifier); - location = new URI(flowClassifierId); - } catch (IOException | URISyntaxException ex) { - throw new IllegalArgumentException(ex); - } - return Response.created(location).build(); + return ok(result.toString()).build(); } /** @@ -125,32 +104,32 @@ public class FlowClassifierWebResource extends AbstractWebResource { * * @param stream flow classifier from JSON * @return status of the request - CREATED if the JSON is correct, - * BAD_REQUEST if the JSON is invalid + * BAD_REQUEST if the JSON is invalid */ @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public Response createFlowClassifier(InputStream stream) { - URI location; try { - ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); - - FlowClassifier flowClassifier = codec(FlowClassifier.class).decode(jsonTree, this); - service.createFlowClassifier(flowClassifier); - location = new URI(flowClassifier.flowClassifierId().toString()); - } catch (IOException | URISyntaxException ex) { + ObjectMapper mapper = new ObjectMapper(); + ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream); + JsonNode flow = jsonTree.get("flow_classifier"); + + FlowClassifier flowClassifier = new FlowClassifierCodec().decode((ObjectNode) flow, this); + Boolean issuccess = nullIsNotFound(service.createFlowClassifier(flowClassifier), FLOW_CLASSIFIER_NOT_FOUND); + return Response.status(OK).entity(issuccess.toString()).build(); + } catch (IOException ex) { + log.error("Exception while creating flow classifier {}.", ex.toString()); throw new IllegalArgumentException(ex); } - return Response.created(location).build(); } /** - * Update details of a flow classifier. Update details of a specified flow - * classifier id. + * Update details of a flow classifier. * * @param id flow classifier id * @param stream InputStream - * @return 200 OK + * @return 200 OK, 404 if given identifier does not exist */ @PUT @Path("{flow_id}") @@ -158,35 +137,29 @@ public class FlowClassifierWebResource extends AbstractWebResource { @Consumes(MediaType.APPLICATION_JSON) public Response updateFlowClassifier(@PathParam("flow_id") String id, final InputStream stream) { try { - ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); - FlowClassifier flowClassifier = codec(FlowClassifier.class).decode(jsonTree, this); + + JsonNode jsonTree = mapper().readTree(stream); + JsonNode flow = jsonTree.get("flow_classifier"); + FlowClassifier flowClassifier = new FlowClassifierCodec().decode((ObjectNode) flow, this); Boolean result = nullIsNotFound(service.updateFlowClassifier(flowClassifier), FLOW_CLASSIFIER_NOT_FOUND); - if (!result) { - return Response.status(204).entity(FLOW_CLASSIFIER_NOT_FOUND).build(); - } - return Response.status(203).entity(result.toString()).build(); - } catch (Exception e) { - return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()).build(); + return Response.status(OK).entity(result.toString()).build(); + } catch (IOException e) { + log.error("Update flow classifier failed because of exception {}.", e.toString()); + throw new IllegalArgumentException(e); } } /** - * Delete details of a flow classifier. Delete details of a specified flow - * classifier id. + * Delete details of a flow classifier. * * @param id flow classifier id - * @return 200 OK - * @throws IOException when input doesn't match. */ @Path("{flow_id}") @DELETE - public Response deleteFlowClassifier(@PathParam("flow_id") String id) throws IOException { - try { - FlowClassifierId flowClassifierId = FlowClassifierId.flowClassifierId(UUID.fromString(id)); - service.removeFlowClassifier(flowClassifierId); - return Response.status(201).entity("SUCCESS").build(); - } catch (Exception e) { - return Response.status(INTERNAL_SERVER_ERROR).entity(e.toString()).build(); - } + public void deleteFlowClassifier(@PathParam("flow_id") String id) { + log.debug("Deletes flow classifier by identifier {}.", id); + FlowClassifierId flowClassifierId = FlowClassifierId.of(id); + Boolean issuccess = nullIsNotFound(service.removeFlowClassifier(flowClassifierId), FLOW_CLASSIFIER_NOT_FOUND); + } } diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortChainWebResource.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortChainWebResource.java new file mode 100644 index 00000000..db12bcc7 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortChainWebResource.java @@ -0,0 +1,157 @@ +/* + * 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.vtnweb.resources; + +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.onlab.util.Tools.nullIsNotFound; + +import java.io.IOException; +import java.io.InputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.onosproject.rest.AbstractWebResource; +import org.onosproject.vtnrsc.PortChain; +import org.onosproject.vtnrsc.PortChainId; +import org.onosproject.vtnrsc.portchain.PortChainService; +import org.onosproject.vtnweb.web.PortChainCodec; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Query and program port chain. + */ + +@Path("port_chains") +public class PortChainWebResource extends AbstractWebResource { + + private final Logger log = LoggerFactory.getLogger(PortChainWebResource.class); + private final PortChainService service = get(PortChainService.class); + public static final String PORT_CHAIN_NOT_FOUND = "Port chain not found"; + public static final String PORT_CHAIN_ID_EXIST = "Port chain exists"; + public static final String PORT_CHAIN_ID_NOT_EXIST = "Port chain does not exist with identifier"; + + /** + * Get details of all port chains created. + * + * @return 200 OK + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getPortChains() { + Iterable<PortChain> portChains = service.getPortChains(); + ObjectNode result = new ObjectMapper().createObjectNode(); + result.set("port_chains", new PortChainCodec().encode(portChains, this)); + return ok(result).build(); + } + + /** + * Get details of a specified port chain id. + * + * @param id port chain id + * @return 200 OK, 404 if given identifier does not exist + */ + @GET + @Path("{chain_id}") + @Produces(MediaType.APPLICATION_JSON) + public Response getPortPain(@PathParam("chain_id") String id) { + + if (!service.exists(PortChainId.of(id))) { + return Response.status(NOT_FOUND).entity(PORT_CHAIN_NOT_FOUND).build(); + } + PortChain portChain = nullIsNotFound(service.getPortChain(PortChainId.of(id)), + PORT_CHAIN_NOT_FOUND); + ObjectNode result = new ObjectMapper().createObjectNode(); + result.set("port_chain", new PortChainCodec().encode(portChain, this)); + return ok(result).build(); + } + + /** + * Creates a new port chain. + * + * @param stream port chain from JSON + * @return status of the request - CREATED if the JSON is correct, + * BAD_REQUEST if the JSON is invalid + */ + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response createPortChain(InputStream stream) { + try { + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); + PortChain portChain = codec(PortChain.class).decode(jsonTree, this); + Boolean issuccess = nullIsNotFound(service.createPortChain(portChain), PORT_CHAIN_NOT_FOUND); + return Response.status(OK).entity(issuccess.toString()).build(); + } catch (IOException e) { + log.error("Exception while creating port chain {}.", e.toString()); + throw new IllegalArgumentException(e); + } + } + + /** + * Update details of a specified port chain id. + * + * @param id port chain id + * @param stream port chain json + * @return 200 OK, 404 if given identifier does not exist + */ + @PUT + @Path("{chain_id}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response updatePortPain(@PathParam("chain_id") String id, + final InputStream stream) { + try { + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); + PortChain portChain = codec(PortChain.class).decode(jsonTree, this); + Boolean result = nullIsNotFound(service.updatePortChain(portChain), PORT_CHAIN_NOT_FOUND); + return Response.status(OK).entity(result.toString()).build(); + } catch (IOException e) { + log.error("Update port chain failed because of exception {}.", e.toString()); + throw new IllegalArgumentException(e); + } + } + + /** + * Delete details of a specified port chain id. + * + * @param id port chain id + */ + @Path("{chain_id}") + @DELETE + public void deletePortPain(@PathParam("chain_id") String id) { + log.debug("Deletes port chain by identifier {}.", id); + PortChainId portChainId = PortChainId.of(id); + + Boolean issuccess = nullIsNotFound(service.removePortChain(portChainId), PORT_CHAIN_NOT_FOUND); + if (!issuccess) { + log.debug("Port Chain identifier {} does not exist", id); + } + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairGroupWebResource.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairGroupWebResource.java new file mode 100644 index 00000000..69daad37 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairGroupWebResource.java @@ -0,0 +1,163 @@ +/* + * 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.resources; + +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.onlab.util.Tools.nullIsNotFound; + +import java.io.IOException; +import java.io.InputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.onosproject.rest.AbstractWebResource; +import org.onosproject.vtnrsc.PortPairGroup; +import org.onosproject.vtnrsc.PortPairGroupId; +import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; +import org.onosproject.vtnweb.web.PortPairGroupCodec; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Query and program port pair group. + */ + +@Path("port_pair_groups") +public class PortPairGroupWebResource extends AbstractWebResource { + + private final Logger log = LoggerFactory.getLogger(PortPairGroupWebResource.class); + private final PortPairGroupService service = get(PortPairGroupService.class); + public static final String PORT_PAIR_GROUP_NOT_FOUND = "Port pair group not found"; + public static final String PORT_PAIR_GROUP_ID_EXIST = "Port pair group exists"; + public static final String PORT_PAIR_GROUP_ID_NOT_EXIST = "Port pair group does not exist with identifier"; + + /** + * Get details of all port pair groups created. + * + * @return 200 OK + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getPortPairGroups() { + Iterable<PortPairGroup> portPairGroups = service.getPortPairGroups(); + ObjectNode result = new ObjectMapper().createObjectNode(); + result.set("port_pair_groups", new PortPairGroupCodec().encode(portPairGroups, this)); + return ok(result).build(); + } + + /** + * Get details of a specified port pair group id. + * + * @param id port pair group id + * @return 200 OK, 404 if given identifier does not exist + */ + @GET + @Path("{group_id}") + @Produces(MediaType.APPLICATION_JSON) + public Response getPortPairGroup(@PathParam("group_id") String id) { + + if (!service.exists(PortPairGroupId.of(id))) { + return Response.status(NOT_FOUND) + .entity(PORT_PAIR_GROUP_NOT_FOUND).build(); + } + PortPairGroup portPairGroup = nullIsNotFound(service.getPortPairGroup(PortPairGroupId.of(id)), + PORT_PAIR_GROUP_NOT_FOUND); + + ObjectNode result = new ObjectMapper().createObjectNode(); + result.set("port_pair_group", new PortPairGroupCodec().encode(portPairGroup, this)); + return ok(result).build(); + } + + /** + * Creates a new port pair group. + * + * @param stream port pair group from JSON + * @return status of the request - CREATED if the JSON is correct, + * BAD_REQUEST if the JSON is invalid + */ + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response createPortPairGroup(InputStream stream) { + + try { + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); + + PortPairGroup portPairGroup = codec(PortPairGroup.class).decode(jsonTree, this); + Boolean issuccess = nullIsNotFound(service.createPortPairGroup(portPairGroup), + PORT_PAIR_GROUP_NOT_FOUND); + return Response.status(OK).entity(issuccess.toString()).build(); + } catch (IOException e) { + log.error("Exception while creating port pair group {}.", e.toString()); + throw new IllegalArgumentException(e); + } + } + + /** + * Update details of a specified port pair group id. + * + * @param id port pair group id + * @param stream port pair group from json + * @return 200 OK, 404 if given identifier does not exist + */ + @PUT + @Path("{group_id}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response updatePortPairGroup(@PathParam("group_id") String id, + final InputStream stream) { + try { + ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream); + PortPairGroup portPairGroup = codec(PortPairGroup.class).decode(jsonTree, this); + Boolean isSuccess = nullIsNotFound(service.updatePortPairGroup(portPairGroup), PORT_PAIR_GROUP_NOT_FOUND); + return Response.status(OK).entity(isSuccess.toString()).build(); + } catch (IOException e) { + log.error("Update port pair group failed because of exception {}.", e.toString()); + throw new IllegalArgumentException(e); + } + } + + /** + * Delete details of a specified port pair group id. + * + * @param id port pair group id + */ + @Path("{group_id}") + @DELETE + public void deletePortPairGroup(@PathParam("group_id") String id) { + log.debug("Deletes port pair group by identifier {}.", id); + PortPairGroupId portPairGroupId = PortPairGroupId.of(id); + Boolean issuccess = nullIsNotFound(service.removePortPairGroup(portPairGroupId), + PORT_PAIR_GROUP_NOT_FOUND); + if (!issuccess) { + log.debug("Port pair group identifier {} does not exist", id); + } + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java new file mode 100644 index 00000000..b9012898 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/resources/PortPairWebResource.java @@ -0,0 +1,166 @@ +/* + * 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.resources; + +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.onlab.util.Tools.nullIsNotFound; + +import java.io.IOException; +import java.io.InputStream; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.onosproject.rest.AbstractWebResource; +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.portpair.PortPairService; +import org.onosproject.vtnweb.web.PortPairCodec; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Query and program port pair. + */ +@Path("port_pairs") +public class PortPairWebResource extends AbstractWebResource { + + private final Logger log = LoggerFactory.getLogger(PortPairWebResource.class); + private final PortPairService service = get(PortPairService.class); + public static final String PORT_PAIR_NOT_FOUND = "Port pair not found"; + public static final String PORT_PAIR_ID_EXIST = "Port pair exists"; + public static final String PORT_PAIR_ID_NOT_EXIST = "Port pair does not exist with identifier"; + + /** + * Get details of all port pairs created. + * + * @return 200 OK + */ + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getPortPairs() { + Iterable<PortPair> portPairs = service.getPortPairs(); + ObjectNode result = new ObjectMapper().createObjectNode(); + ArrayNode portPairEntry = result.putArray("port_pairs"); + if (portPairs != null) { + for (final PortPair portPair : portPairs) { + portPairEntry.add(new PortPairCodec().encode(portPair, this)); + } + } + return ok(result.toString()).build(); + } + + /** + * Get details of a specified port pair id. + * + * @param id port pair id + * @return 200 OK, 404 if given identifier does not exist + */ + @GET + @Path("{pair_id}") + @Produces(MediaType.APPLICATION_JSON) + public Response getPortPair(@PathParam("pair_id") String id) { + + if (!service.exists(PortPairId.of(id))) { + return Response.status(NOT_FOUND).entity(PORT_PAIR_NOT_FOUND).build(); + } + PortPair portPair = nullIsNotFound(service.getPortPair(PortPairId.of(id)), PORT_PAIR_NOT_FOUND); + ObjectNode result = new ObjectMapper().createObjectNode(); + result.set("port_pair", new PortPairCodec().encode(portPair, this)); + return ok(result.toString()).build(); + } + + /** + * Creates a new port pair. + * + * @param stream port pair from JSON + * @return status of the request - CREATED if the JSON is correct, + * BAD_REQUEST if the JSON is invalid + */ + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public Response createPortPair(InputStream stream) { + try { + ObjectMapper mapper = new ObjectMapper(); + ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream); + JsonNode port = jsonTree.get("port_pair"); + PortPair portPair = new PortPairCodec().decode((ObjectNode) port, this); + Boolean isSuccess = nullIsNotFound(service.createPortPair(portPair), PORT_PAIR_NOT_FOUND); + return Response.status(OK).entity(isSuccess.toString()).build(); + } catch (IOException e) { + log.error("Exception while creating port pair {}.", e.toString()); + throw new IllegalArgumentException(e); + } + } + + /** + * Update details of a specified port pair id. + * + * @param id port pair id + * @param stream port pair from json + * @return 200 OK, 404 if the given identifier does not exist + */ + @PUT + @Path("{pair_id}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response updatePortPair(@PathParam("pair_id") String id, + final InputStream stream) { + try { + ObjectMapper mapper = new ObjectMapper(); + ObjectNode jsonTree = (ObjectNode) mapper.readTree(stream); + JsonNode port = jsonTree.get("port_pair"); + PortPair portPair = new PortPairCodec().decode((ObjectNode) port, this); + Boolean isSuccess = nullIsNotFound(service.updatePortPair(portPair), PORT_PAIR_NOT_FOUND); + return Response.status(OK).entity(isSuccess.toString()).build(); + } catch (IOException e) { + log.error("Update port pair failed because of exception {}.", e.toString()); + throw new IllegalArgumentException(e); + } + } + + /** + * Delete details of a specified port pair id. + * + * @param id port pair id + */ + @Path("{pair_id}") + @DELETE + public void deletePortPair(@PathParam("pair_id") String id) { + + PortPairId portPairId = PortPairId.of(id); + Boolean isSuccess = nullIsNotFound(service.removePortPair(portPairId), PORT_PAIR_NOT_FOUND); + if (!isSuccess) { + log.debug("Port pair identifier {} does not exist", id); + } + } +} diff --git a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/FlowClassifierCodec.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/FlowClassifierCodec.java index fd5b1ee4..a18ca362 100644 --- a/framework/src/onos/apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/web/FlowClassifierCodec.java +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/FlowClassifierCodec.java @@ -13,21 +13,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.vtnrsc.web; +package org.onosproject.vtnweb.web; import static com.google.common.base.Preconditions.checkNotNull; import static org.onlab.util.Tools.nullIsIllegal; -import java.util.UUID; - import org.onlab.packet.IpPrefix; import org.onosproject.codec.CodecContext; import org.onosproject.codec.JsonCodec; import org.onosproject.vtnrsc.DefaultFlowClassifier; import org.onosproject.vtnrsc.FlowClassifier; import org.onosproject.vtnrsc.FlowClassifierId; -import org.onosproject.vtnrsc.VirtualPortId; import org.onosproject.vtnrsc.TenantId; +import org.onosproject.vtnrsc.VirtualPortId; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -40,7 +38,7 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { private static final String TENANT_ID = "tenant_id"; private static final String NAME = "name"; private static final String DESCRIPTION = "description"; - private static final String ETHER_TYPE = "etherType"; + private static final String ETHER_TYPE = "ethertype"; private static final String PROTOCOL = "protocol"; private static final String MIN_SRC_PORT_RANGE = "source_port_range_min"; private static final String MAX_SRC_PORT_RANGE = "source_port_range_max"; @@ -62,7 +60,7 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { String flowClassifierId = nullIsIllegal(json.get(FLOW_CLASSIFIER_ID), FLOW_CLASSIFIER_ID + MISSING_MEMBER_MESSAGE).asText(); - resultBuilder.setFlowClassifierId(FlowClassifierId.flowClassifierId(UUID.fromString(flowClassifierId))); + resultBuilder.setFlowClassifierId(FlowClassifierId.of(flowClassifierId)); String tenantId = nullIsIllegal(json.get(TENANT_ID), TENANT_ID + MISSING_MEMBER_MESSAGE).asText(); resultBuilder.setTenantId(TenantId.tenantId(tenantId)); @@ -70,44 +68,46 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { String flowClassiferName = nullIsIllegal(json.get(NAME), NAME + MISSING_MEMBER_MESSAGE).asText(); resultBuilder.setName(flowClassiferName); - String flowClassiferDescription = nullIsIllegal(json.get(DESCRIPTION), DESCRIPTION + MISSING_MEMBER_MESSAGE) - .asText(); + String flowClassiferDescription = (json.get(DESCRIPTION)).asText(); resultBuilder.setDescription(flowClassiferDescription); String etherType = nullIsIllegal(json.get(ETHER_TYPE), ETHER_TYPE + MISSING_MEMBER_MESSAGE).asText(); resultBuilder.setEtherType(etherType); - String protocol = nullIsIllegal(json.get(PROTOCOL), PROTOCOL + MISSING_MEMBER_MESSAGE).asText(); + String protocol = (json.get(PROTOCOL)).asText(); resultBuilder.setProtocol(protocol); - int minSrcPortRange = nullIsIllegal(json.get(MIN_SRC_PORT_RANGE), MIN_SRC_PORT_RANGE + MISSING_MEMBER_MESSAGE) - .asInt(); + int minSrcPortRange = (json.get(MIN_SRC_PORT_RANGE)).asInt(); resultBuilder.setMinSrcPortRange(minSrcPortRange); - int maxSrcPortRange = nullIsIllegal(json.get(MAX_SRC_PORT_RANGE), MAX_SRC_PORT_RANGE + MISSING_MEMBER_MESSAGE) - .asInt(); + int maxSrcPortRange = (json.get(MAX_SRC_PORT_RANGE)).asInt(); resultBuilder.setMaxSrcPortRange(maxSrcPortRange); - int minDstPortRange = nullIsIllegal(json.get(MIN_DST_PORT_RANGE), MIN_DST_PORT_RANGE + MISSING_MEMBER_MESSAGE) - .asInt(); + int minDstPortRange = (json.get(MIN_DST_PORT_RANGE)).asInt(); resultBuilder.setMinDstPortRange(minDstPortRange); - int maxDstPortRange = nullIsIllegal(json.get(MAX_DST_PORT_RANGE), MAX_DST_PORT_RANGE + MISSING_MEMBER_MESSAGE) - .asInt(); + int maxDstPortRange = (json.get(MAX_DST_PORT_RANGE)).asInt(); resultBuilder.setMaxDstPortRange(maxDstPortRange); - String srcIpPrefix = nullIsIllegal(json.get(SRC_IP_PREFIX), SRC_IP_PREFIX + MISSING_MEMBER_MESSAGE).asText(); - resultBuilder.setSrcIpPrefix(IpPrefix.valueOf(srcIpPrefix)); - - String dstIpPrefix = nullIsIllegal(json.get(DST_IP_PREFIX), DST_IP_PREFIX + MISSING_MEMBER_MESSAGE).asText(); - resultBuilder.setDstIpPrefix(IpPrefix.valueOf(dstIpPrefix)); + String srcIpPrefix = (json.get(SRC_IP_PREFIX)).asText(); + if (!srcIpPrefix.isEmpty()) { + resultBuilder.setSrcIpPrefix(IpPrefix.valueOf(srcIpPrefix)); + } - String srcPort = nullIsIllegal(json.get(SRC_PORT), SRC_PORT + MISSING_MEMBER_MESSAGE).asText(); - resultBuilder.setSrcPort(VirtualPortId.portId(srcPort)); + String dstIpPrefix = (json.get(DST_IP_PREFIX)).asText(); + if (!dstIpPrefix.isEmpty()) { + resultBuilder.setDstIpPrefix(IpPrefix.valueOf(dstIpPrefix)); + } - String dstPort = nullIsIllegal(json.get(DST_PORT), DST_PORT + MISSING_MEMBER_MESSAGE).asText(); - resultBuilder.setDstPort(VirtualPortId.portId(dstPort)); + String srcPort = json.get(SRC_PORT) != null ? (json.get(SRC_PORT)).asText() : ""; + if (!srcPort.isEmpty()) { + resultBuilder.setSrcPort(VirtualPortId.portId(srcPort)); + } + String dstPort = json.get(DST_PORT) != null ? (json.get(DST_PORT)).asText() : ""; + if (!dstPort.isEmpty()) { + resultBuilder.setDstPort(VirtualPortId.portId(dstPort)); + } return resultBuilder.build(); } @@ -115,20 +115,20 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { public ObjectNode encode(FlowClassifier flowClassifier, CodecContext context) { checkNotNull(flowClassifier, "flowClassifier cannot be null"); ObjectNode result = context.mapper().createObjectNode() - .put("FLOW_CLASSIFIER_ID", flowClassifier.flowClassifierId().toString()) - .put("TENANT_ID", flowClassifier.tenantId().toString()) - .put("NAME", flowClassifier.name()) - .put("DESCRIPTION", flowClassifier.description()) - .put("ETHER_TYPE", flowClassifier.etherType()) - .put("PROTOCOL", flowClassifier.protocol()) - .put("MIN_SRC_PORT_RANGE", flowClassifier.minSrcPortRange()) - .put("MAX_SRC_PORT_RANGE", flowClassifier.maxSrcPortRange()) - .put("MIN_DST_PORT_RANGE", flowClassifier.minDstPortRange()) - .put("MAX_DST_PORT_RANGE", flowClassifier.maxDstPortRange()) - .put("SRC_IP_PREFIX", flowClassifier.srcIpPrefix().toString()) - .put("DST_IP_PREFIX", flowClassifier.dstIpPrefix().toString()) - .put("SRC_PORT", flowClassifier.srcPort().toString()) - .put("DST_PORT", flowClassifier.dstPort().toString()); + .put(FLOW_CLASSIFIER_ID, flowClassifier.flowClassifierId().toString()) + .put(TENANT_ID, flowClassifier.tenantId().toString()) + .put(NAME, flowClassifier.name()) + .put(DESCRIPTION, flowClassifier.description()) + .put(ETHER_TYPE, flowClassifier.etherType()) + .put(PROTOCOL, flowClassifier.protocol()) + .put(MIN_SRC_PORT_RANGE, flowClassifier.minSrcPortRange()) + .put(MAX_SRC_PORT_RANGE, flowClassifier.maxSrcPortRange()) + .put(MIN_DST_PORT_RANGE, flowClassifier.minDstPortRange()) + .put(MAX_DST_PORT_RANGE, flowClassifier.maxDstPortRange()) + .put(SRC_IP_PREFIX, flowClassifier.srcIpPrefix().toString()) + .put(DST_IP_PREFIX, flowClassifier.dstIpPrefix().toString()) + .put(SRC_PORT, flowClassifier.srcPort().toString()) + .put(DST_PORT, flowClassifier.dstPort().toString()); return result; } -}
\ No newline at end of file +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortChainCodec.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortChainCodec.java index 28da5cd1..1e9cf009 100644 --- a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortChainCodec.java +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortChainCodec.java @@ -59,7 +59,7 @@ public final class PortChainCodec extends JsonCodec<PortChain> { String id = nullIsIllegal(json.get(ID), ID + MISSING_MEMBER_MESSAGE).asText(); - resultBuilder.setId(PortChainId.portChainId(id)); + resultBuilder.setId(PortChainId.of(id)); String tenantId = nullIsIllegal(json.get(TENANT_ID), TENANT_ID + MISSING_MEMBER_MESSAGE).asText(); @@ -76,14 +76,14 @@ public final class PortChainCodec extends JsonCodec<PortChain> { ArrayNode arrayNode = (ArrayNode) json.path(PORT_PAIR_GROUPS); if (arrayNode != null) { List<PortPairGroupId> list = Lists.newArrayList(); - arrayNode.forEach(i -> list.add(PortPairGroupId.portPairGroupId(i.asText()))); + arrayNode.forEach(i -> list.add(PortPairGroupId.of(i.asText()))); resultBuilder.setPortPairGroups(list); } arrayNode = (ArrayNode) json.path(FLOW_CLASSIFIERS); if (arrayNode != null) { List<FlowClassifierId> list = Lists.newArrayList(); - arrayNode.forEach(i -> list.add(FlowClassifierId.flowClassifierId(UUID.fromString(i.asText())))); + arrayNode.forEach(i -> list.add(FlowClassifierId.of(UUID.fromString(i.asText())))); resultBuilder.setFlowClassifiers(list); } diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortPairCodec.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortPairCodec.java new file mode 100644 index 00000000..691536f4 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortPairCodec.java @@ -0,0 +1,94 @@ +/* + * 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 com.google.common.base.Preconditions.checkNotNull; +import static org.onlab.util.Tools.nullIsIllegal; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.core.CoreService; +import org.onosproject.vtnrsc.DefaultPortPair; +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.TenantId; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Port Pair JSON codec. + */ +public final class PortPairCodec extends JsonCodec<PortPair> { + + private static final String ID = "id"; + private static final String TENANT_ID = "tenant_id"; + private static final String NAME = "name"; + private static final String DESCRIPTION = "description"; + private static final String INGRESS = "ingress"; + private static final String EGRESS = "egress"; + private static final String MISSING_MEMBER_MESSAGE = + " member is required in PortPair"; + + @Override + public PortPair decode(ObjectNode json, CodecContext context) { + if (json == null || !json.isObject()) { + return null; + } + + PortPair.Builder resultBuilder = new DefaultPortPair.Builder(); + + CoreService coreService = context.getService(CoreService.class); + + String id = nullIsIllegal(json.get(ID), + ID + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setId(PortPairId.of(id)); + + String tenantId = nullIsIllegal(json.get(TENANT_ID), + TENANT_ID + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setTenantId(TenantId.tenantId(tenantId)); + + String name = nullIsIllegal(json.get(NAME), + NAME + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setName(name); + + String description = nullIsIllegal(json.get(DESCRIPTION), + DESCRIPTION + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setDescription(description); + + String ingressPort = nullIsIllegal(json.get(INGRESS), + INGRESS + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setIngress(ingressPort); + + String egressPort = nullIsIllegal(json.get(EGRESS), + EGRESS + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setEgress(egressPort); + + return resultBuilder.build(); + } + + @Override + public ObjectNode encode(PortPair portPair, CodecContext context) { + checkNotNull(portPair, "port pair cannot be null"); + ObjectNode result = context.mapper().createObjectNode() + .put(ID, portPair.portPairId().toString()) + .put(TENANT_ID, portPair.tenantId().toString()) + .put(NAME, portPair.name()) + .put(DESCRIPTION, portPair.description()) + .put(INGRESS, portPair.ingress()) + .put(EGRESS, portPair.egress()); + return result; + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortPairGroupCodec.java b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortPairGroupCodec.java new file mode 100644 index 00000000..b5ae266b --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/java/org/onosproject/vtnweb/web/PortPairGroupCodec.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 com.google.common.base.Preconditions.checkNotNull; +import static org.onlab.util.Tools.nullIsIllegal; + +import java.util.List; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.core.CoreService; +import org.onosproject.vtnrsc.DefaultPortPairGroup; +import org.onosproject.vtnrsc.PortPairGroup; +import org.onosproject.vtnrsc.PortPairGroupId; +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.TenantId; + +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.collect.Lists; + +/** + * Port Pair Group JSON codec. + */ +public final class PortPairGroupCodec extends JsonCodec<PortPairGroup> { + + private static final String ID = "id"; + private static final String TENANT_ID = "tenant_id"; + private static final String NAME = "name"; + private static final String DESCRIPTION = "description"; + private static final String PORT_PAIRS = "port_pairs"; + private static final String MISSING_MEMBER_MESSAGE = + " member is required in PortPairGroup"; + + @Override + public PortPairGroup decode(ObjectNode json, CodecContext context) { + if (json == null || !json.isObject()) { + return null; + } + + PortPairGroup.Builder resultBuilder = new DefaultPortPairGroup.Builder(); + + CoreService coreService = context.getService(CoreService.class); + + String id = nullIsIllegal(json.get(ID), + ID + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setId(PortPairGroupId.of(id)); + + String tenantId = nullIsIllegal(json.get(TENANT_ID), + TENANT_ID + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setTenantId(TenantId.tenantId(tenantId)); + + String name = nullIsIllegal(json.get(NAME), + NAME + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setName(name); + + String description = nullIsIllegal(json.get(DESCRIPTION), + DESCRIPTION + MISSING_MEMBER_MESSAGE).asText(); + resultBuilder.setDescription(description); + + List<PortPairId> list = Lists.newArrayList(); + ArrayNode arrayNode = (ArrayNode) json.path(PORT_PAIRS); + arrayNode.forEach(i -> list.add(PortPairId.of(i.asText()))); + resultBuilder.setPortPairs(list); + + return resultBuilder.build(); + } + + @Override + public ObjectNode encode(PortPairGroup portPairGroup, CodecContext context) { + checkNotNull(portPairGroup, "port pair group cannot be null"); + ObjectNode result = context.mapper().createObjectNode() + .put(ID, portPairGroup.portPairGroupId().toString()) + .put(TENANT_ID, portPairGroup.tenantId().toString()) + .put(NAME, portPairGroup.name()) + .put(DESCRIPTION, portPairGroup.description()) + .put(PORT_PAIRS, portPairGroup.portPairs().toString()); + return result; + } +} diff --git a/framework/src/onos/apps/vtn/vtnweb/src/main/webapp/WEB-INF/web.xml b/framework/src/onos/apps/vtn/vtnweb/src/main/webapp/WEB-INF/web.xml index 4cc12455..97337960 100644 --- a/framework/src/onos/apps/vtn/vtnweb/src/main/webapp/WEB-INF/web.xml +++ b/framework/src/onos/apps/vtn/vtnweb/src/main/webapp/WEB-INF/web.xml @@ -33,6 +33,10 @@ org.onosproject.vtnweb.resources.TenantNetworkWebResource, org.onosproject.vtnweb.resources.SubnetWebResource, org.onosproject.vtnweb.resources.VirtualPortWebResource + org.onosproject.vtnweb.resources.FlowClassifierWebResource + org.onosproject.vtnweb.resources.PortChainWebResource + org.onosproject.vtnweb.resources.PortPairGroupWebResource + org.onosproject.vtnweb.resources.PortPairWebResource </param-value> </init-param> <load-on-startup>1</load-on-startup> 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<PortChain> 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/PortPairCodecTest.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairCodecTest.java new file mode 100644 index 00000000..7651e098 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/PortPairCodecTest.java @@ -0,0 +1,94 @@ +/* + * 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.PortPair; +import org.onosproject.vtnrsc.PortPairId; +import org.onosproject.vtnrsc.TenantId; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Port pair codec unit tests. + */ +public class PortPairCodecTest { + + SfcCodecContext context; + JsonCodec<PortPair> portPairCodec; + /** + * Sets up for each test. Creates a context and fetches the port pair + * codec. + */ + @Before + public void setUp() { + context = new SfcCodecContext(); + portPairCodec = context.codec(PortPair.class); + assertThat(portPairCodec, notNullValue()); + } + + /** + * Reads in a port pair from the given resource and decodes it. + * + * @param resourceName resource to use to read the JSON for the port pair + * @return decoded port pair + * @throws IOException if processing the resource fails + */ + private PortPair getPortPair(String resourceName) throws IOException { + InputStream jsonStream = PortPairCodecTest.class + .getResourceAsStream(resourceName); + ObjectMapper mapper = new ObjectMapper(); + JsonNode json = mapper.readTree(jsonStream); + assertThat(json, notNullValue()); + PortPair portPair = portPairCodec.decode((ObjectNode) json, context); + assertThat(portPair, notNullValue()); + return portPair; + } + + /** + * Checks that a simple port pair decodes properly. + * + * @throws IOException if the resource cannot be processed + */ + @Test + public void codecPortPairTest() throws IOException { + + PortPair portPair = getPortPair("portPair.json"); + + assertThat(portPair, notNullValue()); + + PortPairId portPairId = PortPairId.of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); + TenantId tenantId = TenantId.tenantId("d382007aa9904763a801f68ecf065cf5"); + + assertThat(portPair.portPairId().toString(), is(portPairId.toString())); + assertThat(portPair.name(), is("PP1")); + assertThat(portPair.tenantId().toString(), is(tenantId.toString())); + assertThat(portPair.description(), is("SF-A")); + assertThat(portPair.ingress().toString(), is("dace4513-24fc-4fae-af4b-321c5e2eb3d1")); + assertThat(portPair.egress().toString(), is("aef3478a-4a56-2a6e-cd3a-9dee4e2ec345")); + } +} 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<PortPairGroup> 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/java/org/onosproject/vtnweb/web/SfcCodecContext.java b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/SfcCodecContext.java new file mode 100644 index 00000000..fe9d7995 --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/java/org/onosproject/vtnweb/web/SfcCodecContext.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.vtnweb.web; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.onosproject.codec.CodecContext; +import org.onosproject.codec.JsonCodec; +import org.onosproject.vtnrsc.FlowClassifier; +import org.onosproject.vtnrsc.PortChain; +import org.onosproject.vtnrsc.PortPair; +import org.onosproject.vtnrsc.PortPairGroup; + +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Mock codec context for use in codec unit tests. + */ +public class SfcCodecContext implements CodecContext { + + private final ObjectMapper mapper = new ObjectMapper(); + private final Map<Class<?>, JsonCodec> codecs = new ConcurrentHashMap<>(); + + /** + * Constructs a new mock codec context. + */ + public SfcCodecContext() { + codecs.clear(); + registerCodec(PortPair.class, new PortPairCodec()); + registerCodec(PortChain.class, new PortChainCodec()); + registerCodec(PortPairGroup.class, new PortPairGroupCodec()); + registerCodec(FlowClassifier.class, new FlowClassifierCodec()); + } + + @Override + public ObjectMapper mapper() { + return mapper; + } + + @SuppressWarnings("unchecked") + @Override + public <T> T getService(Class<T> serviceClass) { + // TODO + return null; + } + + /** + * Registers the specified JSON codec for the given entity class. + * + * @param entityClass entity class + * @param codec JSON codec + * @param <T> entity type + */ + public <T> void registerCodec(Class<T> entityClass, JsonCodec<T> codec) { + codecs.putIfAbsent(entityClass, codec); + } + + @SuppressWarnings("unchecked") + @Override + public <T> JsonCodec<T> codec(Class<T> entityClass) { + return codecs.get(entityClass); + } +} 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/portPair.json b/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portPair.json new file mode 100644 index 00000000..f858c88c --- /dev/null +++ b/framework/src/onos/apps/vtn/vtnweb/src/test/resources/org/onosproject/vtnweb/web/portPair.json @@ -0,0 +1,9 @@ +{ + "id": "78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae", + "name": "PP1", + "tenant_id": "d382007aa9904763a801f68ecf065cf5", + "description": "SF-A", + "ingress": "dace4513-24fc-4fae-af4b-321c5e2eb3d1", + "egress": "aef3478a-4a56-2a6e-cd3a-9dee4e2ec345" +} + 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/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java b/framework/src/onos/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java deleted file mode 100644 index 1f686aeb..00000000 --- a/framework/src/onos/apps/xos-integration/src/main/java/org/onosproject/xosintegration/OnosXOSIntegrationManager.java +++ /dev/null @@ -1,545 +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.xosintegration; - -import com.eclipsesource.json.JsonArray; -import com.eclipsesource.json.JsonObject; -import com.google.common.collect.Maps; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientHandlerException; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter; -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.Modified; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.Service; -import org.onlab.packet.VlanId; -import org.onlab.util.Tools; -import org.onosproject.cfg.ComponentConfigService; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DeviceId; -import org.onosproject.net.PortNumber; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.flowobjective.DefaultForwardingObjective; -import org.onosproject.net.flowobjective.FlowObjectiveService; -import org.onosproject.net.flowobjective.ForwardingObjective; -import org.osgi.service.component.ComponentContext; -import org.slf4j.Logger; - -import java.util.Dictionary; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -import static com.google.common.base.Strings.isNullOrEmpty; -import static com.google.common.net.MediaType.JSON_UTF_8; -import static java.net.HttpURLConnection.HTTP_CREATED; -import static java.net.HttpURLConnection.HTTP_NO_CONTENT; -import static java.net.HttpURLConnection.HTTP_OK; -import static org.slf4j.LoggerFactory.getLogger; - - -/** - * XOS interface application. - */ -@Component(immediate = true) -@Service -public class OnosXOSIntegrationManager implements VoltTenantService { - private static final String XOS_SERVER_ADDRESS_PROPERTY_NAME = - "xosServerAddress"; - private static final String XOS_SERVER_PORT_PROPERTY_NAME = - "xosServerPort"; - private static final String XOS_PROVIDER_SERVICE_PROPERTY_NAME = - "xosProviderService"; - - private static final String TEST_XOS_SERVER_ADDRESS = "10.254.1.22"; - private static final int TEST_XOS_SERVER_PORT = 8000; - private static final String XOS_TENANT_BASE_URI = "/xoslib/volttenant/"; - private static final int TEST_XOS_PROVIDER_SERVICE = 1; - - private static final int PRIORITY = 50000; - private static final DeviceId FABRIC_DEVICE_ID = DeviceId.deviceId("of:5e3e486e73000187"); - private static final PortNumber FABRIC_OLT_CONNECT_POINT = PortNumber.portNumber(2); - private static final PortNumber FABRIC_VCPE_CONNECT_POINT = PortNumber.portNumber(3); - private static final String FABRIC_CONTROLLER_ADDRESS = "10.0.3.136"; - private static final int FABRIC_SERVER_PORT = 8181; - private static final String FABRIC_BASE_URI = "/onos/cordfabric/vlans/add"; - - private static final DeviceId OLT_DEVICE_ID = DeviceId.deviceId("of:90e2ba82f97791e9"); - private static final int OLT_UPLINK_PORT = 129; - - private static final ConnectPoint FABRIC_PORT = new ConnectPoint( - DeviceId.deviceId("of:000090e2ba82f974"), - PortNumber.portNumber(2)); - - private final Logger log = getLogger(getClass()); - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ComponentConfigService cfgService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected FlowObjectiveService flowObjectiveService; - - @Property(name = XOS_SERVER_ADDRESS_PROPERTY_NAME, - value = TEST_XOS_SERVER_ADDRESS, - label = "XOS Server address") - protected String xosServerAddress = TEST_XOS_SERVER_ADDRESS; - - @Property(name = XOS_SERVER_PORT_PROPERTY_NAME, - intValue = TEST_XOS_SERVER_PORT, - label = "XOS Server port") - protected int xosServerPort = TEST_XOS_SERVER_PORT; - - @Property(name = XOS_PROVIDER_SERVICE_PROPERTY_NAME, - intValue = TEST_XOS_PROVIDER_SERVICE, - label = "XOS Provider Service") - protected int xosProviderService = TEST_XOS_PROVIDER_SERVICE; - - private ApplicationId appId; - private Map<String, ConnectPoint> nodeToPort; - private Map<Long, Short> portToVlan; - private Map<ConnectPoint, String> portToSsid; - - @Activate - public void activate(ComponentContext context) { - log.info("XOS app is starting"); - cfgService.registerProperties(getClass()); - appId = coreService.registerApplication("org.onosproject.xosintegration"); - - setupMap(); - - readComponentConfiguration(context); - - log.info("XOS({}) started", appId.id()); - } - - @Deactivate - public void deactivate() { - cfgService.unregisterProperties(getClass(), false); - log.info("XOS({}) stopped", appId.id()); - } - - @Modified - public void modified(ComponentContext context) { - readComponentConfiguration(context); - } - - private void setupMap() { - nodeToPort = Maps.newHashMap(); - - nodeToPort.put("cordcompute01.onlab.us", new ConnectPoint(FABRIC_DEVICE_ID, - PortNumber.portNumber(4))); - - nodeToPort.put("cordcompute02.onlab.us", new ConnectPoint(FABRIC_DEVICE_ID, - PortNumber.portNumber(3))); - - portToVlan = Maps.newHashMap(); - portToVlan.putIfAbsent(1L, (short) 201); - portToVlan.putIfAbsent(6L, (short) 401); - - portToSsid = Maps.newHashMap(); - portToSsid.put(new ConnectPoint(OLT_DEVICE_ID, PortNumber.portNumber(1)), "0"); - portToSsid.put(new ConnectPoint(FABRIC_DEVICE_ID, PortNumber.portNumber(6)), "1"); - } - - /** - * Converts a JSON representation of a tenant into a tenant object. - * - * @param jsonTenant JSON object representing the tenant - * @return volt tenant object - */ - private VoltTenant jsonToTenant(JsonObject jsonTenant) { - return VoltTenant.builder() - .withHumanReadableName(jsonTenant.get("humanReadableName").asString()) - .withId(jsonTenant.get("id").asInt()) - .withProviderService(jsonTenant.get("provider_service").asInt()) - .withServiceSpecificId(jsonTenant.get("service_specific_id").asString()) - .withVlanId(jsonTenant.get("vlan_id").asString()) - .build(); - } - - /** - * Converts a tenant object into a JSON string. - * - * @param tenant volt tenant object to convert - * @return JSON string for the tenant - */ - private String tenantToJson(VoltTenant tenant) { - return "{" - + "\"humanReadableName\": \"" + tenant.humanReadableName() + "\"," - + "\"id\": \"" + tenant.id() + "\"," - + "\"provider_service\": \"" + tenant.providerService() + "\"," - + "\"service_specific_id\": \"" + tenant.serviceSpecificId() + "\"," - + "\"vlan_id\": \"" + tenant.vlanId() + "\"" - + "}"; - } - - /** - * Gets a client web resource builder for the base XOS REST API - * with no additional URI. - * - * @return web resource builder - * @deprecated in Cardinal Release - */ - @Deprecated - private WebResource.Builder getClientBuilder() { - return getClientBuilder(""); - } - - /** - * Gets a client web resource builder for the base XOS REST API - * with an optional additional URI. - * - * @return web resource builder - * @deprecated in Cardinal Release - */ - @Deprecated - private WebResource.Builder getClientBuilder(String uri) { - String baseUrl = "http://" + xosServerAddress + ":" - + Integer.toString(xosServerPort); - Client client = Client.create(); - client.addFilter(new HTTPBasicAuthFilter("padmin@vicci.org", "letmein")); - WebResource resource = client.resource(baseUrl - + XOS_TENANT_BASE_URI + uri); - return resource.accept(JSON_UTF_8.toString()) - .type(JSON_UTF_8.toString()); - } - - /** - * Performs a REST GET operation on the base XOS REST URI. - * - * @return JSON string fetched by the GET operation - * @deprecated in Cardinal Release - */ - @Deprecated - private String getRest() { - return getRest(""); - } - - /** - * Performs a REST GET operation on the base XOS REST URI with - * an optional additional URI. - * - * @return JSON string fetched by the GET operation - * @deprecated in Cardinal Release - */ - @Deprecated - private String getRest(String uri) { - WebResource.Builder builder = getClientBuilder(uri); - ClientResponse response = builder.get(ClientResponse.class); - - if (response.getStatus() != HTTP_OK) { - log.info("REST GET request returned error code {}", - response.getStatus()); - } - String jsonString = response.getEntity(String.class); - log.info("JSON read:\n{}", jsonString); - - return jsonString; - } - - /** - * Performs a REST POST operation of a json string on the base - * XOS REST URI with an optional additional URI. - * - * @param json JSON string to post - * @deprecated in Cardinal Release - */ - @Deprecated - private String postRest(String json) { - WebResource.Builder builder = getClientBuilder(); - ClientResponse response; - - try { - response = builder.post(ClientResponse.class, json); - } catch (ClientHandlerException e) { - log.warn("Unable to contact REST server: {}", e.getMessage()); - return "{ 'error' : 'oops no one home' }"; - } - - if (response.getStatus() != HTTP_CREATED) { - log.info("REST POST request returned error code {}", - response.getStatus()); - } - return response.getEntity(String.class); - } - - /** - * Performs a REST DELETE operation on the base - * XOS REST URI with an optional additional URI. - * - * @param uri optional additional URI - * @deprecated in Cardinal Release - */ - @Deprecated - private void deleteRest(String uri) { - WebResource.Builder builder = getClientBuilder(uri); - ClientResponse response = builder.delete(ClientResponse.class); - - if (response.getStatus() != HTTP_NO_CONTENT) { - log.info("REST DELETE request returned error code {}", - response.getStatus()); - } - } - - /** - * Deletes the tenant with the given ID. - * - * @param tenantId ID of tenant to delete - */ - private void deleteTenant(long tenantId) { - deleteRest(Long.toString(tenantId)); - } - - @Override - public Set<VoltTenant> getAllTenants() { - String jsonString = getRest(); - - JsonArray voltTenantItems = JsonArray.readFrom(jsonString); - - return IntStream.range(0, voltTenantItems.size()) - .mapToObj(index -> jsonToTenant(voltTenantItems.get(index).asObject())) - .collect(Collectors.toSet()); - } - - @Override - public void removeTenant(long id) { - deleteTenant(id); - } - - @Override - public VoltTenant addTenant(VoltTenant newTenant) { - long providerServiceId = newTenant.providerService(); - if (providerServiceId == -1) { - providerServiceId = xosProviderService; - } - - PortNumber onuPort = newTenant.port().port(); - VlanId subscriberVlan = VlanId.vlanId(portToVlan.get(onuPort.toLong())); - - VoltTenant tenantToCreate = VoltTenant.builder() - .withProviderService(providerServiceId) - .withServiceSpecificId(portToSsid.get(newTenant.port())) - .withVlanId(String.valueOf(subscriberVlan.toShort())) - .withPort(newTenant.port()) - .build(); - String json = tenantToJson(tenantToCreate); - - - provisionVlanOnPort(OLT_DEVICE_ID, OLT_UPLINK_PORT, onuPort, subscriberVlan.toShort()); - - String retJson = postRest(json); - - fetchCPELocation(tenantToCreate, retJson); - - return newTenant; - } - - private void fetchCPELocation(VoltTenant newTenant, String jsonString) { - JsonObject json = JsonObject.readFrom(jsonString); - - if (json.get("computeNodeName") != null) { - ConnectPoint point = nodeToPort.get(json.get("computeNodeName").asString()); - //ConnectPoint fromPoint = newTenant.port(); - ConnectPoint oltPort = new ConnectPoint(FABRIC_DEVICE_ID, FABRIC_OLT_CONNECT_POINT); - - provisionFabric(VlanId.vlanId(Short.parseShort(newTenant.vlanId())), - point, oltPort); - } - - } - - @Override - public VoltTenant getTenant(long id) { - String jsonString = getRest(Long.toString(id)); - JsonObject jsonTenant = JsonObject.readFrom(jsonString); - if (jsonTenant.get("id") != null) { - return jsonToTenant(jsonTenant); - } else { - return null; - } - } - - private void provisionVlanOnPort(DeviceId deviceId, int uplinkPort, PortNumber p, short vlanId) { - - TrafficSelector upstream = DefaultTrafficSelector.builder() - .matchVlanId(VlanId.ANY) - .matchInPort(p) - .build(); - - TrafficSelector downstream = DefaultTrafficSelector.builder() - .matchVlanId(VlanId.vlanId(vlanId)) - .matchInPort(PortNumber.portNumber(uplinkPort)) - .build(); - - TrafficTreatment upstreamTreatment = DefaultTrafficTreatment.builder() - .setVlanId(VlanId.vlanId(vlanId)) - .setOutput(PortNumber.portNumber(uplinkPort)) - .build(); - - TrafficTreatment downstreamTreatment = DefaultTrafficTreatment.builder() - .popVlan() - .setOutput(p) - .build(); - - - ForwardingObjective upFwd = DefaultForwardingObjective.builder() - .withFlag(ForwardingObjective.Flag.VERSATILE) - .withPriority(1000) - .makePermanent() - .withSelector(upstream) - .fromApp(appId) - .withTreatment(upstreamTreatment) - .add(); - - ForwardingObjective downFwd = DefaultForwardingObjective.builder() - .withFlag(ForwardingObjective.Flag.VERSATILE) - .withPriority(1000) - .makePermanent() - .withSelector(downstream) - .fromApp(appId) - .withTreatment(downstreamTreatment) - .add(); - - flowObjectiveService.forward(deviceId, upFwd); - flowObjectiveService.forward(deviceId, downFwd); - - } - - private void provisionDataPlane(VoltTenant tenant) { - VlanId vlan = VlanId.vlanId(Short.parseShort(tenant.vlanId())); - - TrafficSelector fromGateway = DefaultTrafficSelector.builder() - .matchInPhyPort(tenant.port().port()) - .build(); - - TrafficSelector fromFabric = DefaultTrafficSelector.builder() - .matchInPhyPort(FABRIC_PORT.port()) - .matchVlanId(vlan) - .build(); - - TrafficTreatment toFabric = DefaultTrafficTreatment.builder() - .pushVlan() - .setVlanId(vlan) - .setOutput(FABRIC_PORT.port()) - .build(); - - TrafficTreatment toGateway = DefaultTrafficTreatment.builder() - .popVlan() - .setOutput(tenant.port().port()) - .build(); - - ForwardingObjective forwardToFabric = DefaultForwardingObjective.builder() - .withFlag(ForwardingObjective.Flag.VERSATILE) - .withPriority(PRIORITY) - .makePermanent() - .fromApp(appId) - .withSelector(fromGateway) - .withTreatment(toFabric) - .add(); - - ForwardingObjective forwardToGateway = DefaultForwardingObjective.builder() - .withFlag(ForwardingObjective.Flag.VERSATILE) - .withPriority(PRIORITY) - .makePermanent() - .fromApp(appId) - .withSelector(fromFabric) - .withTreatment(toGateway) - .add(); - - flowObjectiveService.forward(FABRIC_PORT.deviceId(), forwardToFabric); - flowObjectiveService.forward(FABRIC_PORT.deviceId(), forwardToGateway); - } - - private void provisionFabric(VlanId vlanId, ConnectPoint point, ConnectPoint fromPoint) { - - long vlan = vlanId.toShort(); - - JsonObject node = new JsonObject(); - node.add("vlan", vlan); - if (vlan == 201) { - node.add("iptv", true); - } else { - node.add("iptv", false); - } - JsonArray array = new JsonArray(); - JsonObject cp1 = new JsonObject(); - JsonObject cp2 = new JsonObject(); - cp1.add("device", point.deviceId().toString()); - cp1.add("port", point.port().toLong()); - cp2.add("device", fromPoint.deviceId().toString()); - cp2.add("port", fromPoint.port().toLong()); - array.add(cp1); - array.add(cp2); - node.add("ports", array); - - - String baseUrl = "http://" + FABRIC_CONTROLLER_ADDRESS + ":" - + Integer.toString(FABRIC_SERVER_PORT); - Client client = Client.create(); - WebResource resource = client.resource(baseUrl + FABRIC_BASE_URI); - WebResource.Builder builder = resource.accept(JSON_UTF_8.toString()) - .type(JSON_UTF_8.toString()); - - try { - builder.post(ClientResponse.class, node.toString()); - } catch (ClientHandlerException e) { - log.warn("Unable to contact fabric REST server: {}", e.getMessage()); - return; - } - } - - /** - * Extracts properties from the component configuration context. - * - * @param context the component context - */ - private void readComponentConfiguration(ComponentContext context) { - Dictionary<?, ?> properties = context.getProperties(); - - String newXosServerAddress = - Tools.get(properties, XOS_SERVER_ADDRESS_PROPERTY_NAME); - if (!isNullOrEmpty(newXosServerAddress)) { - xosServerAddress = newXosServerAddress; - } - - String newXosServerPortString = - Tools.get(properties, XOS_SERVER_PORT_PROPERTY_NAME); - if (!isNullOrEmpty(newXosServerPortString)) { - xosServerPort = Integer.parseInt(newXosServerPortString); - } - - String newXosProviderServiceString = - Tools.get(properties, XOS_PROVIDER_SERVICE_PROPERTY_NAME); - if (!isNullOrEmpty(newXosProviderServiceString)) { - xosProviderService = Integer.parseInt(newXosProviderServiceString); - } - } -} - - diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java index 49432aab..9d44041e 100755 --- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java +++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPController.java @@ -16,11 +16,15 @@ package org.onosproject.bgp.controller; +import java.util.Map; +import java.util.Set; + +import org.onosproject.bgpio.exceptions.BGPParseException; import org.onosproject.bgpio.protocol.BGPMessage; /** - * Abstraction of an BGP controller. Serves as a one stop shop for obtaining BGP devices and (un)register listeners - * on bgp events + * Abstraction of an BGP controller. Serves as a one stop shop for obtaining BGP devices and (un)register listeners on + * bgp events */ public interface BGPController { @@ -40,6 +44,34 @@ public interface BGPController { BGPPeer getPeer(BGPId bgpId); /** + * Register a listener for BGP message events. + * + * @param listener the listener to notify + */ + void addListener(BgpNodeListener listener); + + /** + * Unregister a listener. + * + * @param listener the listener to unregister + */ + void removeListener(BgpNodeListener listener); + + /** + * Register a listener for BGP message events. + * + * @param listener the listener to notify + */ + void addLinkListener(BgpLinkListener listener); + + /** + * Unregister a listener. + * + * @param listener the listener to unregister + */ + void removeLinkListener(BgpLinkListener listener); + + /** * Send a message to a particular bgp peer. * * @param bgpId the id of the peer to send message. @@ -52,8 +84,9 @@ public interface BGPController { * * @param bgpId id of the peer the message arrived on * @param msg the message to process. + * @throws BGPParseException on data processing error */ - void processBGPPacket(BGPId bgpId, BGPMessage msg); + void processBGPPacket(BGPId bgpId, BGPMessage msg) throws BGPParseException; /** * Close all connected BGP peers. @@ -73,5 +106,33 @@ public interface BGPController { * * @return the integer number */ - int getBGPConnNumber(); -}
\ No newline at end of file + int connectedPeerCount(); + + /** + * Return BGP peer manager. + * + * @return BGPPeerManager peer manager instance + */ + BgpPeerManager peerManager(); + + /** + * Return BGP connected peers. + * + * @return connectedPeers connected peers + */ + Map<BGPId, BGPPeer> connectedPeers(); + + /** + * Return BGP node listener. + * + * @return node listener + */ + Set<BgpNodeListener> listener(); + + /** + * Return BGP link listener. + * + * @return link listener + */ + Set<BgpLinkListener> linkListener(); +} diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java index 1b022c76..aafaf06e 100755 --- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java +++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeer.java @@ -16,30 +16,16 @@ package org.onosproject.bgp.controller; import java.util.List; import org.jboss.netty.channel.Channel; +import org.onosproject.bgpio.protocol.BGPFactory; import org.onosproject.bgpio.protocol.BGPMessage; -import org.onosproject.bgpio.protocol.BGPVersion; /** - * Represents the peer side of an bgp peer. + * Represents the peer side of an BGP peer. * */ public interface BGPPeer { /** - * Sets the BGP version for this bgp peer. - * - * @param bgpVersion the version to set. - */ - void setBgpPeerVersion(BGPVersion bgpVersion); - - /** - * Gets the BGP version for this bgp peer. - * - * @return bgp identifier. - */ - int getBgpPeerIdentifier(); - - /** * Sets the associated Netty channel for this bgp peer. * * @param channel the Netty channel @@ -54,27 +40,6 @@ public interface BGPPeer { Channel getChannel(); /** - * Sets the AS Number for this bgp peer. - * - * @param peerASNum the autonomous system number value to set. - */ - void setBgpPeerASNum(short peerASNum); - - /** - * Sets the hold time for this bgp peer. - * - * @param peerHoldTime the hold timer value to set. - */ - void setBgpPeerHoldTime(short peerHoldTime); - - /** - * Sets the peer identifier value. - * - * @param peerIdentifier the bgp peer identifier value. - */ - void setBgpPeerIdentifier(int peerIdentifier); - - /** * Sets whether the bgp peer is connected. * * @param connected whether the bgp peer is connected @@ -82,15 +47,6 @@ public interface BGPPeer { void setConnected(boolean connected); /** - * Initialises the behaviour. - * - * @param bgpId id of bgp peer - * @param bgpVersion BGP version - * @param pktStats packet statistics - */ - void init(BGPId bgpId, BGPVersion bgpVersion, BGPPacketStats pktStats); - - /** * Checks whether the handshake is complete. * * @return true is finished, false if not. @@ -112,18 +68,11 @@ public interface BGPPeer { void sendMessage(List<BGPMessage> msgs); /** - * Gets a string version of the ID for this bgp peer. + * Provides the factory for BGP version. * - * @return string version of the ID + * @return BGP version specific factory. */ - String getStringId(); - - /** - * Gets the ipAddress of the peer. - * - * @return the peer bgpId in IPAddress format - */ - BGPId getBGPId(); + BGPFactory factory(); /** * Checks if the bgp peer is still connected. @@ -146,16 +95,9 @@ public interface BGPPeer { String channelId(); /** - * Gets the negotiated hold time. - * - * @return the negotiated hold time - */ - int getNegotiatedHoldTime(); - - /** - * Sets negotiated hold time for the peer. + * Return the BGP session info. * - * @param negotiatedHoldTime negotiated hold time + * @return sessionInfo bgp session info */ - void setNegotiatedHoldTime(short negotiatedHoldTime); + BgpSessionInfo sessionInfo(); } diff --git a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java index 87ec031f..e7c5d9b4 100755 --- a/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java +++ b/framework/src/onos/bgp/api/src/main/java/org/onosproject/bgp/controller/BGPPeerCfg.java @@ -163,4 +163,18 @@ public interface BGPPeerCfg { * AS number */ void setPeerRouterId(String peerId, int asNumber); + + /** + * Set the peer connect instance. + * + * @param connectpeer connect peer instance + */ + void setConnectPeer(BgpConnectPeer connectpeer); + + /** + * Get the peer connect instance. + * + * @return peer connect instance + */ + BgpConnectPeer connectPeer(); } diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPLSNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPLSNlri.java index 572e2aeb..189edb88 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPLSNlri.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPLSNlri.java @@ -16,7 +16,7 @@ package org.onosproject.bgpio.protocol; import org.onosproject.bgpio.exceptions.BGPParseException; -import org.onosproject.bgpio.protocol.link_state.BGPNodeLSNlriVer4.PROTOCOLTYPE; +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4.PROTOCOLTYPE; import org.onosproject.bgpio.types.RouteDistinguisher; /** @@ -51,4 +51,4 @@ public interface BGPLSNlri { * @return Route distinguisher in Nlri */ RouteDistinguisher getRouteDistinguisher(); -}
\ No newline at end of file +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNodeLSNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNodeLSNlri.java index fd5b8056..b6e4a3a0 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNodeLSNlri.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPNodeLSNlri.java @@ -15,7 +15,7 @@ */ package org.onosproject.bgpio.protocol; -import org.onosproject.bgpio.protocol.link_state.BGPNodeLSIdentifier; +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSIdentifier; /** * Abstraction of an entity providing BGP-LS Node NLRI. @@ -27,4 +27,4 @@ public interface BGPNodeLSNlri extends BGPLSNlri { * @return local node descriptors */ BGPNodeLSIdentifier getLocalNodeDescriptors(); -}
\ No newline at end of file +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java index a8c242b4..bf5d05f4 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPOpenMsg.java @@ -72,13 +72,6 @@ public interface BGPOpenMsg extends BGPMessage { BGPOpenMsg build() throws BGPParseException; /** - * Returns hold time of Open Message. - * - * @return hold time of Open Message - */ - short getHoldTime(); - - /** * Sets hold time in Open Message and return its builder. * * @param holdtime hold timer value in open message @@ -87,13 +80,6 @@ public interface BGPOpenMsg extends BGPMessage { Builder setHoldTime(short holdtime); /** - * Returns as number of Open Message. - * - * @return as number of Open Message - */ - short getAsNumber(); - - /** * Sets AS number in Open Message and return its builder. * * @param asNumber as number in open message @@ -102,13 +88,6 @@ public interface BGPOpenMsg extends BGPMessage { Builder setAsNumber(short asNumber); /** - * Returns BGP Identifier of Open Message. - * - * @return BGP Identifier of Open Message - */ - int getBgpId(); - - /** * Sets BGP Identifier in Open Message and return its builder. * * @param bgpId BGP Identifier in open message @@ -117,13 +96,6 @@ public interface BGPOpenMsg extends BGPMessage { Builder setBgpId(int bgpId); /** - * Returns capabilities of Open Message. - * - * @return capabilities of Open Message - */ - LinkedList<BGPValueType> getCapabilityTlv(); - - /** * Sets capabilities in Open Message and return its builder. * * @param capabilityTlv capabilities in open message diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPPrefixLSNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPPrefixLSNlri.java index 7e849f48..2c331a2e 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPPrefixLSNlri.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BGPPrefixLSNlri.java @@ -18,7 +18,7 @@ package org.onosproject.bgpio.protocol; import java.util.LinkedList; import org.onosproject.bgpio.types.BGPValueType; -import org.onosproject.bgpio.protocol.link_state.NodeDescriptors; +import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; /** * Abstraction of an entity providing BGP-LS Prefix NLRI. @@ -37,4 +37,4 @@ public interface BGPPrefixLSNlri extends BGPLSNlri { * @return list of Prefix descriptor */ LinkedList<BGPValueType> getPrefixdescriptor(); -}
\ No newline at end of file +} diff --git a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepPacketStats.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java index d00cd5a8..dab7a3d2 100644 --- a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepPacketStats.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpLinkLsNlri.java @@ -13,38 +13,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.pcep.controller; +package org.onosproject.bgpio.protocol; -/** - * The representation for PCEP packet statistics. - */ -public interface PcepPacketStats { +import java.util.List; - /** - * Returns the count for no of packets sent out. - * - * @return int value of no of packets sent - */ - int outPacketCount(); +import org.onosproject.bgpio.types.BGPValueType; +import org.onosproject.bgpio.protocol.linkstate.NodeDescriptors; +/** + * Abstraction of an entity providing BGP-LS Link NLRI. + */ +public interface BgpLinkLsNlri extends BGPLSNlri { /** - * Returns the count for no of packets received. + * Returns local node descriptors. * - * @return int value of no of packets sent + * @return local node descriptors */ - int inPacketCount(); + NodeDescriptors localNodeDescriptors(); /** - * Returns the count for no of wrong packets received. + * Returns remote node descriptors. * - * @return int value of no of wrong packets received + * @return remote node descriptors */ - int wrongPacketCount(); + NodeDescriptors remoteNodeDescriptors(); /** - * Returns the time value. + * Returns link descriptors. * - * @return long value of time + * @return link descriptors */ - long getTime(); -} + List<BGPValueType> linkDescriptors(); +}
\ No newline at end of file diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpErrorSpec.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java index 8d3c67a7..969936c8 100644 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpErrorSpec.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/BgpUpdateMsg.java @@ -13,34 +13,36 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.pcepio.types; -import org.jboss.netty.buffer.ChannelBuffer; +package org.onosproject.bgpio.protocol; + +import java.util.List; + +import org.onlab.packet.IpPrefix; +import org.onosproject.bgpio.protocol.ver4.BgpPathAttributes; /** - * Abstraction of an entity which provides PCPE RSVP error spec. + * Abstraction of an entity providing BGP Update Message. */ -public interface PcepRsvpErrorSpec extends PcepValueType { - +public interface BgpUpdateMsg extends BGPMessage { /** - * To write the object information to channelBuffer. + * Returns path attributes in BGP Update Message. * - * @param cb of type channel buffer + * @return path attributes in BGP Update Message */ - @Override - int write(ChannelBuffer cb); + BgpPathAttributes bgpPathAttributes(); /** - * Returns class number. + * Returns withdrawn Routes. * - * @return class number + * @return withdrawn Routes */ - byte getClassNum(); + List<IpPrefix> withdrawnRoutes(); /** - * Returns class type. + * Returns NLRI list of prefix. * - * @return class type + * @return NLRI list of prefix */ - byte getClassType(); + List<IpPrefix> nlri(); } diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java new file mode 100755 index 00000000..ffea74db --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPLinkLSIdentifier.java @@ -0,0 +1,252 @@ +/* + * 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.linkstate; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +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.types.IPv4AddressTlv; +import org.onosproject.bgpio.types.IPv6AddressTlv; +import org.onosproject.bgpio.types.LinkLocalRemoteIdentifiersTlv; +import org.onosproject.bgpio.types.attr.BgpAttrNodeMultiTopologyId; +import org.onosproject.bgpio.util.UnSupportedAttribute; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; + +/** + * Implementation of local node descriptors, remote node descriptors and link descriptors. + */ +public class BGPLinkLSIdentifier { + private static final Logger log = LoggerFactory.getLogger(BGPLinkLSIdentifier.class); + public static final short IPV4_INTERFACE_ADDRESS_TYPE = 259; + public static final short IPV4_NEIGHBOR_ADDRESS_TYPE = 260; + public static final short IPV6_INTERFACE_ADDRESS_TYPE = 261; + public static final short IPV6_NEIGHBOR_ADDRESS_TYPE = 262; + public static final int TYPE_AND_LEN = 4; + + private NodeDescriptors localNodeDescriptors; + private NodeDescriptors remoteNodeDescriptors; + private List<BGPValueType> linkDescriptor; + + /** + * Initialize fields. + */ + public BGPLinkLSIdentifier() { + this.localNodeDescriptors = null; + this.remoteNodeDescriptors = null; + this.linkDescriptor = null; + } + + /** + * Constructors to initialize parameters. + * + * @param localNodeDescriptors local node descriptors + * @param remoteNodeDescriptors remote node descriptors + * @param linkDescriptor link descriptors + */ + public BGPLinkLSIdentifier(NodeDescriptors localNodeDescriptors, NodeDescriptors remoteNodeDescriptors, + LinkedList<BGPValueType> linkDescriptor) { + this.localNodeDescriptors = Preconditions.checkNotNull(localNodeDescriptors); + this.remoteNodeDescriptors = Preconditions.checkNotNull(remoteNodeDescriptors); + this.linkDescriptor = Preconditions.checkNotNull(linkDescriptor); + } + + /** + * Reads channel buffer and parses link identifier. + * + * @param cb ChannelBuffer + * @param protocolId in linkstate nlri + * @return object of BGPLinkLSIdentifier + * @throws BGPParseException while parsing link identifier + */ + public static BGPLinkLSIdentifier parseLinkIdendifier(ChannelBuffer cb, byte protocolId) throws BGPParseException { + //Parse local node descriptor + NodeDescriptors localNodeDescriptors = new NodeDescriptors(); + localNodeDescriptors = parseNodeDescriptors(cb, NodeDescriptors.LOCAL_NODE_DES_TYPE, protocolId); + + //Parse remote node descriptor + NodeDescriptors remoteNodeDescriptors = new NodeDescriptors(); + remoteNodeDescriptors = parseNodeDescriptors(cb, NodeDescriptors.REMOTE_NODE_DES_TYPE, protocolId); + + //Parse link descriptor + LinkedList<BGPValueType> linkDescriptor = new LinkedList<>(); + linkDescriptor = parseLinkDescriptors(cb); + return new BGPLinkLSIdentifier(localNodeDescriptors, remoteNodeDescriptors, linkDescriptor); + } + + /** + * Parses Local/Remote node descriptors. + * + * @param cb ChannelBuffer + * @param desType descriptor type + * @param protocolId protocol identifier + * @return object of NodeDescriptors + * @throws BGPParseException while parsing Local/Remote node descriptors + */ + public static NodeDescriptors parseNodeDescriptors(ChannelBuffer cb, short desType, byte protocolId) + throws BGPParseException { + ChannelBuffer tempBuf = cb; + short type = cb.readShort(); + short length = cb.readShort(); + if (cb.readableBytes() < length) { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR, + tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN)); + } + NodeDescriptors nodeIdentifier = new NodeDescriptors(); + ChannelBuffer tempCb = cb.readBytes(length); + + if (type == desType) { + nodeIdentifier = NodeDescriptors.read(tempCb, length, desType, protocolId); + } else { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null); + } + return nodeIdentifier; + } + + /** + * Parses link descriptors. + * + * @param cb ChannelBuffer + * @return list of link descriptors + * @throws BGPParseException while parsing link descriptors + */ + public static LinkedList<BGPValueType> parseLinkDescriptors(ChannelBuffer cb) throws BGPParseException { + LinkedList<BGPValueType> linkDescriptor = new LinkedList<>(); + BGPValueType tlv = null; + int count = 0; + + while (cb.readableBytes() > 0) { + ChannelBuffer tempBuf = cb; + short type = cb.readShort(); + short length = cb.readShort(); + if (cb.readableBytes() < length) { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR, + tempBuf.readBytes(cb.readableBytes() + TYPE_AND_LEN)); + } + ChannelBuffer tempCb = cb.readBytes(length); + switch (type) { + case LinkLocalRemoteIdentifiersTlv.TYPE: + tlv = LinkLocalRemoteIdentifiersTlv.read(tempCb); + break; + case IPV4_INTERFACE_ADDRESS_TYPE: + tlv = IPv4AddressTlv.read(tempCb, IPV4_INTERFACE_ADDRESS_TYPE); + break; + case IPV4_NEIGHBOR_ADDRESS_TYPE: + tlv = IPv4AddressTlv.read(tempCb, IPV4_NEIGHBOR_ADDRESS_TYPE); + break; + case IPV6_INTERFACE_ADDRESS_TYPE: + tlv = IPv6AddressTlv.read(tempCb, IPV6_INTERFACE_ADDRESS_TYPE); + break; + case IPV6_NEIGHBOR_ADDRESS_TYPE: + tlv = IPv6AddressTlv.read(tempCb, IPV6_NEIGHBOR_ADDRESS_TYPE); + break; + case BgpAttrNodeMultiTopologyId.ATTRNODE_MULTITOPOLOGY: + tlv = BgpAttrNodeMultiTopologyId.read(tempCb); + count = count++; + //MultiTopologyId TLV cannot repeat more than once + if (count > 1) { + //length + 4 implies data contains type, length and value + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.OPTIONAL_ATTRIBUTE_ERROR, tempBuf.readBytes(length + + TYPE_AND_LEN)); + } + break; + default: + UnSupportedAttribute.skipBytes(tempCb, length); + } + linkDescriptor.add(tlv); + } + return linkDescriptor; + } + + /** + * Returns local node descriptors. + * + * @return local node descriptors + */ + public NodeDescriptors localNodeDescriptors() { + return this.localNodeDescriptors; + } + + /** + * Returns remote node descriptors. + * + * @return remote node descriptors + */ + public NodeDescriptors remoteNodeDescriptors() { + return this.remoteNodeDescriptors; + } + + /** + * Returns link descriptors. + * + * @return link descriptors + */ + public List<BGPValueType> linkDescriptors() { + return this.linkDescriptor; + } + + @Override + public int hashCode() { + return Objects.hash(linkDescriptor, localNodeDescriptors, remoteNodeDescriptors); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof BGPLinkLSIdentifier) { + int countObjSubTlv = 0; + int countOtherSubTlv = 0; + boolean isCommonSubTlv = true; + BGPLinkLSIdentifier other = (BGPLinkLSIdentifier) obj; + Iterator<BGPValueType> objListIterator = other.linkDescriptor.iterator(); + countOtherSubTlv = other.linkDescriptor.size(); + countObjSubTlv = linkDescriptor.size(); + if (countObjSubTlv != countOtherSubTlv) { + return false; + } else { + while (objListIterator.hasNext() && isCommonSubTlv) { + BGPValueType subTlv = objListIterator.next(); + isCommonSubTlv = Objects.equals(linkDescriptor.contains(subTlv), + other.linkDescriptor.contains(subTlv)); + } + return isCommonSubTlv && Objects.equals(this.localNodeDescriptors, other.localNodeDescriptors) + && Objects.equals(this.remoteNodeDescriptors, other.remoteNodeDescriptors); + } + } + return false; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("localNodeDescriptors", localNodeDescriptors) + .add("remoteNodeDescriptors", remoteNodeDescriptors) + .add("linkDescriptor", linkDescriptor) + .toString(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSIdentifier.java index cd2422a7..603bf6ec 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSIdentifier.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSIdentifier.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.bgpio.protocol.link_state; +package org.onosproject.bgpio.protocol.linkstate; import java.util.Objects; @@ -110,4 +110,4 @@ public class BGPNodeLSIdentifier { .add("NodeDescriptors", nodeDescriptors) .toString(); } -}
\ No newline at end of file +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSNlriVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSNlriVer4.java index 04780d82..54837ee8 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPNodeLSNlriVer4.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPNodeLSNlriVer4.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.bgpio.protocol.link_state; +package org.onosproject.bgpio.protocol.linkstate; import org.jboss.netty.buffer.ChannelBuffer; import org.onosproject.bgpio.exceptions.BGPParseException; @@ -209,4 +209,4 @@ public class BGPNodeLSNlriVer4 implements BGPNodeLSNlri { .add("localNodeDescriptors", localNodeDescriptors) .toString(); } -}
\ No newline at end of file +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixIPv4LSNlriVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixIPv4LSNlriVer4.java index 0f18c757..6d6f48b1 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixIPv4LSNlriVer4.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixIPv4LSNlriVer4.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.bgpio.protocol.link_state; +package org.onosproject.bgpio.protocol.linkstate; import java.util.LinkedList; @@ -21,7 +21,7 @@ import org.jboss.netty.buffer.ChannelBuffer; import org.onosproject.bgpio.exceptions.BGPParseException; import org.onosproject.bgpio.protocol.BGPPrefixLSNlri; import org.onosproject.bgpio.protocol.NlriType; -import org.onosproject.bgpio.protocol.link_state.BGPNodeLSNlriVer4.PROTOCOLTYPE; +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4.PROTOCOLTYPE; import org.onosproject.bgpio.types.BGPValueType; import org.onosproject.bgpio.types.RouteDistinguisher; import org.onosproject.bgpio.util.Constants; @@ -202,4 +202,4 @@ public class BGPPrefixIPv4LSNlriVer4 implements BGPPrefixLSNlri { .add("bgpPrefixLSIdentifier", bgpPrefixLSIdentifier) .toString(); } -}
\ No newline at end of file +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixLSIdentifier.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixLSIdentifier.java index 4fef47ff..23f41794 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/BGPPrefixLSIdentifier.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/BGPPrefixLSIdentifier.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.onosproject.bgpio.protocol.link_state; +package org.onosproject.bgpio.protocol.linkstate; import java.util.Iterator; import java.util.LinkedList; @@ -225,4 +225,4 @@ public class BGPPrefixLSIdentifier { .add("prefixDescriptor", prefixDescriptor) .toString(); } -}
\ No newline at end of file +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/NodeDescriptors.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java index a03b2bae..74637c7e 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/NodeDescriptors.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/NodeDescriptors.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.onosproject.bgpio.protocol.link_state; +package org.onosproject.bgpio.protocol.linkstate; import java.util.Iterator; import java.util.LinkedList; @@ -222,4 +222,4 @@ public class NodeDescriptors { .add("subTlvs", subTlvs) .toString(); } -}
\ No newline at end of file +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/package-info.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/package-info.java index d2a2ccf3..87ba60f0 100755 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/link_state/package-info.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/linkstate/package-info.java @@ -17,4 +17,4 @@ /** * BGP Protocol specific link state details. */ -package org.onosproject.bgpio.protocol.link_state;
\ No newline at end of file +package org.onosproject.bgpio.protocol.linkstate; diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java index b50342d6..fccbf5f7 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BGPOpenMsgVer4.java @@ -311,8 +311,8 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg { if (this.isLargeAsCapabilityTlvSet) { BGPValueType tlv; - int iValue = this.getAsNumber(); - tlv = new FourOctetAsNumCapabilityTlv(iValue); + int value = this.asNumber; + tlv = new FourOctetAsNumCapabilityTlv(value); this.capabilityTlv.add(tlv); } @@ -333,26 +333,6 @@ public class BGPOpenMsgVer4 implements BGPOpenMsg { } @Override - public short getHoldTime() { - return this.holdTime; - } - - @Override - public short getAsNumber() { - return this.asNumber; - } - - @Override - public int getBgpId() { - return this.bgpId; - } - - @Override - public LinkedList<BGPValueType> getCapabilityTlv() { - return this.capabilityTlv; - } - - @Override public Builder setHoldTime(short holdTime) { this.holdTime = holdTime; this.isHoldTimeSet = true; diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java index 08fea4c6..20a7ba03 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpPathAttributes.java @@ -28,6 +28,8 @@ import org.onosproject.bgpio.types.LocalPref; import org.onosproject.bgpio.types.Med; import org.onosproject.bgpio.types.NextHop; import org.onosproject.bgpio.types.Origin; +import org.onosproject.bgpio.types.MpReachNlri; +import org.onosproject.bgpio.types.MpUnReachNlri; import org.onosproject.bgpio.util.UnSupportedAttribute; import org.onosproject.bgpio.util.Validation; import org.slf4j.Logger; @@ -127,11 +129,14 @@ public class BgpPathAttributes { case LocalPref.LOCAL_PREF_TYPE: pathAttribute = LocalPref.read(cb); break; - case MPREACHNLRI_TYPE: - //TODO: To be merged later + case MpReachNlri.MPREACHNLRI_TYPE: + pathAttribute = MpReachNlri.read(cb); + isMpReach = ((MpReachNlri) pathAttribute).isMpReachNlriSet(); break; - case MPUNREACHNLRI_TYPE: - //TODO: To be merged later + case MpUnReachNlri.MPUNREACHNLRI_TYPE: + pathAttribute = MpUnReachNlri.read(cb); + isMpUnReach = ((MpUnReachNlri) pathAttribute) + .isMpUnReachNlriSet(); break; case LINK_STATE_ATTRIBUTE_TYPE: //TODO: To be merged later diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java new file mode 100644 index 00000000..9f4cf9b9 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/protocol/ver4/BgpUpdateMsgVer4.java @@ -0,0 +1,285 @@ +/* + * 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.ver4; + +import java.util.LinkedList; +import java.util.List; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.onlab.packet.IpPrefix; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.protocol.BGPMessageReader; +import org.onosproject.bgpio.protocol.BGPType; +import org.onosproject.bgpio.protocol.BgpUpdateMsg; +import org.onosproject.bgpio.types.BGPErrorType; +import org.onosproject.bgpio.types.BGPHeader; +import org.onosproject.bgpio.util.Validation; +import org.onosproject.bgpio.protocol.BGPVersion; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/** + * BGP Update Message: UPDATE messages are used to transfer routing information + * between BGP peers. The information in the UPDATE message is used by core to + * construct a graph + */ +public class BgpUpdateMsgVer4 implements BgpUpdateMsg { + + /* 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | | + + + + | | + + + + | Marker | + + + + | | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Length | Type | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Withdrawn Routes Length (2 octets) | + +-----------------------------------------------------+ + | Withdrawn Routes (variable) | + +-----------------------------------------------------+ + | Total Path Attribute Length (2 octets) | + +-----------------------------------------------------+ + | Path Attributes (variable) | + +-----------------------------------------------------+ + | Network Layer Reachability Information (variable) | + +-----------------------------------------------------+ + REFERENCE : RFC 4271 + */ + + protected static final Logger log = LoggerFactory + .getLogger(BgpUpdateMsgVer4.class); + + public static final byte PACKET_VERSION = 4; + //Withdrawn Routes Length(2) + Total Path Attribute Length(2) + public static final int PACKET_MINIMUM_LENGTH = 4; + public static final int BYTE_IN_BITS = 8; + public static final int MIN_LEN_AFTER_WITHDRW_ROUTES = 2; + public static final int MINIMUM_COMMON_HEADER_LENGTH = 19; + public static final BGPType MSG_TYPE = BGPType.UPDATE; + public static final BgpUpdateMsgVer4.Reader READER = new Reader(); + + private List<IpPrefix> withdrawnRoutes; + private BgpPathAttributes bgpPathAttributes; + private BGPHeader bgpHeader; + private List<IpPrefix> nlri; + + /** + * Constructor to initialize parameters for BGP Update message. + * + * @param bgpHeader in Update message + * @param withdrawnRoutes withdrawn routes + * @param bgpPathAttributes BGP Path attributes + * @param nlri Network Layer Reachability Information + */ + public BgpUpdateMsgVer4(BGPHeader bgpHeader, List<IpPrefix> withdrawnRoutes, + BgpPathAttributes bgpPathAttributes, List<IpPrefix> nlri) { + this.bgpHeader = bgpHeader; + this.withdrawnRoutes = withdrawnRoutes; + this.bgpPathAttributes = bgpPathAttributes; + this.nlri = nlri; + } + + /** + * Reader reads BGP Update Message from the channel buffer. + */ + static class Reader implements BGPMessageReader<BgpUpdateMsg> { + + @Override + public BgpUpdateMsg readFrom(ChannelBuffer cb, BGPHeader bgpHeader) + throws BGPParseException { + + if (cb.readableBytes() != (bgpHeader.getLength() - MINIMUM_COMMON_HEADER_LENGTH)) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.BAD_MESSAGE_LENGTH, bgpHeader.getLength()); + } + + LinkedList<IpPrefix> withDrwRoutes = new LinkedList<>(); + LinkedList<IpPrefix> nlri = new LinkedList<>(); + BgpPathAttributes bgpPathAttributes = new BgpPathAttributes(); + // Reading Withdrawn Routes Length + Short withDrwLen = cb.readShort(); + + if (cb.readableBytes() < withDrwLen) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, + cb.readableBytes()); + } + ChannelBuffer tempCb = cb.readBytes(withDrwLen); + if (withDrwLen != 0) { + // Parsing WithdrawnRoutes + withDrwRoutes = parseWithdrawnRoutes(tempCb); + } + if (cb.readableBytes() < MIN_LEN_AFTER_WITHDRW_ROUTES) { + log.debug("Bgp Path Attribute len field not present"); + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null); + } + + // Reading Total Path Attribute Length + short totPathAttrLen = cb.readShort(); + int len = withDrwLen + totPathAttrLen + PACKET_MINIMUM_LENGTH; + if (len > bgpHeader.getLength()) { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, null); + } + if (totPathAttrLen != 0) { + // Parsing BGPPathAttributes + if (cb.readableBytes() < totPathAttrLen) { + Validation + .validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, + cb.readableBytes()); + } + tempCb = cb.readBytes(totPathAttrLen); + bgpPathAttributes = BgpPathAttributes.read(tempCb); + } + if (cb.readableBytes() > 0) { + // Parsing NLRI + nlri = parseNlri(cb); + } + return new BgpUpdateMsgVer4(bgpHeader, withDrwRoutes, + bgpPathAttributes, nlri); + } + } + + /** + * Parses NLRI from channel buffer. + * + * @param cb channelBuffer + * @return list of IP Prefix + * @throws BGPParseException while parsing NLRI + */ + public static LinkedList<IpPrefix> parseNlri(ChannelBuffer cb) + throws BGPParseException { + LinkedList<IpPrefix> nlri = new LinkedList<>(); + while (cb.readableBytes() > 0) { + int length = cb.readByte(); + IpPrefix ipPrefix; + if (length == 0) { + byte[] prefix = new byte[] {0}; + ipPrefix = Validation.bytesToPrefix(prefix, length); + nlri.add(ipPrefix); + } else { + int len = length / BYTE_IN_BITS; + int reminder = length % BYTE_IN_BITS; + if (reminder > 0) { + len = len + 1; + } + if (cb.readableBytes() < len) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, + cb.readableBytes()); + } + byte[] prefix = new byte[len]; + cb.readBytes(prefix, 0, len); + ipPrefix = Validation.bytesToPrefix(prefix, length); + nlri.add(ipPrefix); + } + } + return nlri; + } + + /** + * Parsing withdrawn routes from channel buffer. + * + * @param cb channelBuffer + * @return list of IP prefix + * @throws BGPParseException while parsing withdrawn routes + */ + public static LinkedList<IpPrefix> parseWithdrawnRoutes(ChannelBuffer cb) + throws BGPParseException { + LinkedList<IpPrefix> withDrwRoutes = new LinkedList<>(); + while (cb.readableBytes() > 0) { + int length = cb.readByte(); + IpPrefix ipPrefix; + if (length == 0) { + byte[] prefix = new byte[] {0}; + ipPrefix = Validation.bytesToPrefix(prefix, length); + withDrwRoutes.add(ipPrefix); + } else { + int len = length / BYTE_IN_BITS; + int reminder = length % BYTE_IN_BITS; + if (reminder > 0) { + len = len + 1; + } + if (cb.readableBytes() < len) { + Validation + .validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.MALFORMED_ATTRIBUTE_LIST, + cb.readableBytes()); + } + byte[] prefix = new byte[len]; + cb.readBytes(prefix, 0, len); + ipPrefix = Validation.bytesToPrefix(prefix, length); + withDrwRoutes.add(ipPrefix); + } + } + return withDrwRoutes; + } + + @Override + public BGPVersion getVersion() { + return BGPVersion.BGP_4; + } + + @Override + public BGPType getType() { + return BGPType.UPDATE; + } + + @Override + public void writeTo(ChannelBuffer channelBuffer) throws BGPParseException { + //Not to be implemented as of now + } + + @Override + public BgpPathAttributes bgpPathAttributes() { + return this.bgpPathAttributes; + } + + @Override + public List<IpPrefix> withdrawnRoutes() { + return withdrawnRoutes; + } + + @Override + public List<IpPrefix> nlri() { + return nlri; + } + + @Override + public BGPHeader getHeader() { + return this.bgpHeader; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .omitNullValues() + .add("bgpHeader", bgpHeader) + .add("withDrawnRoutes", withdrawnRoutes) + .add("nlri", nlri) + .add("bgpPathAttributes", bgpPathAttributes) + .toString(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java index 90e94e88..e9df3999 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/As4Path.java @@ -21,6 +21,7 @@ import java.util.Objects; import org.jboss.netty.buffer.ChannelBuffer; import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.util.Constants; import org.onosproject.bgpio.util.Validation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,8 +35,6 @@ public class As4Path implements BGPValueType { private static final Logger log = LoggerFactory.getLogger(AsPath.class); public static final byte AS4PATH_TYPE = 17; public static final byte ASNUM_SIZE = 4; - public static final int TYPE_AND_LEN_AS_SHORT = 4; - public static final int TYPE_AND_LEN_AS_BYTE = 3; private List<Integer> as4pathSet; private List<Integer> as4pathSeq; @@ -77,8 +76,8 @@ public class As4Path implements BGPValueType { validation.getLength()); } //if fourth bit is set length is read as short otherwise as byte , len includes type, length and value - int len = validation.isShort() ? validation.getLength() + TYPE_AND_LEN_AS_SHORT : validation - .getLength() + TYPE_AND_LEN_AS_BYTE; + int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation + .getLength() + Constants.TYPE_AND_LEN_AS_BYTE; ChannelBuffer data = tempCb.readBytes(len); if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) { throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data); diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java index 100e14d7..e3eb2c51 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/AsPath.java @@ -22,6 +22,7 @@ import java.util.Objects; import org.jboss.netty.buffer.ChannelBuffer; import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.util.Constants; import org.onosproject.bgpio.util.Validation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,7 +54,7 @@ public class AsPath implements BGPValueType { * * @return AS type */ - public byte getType() { + public byte type() { return (byte) value; } } @@ -63,8 +64,6 @@ public class AsPath implements BGPValueType { public static final byte ASPATH_SET_TYPE = 1; public static final byte ASPATH_SEQ_TYPE = 2; public static final byte ASNUM_SIZE = 2; - public static final int TYPE_AND_LEN_AS_SHORT = 4; - public static final int TYPE_AND_LEN_AS_BYTE = 3; private boolean isAsPath = false; private List<Short> aspathSet; @@ -108,8 +107,8 @@ public class AsPath implements BGPValueType { validation.getLength()); } //if fourth bit is set, length is read as short otherwise as byte , len includes type, length and value - int len = validation.isShort() ? validation.getLength() + TYPE_AND_LEN_AS_SHORT : validation - .getLength() + TYPE_AND_LEN_AS_BYTE; + int len = validation.isShort() ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : validation + .getLength() + Constants.TYPE_AND_LEN_AS_BYTE; ChannelBuffer data = tempCb.readBytes(len); if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) { throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data); diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java index f643ae00..dfcfc9dc 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BGPErrorType.java @@ -28,8 +28,8 @@ public final class BGPErrorType { public static final byte OPEN_MESSAGE_ERROR = 2; public static final byte UPDATE_MESSAGE_ERROR = 3; public static final byte HOLD_TIMER_EXPIRED = 4; - public static final byte FINITE_STATE_MACHINE_ERROR = 4; - public static final byte CEASE = 5; + public static final byte FINITE_STATE_MACHINE_ERROR = 5; + public static final byte CEASE = 6; //Message Header Error subcodes public static final byte CONNECTION_NOT_SYNCHRONIZED = 1; @@ -42,6 +42,7 @@ public final class BGPErrorType { public static final byte BAD_BGP_IDENTIFIER = 3; public static final byte UNSUPPORTED_OPTIONAL_PARAMETER = 4; public static final byte UNACCEPTABLE_HOLD_TIME = 5; + public static final byte UNSUPPORTED_CAPABILITY = 7; //UPDATE Message Error subcodes public static final byte MALFORMED_ATTRIBUTE_LIST = 1; @@ -54,4 +55,20 @@ public final class BGPErrorType { public static final byte OPTIONAL_ATTRIBUTE_ERROR = 9; public static final byte INVALID_NETWORK_FIELD = 10; public static final byte MALFORMED_ASPATH = 11; + + //FSM Error subcodes + public static final byte UNSPECIFIED_ERROR = 0; + public static final byte RECEIVE_UNEXPECTED_MESSAGE_IN_OPENSENT_STATE = 1; + public static final byte RECEIVE_UNEXPECTED_MESSAGE_IN_OPENCONFIRM_STATE = 2; + public static final byte RECEIVE_UNEXPECTED_MESSAGE_IN_ESTABLISHED_STATE = 3; + + //Cease Error subcodes + public static final byte MAXIMUM_NUMBER_OF_PREFIXES_REACHED = 1; + public static final byte ADMINISTRATIVE_SHUTDOWN = 2; + public static final byte PEER_DECONFIGURED = 3; + public static final byte ADMINISTRATIVE_RESET = 4; + public static final byte CONNECTION_REJECTED = 5; + public static final byte OTHER_CONFIGURATION_CHANGE = 6; + public static final byte CONNECTION_COLLISION_RESOLUTION = 7; + public static final byte OUT_OF_RESOURCES = 8; }
\ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java index 85fb748b..59afbed6 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPReachabilityInformationTlv.java @@ -15,6 +15,7 @@ */ package org.onosproject.bgpio.types; +import java.util.Arrays; import java.util.Objects; import org.jboss.netty.buffer.ChannelBuffer; @@ -86,7 +87,7 @@ public class IPReachabilityInformationTlv implements BGPValueType { @Override public int hashCode() { - return Objects.hash(ipPrefix, prefixLen); + return Objects.hash(Arrays.hashCode(ipPrefix), prefixLen); } @Override @@ -97,7 +98,7 @@ public class IPReachabilityInformationTlv implements BGPValueType { if (obj instanceof IPReachabilityInformationTlv) { IPReachabilityInformationTlv other = (IPReachabilityInformationTlv) obj; - return Objects.equals(prefixLen, other.prefixLen) && Objects.equals(ipPrefix, other.ipPrefix); + return Objects.equals(prefixLen, other.prefixLen) && Arrays.equals(ipPrefix, other.ipPrefix); } return false; } diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java new file mode 100644 index 00000000..d5f03268 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv4AddressTlv.java @@ -0,0 +1,128 @@ +/* + * 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.net.InetAddress; +import java.util.Objects; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.onlab.packet.Ip4Address; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; + +/** + * Provides Implementation of IPv4AddressTlv. + */ +public class IPv4AddressTlv implements BGPValueType { + private static final Logger log = LoggerFactory.getLogger(IPv4AddressTlv.class); + private static final int LENGTH = 4; + + private Ip4Address address; + private short type; + + /** + * Constructor to initialize parameters. + * + * @param address Ipv4 address of interface/neighbor + * @param type address type + */ + public IPv4AddressTlv(Ip4Address address, short type) { + this.address = Preconditions.checkNotNull(address); + this.type = type; + } + + /** + * Returns Ipv4 address of interface/neighbor. + * + * @return Ipv4 address of interface/neighbor + */ + public Ip4Address getValue() { + return address; + } + + @Override + public short getType() { + return this.type; + } + + @Override + public int hashCode() { + return Objects.hash(address); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof IPv4AddressTlv) { + IPv4AddressTlv other = (IPv4AddressTlv) obj; + return Objects.equals(this.address, other.address) && Objects.equals(this.type, other.type); + } + return false; + } + + @Override + public int write(ChannelBuffer cb) { + int iLenStartIndex = cb.writerIndex(); + cb.writeShort(type); + cb.writeShort(LENGTH); + cb.writeInt(address.toInt()); + return cb.writerIndex() - iLenStartIndex; + } + + /** + * Reads the channel buffer and returns object of IPv4AddressTlv. + * + * @param cb channelBuffer + * @param type address type + * @return object of IPv4AddressTlv + * @throws BGPParseException while parsing IPv4AddressTlv + */ + public static IPv4AddressTlv read(ChannelBuffer cb, short type) throws BGPParseException { + //TODO: use Validation.toInetAddress once Validation is merged + InetAddress ipAddress = (InetAddress) cb.readBytes(LENGTH); + if (ipAddress.isMulticastAddress()) { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null); + } + Ip4Address address = Ip4Address.valueOf(ipAddress); + return IPv4AddressTlv.of(address, type); + } + + /** + * Returns object of this class with specified values. + * + * @param address Ipv4 interface/neighbor Address + * @param type says Ipv4 address of interface/neighbor tlv type + * @return object of this class + */ + public static IPv4AddressTlv of(final Ip4Address address , final short type) { + return new IPv4AddressTlv(address, type); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("type", type) + .add("LENGTH", LENGTH) + .add("address", address) + .toString(); + } +}
\ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java new file mode 100644 index 00000000..65b7c16d --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IPv6AddressTlv.java @@ -0,0 +1,128 @@ +/* + * 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.net.InetAddress; +import java.util.Objects; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.onlab.packet.Ip6Address; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; + +/** + * Provides Implementation of IPv6AddressTlv. + */ +public class IPv6AddressTlv implements BGPValueType { + private static final Logger log = LoggerFactory.getLogger(IPv6AddressTlv.class); + private static final int LENGTH = 16; + + private final Ip6Address address; + private short type; + + /** + * Constructor to initialize parameters. + * + * @param address Ipv6 address of interface/neighbor + * @param type address type + */ + public IPv6AddressTlv(Ip6Address address, short type) { + this.address = Preconditions.checkNotNull(address); + this.type = type; + } + + /** + * Returns Ipv6 address of interface/neighbor. + * + * @return Ipv6 address of interface/neighbor + */ + public Ip6Address getValue() { + return address; + } + + @Override + public short getType() { + return type; + } + + @Override + public int hashCode() { + return Objects.hash(address); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof IPv6AddressTlv) { + IPv6AddressTlv other = (IPv6AddressTlv) obj; + return Objects.equals(this.address, other.address) && Objects.equals(this.type, other.type); + } + return false; + } + + @Override + public int write(ChannelBuffer cb) { + int iLenStartIndex = cb.writerIndex(); + cb.writeShort(type); + cb.writeShort(LENGTH); + cb.writeBytes(address.toOctets()); + return cb.writerIndex() - iLenStartIndex; + } + + /** + * Reads the channel buffer and returns object of IPv6AddressTlv. + * + * @param cb channelBuffer + * @param type address type + * @return object of IPv6AddressTlv + * @throws BGPParseException while parsing IPv6AddressTlv + */ + public static IPv6AddressTlv read(ChannelBuffer cb, short type) throws BGPParseException { + //TODO: use Validation.toInetAddress once Validation is merged + InetAddress ipAddress = (InetAddress) cb.readBytes(LENGTH); + if (ipAddress.isMulticastAddress()) { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, (byte) 0, null); + } + Ip6Address address = Ip6Address.valueOf(ipAddress); + return IPv6AddressTlv.of(address, type); + } + + /** + * Returns object of this class with specified values. + * + * @param address Ipv6 interface/neighbor address + * @param type says Ipv6 address of interface/neighbor tlv type + * @return object of this class + */ + public static IPv6AddressTlv of(final Ip6Address address , final short type) { + return new IPv6AddressTlv(address, type); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("type", type) + .add("LENGTH", LENGTH) + .add("address", address) + .toString(); + } +}
\ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java index 5c742d0f..35fd2493 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/IsIsPseudonode.java @@ -15,6 +15,9 @@ */ package org.onosproject.bgpio.types; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; import java.util.Objects; import org.jboss.netty.buffer.ChannelBuffer; @@ -28,12 +31,12 @@ import com.google.common.base.MoreObjects; * Provides implementation of IsIsPseudonode Tlv. */ public class IsIsPseudonode implements IGPRouterID, BGPValueType { - protected static final Logger log = LoggerFactory.getLogger(IsIsPseudonode.class); + private static final Logger log = LoggerFactory.getLogger(IsIsPseudonode.class); public static final short TYPE = 515; public static final short LENGTH = 7; - private final byte[] isoNodeID; + private final List<Byte> isoNodeID; private byte psnIdentifier; /** @@ -42,7 +45,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { * @param isoNodeID ISO system-ID * @param psnIdentifier PSN identifier */ - public IsIsPseudonode(byte[] isoNodeID, byte psnIdentifier) { + public IsIsPseudonode(List<Byte> isoNodeID, byte psnIdentifier) { this.isoNodeID = isoNodeID; this.psnIdentifier = psnIdentifier; } @@ -54,7 +57,8 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { * @param psnIdentifier PSN identifier * @return object of IsIsPseudonode */ - public static IsIsPseudonode of(final byte[] isoNodeID, final byte psnIdentifier) { + public static IsIsPseudonode of(final List<Byte> isoNodeID, + final byte psnIdentifier) { return new IsIsPseudonode(isoNodeID, psnIdentifier); } @@ -63,7 +67,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { * * @return ISO NodeID */ - public byte[] getISONodeID() { + public List<Byte> getISONodeID() { return isoNodeID; } @@ -78,7 +82,7 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { @Override public int hashCode() { - return Objects.hash(isoNodeID, psnIdentifier); + return Objects.hash(isoNodeID) & Objects.hash(psnIdentifier); } @Override @@ -87,8 +91,27 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { return true; } if (obj instanceof IsIsPseudonode) { + int countObjSubTlv = 0; + int countOtherSubTlv = 0; + boolean isCommonSubTlv = true; IsIsPseudonode other = (IsIsPseudonode) obj; - return Objects.equals(isoNodeID, other.isoNodeID) && Objects.equals(psnIdentifier, other.psnIdentifier); + Iterator<Byte> objListIterator = other.isoNodeID.iterator(); + countOtherSubTlv = other.isoNodeID.size(); + countObjSubTlv = isoNodeID.size(); + if (countObjSubTlv != countOtherSubTlv) { + return false; + } else { + while (objListIterator.hasNext() && isCommonSubTlv) { + Byte subTlv = objListIterator.next(); + if (isoNodeID.contains(subTlv) && other.isoNodeID.contains(subTlv)) { + isCommonSubTlv = Objects.equals(isoNodeID.get(isoNodeID.indexOf(subTlv)), + other.isoNodeID.get(other.isoNodeID.indexOf(subTlv))); + } else { + isCommonSubTlv = false; + } + } + return isCommonSubTlv && Objects.equals(psnIdentifier, other.psnIdentifier); + } } return false; } @@ -98,7 +121,11 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { int iLenStartIndex = c.writerIndex(); c.writeShort(TYPE); c.writeShort(LENGTH); - c.writeBytes(isoNodeID); + Iterator<Byte> objListIterator = isoNodeID.iterator(); + while (objListIterator.hasNext()) { + byte value = objListIterator.next(); + c.writeByte(value); + } c.writeByte(psnIdentifier); return c.writerIndex() - iLenStartIndex; } @@ -110,8 +137,12 @@ public class IsIsPseudonode implements IGPRouterID, BGPValueType { * @return object of IsIsPseudonode */ public static IsIsPseudonode read(ChannelBuffer cb) { - byte[] isoNodeID = new byte[LENGTH - 1]; - cb.readBytes(isoNodeID, 0, LENGTH - 1); + List<Byte> isoNodeID = new ArrayList<Byte>(); + byte value; + for (int i = 0; i < LENGTH; i++) { + value = cb.readByte(); + isoNodeID.add(value); + } byte psnIdentifier = cb.readByte(); return IsIsPseudonode.of(isoNodeID, psnIdentifier); } diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java new file mode 100644 index 00000000..988925f5 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTlv.java @@ -0,0 +1,131 @@ +/* + * 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.Objects; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/** + * Provides Implementation of Link Local/Remote IdentifiersTlv. + */ +public class LinkLocalRemoteIdentifiersTlv implements BGPValueType { + private static final Logger log = LoggerFactory.getLogger(LinkLocalRemoteIdentifiersTlv.class); + public static final short TYPE = 258; + private static final int LENGTH = 8; + + private final int linkLocalIdentifer; + private final int linkRemoteIdentifer; + + /** + * Constructor to initialize parameters. + * + * @param linkLocalIdentifer link local Identifer + * @param linkRemoteIdentifer link remote Identifer + */ + public LinkLocalRemoteIdentifiersTlv(int linkLocalIdentifer, int linkRemoteIdentifer) { + this.linkLocalIdentifer = linkLocalIdentifer; + this.linkRemoteIdentifer = linkRemoteIdentifer; + } + + /** + * Returns link remote Identifer. + * + * @return link remote Identifer + */ + public int getLinkRemoteIdentifier() { + return linkRemoteIdentifer; + } + + /** + * Returns link local Identifer. + * + * @return link local Identifer + */ + public int getLinkLocalIdentifier() { + return linkLocalIdentifer; + } + + @Override + public short getType() { + return TYPE; + } + + @Override + public int hashCode() { + return Objects.hash(linkLocalIdentifer, linkRemoteIdentifer); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof LinkLocalRemoteIdentifiersTlv) { + LinkLocalRemoteIdentifiersTlv other = (LinkLocalRemoteIdentifiersTlv) obj; + return Objects.equals(this.linkLocalIdentifer, other.linkLocalIdentifer) + && Objects.equals(this.linkRemoteIdentifer, other.linkRemoteIdentifer); + } + return false; + } + + @Override + public int write(ChannelBuffer cb) { + int iLenStartIndex = cb.writerIndex(); + cb.writeShort(TYPE); + cb.writeShort(LENGTH); + cb.writeInt(linkLocalIdentifer); + cb.writeInt(linkRemoteIdentifer); + return cb.writerIndex() - iLenStartIndex; + } + + /** + * Reads the channel buffer and returns object of LinkLocalRemoteIdentifiersTlv. + * + * @param cb channelBuffer + * @return object of LinkLocalRemoteIdentifiersTlv + */ + public static LinkLocalRemoteIdentifiersTlv read(ChannelBuffer cb) { + int linkLocalIdentifer = cb.readInt(); + int linkRemoteIdentifer = cb.readInt(); + return LinkLocalRemoteIdentifiersTlv.of(linkLocalIdentifer, linkRemoteIdentifer); + } + + /** + * Returns object of this class with specified link local identifer and link remote identifer. + * + * @param linkLocalIdentifer link local identifier + * @param linkRemoteIdentifer link remote identifier + * @return object of LinkLocalRemoteIdentifiersTlv + */ + public static LinkLocalRemoteIdentifiersTlv of(final int linkLocalIdentifer, final int linkRemoteIdentifer) { + return new LinkLocalRemoteIdentifiersTlv(linkLocalIdentifer, linkRemoteIdentifer); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("TYPE", TYPE) + .add("LENGTH", LENGTH) + .add("linkLocalIdentifer", linkLocalIdentifer) + .add("linkRemoteIdentifer", linkRemoteIdentifer) + .toString(); + } +}
\ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java index 048d81ee..0f78ab77 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/LocalPref.java @@ -19,9 +19,8 @@ import java.util.Objects; import org.jboss.netty.buffer.ChannelBuffer; import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.util.Constants; import org.onosproject.bgpio.util.Validation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.MoreObjects; @@ -29,11 +28,7 @@ import com.google.common.base.MoreObjects; * Provides implementation of LocalPref BGP Path Attribute. */ public class LocalPref implements BGPValueType { - - private static final Logger log = LoggerFactory.getLogger(LocalPref.class); public static final byte LOCAL_PREF_TYPE = 5; - public static final int TYPE_AND_LEN_AS_SHORT = 4; - public static final int TYPE_AND_LEN_AS_BYTE = 3; public static final byte LOCAL_PREF_MAX_LEN = 4; private int localPref; @@ -72,8 +67,8 @@ public class LocalPref implements BGPValueType { parseFlags.getLength()); } - int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags.getLength() - + TYPE_AND_LEN_AS_BYTE; + int len = parseFlags.isShort() ? parseFlags.getLength() + + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE; ChannelBuffer data = tempCb.readBytes(len); if (parseFlags.getFirstBit()) { throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data); diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java index 49e1fc5a..23402c26 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Med.java @@ -19,9 +19,8 @@ import java.util.Objects; import org.jboss.netty.buffer.ChannelBuffer; import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.util.Constants; import org.onosproject.bgpio.util.Validation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.MoreObjects; @@ -29,10 +28,7 @@ import com.google.common.base.MoreObjects; * Provides Implementation of Med BGP Path Attribute. */ public class Med implements BGPValueType { - private static final Logger log = LoggerFactory.getLogger(Med.class); public static final byte MED_TYPE = 4; - public static final int TYPE_AND_LEN_AS_SHORT = 4; - public static final int TYPE_AND_LEN_AS_BYTE = 3; public static final byte MED_MAX_LEN = 4; private int med; @@ -71,8 +67,8 @@ public class Med implements BGPValueType { Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR, parseFlags.getLength()); } - int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags - .getLength() + TYPE_AND_LEN_AS_BYTE; + int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags + .getLength() + Constants.TYPE_AND_LEN_AS_BYTE; ChannelBuffer data = tempCb.readBytes(len); if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() && parseFlags.getThirdBit()) { throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data); diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.java new file mode 100644 index 00000000..fe99d28d --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpReachNlri.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.bgpio.types; + +import java.net.InetAddress; +import java.util.LinkedList; +import java.util.List; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.onlab.packet.Ip4Address; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.protocol.BGPLSNlri; +import org.onosproject.bgpio.protocol.linkstate.BGPPrefixIPv4LSNlriVer4; +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4; +import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; +import org.onosproject.bgpio.util.Constants; +import org.onosproject.bgpio.util.Validation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/* + * Provides Implementation of MpReach Nlri BGP Path Attribute. + */ +public class MpReachNlri implements BGPValueType { + + private static final Logger log = LoggerFactory.getLogger(MpReachNlri.class); + public static final byte MPREACHNLRI_TYPE = 14; + public static final byte LINK_NLRITYPE = 2; + + private boolean isMpReachNlri = false; + private final List<BGPLSNlri> mpReachNlri; + private final int length; + private final short afi; + private final byte safi; + private final Ip4Address ipNextHop; + + /** + * Constructor to initialize parameters. + * + * @param mpReachNlri MpReach Nlri attribute + * @param afi address family identifier + * @param safi subsequent address family identifier + * @param ipNextHop nexthop IpAddress + * @param length of MpReachNlri + */ + public MpReachNlri(List<BGPLSNlri> mpReachNlri, short afi, byte safi, Ip4Address ipNextHop, int length) { + this.mpReachNlri = mpReachNlri; + this.isMpReachNlri = true; + this.ipNextHop = ipNextHop; + this.afi = afi; + this.safi = safi; + this.length = length; + } + + /** + * Returns whether MpReachNlri is present. + * + * @return whether MpReachNlri is present + */ + public boolean isMpReachNlriSet() { + return this.isMpReachNlri; + } + + /** + * Returns list of MpReach Nlri. + * + * @return list of MpReach Nlri + */ + public List<BGPLSNlri> mpReachNlri() { + return this.mpReachNlri; + } + + /** + * Returns length of MpReachNlri. + * + * @return length of MpReachNlri + */ + public int mpReachNlriLen() { + return this.length; + } + + /** + * Reads from ChannelBuffer and parses MpReachNlri. + * + * @param cb channelBuffer + * @return object of MpReachNlri + * @throws BGPParseException while parsing MpReachNlri + */ + public static MpReachNlri read(ChannelBuffer cb) throws BGPParseException { + ChannelBuffer tempBuf = cb.copy(); + Validation parseFlags = Validation.parseAttributeHeader(cb); + int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : + parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE; + ChannelBuffer data = tempBuf.readBytes(len); + + if (cb.readableBytes() < parseFlags.getLength()) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR, + parseFlags.getLength()); + } + if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() && parseFlags.getThirdBit()) { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data); + } + + BGPLSNlri bgpLSNlri = null; + List<BGPLSNlri> mpReachNlri = new LinkedList<>(); + ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength()); + short afi = 0; + byte safi = 0; + Ip4Address ipNextHop = null; + while (tempCb.readableBytes() > 0) { + afi = tempCb.readShort(); + safi = tempCb.readByte(); + + //Supporting for AFI 16388 / SAFI 71 and VPN AFI 16388 / SAFI 128 + if ((afi == Constants.AFI_VALUE) && (safi == Constants.SAFI_VALUE) || (afi == Constants.AFI_VALUE) + && (safi == Constants.VPN_SAFI_VALUE)) { + byte nextHopLen = tempCb.readByte(); + InetAddress ipAddress = Validation.toInetAddress(nextHopLen, cb); + if (ipAddress.isMulticastAddress()) { + throw new BGPParseException("Multicast not supported"); + } + ipNextHop = Ip4Address.valueOf(ipAddress); + byte reserved = tempCb.readByte(); + + while (tempCb.readableBytes() > 0) { + short nlriType = tempCb.readShort(); + short totNlriLen = tempCb.readShort(); + if (tempCb.readableBytes() < totNlriLen) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); + } + tempBuf = tempCb.readBytes(totNlriLen); + switch (nlriType) { + case BGPNodeLSNlriVer4.NODE_NLRITYPE: + bgpLSNlri = BGPNodeLSNlriVer4.read(tempBuf, afi, safi); + break; + case BgpLinkLsNlriVer4.LINK_NLRITYPE: + bgpLSNlri = BgpLinkLsNlriVer4.read(tempBuf, afi, safi); + break; + case BGPPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE: + bgpLSNlri = BGPPrefixIPv4LSNlriVer4.read(tempBuf, afi, safi); + break; + default: + log.debug("nlriType not supported" + nlriType); + } + mpReachNlri.add(bgpLSNlri); + } + } else { + throw new BGPParseException("Not Supporting afi " + afi + "safi " + safi); + } + } + return new MpReachNlri(mpReachNlri, afi, safi, ipNextHop, parseFlags.getLength()); + } + + @Override + public short getType() { + return MPREACHNLRI_TYPE; + } + + /** + * Returns AFI. + * + * @return AFI + */ + public short afi() { + return this.afi; + } + + /** + * Returns Nexthop IpAddress. + * + * @return Nexthop IpAddress + */ + public Ip4Address nexthop4() { + return this.ipNextHop; + } + + /** + * Returns SAFI. + * + * @return SAFI + */ + public byte safi() { + return this.safi; + } + + @Override + public int write(ChannelBuffer cb) { + //Not to be Implemented as of now + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("mpReachNlri", mpReachNlri) + .add("afi", afi) + .add("safi", safi) + .add("ipNextHop", ipNextHop) + .add("length", length) + .toString(); + } +}
\ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java new file mode 100644 index 00000000..8763ec59 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/MpUnReachNlri.java @@ -0,0 +1,204 @@ +/* + * 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.LinkedList; +import java.util.List; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.protocol.BGPLSNlri; +import org.onosproject.bgpio.protocol.linkstate.BGPNodeLSNlriVer4; +import org.onosproject.bgpio.protocol.linkstate.BGPPrefixIPv4LSNlriVer4; +import org.onosproject.bgpio.protocol.linkstate.BgpLinkLsNlriVer4; +import org.onosproject.bgpio.util.Constants; +import org.onosproject.bgpio.util.Validation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.MoreObjects; + +/** + * Provides Implementation of MpUnReach Nlri BGP Path Attribute. + */ +public class MpUnReachNlri implements BGPValueType { + + private static final Logger log = LoggerFactory.getLogger(MpUnReachNlri.class); + public static final byte MPUNREACHNLRI_TYPE = 15; + public static final byte LINK_NLRITYPE = 2; + + private boolean isMpUnReachNlri = false; + private final short afi; + private final byte safi; + private final List<BGPLSNlri> mpUnReachNlri; + private final int length; + + /** + * Constructor to initialize parameters. + * + * @param mpUnReachNlri MpUnReach Nlri attribute + * @param afi address family identifier + * @param safi subsequent address family identifier + * @param length of MpUnReachNlri + */ + public MpUnReachNlri(List<BGPLSNlri> mpUnReachNlri, short afi, byte safi, + int length) { + this.mpUnReachNlri = mpUnReachNlri; + this.isMpUnReachNlri = true; + this.afi = afi; + this.safi = safi; + this.length = length; + } + + /** + * Reads from ChannelBuffer and parses MpUnReachNlri. + * + * @param cb ChannelBuffer + * @return object of MpUnReachNlri + * @throws BGPParseException while parsing MpUnReachNlri + */ + public static MpUnReachNlri read(ChannelBuffer cb) throws BGPParseException { + ChannelBuffer tempBuf = cb.copy(); + Validation parseFlags = Validation.parseAttributeHeader(cb); + int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT + : parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_BYTE; + ChannelBuffer data = tempBuf.readBytes(len); + + if (!parseFlags.getFirstBit() && parseFlags.getSecondBit() + && parseFlags.getThirdBit()) { + throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data); + } + + if (cb.readableBytes() < parseFlags.getLength()) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, parseFlags.getLength()); + } + + LinkedList<BGPLSNlri> mpUnReachNlri = new LinkedList<>(); + BGPLSNlri bgpLSNlri = null; + short afi = 0; + byte safi = 0; + ChannelBuffer tempCb = cb.readBytes(parseFlags.getLength()); + while (tempCb.readableBytes() > 0) { + afi = tempCb.readShort(); + safi = tempCb.readByte(); + + //Supporting only for AFI 16388 / SAFI 71 + if ((afi == Constants.AFI_VALUE) && (safi == Constants.SAFI_VALUE) + || (afi == Constants.AFI_VALUE) && (safi == Constants.VPN_SAFI_VALUE)) { + while (tempCb.readableBytes() > 0) { + short nlriType = tempCb.readShort(); + short totNlriLen = tempCb.readShort(); + if (tempCb.readableBytes() < totNlriLen) { + Validation.validateLen( + BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, totNlriLen); + } + tempBuf = tempCb.readBytes(totNlriLen); + switch (nlriType) { + case BGPNodeLSNlriVer4.NODE_NLRITYPE: + bgpLSNlri = BGPNodeLSNlriVer4.read(tempBuf, afi, safi); + break; + case BgpLinkLsNlriVer4.LINK_NLRITYPE: + bgpLSNlri = BgpLinkLsNlriVer4.read(tempBuf, afi, safi); + break; + case BGPPrefixIPv4LSNlriVer4.PREFIX_IPV4_NLRITYPE: + bgpLSNlri = BGPPrefixIPv4LSNlriVer4.read(tempBuf, afi, + safi); + break; + default: + log.debug("nlriType not supported" + nlriType); + } + mpUnReachNlri.add(bgpLSNlri); + } + } else { + //TODO: check with the values got from capability + throw new BGPParseException("Not Supporting afi " + afi + + "safi " + safi); + } + } + return new MpUnReachNlri(mpUnReachNlri, afi, safi, + parseFlags.getLength()); + } + + @Override + public short getType() { + return MPUNREACHNLRI_TYPE; + } + + /** + * Returns SAFI. + * + * @return SAFI + */ + public byte safi() { + return this.safi; + } + + /** + * Returns AFI. + * + * @return AFI + */ + public short afi() { + return this.afi; + } + + /** + * Returns list of MpUnReach Nlri. + * + * @return list of MpUnReach Nlri + */ + public List<BGPLSNlri> mpUnReachNlri() { + return this.mpUnReachNlri; + } + + /** + * Returns whether MpReachNlri is present. + * + * @return whether MpReachNlri is present + */ + public boolean isMpUnReachNlriSet() { + return this.isMpUnReachNlri; + } + + /** + * Returns length of MpUnReach. + * + * @return length of MpUnReach + */ + public int mpUnReachNlriLen() { + return this.length; + } + + @Override + public int write(ChannelBuffer cb) { + //Not to be Implemented as of now + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("mpReachNlri", mpUnReachNlri) + .add("afi", afi) + .add("safi", safi) + .add("length", length) + .toString(); + } +}
\ No newline at end of file diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java index 353ec3d5..1d083b72 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/NextHop.java @@ -21,9 +21,8 @@ import java.util.Objects; import org.jboss.netty.buffer.ChannelBuffer; import org.onlab.packet.Ip4Address; import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.util.Constants; import org.onosproject.bgpio.util.Validation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; @@ -32,10 +31,7 @@ import com.google.common.base.Preconditions; * Implementation of NextHop BGP Path Attribute. */ public class NextHop implements BGPValueType { - private static final Logger log = LoggerFactory.getLogger(NextHop.class); public static final byte NEXTHOP_TYPE = 3; - public static final int TYPE_AND_LEN_AS_SHORT = 4; - public static final int TYPE_AND_LEN_AS_BYTE = 3; private boolean isNextHop = false; private Ip4Address nextHop; @@ -75,15 +71,14 @@ public class NextHop implements BGPValueType { Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR, parseFlags.getLength()); } - int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags - .getLength() + TYPE_AND_LEN_AS_BYTE; + int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags + .getLength() + Constants.TYPE_AND_LEN_AS_BYTE; ChannelBuffer data = tempCb.readBytes(len); if (parseFlags.getFirstBit() && !parseFlags.getSecondBit() && parseFlags.getThirdBit()) { throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_FLAGS_ERROR, data); } - //TODO: use Validation.toInetAddress once Validation is merged - InetAddress ipAddress = (InetAddress) cb.readBytes(parseFlags.getLength()); + InetAddress ipAddress = Validation.toInetAddress(parseFlags.getLength(), cb); if (ipAddress.isMulticastAddress()) { throw new BGPParseException("Multicast address is not supported"); } diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java index 3b2070de..2052e965 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/Origin.java @@ -19,9 +19,8 @@ import java.util.Objects; import org.jboss.netty.buffer.ChannelBuffer; import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.util.Constants; import org.onosproject.bgpio.util.Validation; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.google.common.base.MoreObjects; @@ -29,7 +28,6 @@ import com.google.common.base.MoreObjects; * Provides Implementation of mandatory BGP Origin path attribute. */ public class Origin implements BGPValueType { - private static final Logger log = LoggerFactory.getLogger(Origin.class); /** * Enum to provide ORIGIN types. @@ -58,8 +56,6 @@ public class Origin implements BGPValueType { public static final byte ORIGIN_TYPE = 1; public static final byte ORIGIN_VALUE_LEN = 1; - public static final int TYPE_AND_LEN_AS_SHORT = 4; - public static final int TYPE_AND_LEN_AS_BYTE = 3; private boolean isOrigin = false; private byte origin; @@ -109,8 +105,8 @@ public class Origin implements BGPValueType { ChannelBuffer tempCb = cb.copy(); Validation parseFlags = Validation.parseAttributeHeader(cb); - int len = parseFlags.isShort() ? parseFlags.getLength() + TYPE_AND_LEN_AS_SHORT : parseFlags - .getLength() + TYPE_AND_LEN_AS_BYTE; + int len = parseFlags.isShort() ? parseFlags.getLength() + Constants.TYPE_AND_LEN_AS_SHORT : parseFlags + .getLength() + Constants.TYPE_AND_LEN_AS_BYTE; ChannelBuffer data = tempCb.readBytes(len); if ((parseFlags.getLength() > ORIGIN_VALUE_LEN) || (cb.readableBytes() < parseFlags.getLength())) { Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR, @@ -122,7 +118,7 @@ public class Origin implements BGPValueType { byte originValue; originValue = cb.readByte(); - if ((originValue != ORIGINTYPE.INCOMPLETE.value) || (originValue != ORIGINTYPE.IGP.value) || + if ((originValue != ORIGINTYPE.INCOMPLETE.value) && (originValue != ORIGINTYPE.IGP.value) && (originValue != ORIGINTYPE.EGP.value)) { throw new BGPParseException(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.INVALID_ORIGIN_ATTRIBUTE, data); } diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java index 194d6dac..4b704fb0 100644 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpAttrNodeMultiTopologyId.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.onosproject.bgpio.types.attr; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import org.jboss.netty.buffer.ChannelBuffer; @@ -39,18 +40,28 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType { public static final int ATTRNODE_MULTITOPOLOGY = 263; /* Opaque Node Attribute */ - private short[] multiTopologyId; + private List<Short> multiTopologyId = new ArrayList<Short>(); /** * Constructor to initialize the Node attribute multi-topology ID. * * @param multiTopologyId multi-topology ID */ - BgpAttrNodeMultiTopologyId(short[] multiTopologyId) { + public BgpAttrNodeMultiTopologyId(List<Short> multiTopologyId) { this.multiTopologyId = multiTopologyId; } /** + * Returns object of this class with specified values. + * + * @param multiTopologyId Prefix Metric + * @return object of BgpAttrNodeMultiTopologyId + */ + public static BgpAttrNodeMultiTopologyId of(ArrayList<Short> multiTopologyId) { + return new BgpAttrNodeMultiTopologyId(multiTopologyId); + } + + /** * Reads the Multi-topology ID of Node attribute. * * @param cb ChannelBuffer @@ -59,21 +70,20 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType { */ public static BgpAttrNodeMultiTopologyId read(ChannelBuffer cb) throws BGPParseException { - - log.debug("BgpAttrNodeMultiTopologyId"); + ArrayList<Short> multiTopologyId = new ArrayList<Short>(); + short tempMultiTopologyId; short lsAttrLength = cb.readShort(); int len = lsAttrLength / 2; // Length is 2*n and n is the number of MT-IDs if (cb.readableBytes() < lsAttrLength) { Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, BGPErrorType.ATTRIBUTE_LENGTH_ERROR, - cb.readableBytes()); + lsAttrLength); } - short[] multiTopologyId; - multiTopologyId = new short[len]; for (int i = 0; i < len; i++) { - multiTopologyId[i] = cb.readShort(); + tempMultiTopologyId = cb.readShort(); + multiTopologyId.add(new Short(tempMultiTopologyId)); } return new BgpAttrNodeMultiTopologyId(multiTopologyId); @@ -84,7 +94,7 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType { * * @return multitopology ID */ - short[] getAttrMultiTopologyId() { + public List<Short> attrMultiTopologyId() { return multiTopologyId; } @@ -113,7 +123,7 @@ public class BgpAttrNodeMultiTopologyId implements BGPValueType { @Override public int write(ChannelBuffer cb) { - // TODO Auto-generated method stub + // TODO This will be implemented in the next version return 0; } diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java new file mode 100644 index 00000000..086e8b06 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrIsIsAdminstGrp.java @@ -0,0 +1,130 @@ +/* + * 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 attribute Is Is Administrative area. + */ +public final class BgpLinkAttrIsIsAdminstGrp implements BGPValueType { + + protected static final Logger log = LoggerFactory + .getLogger(BgpLinkAttrIsIsAdminstGrp.class); + + public static final int ATTRLINK_PROTECTIONTYPE = 1088; + public static final int ISIS_ADMIN_DATA_LEN = 4; + + /* ISIS administrative group */ + private final long isisAdminGrp; + + /** + * Constructor to initialize the values. + * + * @param isisAdminGrp ISIS protocol admin group + */ + public BgpLinkAttrIsIsAdminstGrp(long isisAdminGrp) { + this.isisAdminGrp = isisAdminGrp; + } + + /** + * Returns object of this class with specified values. + * + * @param isisAdminGrp ISIS admin group + * @return object of BgpLinkAttrIsIsAdminstGrp + */ + public static BgpLinkAttrIsIsAdminstGrp of(final long isisAdminGrp) { + return new BgpLinkAttrIsIsAdminstGrp(isisAdminGrp); + } + + /** + * Reads the BGP link attributes of ISIS administrative group area. + * + * @param cb Channel buffer + * @return object of type BgpLinkAttrIsIsAdminstGrp + * @throws BGPParseException while parsing BgpLinkAttrIsIsAdminstGrp + */ + public static BgpLinkAttrIsIsAdminstGrp read(ChannelBuffer cb) + throws BGPParseException { + long isisAdminGrp; + short lsAttrLength = cb.readShort(); + + if ((lsAttrLength != ISIS_ADMIN_DATA_LEN) + || (cb.readableBytes() < lsAttrLength)) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, + lsAttrLength); + } + + isisAdminGrp = cb.readUnsignedInt(); + + return BgpLinkAttrIsIsAdminstGrp.of(isisAdminGrp); + } + + /** + * Link attributes of ISIS administrative group area. + * + * @return long value of the administrative group area + */ + public long linkAttrIsIsAdminGrp() { + return isisAdminGrp; + } + + @Override + public short getType() { + return ATTRLINK_PROTECTIONTYPE; + } + + @Override + public int hashCode() { + return Objects.hash(isisAdminGrp); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj instanceof BgpLinkAttrIsIsAdminstGrp) { + BgpLinkAttrIsIsAdminstGrp other = (BgpLinkAttrIsIsAdminstGrp) obj; + return Objects.equals(isisAdminGrp, other.isisAdminGrp); + } + return false; + } + + @Override + public int write(ChannelBuffer cb) { + // TODO This will be implemented in the next version + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("isisAdminGrp", isisAdminGrp).toString(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java new file mode 100644 index 00000000..a1f0198b --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMaxLinkBandwidth.java @@ -0,0 +1,150 @@ +/* + * 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 attribute Max Link bandwidth. + */ +public final class BgpLinkAttrMaxLinkBandwidth implements BGPValueType { + + protected static final Logger log = LoggerFactory + .getLogger(BgpLinkAttrMaxLinkBandwidth.class); + + public static final int MAX_BANDWIDTH_LEN = 4; + public static final int NO_OF_BITS = 8; + + public short type; + + /* ISIS administrative group */ + private final float maxBandwidth; + + /** + * Constructor to initialize the values. + * + * @param maxBandwidth Maximum link bandwidth. + * @param type TLV type + */ + private BgpLinkAttrMaxLinkBandwidth(float maxBandwidth, short type) { + this.maxBandwidth = maxBandwidth; + this.type = type; + } + + /** + * Returns object of this class with specified values. + * + * @param maxBandwidth Maximum link bandwidth. + * @param type TLV type + * @return object of BgpLinkAttrMaxLinkBandwidth + */ + public static BgpLinkAttrMaxLinkBandwidth of(final float maxBandwidth, + final short type) { + return new BgpLinkAttrMaxLinkBandwidth(maxBandwidth, type); + } + + /** + * Reads the BGP link attributes of Maximum link bandwidth. + * + * @param cb Channel buffer + * @param type type of this tlv + * @return object of type BgpLinkAttrMaxLinkBandwidth + * @throws BGPParseException while parsing BgpLinkAttrMaxLinkBandwidth + */ + public static BgpLinkAttrMaxLinkBandwidth read(ChannelBuffer cb, short type) + throws BGPParseException { + float maxBandwidth; + short lsAttrLength = cb.readShort(); + + if ((lsAttrLength != MAX_BANDWIDTH_LEN) + || (cb.readableBytes() < lsAttrLength)) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, + lsAttrLength); + } + + maxBandwidth = ieeeToFloatRead(cb.readInt()) * NO_OF_BITS; + + return BgpLinkAttrMaxLinkBandwidth.of(maxBandwidth, type); + } + + /** + * Returns Maximum link bandwidth. + * + * @return Maximum link bandwidth + */ + float linkAttrMaxLinkBandwidth() { + return maxBandwidth; + } + + /** + * Parse the IEEE floating point notation and returns it in normal float. + * + * @param iVal IEEE floating point number + * @return normal float + */ + static float ieeeToFloatRead(int iVal) { + iVal = (((iVal & 0xFF) << 24) | ((iVal & 0xFF00) << 8) + | ((iVal & 0xFF0000) >> 8) | ((iVal >> 24) & 0xFF)); + + return Float.intBitsToFloat(iVal); + } + + @Override + public short getType() { + return this.type; + } + + @Override + public int hashCode() { + return Objects.hash(maxBandwidth); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj instanceof BgpLinkAttrMaxLinkBandwidth) { + BgpLinkAttrMaxLinkBandwidth other = (BgpLinkAttrMaxLinkBandwidth) obj; + return Objects.equals(maxBandwidth, other.maxBandwidth); + } + return false; + } + + @Override + public int write(ChannelBuffer cb) { + // TODO This will be implemented in the next version + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("maxBandwidth", maxBandwidth).toString(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java index 50591ecf..e44ba7e1 100755 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrName.java @@ -16,7 +16,6 @@ package org.onosproject.bgpio.types.attr; import java.util.Arrays; -import java.util.Objects; import org.jboss.netty.buffer.ChannelBuffer; import org.onosproject.bgpio.exceptions.BGPParseException; @@ -46,11 +45,21 @@ public class BgpLinkAttrName implements BGPValueType { * * @param linkName link name */ - BgpLinkAttrName(byte[] linkName) { + public BgpLinkAttrName(byte[] linkName) { this.linkName = Arrays.copyOf(linkName, linkName.length); } /** + * Returns object of this class with specified values. + * + * @param linkName Prefix Metric + * @return object of BgpLinkAttrName + */ + public static BgpLinkAttrName of(byte[] linkName) { + return new BgpLinkAttrName(linkName); + } + + /** * Reads the BGP link attributes Name. * * @param cb Channel buffer @@ -70,7 +79,7 @@ public class BgpLinkAttrName implements BGPValueType { linkName = new byte[lsAttrLength]; cb.readBytes(linkName); - return new BgpLinkAttrName(linkName); + return BgpLinkAttrName.of(linkName); } /** @@ -78,7 +87,7 @@ public class BgpLinkAttrName implements BGPValueType { * * @return link name */ - byte[] getAttrLinkName() { + public byte[] attrLinkName() { return linkName; } @@ -89,7 +98,7 @@ public class BgpLinkAttrName implements BGPValueType { @Override public int hashCode() { - return Objects.hash(linkName); + return Arrays.hashCode(linkName); } @Override @@ -100,7 +109,7 @@ public class BgpLinkAttrName implements BGPValueType { if (obj instanceof BgpLinkAttrName) { BgpLinkAttrName other = (BgpLinkAttrName) obj; - return Objects.equals(linkName, other.linkName); + return Arrays.equals(linkName, other.linkName); } return false; } diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java new file mode 100755 index 00000000..258598be --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrOpaqLnkAttrib.java @@ -0,0 +1,133 @@ +/* + * 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.Arrays; + +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 link opaque attribute. + */ +public final class BgpLinkAttrOpaqLnkAttrib implements BGPValueType { + + protected static final Logger log = LoggerFactory + .getLogger(BgpLinkAttrOpaqLnkAttrib.class); + + public static final int ATTRNODE_OPAQUELNKATTRIB = 1097; + + /* Opaque Node Attribute */ + private final byte[] opaqueLinkAttribute; + + /** + * Constructor to initialize the data. + * + * @param opaqueLinkAttribute opaque link attribute + */ + private BgpLinkAttrOpaqLnkAttrib(byte[] opaqueLinkAttribute) { + this.opaqueLinkAttribute = Arrays.copyOf(opaqueLinkAttribute, + opaqueLinkAttribute.length); + } + + /** + * Returns object of this class with specified values. + * + * @param opaqueLinkAttribute opaque link attribute + * @return object of BgpLinkAttrOpaqLnkAttrib + */ + public static BgpLinkAttrOpaqLnkAttrib of(final byte[] opaqueLinkAttribute) { + return new BgpLinkAttrOpaqLnkAttrib(opaqueLinkAttribute); + } + + /** + * Reads the BGP link attributes Opaque link attribute. + * + * @param cb Channel buffer + * @return object of type BgpLinkAttrOpaqLnkAttrib + * @throws BGPParseException while parsing BgpLinkAttrOpaqLnkAttrib + */ + public static BgpLinkAttrOpaqLnkAttrib read(ChannelBuffer cb) + throws BGPParseException { + + byte[] opaqueLinkAttribute; + + short lsAttrLength = cb.readShort(); + + if (cb.readableBytes() < lsAttrLength) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, + lsAttrLength); + } + + opaqueLinkAttribute = new byte[lsAttrLength]; + cb.readBytes(opaqueLinkAttribute); + + return BgpLinkAttrOpaqLnkAttrib.of(opaqueLinkAttribute); + } + + /** + * Returns the Opaque link attribute. + * + * @return byte array of opaque link attribute. + */ + public byte[] attrOpaqueLnk() { + return opaqueLinkAttribute; + } + + @Override + public short getType() { + return ATTRNODE_OPAQUELNKATTRIB; + } + + @Override + public int hashCode() { + return Arrays.hashCode(opaqueLinkAttribute); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj instanceof BgpLinkAttrOpaqLnkAttrib) { + BgpLinkAttrOpaqLnkAttrib other = (BgpLinkAttrOpaqLnkAttrib) obj; + return Arrays + .equals(opaqueLinkAttribute, other.opaqueLinkAttribute); + } + return false; + } + + @Override + public int write(ChannelBuffer cb) { + // TODO This will be implemented in the next version + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()).omitNullValues() + .add("opaqueLinkAttribute", opaqueLinkAttribute).toString(); + } +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java new file mode 100755 index 00000000..7febe3c3 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpLinkAttrTeDefaultMetric.java @@ -0,0 +1,132 @@ +/* + * 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 link state Default TE metric link attribute. + */ +public class BgpLinkAttrTeDefaultMetric implements BGPValueType { + + protected static final Logger log = LoggerFactory + .getLogger(BgpLinkAttrTeDefaultMetric.class); + + public static final int ATTRLINK_TEDEFAULTMETRIC = 1092; + public static final int TE_DATA_LEN = 4; + + /* TE Default Metric */ + private int linkTeMetric; + + /** + * Constructor to initialize the value. + * + * @param linkTeMetric TE default metric + * + */ + public BgpLinkAttrTeDefaultMetric(int linkTeMetric) { + this.linkTeMetric = linkTeMetric; + } + + /** + * Returns object of this class with specified values. + * + * @param linkTeMetric TE default metric + * @return object of BgpLinkAttrTeDefaultMetric + */ + public static BgpLinkAttrTeDefaultMetric of(final int linkTeMetric) { + return new BgpLinkAttrTeDefaultMetric(linkTeMetric); + } + + /** + * Reads the BGP link attributes of TE default metric. + * + * @param cb Channel buffer + * @return object of type BgpLinkAttrTeDefaultMetric + * @throws BGPParseException while parsing BgpLinkAttrTeDefaultMetric + */ + public static BgpLinkAttrTeDefaultMetric read(ChannelBuffer cb) + throws BGPParseException { + int linkTeMetric; + + short lsAttrLength = cb.readShort(); + + if ((lsAttrLength != TE_DATA_LEN) + || (cb.readableBytes() < lsAttrLength)) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, + lsAttrLength); + } + + linkTeMetric = cb.readInt(); + + return new BgpLinkAttrTeDefaultMetric(linkTeMetric); + } + + /** + * Returns the TE default metrics. + * + * @return link default metric + */ + public int attrLinkDefTeMetric() { + return linkTeMetric; + } + + @Override + public short getType() { + return ATTRLINK_TEDEFAULTMETRIC; + } + + @Override + public int hashCode() { + return Objects.hash(linkTeMetric); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj instanceof BgpLinkAttrTeDefaultMetric) { + BgpLinkAttrTeDefaultMetric other = (BgpLinkAttrTeDefaultMetric) obj; + return Objects.equals(linkTeMetric, other.linkTeMetric); + } + return false; + } + + @Override + public int write(ChannelBuffer cb) { + // TODO This will be implemented in the next version + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()) + .add("linkTEMetric", linkTeMetric).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 index 035d706c..a215e6f1 100755 --- 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 @@ -30,24 +30,24 @@ import com.google.common.base.MoreObjects; /** * Implements BGP prefix IGP Flag attribute. */ -public class BgpPrefixAttrIGPFlags implements BGPValueType { +public final class BgpPrefixAttrIgpFlags implements BGPValueType { protected static final Logger log = LoggerFactory - .getLogger(BgpPrefixAttrIGPFlags.class); + .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; + 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 boolean bisisUpDownBit = false; - private boolean bOspfNoUnicastBit = false; - private boolean bOspfLclAddrBit = false; - private boolean bOspfNSSABit = false; + private final boolean bisisUpDownBit; + private final boolean bOspfNoUnicastBit; + private final boolean bOspfLclAddrBit; + private final boolean bOspfNSSABit; /** * Constructor to initialize the value. @@ -57,7 +57,8 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { * @param bOspfLclAddrBit OSPF local address Bit * @param bOspfNSSABit OSPF propagate NSSA Bit */ - BgpPrefixAttrIGPFlags(boolean bisisUpDownBit, boolean bOspfNoUnicastBit, + BgpPrefixAttrIgpFlags(boolean bisisUpDownBit, + boolean bOspfNoUnicastBit, boolean bOspfLclAddrBit, boolean bOspfNSSABit) { this.bisisUpDownBit = bisisUpDownBit; this.bOspfNoUnicastBit = bOspfNoUnicastBit; @@ -66,13 +67,30 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { } /** + * 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) + public static BgpPrefixAttrIgpFlags read(ChannelBuffer cb) throws BGPParseException { boolean bisisUpDownBit = false; boolean bOspfNoUnicastBit = false; @@ -90,13 +108,13 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { 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); + 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 new BgpPrefixAttrIGPFlags(bisisUpDownBit, bOspfNoUnicastBit, - bOspfLclAddrBit, bOspfNSSABit); + return BgpPrefixAttrIgpFlags.of(bisisUpDownBit, bOspfNoUnicastBit, + bOspfLclAddrBit, bOspfNSSABit); } /** @@ -104,7 +122,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { * * @return IS-IS Up/Down Bit set or not */ - boolean getisisUpDownBit() { + public boolean isisUpDownBit() { return bisisUpDownBit; } @@ -113,7 +131,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { * * @return OSPF no unicast Bit set or not */ - boolean getOspfNoUnicastBit() { + public boolean ospfNoUnicastBit() { return bOspfNoUnicastBit; } @@ -122,7 +140,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { * * @return OSPF local address Bit set or not */ - boolean getOspfLclAddrBit() { + public boolean ospfLclAddrBit() { return bOspfLclAddrBit; } @@ -131,7 +149,7 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { * * @return OSPF propagate NSSA Bit set or not */ - boolean getOspfNSSABit() { + public boolean ospfNSSABit() { return bOspfNSSABit; } @@ -158,13 +176,13 @@ public class BgpPrefixAttrIGPFlags implements BGPValueType { return true; } - if (obj instanceof BgpPrefixAttrIGPFlags) { - BgpPrefixAttrIGPFlags other = (BgpPrefixAttrIGPFlags) obj; + 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); + && Objects.equals(bOspfLclAddrBit, other.bOspfLclAddrBit) + && Objects.equals(bOspfNSSABit, other.bOspfNSSABit); } return false; } diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java new file mode 100755 index 00000000..c7008ca1 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrOpaqueData.java @@ -0,0 +1,134 @@ +/* + * 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.Arrays; + +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 opaque data attribute. + */ +public final class BgpPrefixAttrOpaqueData implements BGPValueType { + + protected static final Logger log = LoggerFactory + .getLogger(BgpPrefixAttrOpaqueData.class); + + public static final int ATTR_PREFIX_OPAQUEDATA = 1157; + + /* Opaque Node Attribute */ + private final byte[] opaquePrefixAttribute; + + /** + * Constructor to initialize the values. + * + * @param opaquePrefixAttribute opaque prefix data + */ + public BgpPrefixAttrOpaqueData(byte[] opaquePrefixAttribute) { + this.opaquePrefixAttribute = Arrays + .copyOf(opaquePrefixAttribute, opaquePrefixAttribute.length); + } + + /** + * Returns object of this class with specified values. + * + * @param opaquePrefixAttribute opaque prefix data + * @return object of BgpPrefixAttrOpaqueData + */ + public static BgpPrefixAttrOpaqueData of(final byte[] opaquePrefixAttribute) { + return new BgpPrefixAttrOpaqueData(opaquePrefixAttribute); + } + + /** + * Reads the Opaque Prefix Attribute. + * + * @param cb ChannelBuffer + * @return object of BgpPrefixAttrOpaqueData + * @throws BGPParseException while parsing BgpPrefixAttrOpaqueData + */ + public static BgpPrefixAttrOpaqueData read(ChannelBuffer cb) + throws BGPParseException { + byte[] opaquePrefixAttribute; + + short lsAttrLength = cb.readShort(); + opaquePrefixAttribute = new byte[lsAttrLength]; + + if (cb.readableBytes() < lsAttrLength) { + Validation.validateLen(BGPErrorType.UPDATE_MESSAGE_ERROR, + BGPErrorType.ATTRIBUTE_LENGTH_ERROR, + lsAttrLength); + } + + cb.readBytes(opaquePrefixAttribute); + + return BgpPrefixAttrOpaqueData.of(opaquePrefixAttribute); + } + + /** + * Returns the Opaque prefix attribute name. + * + * @return opaque prefix name + */ + public byte[] getOpaquePrefixAttribute() { + return opaquePrefixAttribute; + } + + @Override + public short getType() { + return ATTR_PREFIX_OPAQUEDATA; + } + + @Override + public int hashCode() { + return Arrays.hashCode(opaquePrefixAttribute); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + + if (obj instanceof BgpPrefixAttrOpaqueData) { + BgpPrefixAttrOpaqueData other = (BgpPrefixAttrOpaqueData) obj; + return Arrays.equals(opaquePrefixAttribute, + other.opaquePrefixAttribute); + } + return false; + } + + @Override + public int write(ChannelBuffer cb) { + // TODO This will be implemented in the next version + return 0; + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(getClass()).omitNullValues() + .add("opaquePrefixAttribute", getOpaquePrefixAttribute()) + .toString(); + } + +} diff --git a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java index 0cf02386..426eb274 100755 --- a/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java +++ b/framework/src/onos/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrRouteTag.java @@ -15,7 +15,8 @@ */ package org.onosproject.bgpio.types.attr; -import java.util.Arrays; +import java.util.ArrayList; +import java.util.List; import java.util.Objects; import org.jboss.netty.buffer.ChannelBuffer; @@ -36,18 +37,28 @@ public class BgpPrefixAttrRouteTag implements BGPValueType { protected static final Logger log = LoggerFactory .getLogger(BgpPrefixAttrRouteTag.class); - public static final int ATTR_PREFIX_ROUTETAG = 1153; + public static final short ATTR_PREFIX_ROUTETAG = 1153; /* Prefix Route Tag */ - private int[] pfxRouteTag; + private List<Integer> pfxRouteTag = new ArrayList<Integer>(); /** * Constructor to initialize the values. * * @param pfxRouteTag prefix route tag */ - BgpPrefixAttrRouteTag(int[] pfxRouteTag) { - this.pfxRouteTag = Arrays.copyOf(pfxRouteTag, pfxRouteTag.length); + public BgpPrefixAttrRouteTag(List<Integer> pfxRouteTag) { + this.pfxRouteTag = pfxRouteTag; + } + + /** + * Returns object of this class with specified values. + * + * @param pfxRouteTag Prefix Metric + * @return object of BgpPrefixAttrRouteTag + */ + public static BgpPrefixAttrRouteTag of(ArrayList<Integer> pfxRouteTag) { + return new BgpPrefixAttrRouteTag(pfxRouteTag); } /** @@ -59,7 +70,8 @@ public class BgpPrefixAttrRouteTag implements BGPValueType { */ public static BgpPrefixAttrRouteTag read(ChannelBuffer cb) throws BGPParseException { - int[] pfxRouteTag; + int tmp; + ArrayList<Integer> pfxRouteTag = new ArrayList<Integer>(); short lsAttrLength = cb.readShort(); int len = lsAttrLength / Integer.SIZE; @@ -70,13 +82,12 @@ public class BgpPrefixAttrRouteTag implements BGPValueType { lsAttrLength); } - pfxRouteTag = new int[lsAttrLength]; - for (int i = 0; i < len; i++) { - pfxRouteTag[i] = cb.readInt(); + tmp = cb.readInt(); + pfxRouteTag.add(new Integer(tmp)); } - return new BgpPrefixAttrRouteTag(pfxRouteTag); + return BgpPrefixAttrRouteTag.of(pfxRouteTag); } /** @@ -84,7 +95,7 @@ public class BgpPrefixAttrRouteTag implements BGPValueType { * * @return route tag */ - int[] getPfxRouteTag() { + public List<Integer> getPfxRouteTag() { return pfxRouteTag; } diff --git a/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMaxLinkBandwidthTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMaxLinkBandwidthTest.java new file mode 100644 index 00000000..d4c3b610 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrMaxLinkBandwidthTest.java @@ -0,0 +1,44 @@ +/* + * 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.BgpLinkAttrMaxLinkBandwidth; + +import com.google.common.testing.EqualsTester; + +/** + * Test for BGP link max bandwidth attribute. + */ +public class BgpLinkAttrMaxLinkBandwidthTest { + private final float val = 0x010203; + private final short valLen = 3; + private final float val1 = 0x01020304; + private final short val1Len = 4; + + private final BgpLinkAttrMaxLinkBandwidth data = BgpLinkAttrMaxLinkBandwidth + .of(val, valLen); + private final BgpLinkAttrMaxLinkBandwidth sameAsData = BgpLinkAttrMaxLinkBandwidth + .of(val, valLen); + private final BgpLinkAttrMaxLinkBandwidth diffData = BgpLinkAttrMaxLinkBandwidth + .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/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4InterfaceAddressTlvTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrTeDefaultMetricTest.java index c25a6b5b..b6453c45 100644 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4InterfaceAddressTlvTest.java +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpLinkAttrTeDefaultMetricTest.java @@ -13,27 +13,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.pcepio; - -import com.google.common.testing.EqualsTester; +package org.onosproject.bgp; import org.junit.Test; -import org.onosproject.pcepio.types.IPv4InterfaceAddressTlv; +import org.onosproject.bgpio.types.attr.BgpLinkAttrTeDefaultMetric; + +import com.google.common.testing.EqualsTester; /** - * Test of the IPv4InterfaceAddressTlv. + * Test for BGP link TE default metric attribute. */ -public class IPv4InterfaceAddressTlvTest { +public class BgpLinkAttrTeDefaultMetricTest { + private final int val = 0x010203; + private final int val1 = 0x01020304; - private final IPv4InterfaceAddressTlv tlv1 = IPv4InterfaceAddressTlv.of(2); - private final IPv4InterfaceAddressTlv sameAsTlv1 = IPv4InterfaceAddressTlv.of(2); - private final IPv4InterfaceAddressTlv tlv2 = IPv4InterfaceAddressTlv.of(3); + private final BgpLinkAttrTeDefaultMetric data = BgpLinkAttrTeDefaultMetric + .of(val); + private final BgpLinkAttrTeDefaultMetric sameAsData = BgpLinkAttrTeDefaultMetric + .of(val); + private final BgpLinkAttrTeDefaultMetric diffData = BgpLinkAttrTeDefaultMetric + .of(val1); @Test public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); + 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/BgpPrefixAttrOpaqueDataTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrOpaqueDataTest.java new file mode 100644 index 00000000..7ba6a880 --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgp/BgpPrefixAttrOpaqueDataTest.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.bgp; + +import org.junit.Test; +import org.onosproject.bgpio.types.attr.BgpPrefixAttrOpaqueData; + +import com.google.common.testing.EqualsTester; + +/** + * Test for prefix attribute opaque data Tlv. + */ +public class BgpPrefixAttrOpaqueDataTest { + private final byte[] array = new byte[] {0x01, 0x02, 0x03, 0x04}; + private final byte[] array1 = new byte[] {0x01, 0x02, 0x03, 0x01}; + + private final BgpPrefixAttrOpaqueData isisData = BgpPrefixAttrOpaqueData + .of(array); + private final BgpPrefixAttrOpaqueData sameAsIsisData = BgpPrefixAttrOpaqueData + .of(array); + private final BgpPrefixAttrOpaqueData isisDiff = BgpPrefixAttrOpaqueData + .of(array1); + + @Test + public void basics() { + new EqualsTester().addEqualityGroup(isisData, sameAsIsisData) + .addEqualityGroup(isisDiff).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<BGPMessage> 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<BGPMessage> 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<BGPMessage> 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<BGPMessage> 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<BGPMessage> 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<BGPMessage> 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<BGPMessage> 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<BGPMessage> 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<BGPMessage> 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<BGPMessage> 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<BGPMessage> 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<BGPMessage> 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<BGPMessage> 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<BGPMessage> 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<Integer> as4pathSet1 = new ArrayList<>(); + private final List<Integer> as4pathSeq1 = new ArrayList<>(); + private final List<Integer> as4pathSet2 = new ArrayList<>(); + private final List<Integer> 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<Short> aspathSet1 = new ArrayList<>(); + private final List<Short> aspathSet2 = new ArrayList<>(); + private final List<Short> aspathSeq1 = new ArrayList<>(); + private final List<Short> 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/pcep/pcepio/src/test/java/org/onosproject/pcepio/AutonomousSystemTlvTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AutonomousSystemTest.java index 7a0078f9..1695583b 100644 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/AutonomousSystemTlvTest.java +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/AutonomousSystemTest.java @@ -13,23 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.pcepio; - -import com.google.common.testing.EqualsTester; +package org.onosproject.bgpio.types; import org.junit.Test; -import org.onosproject.pcepio.types.AutonomousSystemTlv; + +import com.google.common.testing.EqualsTester; /** - * Test of the AutonomousSystemTlv. + * Test for AutonomousSystem Tlv. */ -public class AutonomousSystemTlvTest { - private final AutonomousSystemTlv tlv1 = AutonomousSystemTlv.of(1); - private final AutonomousSystemTlv sameAsTlv1 = AutonomousSystemTlv.of(1); - private final AutonomousSystemTlv tlv2 = AutonomousSystemTlv.of(2); +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 basics() { + public void testEquality() { new EqualsTester() .addEqualityGroup(tlv1, sameAsTlv1) .addEqualityGroup(tlv2) diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/BGPLSidentifierTlvTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BGPLSIdentifierTest.java index d7a1f852..f3355d35 100644 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/BGPLSidentifierTlvTest.java +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BGPLSIdentifierTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Open Networking Laboratory + * 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. @@ -13,20 +13,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.pcepio; - -import com.google.common.testing.EqualsTester; +package org.onosproject.bgpio.types; import org.junit.Test; -import org.onosproject.pcepio.types.BGPLSidentifierTlv; + +import com.google.common.testing.EqualsTester; /** - * Test of the BGPLSidentifierTlv. + * Test for BGPLSIdentifier Tlv. */ -public class BGPLSidentifierTlvTest { - private final BGPLSidentifierTlv tlv1 = BGPLSidentifierTlv.of(1); - private final BGPLSidentifierTlv sameAsTlv1 = BGPLSidentifierTlv.of(1); - private final BGPLSidentifierTlv tlv2 = BGPLSidentifierTlv.of(2); +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() { 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/pcep/pcepio/src/test/java/org/onosproject/pcepio/AdministrativeGroupTlvTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPv6AddressTest.java index b3ff2cbb..781935b4 100644 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/AdministrativeGroupTlvTest.java +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IPv6AddressTest.java @@ -13,20 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.pcepio; - -import com.google.common.testing.EqualsTester; +package org.onosproject.bgpio.types; import org.junit.Test; -import org.onosproject.pcepio.types.AdministrativeGroupTlv; +import org.onlab.packet.Ip6Address; + +import com.google.common.testing.EqualsTester; /** - * Test of the AdministrativeGroupTlv. + * Test for IPv6Address Tlv. */ -public class AdministrativeGroupTlvTest { - private final AdministrativeGroupTlv tlv1 = AdministrativeGroupTlv.of(1); - private final AdministrativeGroupTlv sameAsTlv1 = AdministrativeGroupTlv.of(1); - private final AdministrativeGroupTlv tlv2 = AdministrativeGroupTlv.of(2); +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() { 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..00e85dcf --- /dev/null +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/IsIsPseudonodeTest.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.bgpio.types; + +import java.util.ArrayList; +import java.util.List; + +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; +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}; + byte value; + List<Byte> isoNodeID1 = new ArrayList<Byte>(); + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + private final byte[] value2 = new byte[] {0x01, 0x02, 0x01, 0x02, 0x01, 0x03}; + List<Byte> isoNodeID2 = new ArrayList<Byte>(); + ChannelBuffer buffer1 = ChannelBuffers.dynamicBuffer(); + private final IsIsPseudonode tlv1 = IsIsPseudonode.of(isoNodeID1, (byte) 1); + private final IsIsPseudonode sameAsTlv1 = IsIsPseudonode.of(isoNodeID1, (byte) 1); + private final IsIsPseudonode tlv2 = IsIsPseudonode.of(isoNodeID2, (byte) 1); + + @Test + public void testEquality() { + buffer.writeBytes(value1); + for (int i = 0; i < 6; i++) { + value = buffer.readByte(); + isoNodeID1.add(value); + } + buffer1.writeBytes(value2); + for (int i = 0; i < 6; i++) { + value = buffer1.readByte(); + isoNodeID1.add(value); + } + new EqualsTester() + .addEqualityGroup(tlv1, sameAsTlv1) + .addEqualityGroup(tlv2) + .testEquals(); + } +} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LinkLocalRemoteIdentifiersTlvTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTest.java index 1d04b47c..f1510b17 100644 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LinkLocalRemoteIdentifiersTlvTest.java +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LinkLocalRemoteIdentifiersTest.java @@ -13,24 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.pcepio; - -import com.google.common.testing.EqualsTester; +package org.onosproject.bgpio.types; import org.junit.Test; -import org.onosproject.pcepio.types.LinkLocalRemoteIdentifiersTlv; + +import com.google.common.testing.EqualsTester; /** - * Test of the LinkLocalRemoteIdentifiersTlv. + * Test for LinkLocalRemoteIdentifiers Tlv. */ -public class LinkLocalRemoteIdentifiersTlvTest { - - private final LinkLocalRemoteIdentifiersTlv tlv1 = LinkLocalRemoteIdentifiersTlv.of(10, 20); - private final LinkLocalRemoteIdentifiersTlv sameAsTlv1 = LinkLocalRemoteIdentifiersTlv.of(10, 20); - private final LinkLocalRemoteIdentifiersTlv tlv2 = LinkLocalRemoteIdentifiersTlv.of(20, 30); +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 basics() { + public void testEquality() { new EqualsTester() .addEqualityGroup(tlv1, sameAsTlv1) .addEqualityGroup(tlv2) diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PathKeySubObjectTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java index cab43794..02a06e05 100644 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PathKeySubObjectTest.java +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/LocalPrefTest.java @@ -13,27 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.pcepio; +package org.onosproject.bgpio; import org.junit.Test; -import org.onosproject.pcepio.types.PathKeySubObject; +import org.onosproject.bgpio.types.LocalPref; import com.google.common.testing.EqualsTester; /** - * Test of the PathKeySubObject. + * Test for LocalPref BGP Path Attribute. */ -public class PathKeySubObjectTest { - - private final PathKeySubObject tlv1 = new PathKeySubObject((short) 0x0A, 0x0A); - private final PathKeySubObject sameAsTlv1 = PathKeySubObject.of((short) 0x0A, 0x0A); - private final PathKeySubObject tlv2 = new PathKeySubObject((short) 0x0B, 0x0B); +public class LocalPrefTest { + private final int value1 = 800; + private final int value2 = 300; + private final LocalPref attr1 = new LocalPref(value1); + private final LocalPref sameAsAttr1 = new LocalPref(value1); + private final LocalPref attr2 = new LocalPref(value2); @Test - public void basics() { + public void testEquality() { new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) + .addEqualityGroup(attr1, sameAsAttr1) + .addEqualityGroup(attr2) .testEquals(); } } diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepNaiIpv4NodeIdTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java index bcd69bea..eafcec74 100644 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepNaiIpv4NodeIdTest.java +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/MedTest.java @@ -13,24 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.pcepio; +package org.onosproject.bgpio; import org.junit.Test; -import org.onosproject.pcepio.types.PcepNaiIpv4NodeId; +import org.onosproject.bgpio.types.Med; import com.google.common.testing.EqualsTester; -public class PcepNaiIpv4NodeIdTest { - - private final PcepNaiIpv4NodeId tlv1 = PcepNaiIpv4NodeId.of(1); - private final PcepNaiIpv4NodeId tlv2 = PcepNaiIpv4NodeId.of(1); - private final PcepNaiIpv4NodeId tlv3 = PcepNaiIpv4NodeId.of(3); +/** + * Test for MED BGP Path Attribute. + */ +public class MedTest { + private final int value1 = 800; + private final int value2 = 200; + private final Med attr1 = new Med(value1); + private final Med sameAsAttr1 = new Med(value1); + private final Med attr2 = new Med(value2); @Test - public void basics() { + public void testEquality() { new EqualsTester() - .addEqualityGroup(tlv1, tlv2) - .addEqualityGroup(tlv3) + .addEqualityGroup(attr1, sameAsAttr1) + .addEqualityGroup(attr2) .testEquals(); } } 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/bgpio/types/NextHopTest.java index 109197bb..799419a1 100755 --- 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/bgpio/types/NextHopTest.java @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.bgp; +package org.onosproject.bgpio.types; import org.junit.Test; import org.onlab.packet.Ip4Address; -import org.onosproject.bgpio.types.NextHop; import com.google.common.testing.EqualsTester; @@ -38,4 +37,4 @@ public class NextHopTest { .addEqualityGroup(attr2) .testEquals(); } -}
\ No newline at end of file +} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/OSPFareaIDsubTlvTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OriginTest.java index 4b67a900..da7b5570 100644 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/OSPFareaIDsubTlvTest.java +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OriginTest.java @@ -13,26 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.pcepio; - -import com.google.common.testing.EqualsTester; +package org.onosproject.bgpio.types; import org.junit.Test; -import org.onosproject.pcepio.types.OSPFareaIDsubTlv; + +import com.google.common.testing.EqualsTester; /** - * Test of the OSPFareaIDsubTlv. + * Test for Origin BGP Path Attribute. */ -public class OSPFareaIDsubTlvTest { - private final int rawValue1 = 0x0A; - - private final OSPFareaIDsubTlv tlv1 = new OSPFareaIDsubTlv(rawValue1); - private final OSPFareaIDsubTlv tlv2 = OSPFareaIDsubTlv.of(tlv1.getInt()); +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(tlv1, tlv2) + .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/pcep/pcepio/src/test/java/org/onosproject/pcepio/GmplsCapabilityTlvTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OspfRouteTypeTest.java index 3a5c972b..859bdbe5 100644 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/GmplsCapabilityTlvTest.java +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/OspfRouteTypeTest.java @@ -13,23 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.pcepio; - -import com.google.common.testing.EqualsTester; +package org.onosproject.bgpio.types; import org.junit.Test; -import org.onosproject.pcepio.types.GmplsCapabilityTlv; + +import com.google.common.testing.EqualsTester; /** - * Test of the GmplsCapabilityTlv. + * Test for OSPFRouteType Tlv. */ -public class GmplsCapabilityTlvTest { - private final GmplsCapabilityTlv tlv1 = GmplsCapabilityTlv.of(1); - private final GmplsCapabilityTlv sameAsTlv1 = GmplsCapabilityTlv.of(1); - private final GmplsCapabilityTlv tlv2 = GmplsCapabilityTlv.of(2); +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 basics() { + public void testEquality() { new EqualsTester() .addEqualityGroup(tlv1, sameAsTlv1) .addEqualityGroup(tlv2) 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/bgpio/types/attr/BgpAttrNodeFlagBitTlvTest.java index 5f1411ff..4efb7f5b 100644 --- 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/bgpio/types/attr/BgpAttrNodeFlagBitTlvTest.java @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.bgp; +package org.onosproject.bgpio.types.attr; import org.junit.Test; -import org.onosproject.bgpio.types.attr.BgpAttrNodeFlagBitTlv; import com.google.common.testing.EqualsTester; @@ -48,4 +47,4 @@ public class BgpAttrNodeFlagBitTlvTest { 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/bgpio/types/attr/BgpAttrRouterIdV6Test.java index 72ca5dbf..16ca58ee 100644 --- 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/bgpio/types/attr/BgpAttrRouterIdV6Test.java @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.bgp; +package org.onosproject.bgpio.types.attr; import org.junit.Test; import org.onlab.packet.Ip6Address; -import org.onosproject.bgpio.types.attr.BgpAttrRouterIdV6; import com.google.common.testing.EqualsTester; @@ -47,4 +46,4 @@ public class BgpAttrRouterIdV6Test { 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/bgpio/types/attr/BgpLinkAttrIgpMetricTest.java index 32280a79..ef1cfcea 100644 --- 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/bgpio/types/attr/BgpLinkAttrIgpMetricTest.java @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.bgp; +package org.onosproject.bgpio.types.attr; import org.junit.Test; -import org.onosproject.bgpio.types.attr.BgpLinkAttrIgpMetric; import com.google.common.testing.EqualsTester; @@ -41,4 +40,4 @@ public class BgpLinkAttrIgpMetricTest { new EqualsTester().addEqualityGroup(data, sameAsData) .addEqualityGroup(diffData).testEquals(); } -}
\ No newline at end of file +} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepNaiIpv4AdjacencyTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMaskTest.java index 390f5738..c0d7f986 100644 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepNaiIpv4AdjacencyTest.java +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpLinkAttrMplsProtocolMaskTest.java @@ -13,26 +13,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -package org.onosproject.pcepio; +package org.onosproject.bgpio.types.attr; import org.junit.Test; -import org.onosproject.pcepio.types.PcepNaiIpv4Adjacency; import com.google.common.testing.EqualsTester; /** - * Equality test for PcepNaiIpv4Adjacency. + * Test for MPLS protocol mask attribute. */ -public class PcepNaiIpv4AdjacencyTest { +public class BgpLinkAttrMplsProtocolMaskTest { + private final boolean val = true; + private final boolean val1 = false; - private final PcepNaiIpv4Adjacency obj1 = PcepNaiIpv4Adjacency.of(2, 16); - private final PcepNaiIpv4Adjacency sameAsObj1 = PcepNaiIpv4Adjacency.of(2, 16); - private final PcepNaiIpv4Adjacency obj2 = PcepNaiIpv4Adjacency.of(3, 16); + 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(obj1, sameAsObj1).addEqualityGroup(obj2).testEquals(); - } + new EqualsTester().addEqualityGroup(data, sameAsData) + .addEqualityGroup(diffData).testEquals(); + } } 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/bgpio/types/attr/BgpLinkAttrProtectionTypeTest.java index 89f97a83..2fb76352 100644 --- 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/bgpio/types/attr/BgpLinkAttrProtectionTypeTest.java @@ -13,10 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.bgp; +package org.onosproject.bgpio.types.attr; import org.junit.Test; -import org.onosproject.bgpio.types.attr.BgpLinkAttrProtectionType; import com.google.common.testing.EqualsTester; @@ -54,4 +53,4 @@ public class BgpLinkAttrProtectionTypeTest { 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/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/pcep/pcepio/src/test/java/org/onosproject/pcepio/RoutingUniverseTlvTest.java b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetricTest.java index 9b119c90..fe6079fd 100644 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/RoutingUniverseTlvTest.java +++ b/framework/src/onos/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/attr/BgpPrefixAttrMetricTest.java @@ -13,25 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -package org.onosproject.pcepio; +package org.onosproject.bgpio.types.attr; import org.junit.Test; -import org.onosproject.pcepio.types.RoutingUniverseTlv; import com.google.common.testing.EqualsTester; /** - * Equality test for RoutingUniverseTlv. + * Test for BGP prefix metric attribute. */ -public class RoutingUniverseTlvTest { +public class BgpPrefixAttrMetricTest { + private final int val = 1111; + private final int val1 = 2222; - private final RoutingUniverseTlv tlv1 = RoutingUniverseTlv.of(2); - private final RoutingUniverseTlv tlv2 = RoutingUniverseTlv.of(2); - private final RoutingUniverseTlv tlv3 = RoutingUniverseTlv.of(3); + 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(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); + + new EqualsTester().addEqualityGroup(data, sameAsData) + .addEqualityGroup(diffData).testEquals(); } } 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/bgpio/types/attr/BgpPrefixAttrOspfFwdAddrTest.java index f736bead..f6fe39f8 100644 --- 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/bgpio/types/attr/BgpPrefixAttrOspfFwdAddrTest.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.bgp; +package org.onosproject.bgpio.types.attr; 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; @@ -49,4 +48,4 @@ public class BgpPrefixAttrOspfFwdAddrTest { new EqualsTester().addEqualityGroup(data, sameAsData) .addEqualityGroup(diffData).testEquals(); } -}
\ No newline at end of file +} diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPChannelHandler.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPChannelHandler.java index c17736ed..f21c311c 100755 --- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPChannelHandler.java +++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPChannelHandler.java @@ -17,13 +17,19 @@ package org.onosproject.bgp.controller.impl; import java.io.IOException; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.SocketAddress; +import java.net.UnknownHostException; import java.nio.channels.ClosedChannelException; -import java.util.Date; +import java.util.Collections; import java.util.List; +import java.util.LinkedList; +import java.util.ListIterator; import java.util.concurrent.RejectedExecutionException; +import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelStateEvent; @@ -32,17 +38,24 @@ import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler; import org.jboss.netty.handler.timeout.ReadTimeoutException; import org.jboss.netty.handler.timeout.ReadTimeoutHandler; +import org.onlab.packet.Ip4Address; import org.onlab.packet.IpAddress; import org.onosproject.bgp.controller.BGPCfg; +import org.onosproject.bgp.controller.BGPController; import org.onosproject.bgp.controller.BGPId; import org.onosproject.bgp.controller.BGPPeer; import org.onosproject.bgp.controller.BGPPeerCfg; -import org.onosproject.bgp.controller.impl.BGPControllerImpl.BGPPeerManager; +import org.onosproject.bgp.controller.impl.BGPControllerImpl.BGPPeerManagerImpl; import org.onosproject.bgpio.exceptions.BGPParseException; +import org.onosproject.bgpio.protocol.BGPFactory; import org.onosproject.bgpio.protocol.BGPMessage; -//import org.onosproject.bgpio.protocol.BGPOpenMsg; +import org.onosproject.bgpio.protocol.BGPOpenMsg; import org.onosproject.bgpio.protocol.BGPType; import org.onosproject.bgpio.protocol.BGPVersion; +import org.onosproject.bgpio.types.BGPErrorType; +import org.onosproject.bgpio.types.BGPValueType; +import org.onosproject.bgpio.types.FourOctetAsNumCapabilityTlv; +import org.onosproject.bgpio.types.MultiProtocolExtnCapabilityTlv; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,18 +65,25 @@ import org.slf4j.LoggerFactory; class BGPChannelHandler extends IdleStateAwareChannelHandler { private static final Logger log = LoggerFactory.getLogger(BGPChannelHandler.class); - + static final int BGP_MIN_HOLDTIME = 3; static final int BGP_MAX_KEEPALIVE_INTERVAL = 3; private BGPPeer bgpPeer; private BGPId thisbgpId; - Channel channel; + private Channel channel; private BGPKeepAliveTimer keepAliveTimer = null; private short peerHoldTime = 0; private short negotiatedHoldTime = 0; - private short peerAsNum; + private long peerAsNum; private int peerIdentifier; private BGPPacketStatsImpl bgpPacketStats; static final int MAX_WRONG_COUNT_PACKET = 5; + static final byte MULTI_PROTOCOL_EXTN_CAPA_TYPE = 1; + static final byte FOUR_OCTET_AS_NUM_CAPA_TYPE = 65; + static final int AS_TRANS = 23456; + static final int MAX_AS2_NUM = 65535; + static final short AFI = 16388; + static final byte RES = 0; + static final byte SAFI = 71; // State needs to be volatile because the HandshakeTimeoutHandler // needs to check if the handshake is complete @@ -72,13 +92,17 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { // When a bgp peer with a ip addresss is found (i.e we already have a // connected peer with the same ip), the new peer is immediately // disconnected. At that point netty callsback channelDisconnected() which - // proceeds to cleaup peer state - we need to ensure that it does not cleanup + // proceeds to cleaup peer state - we need to ensure that it does not + // cleanup // peer state for the older (still connected) peer private volatile Boolean duplicateBGPIdFound; // Indicates the bgp version used by this bgp peer protected BGPVersion bgpVersion; - private BGPControllerImpl bgpControllerImpl; - private BGPPeerManager peerManager; + private BGPController bgpController; + protected BGPFactory factory4; + private boolean isIbgpSession; + private BgpSessionInfoImpl sessionInfo; + private BGPPeerManagerImpl peerManager; private InetSocketAddress inetAddress; private IpAddress ipAddress; private SocketAddress address; @@ -88,15 +112,16 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { /** * Create a new unconnected BGPChannelHandler. * - * @param bgpCtrlImpl bgp controller implementation object + * @param bgpController bgp controller */ - BGPChannelHandler(BGPControllerImpl bgpCtrlImpl) { - this.bgpControllerImpl = bgpCtrlImpl; - this.peerManager = bgpCtrlImpl.getPeerManager(); + BGPChannelHandler(BGPController bgpController) { + this.bgpController = bgpController; + this.peerManager = (BGPPeerManagerImpl) bgpController.peerManager(); this.state = ChannelState.IDLE; + this.factory4 = Controller.getBGPMessageFactory4(); this.duplicateBGPIdFound = Boolean.FALSE; this.bgpPacketStats = new BGPPacketStatsImpl(); - this.bgpconfig = bgpCtrlImpl.getConfig(); + this.bgpconfig = bgpController.getConfig(); } // To disconnect peer session. @@ -127,17 +152,19 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { // check for OPEN message if (m.getType() != BGPType.OPEN) { // When the message type is not keep alive message increment the wrong packet statistics - h.processUnknownMsg(); + h.processUnknownMsg(BGPErrorType.FINITE_STATE_MACHINE_ERROR, + BGPErrorType.RECEIVE_UNEXPECTED_MESSAGE_IN_OPENSENT_STATE, m.getType() + .getType()); log.debug("Message is not OPEN message"); } else { log.debug("Sending keep alive message in OPENSENT state"); h.bgpPacketStats.addInPacket(); - // TODO: initialize openmessage BGPOpenMsg pOpenmsg = (BGPOpenMsg) m; - // TODO: initialize identifier from open messgae h.peerIdentifier = pOpenmsg.getBgpId(); + BGPOpenMsg pOpenmsg = (BGPOpenMsg) m; + h.peerIdentifier = pOpenmsg.getBgpId(); // validate capabilities and open msg - if (h.openMsgValidation(h)) { + if (h.openMsgValidation(h, pOpenmsg)) { log.debug("Sending handshake OPEN message"); /* @@ -145,7 +172,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { * value of the Hold Timer by using the smaller of its configured Hold Time and the Hold Time * received in the OPEN message */ - // TODO: initialize holdtime from open message h.peerHoldTime = pOpenmsg.getHoldTime(); + h.peerHoldTime = pOpenmsg.getHoldTime(); if (h.peerHoldTime < h.bgpconfig.getHoldTime()) { h.channel.getPipeline().replace("holdTime", "holdTime", @@ -155,7 +182,8 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { log.info("Hold Time : " + h.peerHoldTime); - // TODO: get AS number for open message update AS number + // update AS number + h.peerAsNum = pOpenmsg.getAsNumber(); } // Send keepalive message to peer. @@ -175,15 +203,17 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { // check for open message if (m.getType() != BGPType.OPEN) { // When the message type is not open message increment the wrong packet statistics - h.processUnknownMsg(); + h.processUnknownMsg(BGPErrorType.FINITE_STATE_MACHINE_ERROR, BGPErrorType.UNSPECIFIED_ERROR, m + .getType().getType()); log.debug("Message is not OPEN message"); } else { h.bgpPacketStats.addInPacket(); - // TODO: initialize open message BGPOpenMsg pOpenmsg = (BGPOpenMsg) m; + BGPOpenMsg pOpenmsg = (BGPOpenMsg) m; + h.peerIdentifier = pOpenmsg.getBgpId(); // Validate open message - if (h.openMsgValidation(h)) { + if (h.openMsgValidation(h, pOpenmsg)) { log.debug("Sending handshake OPEN message"); /* @@ -191,7 +221,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { * value of the Hold Timer by using the smaller of its configured Hold Time and the Hold Time * received in the OPEN message */ - // TODO: get hold time from open message h.peerHoldTime = pOpenmsg.getHoldTime(); + h.peerHoldTime = pOpenmsg.getHoldTime(); if (h.peerHoldTime < h.bgpconfig.getHoldTime()) { h.channel.getPipeline().replace("holdTime", "holdTime", @@ -201,7 +231,8 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { log.debug("Hold Time : " + h.peerHoldTime); - //TODO: update AS number form open messsage update AS number + // update AS number + h.peerAsNum = pOpenmsg.getAsNumber(); h.sendHandshakeOpenMessage(); h.bgpPacketStats.addOutPacket(); @@ -218,7 +249,9 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { // check for keep alive message if (m.getType() != BGPType.KEEP_ALIVE) { // When the message type is not keep alive message handle the wrong packet - h.processUnknownMsg(); + h.processUnknownMsg(BGPErrorType.FINITE_STATE_MACHINE_ERROR, + BGPErrorType.RECEIVE_UNEXPECTED_MESSAGE_IN_OPENCONFIRM_STATE, m.getType() + .getType()); log.debug("Message is not KEEPALIVE message"); } else { @@ -229,30 +262,28 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { final InetSocketAddress inetAddress = (InetSocketAddress) h.address; h.thisbgpId = BGPId.bgpId(IpAddress.valueOf(inetAddress.getAddress())); - h.bgpPeer = h.peerManager.getBGPPeerInstance(h.thisbgpId, h.bgpVersion, h.bgpPacketStats); - // set the status fo bgp as connected + // set session parameters + h.negotiatedHoldTime = (h.peerHoldTime < h.bgpconfig.getHoldTime()) ? h.peerHoldTime + : h.bgpconfig.getHoldTime(); + h.sessionInfo = new BgpSessionInfoImpl(h.thisbgpId, h.bgpVersion, h.peerAsNum, h.peerHoldTime, + h.peerIdentifier, h.negotiatedHoldTime, h.isIbgpSession); + + h.bgpPeer = h.peerManager.getBGPPeerInstance(h.bgpController, h.sessionInfo, h.bgpPacketStats); + // set the status of bgp as connected h.bgpPeer.setConnected(true); h.bgpPeer.setChannel(h.channel); - // set specific parameters to bgp peer - h.bgpPeer.setBgpPeerVersion(h.bgpVersion); - h.bgpPeer.setBgpPeerASNum(h.peerAsNum); - h.bgpPeer.setBgpPeerHoldTime(h.peerHoldTime); - h.bgpPeer.setBgpPeerIdentifier(h.peerIdentifier); - - h.negotiatedHoldTime = (h.peerHoldTime < h.bgpconfig.getHoldTime()) ? h.peerHoldTime : h.bgpconfig - .getHoldTime(); - h.bgpPeer.setNegotiatedHoldTime(h.negotiatedHoldTime); /* * RFC 4271, When an OPEN message is received, sends a KEEPALIVE message, If the negotiated hold * time value is zero, then the HoldTimer and KeepaliveTimer are not started. A reasonable maximum * time between KEEPALIVE messages would be one third of the Hold Time interval. */ - h.sendKeepAliveMessage(); if (h.negotiatedHoldTime != 0) { - h.keepAliveTimer - = new BGPKeepAliveTimer(h, (h.negotiatedHoldTime / BGP_MAX_KEEPALIVE_INTERVAL)); + h.keepAliveTimer = new BGPKeepAliveTimer(h, + (h.negotiatedHoldTime / BGP_MAX_KEEPALIVE_INTERVAL)); + } else { + h.sendKeepAliveMessage(); } h.bgpPacketStats.addOutPacket(); @@ -349,8 +380,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { } inetAddress = (InetSocketAddress) address; - ipAddress = IpAddress.valueOf(inetAddress.getAddress()); - peerAddr = ipAddress.toString(); + peerAddr = IpAddress.valueOf(inetAddress.getAddress()).toString(); // if peer is not configured disconnect session if (!bgpconfig.isPeerConfigured(peerAddr)) { @@ -360,7 +390,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { } // if connection is already established close channel - if (peerManager.isPeerConnected(peerAddr)) { + if (peerManager.isPeerConnected(BGPId.bgpId(IpAddress.valueOf(peerAddr)))) { log.debug("Duplicate connection received, peer {}", peerAddr); channel.close(); return; @@ -392,8 +422,7 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { } inetAddress = (InetSocketAddress) address; - ipAddress = IpAddress.valueOf(inetAddress.getAddress()); - peerAddr = ipAddress.toString(); + peerAddr = IpAddress.valueOf(inetAddress.getAddress()).toString(); if (thisbgpId != null) { if (!duplicateBGPIdFound) { @@ -432,14 +461,14 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { if ((ChannelState.OPENWAIT == state) || (ChannelState.OPENSENT == state)) { // When ReadTimeout timer is expired in OPENWAIT/OPENSENT state, it is considered - // TODO: Send notification + sendNotification(BGPErrorType.HOLD_TIMER_EXPIRED, (byte) 0, null); channel.close(); state = ChannelState.IDLE; return; } else if (ChannelState.OPENCONFIRM == state) { // When ReadTimeout timer is expired in OPENCONFIRM state. - // TODO: Send Notification + sendNotification(BGPErrorType.HOLD_TIMER_EXPIRED, (byte) 0, null); channel.close(); state = ChannelState.IDLE; return; @@ -454,8 +483,17 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { } channel.close(); } else if (e.getCause() instanceof BGPParseException) { - // TODO: SEND NOTIFICATION - log.debug("BGP Parse Exception: ", e.getCause()); + byte[] data = new byte[] {}; + BGPParseException errMsg = (BGPParseException) e.getCause(); + byte errorCode = errMsg.getErrorCode(); + byte errorSubCode = errMsg.getErrorSubCode(); + ChannelBuffer tempCb = errMsg.getData(); + if (tempCb != null) { + int dataLength = tempCb.capacity(); + data = new byte[dataLength]; + tempCb.readBytes(data, 0, dataLength); + } + sendNotification(errorCode, errorSubCode, data); } else if (e.getCause() instanceof RejectedExecutionException) { log.warn("Could not process message: queue full"); } else { @@ -507,11 +545,12 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { /** * To handle the BGP message. * - * @param m BGP message + * @param m bgp message + * @throws BGPParseException throw exception */ private void dispatchMessage(BGPMessage m) throws BGPParseException { bgpPacketStats.addInPacket(); - bgpControllerImpl.processBGPPacket(thisbgpId, m); + bgpController.processBGPPacket(thisbgpId, m); } /** @@ -557,14 +596,39 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { /** * Send handshake open message to the peer. * - * @throws IOException ,BGPParseException + * @throws IOException, BGPParseException */ private void sendHandshakeOpenMessage() throws IOException, BGPParseException { - // TODO: send open message. + int bgpId; + + bgpId = Ip4Address.valueOf(bgpconfig.getRouterId()).toInt(); + BGPMessage msg = factory4.openMessageBuilder().setAsNumber((short) bgpconfig.getAsNumber()) + .setHoldTime(bgpconfig.getHoldTime()).setBgpId(bgpId) + .setLsCapabilityTlv(bgpconfig.getLsCapability()) + .setLargeAsCapabilityTlv(bgpconfig.getLargeASCapability()) + .build(); + log.debug("Sending open message to {}", channel.getRemoteAddress()); + channel.write(Collections.singletonList(msg)); } /** + * Send notification message to peer. + * + * @param errorCode error code send in notification + * @param errorSubCode sub error code send in notification + * @param data data to send in notification + * @throws IOException, BGPParseException while building message + */ + private void sendNotification(byte errorCode, byte errorSubCode, byte[] data) + throws IOException, BGPParseException { + BGPMessage msg = factory4.notificationMessageBuilder().setErrorCode(errorCode).setErrorSubCode(errorSubCode) + .setData(data).build(); + log.debug("Sending notification message to {}", channel.getRemoteAddress()); + channel.write(Collections.singletonList(msg)); + } + + /** * Send keep alive message. * * @throws IOException when channel is disconnected @@ -572,60 +636,220 @@ class BGPChannelHandler extends IdleStateAwareChannelHandler { */ synchronized void sendKeepAliveMessage() throws IOException, BGPParseException { - // TODO: send keep alive message. + BGPMessage msg = factory4.keepaliveMessageBuilder().build(); + log.debug("Sending keepalive message to {}", channel.getRemoteAddress()); + channel.write(Collections.singletonList(msg)); } /** - * Send notification and close channel with peer. + * Process unknown BGP message received. + * + * @param errorCode error code + * @param errorSubCode error sub code + * @param data message type + * @throws BGPParseException while processing error messsage + * @throws IOException while processing error message */ - private void sendErrNotificationAndCloseChannel() { - // TODO: send notification + public void processUnknownMsg(byte errorCode, byte errorSubCode, byte data) throws BGPParseException, IOException { + log.debug("UNKNOWN message received"); + byte[] byteArray = new byte[1]; + byteArray[0] = data; + sendNotification(errorCode, errorSubCode, byteArray); channel.close(); } /** - * Process unknown BGP message received. + * BGP open message validation. * - * @throws BGPParseException when received invalid message + * @param h channel handler + * @param openMsg open message + * @return true if valid message, otherwise false + * @throws BGPParseException throw exception */ - public void processUnknownMsg() throws BGPParseException { - log.debug("UNKNOWN message received"); - Date now = null; - if (bgpPacketStats.wrongPacketCount() == 0) { - now = new Date(); - bgpPacketStats.setTime(now.getTime()); - bgpPacketStats.addWrongPacket(); - sendErrNotificationAndCloseChannel(); + public boolean openMsgValidation(BGPChannelHandler h, BGPOpenMsg openMsg) throws BGPParseException { + boolean result; + + // Validate BGP ID + result = bgpIdValidation(openMsg); + if (!result) { + throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.BAD_BGP_IDENTIFIER, null); + } + + // Validate AS number + result = asNumberValidation(h, openMsg); + if (!result) { + throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.BAD_PEER_AS, null); + } + + // Validate hold timer + if ((openMsg.getHoldTime() != 0) && (openMsg.getHoldTime() < BGP_MIN_HOLDTIME)) { + throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.UNACCEPTABLE_HOLD_TIME, null); + } + + // Validate capabilities + result = capabilityValidation(h, openMsg); + return result; + } + + /** + * Capability Validation. + * + * @param h channel handler + * @param openmsg open message + * @return success or failure + * @throws BGPParseException + */ + private boolean capabilityValidation(BGPChannelHandler h, BGPOpenMsg openmsg) throws BGPParseException { + log.debug("capabilityValidation"); + + boolean isMultiProtocolcapabilityExists = false; + boolean isFourOctetCapabilityExits = false; + int capAsNum = 0; + + List<BGPValueType> capabilityTlv = openmsg.getCapabilityTlv(); + ListIterator<BGPValueType> listIterator = capabilityTlv.listIterator(); + List<BGPValueType> unSupportedCapabilityTlv = new LinkedList<>(); + ListIterator<BGPValueType> unSupportedCaplistIterator = unSupportedCapabilityTlv.listIterator(); + BGPValueType tempTlv; + boolean isLargeAsCapabilityCfg = h.bgpconfig.getLargeASCapability(); + boolean isLsCapabilityCfg = h.bgpconfig.getLsCapability(); + + while (listIterator.hasNext()) { + BGPValueType tlv = listIterator.next(); + if (tlv.getType() == MULTI_PROTOCOL_EXTN_CAPA_TYPE) { + isMultiProtocolcapabilityExists = true; + } + if (tlv.getType() == FOUR_OCTET_AS_NUM_CAPA_TYPE) { + isFourOctetCapabilityExits = true; + capAsNum = ((FourOctetAsNumCapabilityTlv) tlv).getInt(); + } } - if (bgpPacketStats.wrongPacketCount() > 1) { - Date lastest = new Date(); - bgpPacketStats.addWrongPacket(); - // converting to seconds - if (((lastest.getTime() - bgpPacketStats.getTime()) / 1000) > 60) { - now = lastest; - bgpPacketStats.setTime(now.getTime()); - bgpPacketStats.resetWrongPacket(); - bgpPacketStats.addWrongPacket(); - } else if (((int) (lastest.getTime() - now.getTime()) / 1000) < 60) { - if (MAX_WRONG_COUNT_PACKET <= bgpPacketStats.wrongPacketCount()) { - // reset once wrong packet count reaches MAX_WRONG_COUNT_PACKET - bgpPacketStats.resetWrongPacket(); - // max wrong packets received send error message and close the session - sendErrNotificationAndCloseChannel(); + + if (isFourOctetCapabilityExits) { + if (capAsNum > MAX_AS2_NUM) { + if (openmsg.getAsNumber() != AS_TRANS) { + throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.BAD_PEER_AS, null); + } + } else { + if (capAsNum != openmsg.getAsNumber()) { + throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, BGPErrorType.BAD_PEER_AS, null); } } } + + if ((isLsCapabilityCfg)) { + if (!isMultiProtocolcapabilityExists) { + tempTlv = new MultiProtocolExtnCapabilityTlv(AFI, RES, SAFI); + unSupportedCapabilityTlv.add(tempTlv); + } + } + + if ((isLargeAsCapabilityCfg)) { + if (!isFourOctetCapabilityExits) { + tempTlv = new FourOctetAsNumCapabilityTlv(h.bgpconfig.getAsNumber()); + unSupportedCapabilityTlv.add(tempTlv); + } + } + + if (unSupportedCaplistIterator.hasNext()) { + ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); + while (unSupportedCaplistIterator.hasNext()) { + BGPValueType tlv = unSupportedCaplistIterator.next(); + tlv.write(buffer); + } + throw new BGPParseException(BGPErrorType.OPEN_MESSAGE_ERROR, + BGPErrorType.UNSUPPORTED_CAPABILITY, buffer); + } else { + return true; + } } /** - * Open message validation. + * AS Number Validation. * - * @param h channel handler - * @return true if validation succeed, otherwise false - * @throws BGPParseException when received invalid message + * @param h channel Handler + * @param openMsg open message + * @return true or false */ - public boolean openMsgValidation(BGPChannelHandler h) throws BGPParseException { - // TODO: Open message validation. + private boolean asNumberValidation(BGPChannelHandler h, BGPOpenMsg openMsg) { + log.debug("AS Num validation"); + + int capAsNum = 0; + boolean isFourOctetCapabilityExits = false; + + BGPPeerCfg peerCfg = h.bgpconfig.displayPeers(peerAddr); + List<BGPValueType> capabilityTlv = openMsg.getCapabilityTlv(); + ListIterator<BGPValueType> listIterator = capabilityTlv.listIterator(); + + while (listIterator.hasNext()) { + BGPValueType tlv = listIterator.next(); + if (tlv.getType() == FOUR_OCTET_AS_NUM_CAPA_TYPE) { + isFourOctetCapabilityExits = true; + capAsNum = ((FourOctetAsNumCapabilityTlv) tlv).getInt(); + } + } + + if (peerCfg.getAsNumber() > MAX_AS2_NUM) { + if (openMsg.getAsNumber() != AS_TRANS) { + return false; + } + + if (!isFourOctetCapabilityExits) { + return false; + } + + if (peerCfg.getAsNumber() != capAsNum) { + return false; + } + + isIbgpSession = peerCfg.getIsIBgp(); + if (isIbgpSession) { + // IBGP - AS number should be same for Peer and local if it is IBGP + if (h.bgpconfig.getAsNumber() != capAsNum) { + return false; + } + } + } else { + + if (openMsg.getAsNumber() != peerCfg.getAsNumber()) { + return false; + } + + if (isFourOctetCapabilityExits) { + if (capAsNum != peerCfg.getAsNumber()) { + return false; + } + } + + isIbgpSession = peerCfg.getIsIBgp(); + if (isIbgpSession) { + // IBGP - AS number should be same for Peer and local if it is IBGP + if (openMsg.getAsNumber() != h.bgpconfig.getAsNumber()) { + return false; + } + } + } + return true; + } + + /** + * Validates BGP ID. + * + * @param openMsg open message + * @return true or false + */ + private boolean bgpIdValidation(BGPOpenMsg openMsg) { + String openMsgBgpId = Ip4Address.valueOf(openMsg.getBgpId()).toString(); + + InetAddress ipAddress; + try { + ipAddress = InetAddress.getByName(openMsgBgpId); + if (ipAddress.isMulticastAddress()) { + return false; + } + } catch (UnknownHostException e) { + log.debug("InetAddress convertion failed"); + } return true; } } diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPControllerImpl.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPControllerImpl.java index d8378e31..35c31ab7 100755 --- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPControllerImpl.java +++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPControllerImpl.java @@ -16,25 +16,25 @@ package org.onosproject.bgp.controller.impl; -import static org.onlab.util.Tools.groupedThreads; - +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; +import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; + 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.Service; -import org.onlab.packet.IpAddress; import org.onosproject.bgp.controller.BGPCfg; import org.onosproject.bgp.controller.BGPController; import org.onosproject.bgp.controller.BGPId; -import org.onosproject.bgp.controller.BGPPacketStats; import org.onosproject.bgp.controller.BGPPeer; +import org.onosproject.bgp.controller.BgpLinkListener; +import org.onosproject.bgp.controller.BgpNodeListener; +import org.onosproject.bgp.controller.BgpPeerManager; +import org.onosproject.bgpio.exceptions.BGPParseException; import org.onosproject.bgpio.protocol.BGPMessage; -import org.onosproject.bgpio.protocol.BGPVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,16 +44,13 @@ public class BGPControllerImpl implements BGPController { private static final Logger log = LoggerFactory.getLogger(BGPControllerImpl.class); - private final ExecutorService executorMsgs = Executors.newFixedThreadPool(32, - groupedThreads("onos/bgp", - "event-stats-%d")); - - private final ExecutorService executorBarrier = Executors.newFixedThreadPool(4, - groupedThreads("onos/bgp", - "event-barrier-%d")); protected ConcurrentHashMap<BGPId, BGPPeer> connectedPeers = new ConcurrentHashMap<BGPId, BGPPeer>(); - protected BGPPeerManager peerManager = new BGPPeerManager(); + protected BGPPeerManagerImpl peerManager = new BGPPeerManagerImpl(); + + protected Set<BgpNodeListener> bgpNodeListener = new CopyOnWriteArraySet<>(); + protected Set<BgpLinkListener> bgpLinkListener = new CopyOnWriteArraySet<>(); + final Controller ctrl = new Controller(this); private BGPConfig bgpconfig = new BGPConfig(); @@ -83,12 +80,42 @@ public class BGPControllerImpl implements BGPController { } @Override + public void addListener(BgpNodeListener listener) { + this.bgpNodeListener.add(listener); + } + + @Override + public void removeListener(BgpNodeListener listener) { + this.bgpNodeListener.remove(listener); + } + + @Override + public Set<BgpNodeListener> listener() { + return bgpNodeListener; + } + + @Override + public void addLinkListener(BgpLinkListener listener) { + this.bgpLinkListener.add(listener); + } + + @Override + public void removeLinkListener(BgpLinkListener listener) { + this.bgpLinkListener.remove(listener); + } + + @Override + public Set<BgpLinkListener> linkListener() { + return bgpLinkListener; + } + + @Override public void writeMsg(BGPId bgpId, BGPMessage msg) { - // TODO: Send message + this.getPeer(bgpId).sendMessage(msg); } @Override - public void processBGPPacket(BGPId bgpId, BGPMessage msg) { + public void processBGPPacket(BGPId bgpId, BGPMessage msg) throws BGPParseException { switch (msg.getType()) { case OPEN: @@ -122,18 +149,12 @@ public class BGPControllerImpl implements BGPController { * Implementation of an BGP Peer which is responsible for keeping track of connected peers and the state in which * they are. */ - public class BGPPeerManager { + public class BGPPeerManagerImpl implements BgpPeerManager { - private final Logger log = LoggerFactory.getLogger(BGPPeerManager.class); + private final Logger log = LoggerFactory.getLogger(BGPPeerManagerImpl.class); private final Lock peerLock = new ReentrantLock(); - /** - * Add a BGP peer that has just connected to the system. - * - * @param bgpId the id of bgp peer to add - * @param bgpPeer the actual bgp peer object. - * @return true if added, false otherwise. - */ + @Override public boolean addConnectedPeer(BGPId bgpId, BGPPeer bgpPeer) { if (connectedPeers.get(bgpId) != null) { @@ -147,119 +168,49 @@ public class BGPControllerImpl implements BGPController { } } - /** - * Checks if the activation for this bgp peer is valid. - * - * @param bgpId the id of bgp peer to check - * @return true if valid, false otherwise - */ + @Override public boolean isPeerConnected(BGPId bgpId) { if (connectedPeers.get(bgpId) == null) { - this.log.error("Trying to activate peer but is not in " + "connected peer: bgpIp {}. Aborting ..", - bgpId.toString()); + this.log.error("Is peer connected: bgpIp {}.", bgpId.toString()); return false; } return true; } - /** - * Checks if the activation for this bgp peer is valid. - * - * @param routerid the routerid of bgp peer to check - * @return true if valid, false otherwise - */ - public boolean isPeerConnected(String routerid) { - - final BGPId bgpId; - bgpId = BGPId.bgpId(IpAddress.valueOf(routerid)); - - if (connectedPeers.get(bgpId) != null) { - this.log.info("Peer connection exist "); - return true; - } - this.log.info("Initiate connect request to " + "peer: bgpIp {}", bgpId.toString()); - - return false; - } - - /** - * Clear all state in controller peer maps for a bgp peer that has - * disconnected from the local controller. - * - * @param bgpId the id of bgp peer to remove. - */ + @Override public void removeConnectedPeer(BGPId bgpId) { connectedPeers.remove(bgpId); } - /** - * Clear all state in controller peer maps for a bgp peer that has - * disconnected from the local controller. - * - * @param routerid the router id of bgp peer to remove. - */ - public void removeConnectedPeer(String routerid) { - final BGPId bgpId; - - bgpId = BGPId.bgpId(IpAddress.valueOf(routerid)); - - connectedPeers.remove(bgpId); - } - - /** - * Gets bgp peer for connected peer map. - * - * @param routerid router id - * @return peer if available, null otherwise - */ - public BGPPeer getPeer(String routerid) { - final BGPId bgpId; - bgpId = BGPId.bgpId(IpAddress.valueOf(routerid)); - + @Override + public BGPPeer getPeer(BGPId bgpId) { return connectedPeers.get(bgpId); } /** - * Gets bgp peer instance. - * - * @param bgpId bgp identifier. - * @param pv bgp version. - * @param pktStats packet statistics. - * @return BGPPeer peer instance. - */ - public BGPPeer getBGPPeerInstance(BGPId bgpId, BGPVersion pv, BGPPacketStats pktStats) { - BGPPeer bgpPeer = new BGPPeerImpl(); - bgpPeer.init(bgpId, pv, pktStats); + * Gets bgp peer instance. + * + * @param bgpController controller instance. + * @param sessionInfo bgp session info. + * @param pktStats packet statistics. + * @return BGPPeer peer instance. + */ + public BGPPeer getBGPPeerInstance(BGPController bgpController, BgpSessionInfoImpl sessionInfo, + BGPPacketStatsImpl pktStats) { + BGPPeer bgpPeer = new BGPPeerImpl(bgpController, sessionInfo, pktStats); return bgpPeer; } } - /** - * Gets controller instance. - * - * @return Controller instance. - */ - public Controller getController() { - return ctrl; - } - - /** - * Gets connected peers. - * - * @return connectedPeers from connected Peers Map. - */ - public ConcurrentHashMap<BGPId, BGPPeer> getConnectedPeers() { + @Override + public ConcurrentHashMap<BGPId, BGPPeer> connectedPeers() { return connectedPeers; } - /** - * Gets peer manager. - * - * @return peerManager. - */ - public BGPPeerManager getPeerManager() { + @Override + public BGPPeerManagerImpl peerManager() { return peerManager; } @@ -269,7 +220,7 @@ public class BGPControllerImpl implements BGPController { } @Override - public int getBGPConnNumber() { + public int connectedPeerCount() { return connectedPeers.size(); } -}
\ No newline at end of file +} diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPMessageDecoder.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPMessageDecoder.java index 39f2862d..636b78cc 100755 --- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPMessageDecoder.java +++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPMessageDecoder.java @@ -24,6 +24,9 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.handler.codec.frame.FrameDecoder; import org.onosproject.bgpio.protocol.BGPMessage; import org.onlab.util.HexDump; +import org.onosproject.bgpio.protocol.BGPFactories; +import org.onosproject.bgpio.protocol.BGPMessageReader; +import org.onosproject.bgpio.types.BGPHeader; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,9 +39,6 @@ public class BGPMessageDecoder extends FrameDecoder { @Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { - - List<BGPMessage> msgList = new LinkedList<BGPMessage>(); - log.debug("MESSAGE IS RECEIVED."); if (!channel.isConnected()) { log.info("Channel is not connected."); @@ -47,7 +47,14 @@ public class BGPMessageDecoder extends FrameDecoder { HexDump.dump(buffer); - // TODO: decode bgp messages + BGPMessageReader<BGPMessage> reader = BGPFactories.getGenericReader(); + List<BGPMessage> msgList = new LinkedList<BGPMessage>(); + + while (buffer.readableBytes() > 0) { + BGPHeader bgpHeader = new BGPHeader(); + BGPMessage message = reader.readFrom(buffer, bgpHeader); + msgList.add(message); + } return msgList; } }
\ No newline at end of file diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerConfig.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerConfig.java index 51b95a4b..14a68cf6 100755 --- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerConfig.java +++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerConfig.java @@ -16,6 +16,7 @@ package org.onosproject.bgp.controller.impl; import org.onlab.packet.Ip4Address; +import org.onosproject.bgp.controller.BgpConnectPeer; import org.onosproject.bgp.controller.BGPPeerCfg; /** @@ -28,6 +29,7 @@ public class BGPPeerConfig implements BGPPeerCfg { private Ip4Address peerId = null; private State state; private boolean selfInitiated; + private BgpConnectPeer connectPeer; /** * Constructor to initialize the values. @@ -106,4 +108,14 @@ public class BGPPeerConfig implements BGPPeerCfg { public void setSelfInnitConnection(boolean selfInit) { this.selfInitiated = selfInit; } + + @Override + public BgpConnectPeer connectPeer() { + return this.connectPeer; + } + + @Override + public void setConnectPeer(BgpConnectPeer connectPeer) { + this.connectPeer = connectPeer; + } } diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerImpl.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerImpl.java index 212b24d3..45f74634 100755 --- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerImpl.java +++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPeerImpl.java @@ -24,11 +24,12 @@ import java.util.concurrent.RejectedExecutionException; import org.jboss.netty.channel.Channel; import org.onlab.packet.IpAddress; -import org.onosproject.bgp.controller.BGPId; -import org.onosproject.bgp.controller.BGPPacketStats; +import org.onosproject.bgp.controller.BGPController; import org.onosproject.bgp.controller.BGPPeer; +import org.onosproject.bgp.controller.BgpSessionInfo; +import org.onosproject.bgpio.protocol.BGPFactories; +import org.onosproject.bgpio.protocol.BGPFactory; import org.onosproject.bgpio.protocol.BGPMessage; -import org.onosproject.bgpio.protocol.BGPVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,19 +44,31 @@ public class BGPPeerImpl implements BGPPeer { private static final String SHUTDOWN_MSG = "Worker has already been shutdown"; + private BGPController bgpController; private Channel channel; protected String channelId; private boolean connected; protected boolean isHandShakeComplete = false; - public BGPSessionInfo sessionInfo; + private BgpSessionInfo sessionInfo; private BGPPacketStatsImpl pktStats; + @Override - public void init(BGPId bgpId, BGPVersion bgpVersion, BGPPacketStats pktStats) { - this.sessionInfo.setRemoteBgpId(bgpId); - this.sessionInfo.setRemoteBgpVersion(bgpVersion); - this.pktStats = (BGPPacketStatsImpl) pktStats; - this.sessionInfo = new BGPSessionInfo(); + public BgpSessionInfo sessionInfo() { + return sessionInfo; + } + + /** + * Initialize peer. + * + *@param bgpController controller instance + *@param sessionInfo bgp session info + *@param pktStats packet statistics + */ + public BGPPeerImpl(BGPController bgpController, BgpSessionInfo sessionInfo, BGPPacketStatsImpl pktStats) { + this.bgpController = bgpController; + this.sessionInfo = sessionInfo; + this.pktStats = pktStats; } // ************************ @@ -129,53 +142,9 @@ public class BGPPeerImpl implements BGPPeer { return channelId; } - // ************************ - // BGP Peer features related - // ************************ - - @Override - public final BGPId getBGPId() { - return this.sessionInfo.getRemoteBgpId(); - }; - - @Override - public final String getStringId() { - return this.sessionInfo.getRemoteBgpId().toString(); - } - - @Override - public final void setBgpPeerVersion(BGPVersion peerVersion) { - this.sessionInfo.setRemoteBgpVersion(peerVersion); - } - - @Override - public void setBgpPeerASNum(short peerASNum) { - this.sessionInfo.setRemoteBgpASNum(peerASNum); - } - - @Override - public void setBgpPeerHoldTime(short peerHoldTime) { - this.sessionInfo.setRemoteBgpHoldTime(peerHoldTime); - } - - @Override - public void setBgpPeerIdentifier(int peerIdentifier) { - this.sessionInfo.setRemoteBgpIdentifier(peerIdentifier); - } - - @Override - public int getBgpPeerIdentifier() { - return this.sessionInfo.getRemoteBgpIdentifier(); - } - - @Override - public int getNegotiatedHoldTime() { - return this.sessionInfo.getNegotiatedholdTime(); - } - @Override - public void setNegotiatedHoldTime(short negotiatedHoldTime) { - this.sessionInfo.setNegotiatedholdTime(negotiatedHoldTime); + public BGPFactory factory() { + return BGPFactories.getFactory(sessionInfo.remoteBgpVersion()); } @Override @@ -185,7 +154,8 @@ public class BGPPeerImpl implements BGPPeer { @Override public String toString() { - return MoreObjects.toStringHelper(getClass()).omitNullValues().add("channel", channelId()) - .add("bgpId", getBGPId()).toString(); + return MoreObjects.toStringHelper(getClass()).omitNullValues() + .add("channel", channelId()) + .add("bgpId", sessionInfo().remoteBgpId()).toString(); } } diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPipelineFactory.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPipelineFactory.java index b2ca5077..e6f09f20 100755 --- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPipelineFactory.java +++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPPipelineFactory.java @@ -23,6 +23,7 @@ import org.jboss.netty.handler.timeout.ReadTimeoutHandler; import org.jboss.netty.util.ExternalResourceReleasable; import org.jboss.netty.util.HashedWheelTimer; import org.jboss.netty.util.Timer; +import org.onosproject.bgp.controller.BGPController; /** * Creates a ChannelPipeline for a server-side bgp channel. @@ -32,30 +33,36 @@ public class BGPPipelineFactory static final Timer TIMER = new HashedWheelTimer(); protected ReadTimeoutHandler readTimeoutHandler; - BGPControllerImpl bgpCtrlImpl; + private boolean isBgpServ; + private BGPController bgpController; /** * Constructor to initialize the values. * - * @param ctrlImpl parent ctrlImpl - * @param isServBgp if it is a server or not + * @param bgpController parent controller + * @param isBgpServ if it is a server or remote peer */ - public BGPPipelineFactory(BGPControllerImpl ctrlImpl, boolean isServBgp) { + public BGPPipelineFactory(BGPController bgpController, boolean isBgpServ) { super(); - bgpCtrlImpl = ctrlImpl; - /* hold time*/ - readTimeoutHandler = new ReadTimeoutHandler(TIMER, bgpCtrlImpl.getConfig().getHoldTime()); + this.isBgpServ = isBgpServ; + this.bgpController = bgpController; + /* hold time */ + this.readTimeoutHandler = new ReadTimeoutHandler(TIMER, bgpController.getConfig().getHoldTime()); } @Override public ChannelPipeline getPipeline() throws Exception { - BGPChannelHandler handler = new BGPChannelHandler(bgpCtrlImpl); + BGPChannelHandler handler = new BGPChannelHandler(bgpController); ChannelPipeline pipeline = Channels.pipeline(); pipeline.addLast("bgpmessagedecoder", new BGPMessageDecoder()); pipeline.addLast("bgpmessageencoder", new BGPMessageEncoder()); pipeline.addLast("holdTime", readTimeoutHandler); - pipeline.addLast("PassiveHandler", handler); + if (isBgpServ) { + pipeline.addLast("PassiveHandler", handler); + } else { + pipeline.addLast("ActiveHandler", handler); + } return pipeline; } diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPSessionInfo.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPSessionInfo.java deleted file mode 100755 index 207d7831..00000000 --- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BGPSessionInfo.java +++ /dev/null @@ -1,149 +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.controller.impl; - -import org.onosproject.bgp.controller.BGPId; -import org.onosproject.bgpio.protocol.BGPVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class maintains BGP peer session info. - */ -public class BGPSessionInfo { - - protected final Logger log = LoggerFactory.getLogger(BGPSessionInfo.class); - private BGPId remoteBgpId; - private BGPVersion remoteBgpVersion; - private short remoteBgpASNum; - private short remoteBgpholdTime; - private int remoteBgpIdentifier; - private short negotiatedholdTime; - - /** - * Gets the negotiated hold time for the session. - * - * @return negotiated hold time. - */ - public short getNegotiatedholdTime() { - return negotiatedholdTime; - } - - /** - * Sets the negotiated hold time for the session. - * - * @param negotiatedholdTime negotiated hold time. - */ - public void setNegotiatedholdTime(short negotiatedholdTime) { - this.negotiatedholdTime = negotiatedholdTime; - } - - /** - * Gets the BGP ID of BGP peer. - * - * @return bgp ID. - */ - public BGPId getRemoteBgpId() { - return remoteBgpId; - } - - /** - * Sets the BGP ID of bgp peer. - * - * @param bgpId BGP ID to set. - */ - public void setRemoteBgpId(BGPId bgpId) { - log.debug("Remote BGP ID {}", bgpId); - this.remoteBgpId = bgpId; - } - - /** - * Gets the BGP version of peer. - * - * @return bgp version. - */ - public BGPVersion getRemoteBgpVersion() { - return remoteBgpVersion; - } - - /** - * Sets the BGP version for this bgp peer. - * - * @param bgpVersion bgp version to set. - */ - public void setRemoteBgpVersion(BGPVersion bgpVersion) { - log.debug("Remote BGP version {}", bgpVersion); - this.remoteBgpVersion = bgpVersion; - } - - /** - * Gets the BGP remote bgp AS number. - * - * @return remoteBgpASNum peer AS number. - */ - public short getRemoteBgpASNum() { - return remoteBgpASNum; - } - - /** - * Sets the AS Number for this bgp peer. - * - * @param bgpASNum the autonomous system number value to set. - */ - public void setRemoteBgpASNum(short bgpASNum) { - log.debug("Remote BGP AS number {}", bgpASNum); - this.remoteBgpASNum = bgpASNum; - } - - /** - * Gets the BGP peer hold time. - * - * @return bgp hold time. - */ - public short getRemoteBgpHoldTime() { - return remoteBgpholdTime; - } - - /** - * Sets the hold time for this bgp peer. - * - * @param holdTime the hold timer value to set. - */ - public void setRemoteBgpHoldTime(short holdTime) { - log.debug("Remote BGP HoldTime {}", holdTime); - this.remoteBgpholdTime = holdTime; - } - - /** - * Gets the BGP version for this bgp peer. - * - * @return bgp identifier. - */ - public int getRemoteBgpIdentifier() { - return remoteBgpIdentifier; - } - - /** - * Sets the peer identifier value. - * - * @param bgpIdentifier the bgp peer identifier value. - */ - public void setRemoteBgpIdentifier(int bgpIdentifier) { - log.debug("Remote BGP Identifier {}", bgpIdentifier); - this.remoteBgpIdentifier = bgpIdentifier; - } -} diff --git a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java index 402e8c94..017c39e5 100755 --- a/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java +++ b/framework/src/onos/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/Controller.java @@ -24,11 +24,17 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.Executors; +import org.jboss.netty.bootstrap.ClientBootstrap; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.ChannelPipelineFactory; import org.jboss.netty.channel.group.ChannelGroup; import org.jboss.netty.channel.group.DefaultChannelGroup; +import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory; import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; +import org.onosproject.bgp.controller.BGPController; +import org.onosproject.bgpio.protocol.BGPFactories; +import org.onosproject.bgpio.protocol.BGPFactory; +import org.onosproject.bgpio.protocol.BGPVersion; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,36 +44,45 @@ import org.slf4j.LoggerFactory; */ public class Controller { - protected static final Logger log = LoggerFactory.getLogger(Controller.class); + private static final Logger log = LoggerFactory.getLogger(Controller.class); + + private static final BGPFactory FACTORY4 = BGPFactories.getFactory(BGPVersion.BGP_4); private ChannelGroup cg; // Configuration options private static final short BGP_PORT_NUM = 179; - private int workerThreads = 16; + private final int workerThreads = 16; + private final int peerWorkerThreads = 16; // Start time of the controller - protected long systemStartTime; + private long systemStartTime; private NioServerSocketChannelFactory serverExecFactory; + private NioClientSocketChannelFactory peerExecFactory; + private static ClientBootstrap peerBootstrap; + private BGPController bgpController; // Perf. related configuration - protected static final int SEND_BUFFER_SIZE = 4 * 1024 * 1024; - - BGPControllerImpl bgpCtrlImpl; + private static final int SEND_BUFFER_SIZE = 4 * 1024 * 1024; /** - * Constructor to initialize parameter. + * Constructor to initialize the values. * - * @param bgpCtrlImpl BGP controller Impl instance + * @param bgpController bgp controller instance */ - public Controller(BGPControllerImpl bgpCtrlImpl) { - this.bgpCtrlImpl = bgpCtrlImpl; + public Controller(BGPController bgpController) { + this.bgpController = bgpController; } - // *************** - // Getters/Setters - // *************** + /** + * Returns factory version for processing BGP messages. + * + * @return instance of factory version + */ + static BGPFactory getBGPMessageFactory4() { + return FACTORY4; + } /** * To get system start time. @@ -78,16 +93,20 @@ public class Controller { return (this.systemStartTime); } - // ************** - // Initialization - // ************** - /** * Tell controller that we're ready to accept bgp peer connections. */ public void run() { try { + + peerBootstrap = createPeerBootStrap(); + + peerBootstrap.setOption("reuseAddr", true); + peerBootstrap.setOption("child.keepAlive", true); + peerBootstrap.setOption("child.tcpNoDelay", true); + peerBootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE); + final ServerBootstrap bootstrap = createServerBootStrap(); bootstrap.setOption("reuseAddr", true); @@ -95,7 +114,7 @@ public class Controller { bootstrap.setOption("child.tcpNoDelay", true); bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE); - ChannelPipelineFactory pfact = new BGPPipelineFactory(bgpCtrlImpl, true); + ChannelPipelineFactory pfact = new BGPPipelineFactory(bgpController, true); bootstrap.setPipelineFactory(pfact); InetSocketAddress sa = new InetSocketAddress(getBgpPortNum()); @@ -129,6 +148,36 @@ public class Controller { } /** + * Creates peer boot strap. + * + * @return ClientBootstrap + */ + private ClientBootstrap createPeerBootStrap() { + + if (peerWorkerThreads == 0) { + peerExecFactory = new NioClientSocketChannelFactory( + Executors.newCachedThreadPool(groupedThreads("onos/bgp", "boss-%d")), + Executors.newCachedThreadPool(groupedThreads("onos/bgp", "worker-%d"))); + return new ClientBootstrap(peerExecFactory); + } else { + peerExecFactory = new NioClientSocketChannelFactory( + Executors.newCachedThreadPool(groupedThreads("onos/bgp", "boss-%d")), + Executors.newCachedThreadPool(groupedThreads("onos/bgp", "worker-%d")), + peerWorkerThreads); + return new ClientBootstrap(peerExecFactory); + } + } + + /** + * Gets peer bootstrap. + * + * @return peer bootstrap + */ + public static ClientBootstrap peerBootstrap() { + return peerBootstrap; + } + + /** * Initialize internal data structures. */ public void init() { @@ -137,10 +186,11 @@ public class Controller { this.systemStartTime = System.currentTimeMillis(); } - // ************** - // Utility methods - // ************** - + /** + * Gets run time memory. + * + * @return m run time memory + */ public Map<String, Long> getMemory() { Map<String, Long> m = new HashMap<>(); Runtime runtime = Runtime.getRuntime(); @@ -149,6 +199,11 @@ public class Controller { return m; } + /** + * Gets UP time. + * + * @return UP time + */ public Long getUptime() { RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); return rb.getUptime(); @@ -169,6 +224,7 @@ public class Controller { public void stop() { log.info("Stopped"); serverExecFactory.shutdown(); + peerExecFactory.shutdown(); cg.close(); } diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java index 17cf89e2..100f6823 100644 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java +++ b/framework/src/onos/cli/src/main/java/org/onosproject/cli/app/ApplicationsListCommand.java @@ -41,7 +41,7 @@ public class ApplicationsListCommand extends AbstractShellCommand { private static final String FMT = "%s id=%d, name=%s, version=%s, origin=%s, description=%s, " + - "features=%s, featuresRepo=%s, permissions=%s"; + "features=%s, featuresRepo=%s, apps=%s, permissions=%s"; private static final String SHORT_FMT = "%s %3d %-32s %-8s %s"; @@ -76,7 +76,7 @@ public class ApplicationsListCommand extends AbstractShellCommand { app.id().id(), app.id().name(), app.version(), app.origin(), app.description(), app.features(), app.featuresRepo().isPresent() ? app.featuresRepo().get().toString() : "", - app.permissions()); + app.requiredApps(), app.permissions()); } } } diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java index 62cf042a..fbce9648 100644 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java +++ b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/ConnectivityIntentCommand.java @@ -15,12 +15,6 @@ */ package org.onosproject.cli.net; -import static com.google.common.base.Strings.isNullOrEmpty; -import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; - -import java.util.LinkedList; -import java.util.List; - import org.apache.karaf.shell.commands.Option; import org.onlab.packet.Ip6Address; import org.onlab.packet.IpAddress; @@ -33,6 +27,7 @@ import org.onosproject.cli.AbstractShellCommand; import org.onosproject.core.ApplicationId; import org.onosproject.core.CoreService; import org.onosproject.net.Link; +import org.onosproject.net.PortNumber; import org.onosproject.net.flow.DefaultTrafficSelector; import org.onosproject.net.flow.DefaultTrafficTreatment; import org.onosproject.net.flow.TrafficSelector; @@ -46,6 +41,12 @@ import org.onosproject.net.intent.constraint.LinkTypeConstraint; import org.onosproject.net.intent.constraint.PartialFailureConstraint; import org.onosproject.net.resource.link.BandwidthResource; +import java.util.LinkedList; +import java.util.List; + +import static com.google.common.base.Strings.isNullOrEmpty; +import static org.onosproject.net.flow.DefaultTrafficTreatment.builder; + /** * Base class for command line operations for connectivity based intents. */ @@ -98,11 +99,11 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { @Option(name = "--ndSLL", description = "IPv6 Neighbor Discovery Source Link-Layer", required = false, multiValued = false) - private String ndSLLString = null; + private String ndSllString = null; @Option(name = "--ndTLL", description = "IPv6 Neighbor Discovery Target Link-Layer", required = false, multiValued = false) - private String ndTLLString = null; + private String ndTllString = null; @Option(name = "--tcpSrc", description = "Source TCP Port", required = false, multiValued = false) @@ -166,7 +167,8 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { required = false, multiValued = false) private String pushVlan = null; - @Option(name = "--setQueue", description = "Set Queue ID", + @Option(name = "--setQueue", description = "Set Queue ID (for OpenFlow 1.0, " + + "also the port has to be specified, i.e., <port>/<queue>", required = false, multiValued = false) private String setQueue = null; @@ -262,12 +264,12 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { selectorBuilder.matchIPv6NDTargetAddress(Ip6Address.valueOf(ndTargetString)); } - if (!isNullOrEmpty(ndSLLString)) { - selectorBuilder.matchIPv6NDSourceLinkLayerAddress(MacAddress.valueOf(ndSLLString)); + if (!isNullOrEmpty(ndSllString)) { + selectorBuilder.matchIPv6NDSourceLinkLayerAddress(MacAddress.valueOf(ndSllString)); } - if (!isNullOrEmpty(ndTLLString)) { - selectorBuilder.matchIPv6NDTargetLinkLayerAddress(MacAddress.valueOf(ndTLLString)); + if (!isNullOrEmpty(ndTllString)) { + selectorBuilder.matchIPv6NDTargetLinkLayerAddress(MacAddress.valueOf(ndTllString)); } if (!isNullOrEmpty(srcTcpString)) { @@ -332,7 +334,15 @@ public abstract class ConnectivityIntentCommand extends AbstractShellCommand { emptyTreatment = false; } if (!isNullOrEmpty(setQueue)) { - treatmentBuilder.setQueue(Long.parseLong(setQueue)); + // OpenFlow 1.0 notation (for ENQUEUE): <port>/<queue> + if (setQueue.contains("/")) { + String[] queueConfig = setQueue.split("/"); + PortNumber port = PortNumber.portNumber(Long.parseLong(queueConfig[0])); + long queueId = Long.parseLong(queueConfig[1]); + treatmentBuilder.setQueue(queueId, port); + } else { + treatmentBuilder.setQueue(Long.parseLong(setQueue)); + } emptyTreatment = false; } diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/DeviceSetControllersCommand.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/DeviceSetControllersCommand.java index c3693799..cb4ff04a 100644 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/DeviceSetControllersCommand.java +++ b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/DeviceSetControllersCommand.java @@ -59,8 +59,11 @@ public class DeviceSetControllersCommand extends AbstractShellCommand { ControllerConfig config = h.behaviour(ControllerConfig.class); print("before:"); config.getControllers().forEach(c -> print(c.target())); - - config.setControllers(newControllers); + try { + config.setControllers(newControllers); + } catch (NullPointerException e) { + print("No Device with requested parameters {} ", uri); + } print("after:"); config.getControllers().forEach(c -> print(c.target())); print("size %d", config.getControllers().size()); diff --git a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/GetFlowStatistics.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/GetFlowStatistics.java index cafe87f9..4bbf4f10 100644 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/GetFlowStatistics.java +++ b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/GetFlowStatistics.java @@ -82,15 +82,15 @@ public class GetFlowStatistics extends AbstractShellCommand { DeviceService deviceService = get(DeviceService.class);
FlowStatisticService flowStatsService = get(FlowStatisticService.class);
- String deviceURI = getDeviceId(devicePort);
- String portURI = getPortNumber(devicePort);
+ String deviceUri = getDeviceId(devicePort);
+ String portUri = getPortNumber(devicePort);
- DeviceId ingressDeviceId = deviceId(deviceURI);
+ DeviceId ingressDeviceId = deviceId(deviceUri);
PortNumber ingressPortNumber;
- if (portURI.length() == 0) {
+ if (portUri.length() == 0) {
ingressPortNumber = null;
} else {
- ingressPortNumber = portNumber(portURI);
+ ingressPortNumber = portNumber(portUri);
}
Device device = deviceService.getDevice(ingressDeviceId);
@@ -102,7 +102,7 @@ public class GetFlowStatistics extends AbstractShellCommand { if (ingressPortNumber != null) {
Port port = deviceService.getPort(ingressDeviceId, ingressPortNumber);
if (port == null) {
- error("No such port %s on device %s", portURI, ingressDeviceId.uri());
+ error("No such port %s on device %s", portUri, ingressDeviceId.uri());
return;
}
}
@@ -148,7 +148,7 @@ public class GetFlowStatistics extends AbstractShellCommand { // print show topn head line with type
print("deviceId=%s, show TOPN=%s flows, live type=%s, instruction type=%s",
- deviceURI,
+ deviceUri,
Integer.toString(topn),
flowLiveType == null ? "ALL" : flowLiveType,
instructionType == null ? "ALL" : instructionType);
@@ -169,7 +169,7 @@ public class GetFlowStatistics extends AbstractShellCommand { } else if (showAll) { // is true?
// print show all head line with type
print("deviceId=%s, show ALL flows, live type=%s, instruction type=%s",
- deviceURI,
+ deviceUri,
flowLiveType == null ? "ALL" : flowLiveType,
instructionType == null ? "ALL" : instructionType);
if (ingressPortNumber == null) {
@@ -188,7 +188,7 @@ public class GetFlowStatistics extends AbstractShellCommand { }
} else { // if (showSummary == true) //always is true
// print show summary head line
- print("deviceId=%s, show SUMMARY flows", deviceURI);
+ print("deviceId=%s, show SUMMARY flows", deviceUri);
if (ingressPortNumber == null) {
Map<ConnectPoint, SummaryFlowEntryWithLoad> summaryFlowLoadMap =
flowStatsService.loadSummary(device);
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..ee6d31b8 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 @@ -46,9 +46,9 @@ import static com.google.common.collect.Lists.newArrayList; public class GroupsListCommand extends AbstractShellCommand { private static final String FORMAT = - " id=%s, state=%s, type=%s, bytes=%s, packets=%s, appId=%s"; + " id=0x%s, state=%s, type=%s, bytes=%s, packets=%s, appId=%s"; private static final String BUCKET_FORMAT = - " id=%s, bucket=%s, bytes=%s, packets=%s, actions=%s"; + " id=0x%s, bucket=%s, bytes=%s, packets=%s, actions=%s"; @Argument(index = 1, name = "uri", description = "Device ID", required = false, multiValued = false) @@ -121,11 +121,11 @@ public class GroupsListCommand extends AbstractShellCommand { private void printGroups(DeviceId deviceId, List<Group> 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/cli/src/main/java/org/onosproject/cli/net/LinkResourceTestCommand.java b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/LinkResourceTestCommand.java index 12e9ab5f..a1a76925 100644 --- a/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/LinkResourceTestCommand.java +++ b/framework/src/onos/cli/src/main/java/org/onosproject/cli/net/LinkResourceTestCommand.java @@ -15,24 +15,23 @@ */ package org.onosproject.cli.net; -import java.util.Set; -import java.util.List; - +import com.google.common.collect.Lists; import org.apache.karaf.shell.commands.Argument; import org.apache.karaf.shell.commands.Command; import org.apache.karaf.shell.commands.Option; import org.onosproject.cli.AbstractShellCommand; +import org.onosproject.net.DeviceId; +import org.onosproject.net.Link; +import org.onosproject.net.Path; import org.onosproject.net.intent.IntentId; import org.onosproject.net.resource.link.DefaultLinkResourceRequest; import org.onosproject.net.resource.link.LinkResourceAllocations; import org.onosproject.net.resource.link.LinkResourceRequest; import org.onosproject.net.resource.link.LinkResourceService; import org.onosproject.net.topology.PathService; -import org.onosproject.net.DeviceId; -import org.onosproject.net.Link; -import org.onosproject.net.Path; -import com.google.common.collect.Lists; +import java.util.List; +import java.util.Set; /** * Commands to test out LinkResourceManager directly. @@ -44,7 +43,7 @@ public class LinkResourceTestCommand extends AbstractShellCommand { // default is bandwidth. @Option(name = "-m", aliases = "--mpls", description = "MPLS resource", required = false, multiValued = false) - private boolean isMPLS = false; + private boolean isMpls = false; @Option(name = "-o", aliases = "--optical", description = "Optical resource", required = false, multiValued = false) @@ -96,7 +95,7 @@ public class LinkResourceTestCommand extends AbstractShellCommand { for (Path p : paths) { List<Link> links = p.links(); LinkResourceRequest.Builder request = null; - if (isMPLS) { + if (isMpls) { List<Link> nlinks = Lists.newArrayList(); try { nlinks.addAll(links.subList(1, links.size() - 2)); diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationDescription.java index 2561280b..e8ff9ec4 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationDescription.java @@ -86,4 +86,11 @@ public interface ApplicationDescription { * @return application features */ List<String> features(); + + /** + * Returns list of required application names. + * + * @return list of application names + */ + List<String> requiredApps(); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationService.java index 73dcc86c..1e543b85 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationService.java @@ -67,4 +67,11 @@ public interface ApplicationService */ Set<Permission> getPermissions(ApplicationId appId); + /** + * Registers application pre-deactivation processing hook. + * + * @param appId application identifier + * @param hook pre-deactivation hook + */ + void registerDeactivateHook(ApplicationId appId, Runnable hook); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationStore.java b/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationStore.java index b3cdc43e..0a1f0727 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationStore.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/app/ApplicationStore.java @@ -76,7 +76,7 @@ public interface ApplicationStore extends Store<ApplicationEvent, ApplicationSto void remove(ApplicationId appId); /** - * Mark the application as actived. + * Mark the application as active. * * @param appId application identifier */ diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/app/DefaultApplicationDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/app/DefaultApplicationDescription.java index 710d0f9c..569183a7 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/app/DefaultApplicationDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/app/DefaultApplicationDescription.java @@ -41,6 +41,7 @@ public class DefaultApplicationDescription implements ApplicationDescription { private final Set<Permission> permissions; private final Optional<URI> featuresRepo; private final List<String> features; + private final List<String> requiredApps; /** * Creates a new application descriptor using the supplied data. @@ -53,11 +54,13 @@ public class DefaultApplicationDescription implements ApplicationDescription { * @param permissions requested permissions * @param featuresRepo optional features repo URI * @param features application features + * @param requiredApps list of required application names */ public DefaultApplicationDescription(String name, Version version, String description, String origin, ApplicationRole role, Set<Permission> permissions, - URI featuresRepo, List<String> features) { + URI featuresRepo, List<String> features, + List<String> requiredApps) { this.name = checkNotNull(name, "Name cannot be null"); this.version = checkNotNull(version, "Version cannot be null"); this.description = checkNotNull(description, "Description cannot be null"); @@ -66,6 +69,7 @@ public class DefaultApplicationDescription implements ApplicationDescription { this.permissions = checkNotNull(permissions, "Permissions cannot be null"); this.featuresRepo = Optional.ofNullable(featuresRepo); this.features = checkNotNull(features, "Features cannot be null"); + this.requiredApps = checkNotNull(requiredApps, "Required apps cannot be null"); checkArgument(!features.isEmpty(), "There must be at least one feature"); } @@ -110,6 +114,11 @@ public class DefaultApplicationDescription implements ApplicationDescription { } @Override + public List<String> requiredApps() { + return requiredApps; + } + + @Override public String toString() { return toStringHelper(this) .add("name", name) @@ -120,6 +129,7 @@ public class DefaultApplicationDescription implements ApplicationDescription { .add("permissions", permissions) .add("featuresRepo", featuresRepo) .add("features", features) + .add("requiredApps", requiredApps) .toString(); } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cfg/ConfigProperty.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cfg/ConfigProperty.java index 36cd22b5..f1b602e8 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/cfg/ConfigProperty.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cfg/ConfigProperty.java @@ -245,7 +245,7 @@ public final class ConfigProperty { @Override public int hashCode() { - return Objects.hash(name); + return name.hashCode(); } /** diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/DefaultControllerNode.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/DefaultControllerNode.java index 5f3e0e19..3787daa5 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/DefaultControllerNode.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/DefaultControllerNode.java @@ -20,6 +20,7 @@ import org.onlab.packet.IpAddress; import java.util.Objects; import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; /** * Default implementation of a controller instance descriptor. @@ -57,7 +58,7 @@ public class DefaultControllerNode implements ControllerNode { * @param tcpPort TCP port */ public DefaultControllerNode(NodeId id, IpAddress ip, int tcpPort) { - this.id = id; + this.id = checkNotNull(id); this.ip = ip; this.tcpPort = tcpPort; } @@ -79,7 +80,7 @@ public class DefaultControllerNode implements ControllerNode { @Override public int hashCode() { - return Objects.hash(id); + return id.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/NodeId.java b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/NodeId.java index 6cfb42c7..e5ab9dc8 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/NodeId.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/cluster/NodeId.java @@ -35,7 +35,7 @@ public class NodeId implements Comparable<NodeId> { @Override public int hashCode() { - return Objects.hash(id); + return id.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/core/Application.java b/framework/src/onos/core/api/src/main/java/org/onosproject/core/Application.java index fca53843..ea2eab9b 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/core/Application.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/core/Application.java @@ -84,4 +84,11 @@ public interface Application { * @return application features */ List<String> features(); + + /** + * Returns list of required application names. + * + * @return list of application names + */ + List<String> requiredApps(); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/core/CoreService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/core/CoreService.java index 303ad395..0825a6d1 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/core/CoreService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/core/CoreService.java @@ -50,6 +50,7 @@ public interface CoreService { /** * Returns an existing application id from a given id. + * * @param id the short value of the id * @return an application id */ @@ -57,6 +58,7 @@ public interface CoreService { /** * Returns an existing application id from a given id. + * * @param name the name portion of the ID to look up * @return an application id */ @@ -67,10 +69,21 @@ public interface CoreService { * to follow the reverse DNS convention, e.g. * {@code org.flying.circus.app} * - * @param identifier string identifier + * @param name string identifier + * @return the application id + */ + ApplicationId registerApplication(String name); + + /** + * Registers a new application by its name, which is expected + * to follow the reverse DNS convention, e.g. + * {@code org.flying.circus.app}, along with its pre-deactivation hook. + * + * @param name string identifier + * @param preDeactivate pre-deactivation hook * @return the application id */ - ApplicationId registerApplication(String identifier); + ApplicationId registerApplication(String name, Runnable preDeactivate); /** * Returns an id generator for a given topic. diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplication.java b/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplication.java index d8062ddf..c3515638 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplication.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplication.java @@ -40,6 +40,7 @@ public class DefaultApplication implements Application { private final Set<Permission> permissions; private final Optional<URI> featuresRepo; private final List<String> features; + private final List<String> requiredApps; /** * Creates a new application descriptor using the supplied data. @@ -52,11 +53,13 @@ public class DefaultApplication implements Application { * @param permissions requested permissions * @param featuresRepo optional features repo URI * @param features application features + * @param requiredApps list of required application names */ public DefaultApplication(ApplicationId appId, Version version, String description, String origin, ApplicationRole role, Set<Permission> permissions, - Optional<URI> featuresRepo, List<String> features) { + Optional<URI> featuresRepo, List<String> features, + List<String> requiredApps) { this.appId = checkNotNull(appId, "ID cannot be null"); this.version = checkNotNull(version, "Version cannot be null"); this.description = checkNotNull(description, "Description cannot be null"); @@ -65,6 +68,7 @@ public class DefaultApplication implements Application { this.permissions = checkNotNull(permissions, "Permissions cannot be null"); this.featuresRepo = checkNotNull(featuresRepo, "Features repo cannot be null"); this.features = checkNotNull(features, "Features cannot be null"); + this.requiredApps = checkNotNull(requiredApps, "Required apps cannot be null"); checkArgument(!features.isEmpty(), "There must be at least one feature"); } @@ -109,9 +113,14 @@ public class DefaultApplication implements Application { } @Override + public List<String> requiredApps() { + return requiredApps; + } + + @Override public int hashCode() { return Objects.hash(appId, version, description, origin, role, permissions, - featuresRepo, features); + featuresRepo, features, requiredApps); } @Override @@ -130,7 +139,8 @@ public class DefaultApplication implements Application { Objects.equals(this.role, other.role) && Objects.equals(this.permissions, other.permissions) && Objects.equals(this.featuresRepo, other.featuresRepo) && - Objects.equals(this.features, other.features); + Objects.equals(this.features, other.features) && + Objects.equals(this.requiredApps, other.requiredApps); } @Override @@ -144,6 +154,7 @@ public class DefaultApplication implements Application { .add("permissions", permissions) .add("featuresRepo", featuresRepo) .add("features", features) + .add("requiredApps", requiredApps) .toString(); } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplicationId.java b/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplicationId.java index c7b5b2da..aedfb0d3 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplicationId.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultApplicationId.java @@ -58,7 +58,7 @@ public class DefaultApplicationId implements ApplicationId { @Override public int hashCode() { - return Objects.hash(id); + return Short.hashCode(id); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultGroupId.java b/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultGroupId.java index 9fa8d2b6..243e5216 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultGroupId.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/core/DefaultGroupId.java @@ -42,7 +42,7 @@ public class DefaultGroupId implements GroupId { @Override public int hashCode() { - return Objects.hash(id); + return id; } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/core/Version.java b/framework/src/onos/core/api/src/main/java/org/onosproject/core/Version.java index a5377016..06e9e206 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/core/Version.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/core/Version.java @@ -127,7 +127,7 @@ public final class Version { @Override public int hashCode() { - return Objects.hash(format); + return format.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/AbstractDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/AbstractDescription.java index d81b83cc..34042dad 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/AbstractDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/AbstractDescription.java @@ -16,6 +16,7 @@ package org.onosproject.net; import static com.google.common.base.Preconditions.checkArgument; +import com.google.common.base.Objects; /** * Base implementation of an annotated model description. @@ -46,4 +47,18 @@ public abstract class AbstractDescription implements Annotated { return annotations; } + @Override + public int hashCode() { + return Objects.hashCode(annotations); + } + + @Override + public boolean equals(Object object) { + if (object instanceof AbstractDescription) { + AbstractDescription that = (AbstractDescription) object; + return Objects.equal(this.annotations, that.annotations); + } + return false; + } + } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultHost.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultHost.java index 2877701e..557fa5c1 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultHost.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultHost.java @@ -98,7 +98,8 @@ public class DefaultHost extends AbstractElement implements Host { return Objects.equals(this.id, other.id) && Objects.equals(this.mac, other.mac) && Objects.equals(this.vlan, other.vlan) && - Objects.equals(this.location, other.location); + Objects.equals(this.location, other.location) && + Objects.equals(this.ipAddresses(), other.ipAddresses()); } return false; } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultPath.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultPath.java index a4789cac..2da2463a 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultPath.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DefaultPath.java @@ -88,7 +88,7 @@ public class DefaultPath extends DefaultLink implements Path { @Override public int hashCode() { - return Objects.hash(links); + return links.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/DeviceId.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DeviceId.java index 5331342e..e2c1214f 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/DeviceId.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/DeviceId.java @@ -75,7 +75,7 @@ public final class DeviceId extends ElementId { @Override public int hashCode() { - return Objects.hash(str); + return str.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/PortNumber.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/PortNumber.java index 03e6dba9..8c9b1349 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/PortNumber.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/PortNumber.java @@ -15,6 +15,16 @@ */ package org.onosproject.net; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import com.google.common.base.Supplier; +import com.google.common.base.Suppliers; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMap.Builder; import com.google.common.primitives.UnsignedLongs; /** @@ -26,8 +36,7 @@ public final class PortNumber { // TODO: revisit the max and the logical port value assignments - private static final long MAX_NUMBER = (2L * Integer.MAX_VALUE) + 1; - + static final long MAX_NUMBER = (2L * Integer.MAX_VALUE) + 1; static final long IN_PORT_NUMBER = -8L; static final long TABLE_NUMBER = -7L; @@ -37,6 +46,39 @@ public final class PortNumber { static final long LOCAL_NUMBER = -2L; static final long CONTROLLER_NUMBER = -3L; + /** + * Logical PortNumbers. + */ + public static enum Logical { + IN_PORT(IN_PORT_NUMBER), + TABLE(TABLE_NUMBER), + NORMAL(NORMAL_NUMBER), + FLOOD(FLOOD_NUMBER), + ALL(ALL_NUMBER), + LOCAL(LOCAL_NUMBER), + CONTROLLER(CONTROLLER_NUMBER); + + private final long number; + private final PortNumber instance; + + public long number() { + return number; + } + + /** + * PortNumber instance for the logical port. + * @return {@link PortNumber} + */ + public PortNumber instance() { + return instance; + } + + Logical(long number) { + this.number = number; + this.instance = new PortNumber(number); + } + } + public static final PortNumber IN_PORT = new PortNumber(IN_PORT_NUMBER); public static final PortNumber TABLE = new PortNumber(TABLE_NUMBER); public static final PortNumber NORMAL = new PortNumber(NORMAL_NUMBER); @@ -45,6 +87,15 @@ public final class PortNumber { public static final PortNumber LOCAL = new PortNumber(LOCAL_NUMBER); public static final PortNumber CONTROLLER = new PortNumber(CONTROLLER_NUMBER); + // lazily populated Logical port number to PortNumber + static final Supplier<Map<Long, Logical>> LOGICAL = Suppliers.memoize(() -> { + Builder<Long, Logical> builder = ImmutableMap.<Long, Logical>builder(); + for (Logical lp : Logical.values()) { + builder.put(lp.number(), lp); + } + return builder.build(); + }); + private final long number; private final String name; private final boolean hasName; @@ -136,30 +187,68 @@ public final class PortNumber { } private String decodeLogicalPort() { - if (number == CONTROLLER_NUMBER) { - return "CONTROLLER"; - } else if (number == LOCAL_NUMBER) { - return "LOCAL"; - } else if (number == ALL_NUMBER) { - return "ALL"; - } else if (number == FLOOD_NUMBER) { - return "FLOOD"; - } else if (number == NORMAL_NUMBER) { - return "NORMAL"; - } else if (number == TABLE_NUMBER) { - return "TABLE"; - } else if (number == IN_PORT_NUMBER) { - return "IN_PORT"; + Logical logical = LOGICAL.get().get(number); + if (logical != null) { + // enum name + return logical.toString(); + } + return String.format("UNKNOWN(%s)", UnsignedLongs.toString(number)); + } + + + /** + * Regular expression to match String representation of named PortNumber. + * + * Format: "[name](num:unsigned decimal string)" + */ + private static final Pattern NAMED = Pattern.compile("^\\[(?<name>.*)\\]\\((?<num>\\d+)\\)$"); + + private static boolean isAsciiDecimal(char c) { + return '0' <= c && c <= '9'; + } + + /** + * Returns PortNumber instance from String representation. + * + * @param s String representation equivalent to {@link PortNumber#toString()} + * @return {@link PortNumber} instance + * @throws IllegalArgumentException if given String was malformed + */ + public static PortNumber fromString(String s) { + checkNotNull(s); + checkArgument(!s.isEmpty(), "cannot be empty"); + + if (isAsciiDecimal(s.charAt(0))) { + // unsigned decimal string + return portNumber(s); + } else if (s.startsWith("[")) { + // named PortNumber + Matcher matcher = NAMED.matcher(s); + checkArgument(matcher.matches(), "Invalid named PortNumber %s", s); + + String name = matcher.group("name"); + String num = matcher.group("num"); + return portNumber(UnsignedLongs.parseUnsignedLong(num), name); + } + + // Logical + if (s.startsWith("UNKNOWN(") && s.endsWith(")")) { + return portNumber(s.substring("UNKNOWN(".length(), s.length() - 1)); + } else { + return Logical.valueOf(s).instance; } - return "UNKNOWN"; } @Override public String toString() { - if (!isLogical()) { - return name; - } else { + if (isLogical()) { return decodeLogicalPort(); + } else if (hasName()) { + // named port + return String.format("[%s](%d)", name, number); + } else { + // unsigned decimal string + return name; } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeConfig.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeConfig.java index e3d6993c..cf7bed6d 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeConfig.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeConfig.java @@ -36,6 +36,15 @@ public interface BridgeConfig extends HandlerBehaviour { void addBridge(BridgeName bridgeName); /** + * Adds a bridge with given bridge name, dpid and exPortName. + * + * @param bridgeName bridge name + * @param dpid dpid + * @param exPortName external port name + */ + void addBridge(BridgeName bridgeName, String dpid, String exPortName); + + /** * Adds a bridge with given bridge name and dpid, and sets the controller * of the bridge with given controllers. * diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeName.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeName.java index 3f782954..a15217c6 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeName.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/behaviour/BridgeName.java @@ -52,7 +52,7 @@ public final class BridgeName { @Override public int hashCode() { - return Objects.hash(name); + return name.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/Config.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/Config.java index 5cdc0c12..3757d327 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/Config.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/Config.java @@ -20,10 +20,15 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.common.annotations.Beta; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterators; import com.google.common.collect.Lists; +import org.onlab.packet.IpAddress; +import org.onlab.packet.MacAddress; import java.util.Collection; import java.util.List; +import java.util.Set; import java.util.function.Function; import static com.google.common.base.Preconditions.checkNotNull; @@ -51,6 +56,21 @@ public abstract class Config<S> { protected ConfigApplyDelegate delegate; /** + * Indicator of whether a configuration JSON field is required. + */ + public enum FieldPresence { + /** + * Signifies that config field is an optional one. + */ + OPTIONAL, + + /** + * Signifies that config field is mandatory. + */ + MANDATORY + } + + /** * Initializes the configuration behaviour with necessary context. * * @param subject configuration subject @@ -71,6 +91,29 @@ public abstract class Config<S> { } /** + * Indicates whether or not the backing JSON node contains valid data. + * <p> + * Default implementation returns true. + * Subclasses are expected to override this with their own validation. + * </p> + * + * @return true if the data is valid; false otherwise + */ + public boolean isValid() { + // TODO: figure out what assertions could be made in the base class + // NOTE: The thought is to have none, but instead to provide a set + // of predicates to allow configs to test validity of present fields, + // e.g.: + // isString(path) + // isBoolean(path) + // isNumber(path, [min, max]) + // isDecimal(path, [min, max]) + // isMacAddress(path) + // isIpAddress(path) + return true; + } + + /** * Returns the specific subject to which this configuration pertains. * * @return configuration subject @@ -309,4 +352,104 @@ public abstract class Config<S> { return this; } + /** + * Indicates whether only the specified fields are present in the backing JSON. + * + * @param allowedFields allowed field names + * @return true if all allowedFields are present; false otherwise + */ + protected boolean hasOnlyFields(String... allowedFields) { + Set<String> fields = ImmutableSet.copyOf(allowedFields); + return !Iterators.any(object.fieldNames(), f -> !fields.contains(f)); + } + + /** + * Indicates whether the specified field holds a valid MAC address. + * + * @param field JSON field name + * @param presence specifies if field is optional or mandatory + * @return true if valid; false otherwise + * @throws IllegalArgumentException if field is present, but not valid MAC + */ + protected boolean isMacAddress(String field, FieldPresence presence) { + JsonNode node = object.path(field); + return isValid(node, presence, node.isTextual() && + MacAddress.valueOf(node.asText()) != null); + } + + /** + * Indicates whether the specified field holds a valid IP address. + * + * @param field JSON field name + * @param presence specifies if field is optional or mandatory + * @return true if valid; false otherwise + * @throws IllegalArgumentException if field is present, but not valid IP + */ + protected boolean isIpAddress(String field, FieldPresence presence) { + JsonNode node = object.path(field); + return isValid(node, presence, node.isTextual() && + IpAddress.valueOf(node.asText()) != null); + } + + /** + * Indicates whether the specified field holds a valid string value. + * + * @param field JSON field name + * @param presence specifies if field is optional or mandatory + * @param pattern optional regex pattern + * @return true if valid; false otherwise + * @throws IllegalArgumentException if field is present, but not valid MAC + */ + protected boolean isString(String field, FieldPresence presence, String... pattern) { + JsonNode node = object.path(field); + return isValid(node, presence, node.isTextual() && + (pattern.length > 0 && node.asText().matches(pattern[0]) || pattern.length < 1)); + } + + /** + * Indicates whether the specified field holds a valid number. + * + * @param field JSON field name + * @param presence specifies if field is optional or mandatory + * @param minMax optional min/max values + * @return true if valid; false otherwise + * @throws IllegalArgumentException if field is present, but not valid + */ + protected boolean isNumber(String field, FieldPresence presence, long... minMax) { + JsonNode node = object.path(field); + return isValid(node, presence, (node.isLong() || node.isInt()) && + (minMax.length > 0 && minMax[0] <= node.asLong() || minMax.length < 1) && + (minMax.length > 1 && minMax[1] > node.asLong() || minMax.length < 2)); + } + + /** + * Indicates whether the specified field holds a valid decimal number. + * + * @param field JSON field name + * @param presence specifies if field is optional or mandatory + * @param minMax optional min/max values + * @return true if valid; false otherwise + * @throws IllegalArgumentException if field is present, but not valid + */ + protected boolean isDecimal(String field, FieldPresence presence, double... minMax) { + JsonNode node = object.path(field); + return isValid(node, presence, (node.isDouble() || node.isFloat()) && + (minMax.length > 0 && minMax[0] <= node.asDouble() || minMax.length < 1) && + (minMax.length > 1 && minMax[1] > node.asDouble() || minMax.length < 2)); + } + + /** + * Indicates whether the node is present and of correct value or not + * mandatory and absent. + * + * @param node JSON node + * @param presence specifies if field is optional or mandatory + * @param correctValue true if the value is correct + * @return true if the field is as expected + */ + private boolean isValid(JsonNode node, FieldPresence presence, boolean correctValue) { + boolean isMandatory = presence == FieldPresence.MANDATORY; + return isMandatory && correctValue || !isMandatory && !node.isNull() || correctValue; + } + } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigService.java index 8eb69a45..f1b22c41 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigService.java @@ -119,7 +119,7 @@ public interface NetworkConfigService /** * Applies configuration for the specified subject and configuration - * class using the raw JSON object. If configuration already exists, it + * class using the raw JSON node. If configuration already exists, it * will be updated. * * @param subject configuration subject @@ -128,6 +128,8 @@ public interface NetworkConfigService * @param <S> type of subject * @param <C> type of configuration * @return configuration or null if one is not available + * @throws IllegalArgumentException if the supplied JSON node contains + * invalid data */ <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json); diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigStore.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigStore.java index 9dd66e8d..9be4b120 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigStore.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/config/NetworkConfigStore.java @@ -113,6 +113,8 @@ public interface NetworkConfigStore extends Store<NetworkConfigEvent, NetworkCon * @param <S> type of subject * @param <C> type of configuration * @return configuration object + * @throws IllegalArgumentException if the supplied JSON node contains + * invalid data */ <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json); diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java index 3a8c8c1f..9074792c 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultDeviceDescription.java @@ -24,6 +24,7 @@ import java.net.URI; import static com.google.common.base.MoreObjects.toStringHelper; import static com.google.common.base.Preconditions.checkNotNull; import static org.onosproject.net.Device.Type; +import com.google.common.base.Objects; /** * Default implementation of immutable device description entity. @@ -71,7 +72,7 @@ public class DefaultDeviceDescription extends AbstractDescription */ public DefaultDeviceDescription(DeviceDescription base, SparseAnnotations... annotations) { - this(base.deviceURI(), base.type(), base.manufacturer(), + this(base.deviceUri(), base.type(), base.manufacturer(), base.hwVersion(), base.swVersion(), base.serialNumber(), base.chassisId(), annotations); } @@ -83,13 +84,13 @@ public class DefaultDeviceDescription extends AbstractDescription * @param annotations Annotations to use. */ public DefaultDeviceDescription(DeviceDescription base, Type type, SparseAnnotations... annotations) { - this(base.deviceURI(), type, base.manufacturer(), + this(base.deviceUri(), type, base.manufacturer(), base.hwVersion(), base.swVersion(), base.serialNumber(), base.chassisId(), annotations); } @Override - public URI deviceURI() { + public URI deviceUri() { return uri; } @@ -132,6 +133,30 @@ public class DefaultDeviceDescription extends AbstractDescription .toString(); } + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), uri, type, manufacturer, + hwVersion, swVersion, serialNumber, chassisId); + } + + @Override + public boolean equals(Object object) { + if (object instanceof DefaultDeviceDescription) { + if (!super.equals(object)) { + return false; + } + DefaultDeviceDescription that = (DefaultDeviceDescription) object; + return Objects.equal(this.uri, that.uri) + && Objects.equal(this.type, that.type) + && Objects.equal(this.manufacturer, that.manufacturer) + && Objects.equal(this.hwVersion, that.hwVersion) + && Objects.equal(this.swVersion, that.swVersion) + && Objects.equal(this.serialNumber, that.serialNumber) + && Objects.equal(this.chassisId, that.chassisId); + } + return false; + } + // default constructor for serialization private DefaultDeviceDescription() { this.uri = null; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultPortDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultPortDescription.java index 572d201c..d62e932c 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultPortDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DefaultPortDescription.java @@ -21,6 +21,7 @@ import org.onosproject.net.PortNumber; import org.onosproject.net.SparseAnnotations; import static org.onosproject.net.Port.Type; +import com.google.common.base.Objects; /** * Default implementation of immutable port description. @@ -117,4 +118,25 @@ public class DefaultPortDescription extends AbstractDescription .toString(); } + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), number, isEnabled, type, + portSpeed); + } + + @Override + public boolean equals(Object object) { + if (object != null && getClass() == object.getClass()) { + if (!super.equals(object)) { + return false; + } + DefaultPortDescription that = (DefaultPortDescription) object; + return Objects.equal(this.number, that.number) + && Objects.equal(this.isEnabled, that.isEnabled) + && Objects.equal(this.type, that.type) + && Objects.equal(this.portSpeed, that.portSpeed); + } + return false; + } + } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DeviceDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DeviceDescription.java index 64b84b5a..f206b080 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DeviceDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/device/DeviceDescription.java @@ -33,7 +33,7 @@ public interface DeviceDescription extends Description { * * @return provider specific URI for the device */ - URI deviceURI(); + URI deviceUri(); /** * Returns the type of the infrastructure device. diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java index 453a7648..a842d600 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficSelector.java @@ -23,6 +23,7 @@ import java.util.Objects; import java.util.Set; import java.util.TreeSet; +import org.onlab.packet.Ip4Address; import org.onlab.packet.Ip6Address; import org.onlab.packet.IpPrefix; import org.onlab.packet.MacAddress; @@ -353,6 +354,26 @@ public final class DefaultTrafficSelector implements TrafficSelector { } @Override + public Builder matchArpTpa(Ip4Address addr) { + return add(Criteria.matchArpTpa(addr)); + } + + @Override + public Builder matchArpSpa(Ip4Address addr) { + return add(Criteria.matchArpSpa(addr)); + } + + @Override + public Builder matchArpTha(MacAddress addr) { + return add(Criteria.matchArpTha(addr)); + } + + @Override + public Builder matchArpSha(MacAddress addr) { + return add(Criteria.matchArpSha(addr)); + } + + @Override public TrafficSelector build() { return new DefaultTrafficSelector(ImmutableSet.copyOf(selector.values())); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java index 6beeecc9..4615a82b 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/DefaultTrafficTreatment.java @@ -388,7 +388,12 @@ public final class DefaultTrafficTreatment implements TrafficTreatment { @Override public Builder setQueue(long queueId) { - return add(Instructions.setQueue(queueId)); + return add(Instructions.setQueue(queueId, null)); + } + + @Override + public Builder setQueue(long queueId, PortNumber port) { + return add(Instructions.setQueue(queueId, port)); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java index 1286ffc1..9fe88d5a 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficSelector.java @@ -17,6 +17,7 @@ package org.onosproject.net.flow; import java.util.Set; +import org.onlab.packet.Ip4Address; import org.onlab.packet.Ip6Address; import org.onlab.packet.IpPrefix; import org.onlab.packet.MacAddress; @@ -386,6 +387,38 @@ public interface TrafficSelector { Builder matchIPv6ExthdrFlags(short exthdrFlags); /** + * Matches a arp IPv4 destination address. + * + * @param addr a arp IPv4 destination address + * @return a selection builder + */ + Builder matchArpTpa(Ip4Address addr); + + /** + * Matches a arp IPv4 source address. + * + * @param addr a arp IPv4 source address + * @return a selection builder + */ + Builder matchArpSpa(Ip4Address addr); + + /** + * Matches a arp_eth_dst address. + * + * @param addr a arp_eth_dst address + * @return a selection builder + */ + Builder matchArpTha(MacAddress addr); + + /** + * Matches a arp_eth_src address. + * + * @param addr a arp_eth_src address + * @return a selection builder + */ + Builder matchArpSha(MacAddress addr); + + /** * Builds an immutable traffic selector. * * @return traffic selector diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java index b14ab99c..f1a676ab 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/TrafficTreatment.java @@ -271,6 +271,15 @@ public interface TrafficTreatment { Builder setQueue(long queueId); /** + * Sets the Queue ID for a specific port. + * + * @param queueId a queue ID + * @param port a port number + * @return a treatment builder + */ + Builder setQueue(long queueId, PortNumber port); + + /** * Sets a meter to be used by this flow. * * @param meterId a meter id diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ArpHaCriterion.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ArpHaCriterion.java new file mode 100644 index 00000000..71269dd1 --- /dev/null +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/ArpHaCriterion.java @@ -0,0 +1,83 @@ +/* + * 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.flow.criteria; + +import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Objects; + +import org.onlab.packet.MacAddress; + +/** + * Implementation of arp_eth_src address or arp_eth_dst address criterion. + */ +public final class ArpHaCriterion implements Criterion { + private final MacAddress mac; + private final Type type; + + /** + * Constructor. + * + * @param mac the MAC Address to match. + * @param type the match type. Should be one of the following: + * Type.ARP_SHA, Type.ARP_THA + */ + ArpHaCriterion(MacAddress mac, Type type) { + checkNotNull(mac, "mac cannot be null"); + checkNotNull(type, "type cannot be null"); + this.mac = mac; + this.type = type; + } + + @Override + public Type type() { + return this.type; + } + + /** + * Gets the MAC Address to match. + * + * @return the MAC Address to match + */ + public MacAddress mac() { + return this.mac; + } + + @Override + public String toString() { + return toStringHelper(type().toString()) + .add("mac", mac).toString(); + } + + @Override + public int hashCode() { + return Objects.hash(type().ordinal(), mac); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj instanceof ArpHaCriterion) { + ArpHaCriterion that = (ArpHaCriterion) obj; + return Objects.equals(mac, that.mac) && + Objects.equals(type, that.type); + } + return false; + } +}
\ No newline at end of file diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java index 778d50a5..554b8e74 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/criteria/Criteria.java @@ -510,15 +510,45 @@ public final class Criteria { } /** - * Creates a match on IPv4 source field using the specified value. + * Creates a match on IPv4 destination field using the specified value. * - * @param ip ipv4 source value + * @param ip ipv4 destination value * @return match criterion */ public static Criterion matchArpTpa(Ip4Address ip) { return new ArpPaCriterion(ip, Type.ARP_TPA); } + /** + * Creates a match on IPv4 source field using the specified value. + * + * @param ip ipv4 source value + * @return match criterion + */ + public static Criterion matchArpSpa(Ip4Address ip) { + return new ArpPaCriterion(ip, Type.ARP_SPA); + } + + /** + * Creates a match on MAC destination field using the specified value. + * + * @param mac MAC destination value + * @return match criterion + */ + public static Criterion matchArpTha(MacAddress mac) { + return new ArpHaCriterion(mac, Type.ARP_THA); + } + + /** + * Creates a match on MAC source field using the specified value. + * + * @param mac MAC source value + * @return match criterion + */ + public static Criterion matchArpSha(MacAddress mac) { + return new ArpHaCriterion(mac, Type.ARP_SHA); + } + public static Criterion dummy() { return new DummyCriterion(); } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionType.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionType.java index 747a85b5..3e1cb75c 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionType.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/ExtensionType.java @@ -32,7 +32,8 @@ public final class ExtensionType { */ public enum ExtensionTypes { // TODO fix type numbers to include experimenter id - NICIRA_SET_TUNNEL_DST(31); + NICIRA_SET_TUNNEL_DST(31), + NICIRA_RESUBMIT(32); private ExtensionType type; 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 aad407c8..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 @@ -15,6 +15,7 @@ */ package org.onosproject.net.flow.instructions; +import com.google.common.base.MoreObjects; import org.onlab.packet.EthType; import org.onlab.packet.IpAddress; import org.onlab.packet.MacAddress; @@ -99,11 +100,12 @@ public final class Instructions { * Creates a set-queue instruction. * * @param queueId Queue Id + * @param port Port number * @return set-queue instruction */ - public static SetQueueInstruction setQueue(final long queueId) { + public static SetQueueInstruction setQueue(final long queueId, final PortNumber port) { checkNotNull(queueId, "queue ID cannot be null"); - return new SetQueueInstruction(queueId); + return new SetQueueInstruction(queueId, port); } public static MeterInstruction meterTraffic(final MeterId meterId) { @@ -514,7 +516,7 @@ public final class Instructions { @Override public int hashCode() { - return Objects.hash(type().ordinal()); + return type().ordinal(); } @Override @@ -548,7 +550,7 @@ public final class Instructions { @Override public int hashCode() { - return Objects.hash(type().ordinal()); + return type().ordinal(); } @Override @@ -628,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 @@ -655,15 +658,26 @@ public final class Instructions { */ public static final class SetQueueInstruction implements Instruction { private final long queueId; + private final PortNumber port; private SetQueueInstruction(long queueId) { this.queueId = queueId; + this.port = null; + } + + private SetQueueInstruction(long queueId, PortNumber port) { + this.queueId = queueId; + this.port = port; } public long queueId() { return queueId; } + public PortNumber port() { + return port; + } + @Override public Type type() { return Type.QUEUE; @@ -671,13 +685,18 @@ public final class Instructions { @Override public String toString() { - return toStringHelper(type().toString()) - .add("queueId", queueId).toString(); + MoreObjects.ToStringHelper toStringHelper = toStringHelper(type().toString()); + toStringHelper.add("queueId", queueId); + + if (port() != null) { + toStringHelper.add("port", port); + } + return toStringHelper.toString(); } @Override public int hashCode() { - return Objects.hash(type().ordinal(), queueId); + return Objects.hash(type().ordinal(), queueId, port); } @Override @@ -687,7 +706,7 @@ public final class Instructions { } if (obj instanceof SetQueueInstruction) { SetQueueInstruction that = (SetQueueInstruction) obj; - return Objects.equals(queueId, that.queueId); + return Objects.equals(queueId, that.queueId) && Objects.equals(port, that.port); } return false; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L0ModificationInstruction.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L0ModificationInstruction.java index a6e5903c..4af3d168 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L0ModificationInstruction.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L0ModificationInstruction.java @@ -114,7 +114,7 @@ public abstract class L0ModificationInstruction implements Instruction { @Override public int hashCode() { - return Objects.hash(lambda); + return lambda.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L1ModificationInstruction.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L1ModificationInstruction.java index c6847d1c..b72dd7bc 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L1ModificationInstruction.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/flow/instructions/L1ModificationInstruction.java @@ -62,7 +62,7 @@ public abstract class L1ModificationInstruction implements Instruction { @Override public int hashCode() { - return Objects.hash(oduSignalId); + return oduSignalId.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/group/DefaultGroup.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/group/DefaultGroup.java index 546a4513..97f8aedf 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/group/DefaultGroup.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/group/DefaultGroup.java @@ -186,7 +186,7 @@ public class DefaultGroup extends DefaultGroupDescription */ @Override public int hashCode() { - return super.hashCode() + Objects.hash(id); + return Objects.hash(super.hashCode(), id); } /* diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java index 1f05197a..307a6078 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/DefaultHostDescription.java @@ -28,6 +28,7 @@ import org.onlab.packet.VlanId; import com.google.common.collect.ImmutableSet; import static com.google.common.base.MoreObjects.toStringHelper; +import com.google.common.base.Objects; /** * Default implementation of an immutable host description. @@ -119,4 +120,24 @@ public class DefaultHostDescription extends AbstractDescription .toString(); } + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), mac, vlan, location, ip); + } + + @Override + public boolean equals(Object object) { + if (object != null && getClass() == object.getClass()) { + if (!super.equals(object)) { + return false; + } + DefaultHostDescription that = (DefaultHostDescription) object; + return Objects.equal(this.mac, that.mac) + && Objects.equal(this.vlan, that.vlan) + && Objects.equal(this.location, that.location) + && Objects.equal(this.ip, that.ip); + } + return false; + } + } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostEvent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostEvent.java index 98329df0..92824cf8 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostEvent.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/host/HostEvent.java @@ -15,9 +15,12 @@ */ package org.onosproject.net.host; +import org.joda.time.LocalDateTime; import org.onosproject.event.AbstractEvent; import org.onosproject.net.Host; +import static com.google.common.base.MoreObjects.toStringHelper; + /** * Describes end-station host event. */ @@ -48,6 +51,8 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { HOST_MOVED } + private Host prevSubject; + /** * Creates an event of a given type and for the specified host and the * current time. @@ -70,4 +75,39 @@ public class HostEvent extends AbstractEvent<HostEvent.Type, Host> { super(type, host, time); } + /** + * Creates an event with previous subject. + * + * The previous subject is ignored if the type is not moved or updated + * + * @param type host event type + * @param host event host subject + * @param prevSubject previous host subject + */ + public HostEvent(Type type, Host host, Host prevSubject) { + super(type, host); + if (type == Type.HOST_MOVED || type == Type.HOST_UPDATED) { + this.prevSubject = prevSubject; + } + } + + /** + * Gets the previous subject in this host event. + * + * @return the previous subject, or null if previous subject is not + * specified. + */ + public Host prevSubject() { + return this.prevSubject; + } + + @Override + public String toString() { + return toStringHelper(this) + .add("time", new LocalDateTime(time())) + .add("type", type()) + .add("subject", subject()) + .add("prevSubject", prevSubject()) + .toString(); + } } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java index caa5fbb9..4548c44d 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/MplsPathIntent.java @@ -42,6 +42,7 @@ public final class MplsPathIntent extends PathIntent { * ports and using the specified explicit path. * * @param appId application identifier + * @param key intent key * @param selector traffic selector * @param treatment treatment * @param path traversed links @@ -51,11 +52,11 @@ public final class MplsPathIntent extends PathIntent { * @param priority priority to use for flows generated by this intent * @throws NullPointerException {@code path} is null */ - private MplsPathIntent(ApplicationId appId, TrafficSelector selector, + private MplsPathIntent(ApplicationId appId, Key key, TrafficSelector selector, TrafficTreatment treatment, Path path, Optional<MplsLabel> ingressLabel, Optional<MplsLabel> egressLabel, List<Constraint> constraints, int priority) { - super(appId, selector, treatment, path, constraints, + super(appId, key, selector, treatment, path, constraints, priority); this.ingressLabel = checkNotNull(ingressLabel); @@ -149,6 +150,7 @@ public final class MplsPathIntent extends PathIntent { return new MplsPathIntent( appId, + key, selector, treatment, path, diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java index 0c831fd5..9bf137a1 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/PathIntent.java @@ -42,6 +42,7 @@ public class PathIntent extends ConnectivityIntent { * ports and using the specified explicit path. * * @param appId application identifier + * @param key intent key * @param selector traffic selector * @param treatment treatment * @param path traversed links @@ -50,12 +51,13 @@ public class PathIntent extends ConnectivityIntent { * @throws NullPointerException {@code path} is null */ protected PathIntent(ApplicationId appId, + Key key, TrafficSelector selector, TrafficTreatment treatment, Path path, List<Constraint> constraints, int priority) { - super(appId, null, resources(path.links()), selector, treatment, constraints, + super(appId, key, resources(path.links()), selector, treatment, constraints, priority); PathIntent.validate(path.links()); this.path = path; @@ -138,6 +140,7 @@ public class PathIntent extends ConnectivityIntent { return new PathIntent( appId, + key, selector, treatment, path, @@ -184,6 +187,7 @@ public class PathIntent extends ConnectivityIntent { public String toString() { return MoreObjects.toStringHelper(getClass()) .add("id", id()) + .add("key", key()) .add("appId", appId()) .add("priority", priority()) .add("resources", resources()) diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/BandwidthConstraint.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/BandwidthConstraint.java index 20ccb55d..444feee4 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/BandwidthConstraint.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/BandwidthConstraint.java @@ -87,7 +87,7 @@ public final class BandwidthConstraint extends BooleanConstraint { @Override public int hashCode() { - return Objects.hash(bandwidth); + return bandwidth.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LambdaConstraint.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LambdaConstraint.java index 9dd813b2..7811a004 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LambdaConstraint.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LambdaConstraint.java @@ -69,7 +69,7 @@ public class LambdaConstraint extends BooleanConstraint { @Override public int hashCode() { - return Objects.hash(lambda); + return Objects.hashCode(lambda); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LatencyConstraint.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LatencyConstraint.java index 54eb4ea5..aecef879 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LatencyConstraint.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/LatencyConstraint.java @@ -67,7 +67,7 @@ public class LatencyConstraint implements Constraint { @Override public int hashCode() { - return Objects.hash(latency); + return latency.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/ObstacleConstraint.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/ObstacleConstraint.java index cb1e6b2b..ca4f3fd3 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/ObstacleConstraint.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/ObstacleConstraint.java @@ -66,7 +66,7 @@ public class ObstacleConstraint extends BooleanConstraint { @Override public int hashCode() { - return Objects.hash(obstacles); + return obstacles.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/WaypointConstraint.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/WaypointConstraint.java index 1acf6dfe..4839feec 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/WaypointConstraint.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/intent/constraint/WaypointConstraint.java @@ -91,7 +91,7 @@ public class WaypointConstraint implements Constraint { @Override public int hashCode() { - return Objects.hash(waypoints); + return waypoints.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/link/DefaultLinkDescription.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/link/DefaultLinkDescription.java index 891eb65d..cba17640 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/link/DefaultLinkDescription.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/link/DefaultLinkDescription.java @@ -20,6 +20,7 @@ import org.onosproject.net.AbstractDescription; import org.onosproject.net.ConnectPoint; import org.onosproject.net.Link; import org.onosproject.net.SparseAnnotations; +import com.google.common.base.Objects; /** * Default implementation of immutable link description entity. @@ -70,4 +71,23 @@ public class DefaultLinkDescription extends AbstractDescription .add("type", type()).toString(); } + @Override + public int hashCode() { + return Objects.hashCode(super.hashCode(), src, dst, type); + } + + @Override + public boolean equals(Object object) { + if (object != null && getClass() == object.getClass()) { + if (!super.equals(object)) { + return false; + } + DefaultLinkDescription that = (DefaultLinkDescription) object; + return Objects.equal(this.src, that.src) + && Objects.equal(this.dst, that.dst) + && Objects.equal(this.type, that.type); + } + return false; + } + } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceAdminService.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceAdminService.java index e94ee452..cdcd4072 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceAdminService.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceAdminService.java @@ -26,7 +26,7 @@ import java.util.List; @Beta public interface ResourceAdminService { /** - * Register resources as the children of the parent resource path. + * Registers resources as the children of the parent resource path. * * @param parent parent resource path under which the resource are registered * @param children resources to be registered as the children of the parent @@ -39,7 +39,7 @@ public interface ResourceAdminService { } /** - * Register resources as the children of the parent resource path. + * Registers resources as the children of the parent resource path. * * @param parent parent resource path under which the resource are registered * @param children resources to be registered as the children of the parent @@ -50,7 +50,7 @@ public interface ResourceAdminService { <T> boolean registerResources(ResourcePath parent, List<T> children); /** - * Unregister resources as the children of the parent resource path. + * Unregisters resources as the children of the parent resource path. * * @param parent parent resource path under which the resource are unregistered * @param children resources to be unregistered as the children of the parent @@ -63,7 +63,7 @@ public interface ResourceAdminService { } /** - * Unregister resources as the children of the parent resource path. + * Unregisters resources as the children of the parent resource path. * * @param parent parent resource path under which the resource are unregistered * @param children resources to be unregistered as the children of the parent 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<ResourceEvent.Type, ResourcePath> { + + /** + * 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/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowOpticalSwitch.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceListener.java index af678d63..3f871900 100644 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowOpticalSwitch.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourceListener.java @@ -13,11 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.openflow.controller; +package org.onosproject.net.newresource; + +import com.google.common.annotations.Beta; +import org.onosproject.event.EventListener; /** - * A marker interface for optical switches, which require the ability to pass - * port information to a Device provider. + * Entity capable of receiving resource related events. */ -public interface OpenFlowOpticalSwitch extends OpenFlowSwitch, WithTypedPorts { +@Beta +public interface ResourceListener extends EventListener<ResourceEvent> { } diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java index 3aa29f6b..d87682a9 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/newresource/ResourcePath.java @@ -19,12 +19,14 @@ import com.google.common.annotations.Beta; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; -import java.util.Arrays; +import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Optional; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.checkState; /** * An object that is used to locate a resource in a network. @@ -32,32 +34,45 @@ import static com.google.common.base.Preconditions.checkNotNull; * of elementary resources that are not globally identifiable. A ResourcePath can be a globally * unique resource identifier. * + * Two types of resource are considered. One is discrete type and the other is continuous type. + * Discrete type resource is a resource whose amount is measured as a discrete unit. VLAN ID and + * MPLS label are examples of discrete type resource. Continuous type resource is a resource whose + * amount is measured as a continuous value. Bandwidth is an example of continuous type resource. + * A double value is associated with a continuous type value. + * * Users of this class must keep the semantics of resources regarding the hierarchical structure. * For example, resource path, Link:1/VLAN ID:100, is valid, but resource path, VLAN ID:100/Link:1 * is not valid because a link is not a sub-component of a VLAN ID. */ @Beta -public final class ResourcePath { +public abstract class ResourcePath { - private final List<Object> resources; + private final Discrete parent; + private final Object last; - public static final ResourcePath ROOT = new ResourcePath(ImmutableList.of()); + public static final Discrete ROOT = new Discrete(); - public static ResourcePath child(ResourcePath parent, Object child) { - ImmutableList<Object> components = ImmutableList.builder() - .addAll(parent.components()) - .add(child) - .build(); - return new ResourcePath(components); + /** + * Creates an resource path which represents a discrete-type resource from the specified components. + * + * @param components components of the path. The order represents hierarchical structure of the resource. + */ + public static ResourcePath discrete(Object... components) { + if (components.length == 0) { + return ROOT; + } else { + return new Discrete(ImmutableList.copyOf(components)); + } } /** - * Creates an resource path from the specified components. + * Creates an resource path which represents a continuous-type resource from the specified components. * + * @param value amount of the resource * @param components components of the path. The order represents hierarchical structure of the resource. */ - public ResourcePath(Object... components) { - this(Arrays.asList(components)); + public static ResourcePath continuous(double value, Object... components) { + return new Continuous(ImmutableList.copyOf(components), value); } /** @@ -65,15 +80,37 @@ public final class ResourcePath { * * @param components components of the path. The order represents hierarchical structure of the resource. */ - public ResourcePath(List<Object> components) { + ResourcePath(List<Object> components) { checkNotNull(components); + checkArgument(!components.isEmpty()); + + LinkedList<Object> children = new LinkedList<>(components); + this.last = children.pollLast(); + if (children.isEmpty()) { + this.parent = ROOT; + } else { + this.parent = new Discrete(children); + } + } - this.resources = ImmutableList.copyOf(components); + /** + * Creates an resource path from the specified parent and child. + * + * @param parent the parent of this resource + * @param last a child of the parent + */ + ResourcePath(Discrete parent, Object last) { + checkNotNull(parent); + checkNotNull(last); + + this.parent = parent; + this.last = last; } // for serialization private ResourcePath() { - this.resources = null; + this.parent = null; + this.last = null; } /** @@ -82,7 +119,15 @@ public final class ResourcePath { * @return the components of this resource path */ public List<Object> components() { - return resources; + LinkedList<Object> components = new LinkedList<>(); + + ResourcePath current = this; + while (current.parent().isPresent()) { + components.addFirst(current.last); + current = current.parent; + } + + return components; } /** @@ -92,21 +137,20 @@ public final class ResourcePath { * @return the parent resource path of this instance. * If there is no parent, empty instance will be returned. */ - public Optional<ResourcePath> parent() { - if (!isRoot()) { - return Optional.of(new ResourcePath(resources.subList(0, resources.size() - 1))); - } + public Optional<Discrete> parent() { + return Optional.ofNullable(parent); + } + + public ResourcePath child(Object child) { + checkState(this instanceof Discrete); - return Optional.empty(); + return new Discrete((Discrete) this, child); } - /** - * Returns true if the path represents root. - * - * @return true if the path represents root, false otherwise. - */ - public boolean isRoot() { - return resources.size() == 0; + public ResourcePath child(Object child, double value) { + checkState(this instanceof Discrete); + + return new Continuous((Discrete) this, child, value); } /** @@ -115,14 +159,13 @@ public final class ResourcePath { * @return the last component of this instance. * The return value is equal to the last object of {@code components()}. */ - public Object lastComponent() { - int last = resources.size() - 1; - return resources.get(last); + public Object last() { + return last; } @Override public int hashCode() { - return resources.hashCode(); + return Objects.hash(this.parent, this.last); } @Override @@ -134,13 +177,68 @@ public final class ResourcePath { return false; } final ResourcePath that = (ResourcePath) obj; - return Objects.equals(this.resources, that.resources); + return Objects.equals(this.parent, that.parent) + && Objects.equals(this.last, that.last); } @Override public String toString() { return MoreObjects.toStringHelper(this) - .add("resources", resources) + .add("parent", parent) + .add("last", last) .toString(); } + + /** + * Represents a resource path which specifies a resource which can be measured + * as a discrete unit. A VLAN ID and a MPLS label of a link are examples of the resource. + * <p> + * Note: This class is exposed to the public, but intended to be used in the resource API + * implementation only. It is not for resource API user. + * </p> + */ + public static final class Discrete extends ResourcePath { + private Discrete() { + super(); + } + + private Discrete(List<Object> components) { + super(components); + } + + private Discrete(Discrete parent, Object last) { + super(parent, last); + } + } + + /** + * Represents a resource path which specifies a resource which can be measured + * as continuous value. Bandwidth of a link is an example of the resource. + * <p> + * Note: This class is exposed to the public, but intended to be used in the resource API + * implementation only. It is not for resource API user. + */ + public static final class Continuous extends ResourcePath { + // Note: value is not taken into account for equality + private final double value; + + private Continuous(List<Object> components, double value) { + super(components); + this.value = value; + } + + public Continuous(Discrete parent, Object last, double value) { + super(parent, last); + this.value = value; + } + + /** + * Returns the value of the resource amount. + * + * @return the value of the resource amount + */ + public double value() { + return value; + } + } } 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<ResourceEvent, ResourceListener> { /** * 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<ResourceEvent, ResourceStoreDelegate> { /** * 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<ResourceEvent> { +} 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 74f6e102..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; @@ -53,7 +56,7 @@ public class BandwidthResourceAllocation implements ResourceAllocation { @Override public int hashCode() { - return Objects.hash(bandwidth); + return bandwidth.hashCode(); } @Override 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 e07309cb..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; @@ -53,7 +56,7 @@ public class BandwidthResourceRequest implements ResourceRequest { @Override public int hashCode() { - return Objects.hash(bandwidth); + return bandwidth.hashCode(); } @Override 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 545f025f..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; @@ -53,7 +56,7 @@ public class LambdaResourceAllocation implements ResourceAllocation { @Override public int hashCode() { - return Objects.hash(lambda); + return Objects.hashCode(lambda); } @Override 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<LinkResourceEvent.Type, Collection<LinkResourceAllocations>> { 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<LinkResourceEvent> { } 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<LinkResourceEvent> { } 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 10911539..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; @@ -54,7 +57,7 @@ public class MplsLabelResourceAllocation implements ResourceAllocation { @Override public int hashCode() { - return Objects.hash(mplsLabel); + return Objects.hashCode(mplsLabel); } @Override 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. + * <p> + * Note: Classes under the package will be remove. + * Developers should not use the classes. + * This package is marked as deprecated in Emu Release. + * </p> */ +@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. + * <p> + * Note: Classes under the package will be removed. + * Developers should not use the classes. + * </p> */ package org.onosproject.net.resource; diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/ClusterId.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/ClusterId.java index 676f0068..1e6780fa 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/ClusterId.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/ClusterId.java @@ -53,7 +53,7 @@ public final class ClusterId { @Override public int hashCode() { - return Objects.hash(id); + return id; } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyEdge.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyEdge.java index dacb5fd8..99d700e1 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyEdge.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyEdge.java @@ -20,6 +20,7 @@ import org.onosproject.net.Link; import java.util.Objects; import static com.google.common.base.MoreObjects.toStringHelper; +import static com.google.common.base.Preconditions.checkNotNull; /** * Implementation of the topology edge backed by a link. @@ -40,7 +41,7 @@ public class DefaultTopologyEdge implements TopologyEdge { public DefaultTopologyEdge(TopologyVertex src, TopologyVertex dst, Link link) { this.src = src; this.dst = dst; - this.link = link; + this.link = checkNotNull(link); } @Override @@ -60,7 +61,7 @@ public class DefaultTopologyEdge implements TopologyEdge { @Override public int hashCode() { - return Objects.hash(link); + return link.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyVertex.java b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyVertex.java index 07a09cbd..4782bc95 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyVertex.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/net/topology/DefaultTopologyVertex.java @@ -42,7 +42,7 @@ public class DefaultTopologyVertex implements TopologyVertex { @Override public int hashCode() { - return Objects.hash(deviceId); + return deviceId.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/WallClockTimestamp.java b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/WallClockTimestamp.java index 0cc7b453..4be7ede7 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/WallClockTimestamp.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/store/service/WallClockTimestamp.java @@ -52,7 +52,7 @@ public class WallClockTimestamp implements Timestamp { } @Override public int hashCode() { - return Objects.hash(unixTimestamp); + return Long.hashCode(unixTimestamp); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/UiView.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/UiView.java index 2b8b7fa2..c8671159 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/UiView.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/UiView.java @@ -138,7 +138,7 @@ public class UiView { @Override public int hashCode() { - return Objects.hash(id); + return id.hashCode(); } @Override diff --git a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java index a165be33..c75eccf9 100644 --- a/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java +++ b/framework/src/onos/core/api/src/main/java/org/onosproject/ui/topo/PropertyPanel.java @@ -18,7 +18,7 @@ package org.onosproject.ui.topo; import com.google.common.collect.Sets; -import java.text.DecimalFormat; +import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -28,7 +28,7 @@ import java.util.Set; */ public class PropertyPanel { - private static final DecimalFormat DF0 = new DecimalFormat("#,###"); + private static final NumberFormat NF = NumberFormat.getInstance(); private String title; private String typeId; @@ -49,6 +49,24 @@ public class PropertyPanel { } /** + * Returns a number formatter to use for formatting integer and long + * property values. + * <p> + * This default implementation uses a formatter for the default + * locale. For example: + * <pre> + * Locale.ENGLISH : 1000 -> "1,000" + * Locale.FRENCH : 1000 -> "1 000" + * Locale.GERMAN : 1000 -> "1.000" + * </pre> + * + * @return the number formatter + */ + protected NumberFormat formatter() { + return NF; + } + + /** * Adds an ID field to the panel data, to be included in * the returned JSON data to the client. * @@ -80,7 +98,7 @@ public class PropertyPanel { * @return self, for chaining */ public PropertyPanel addProp(String key, int value) { - properties.add(new Prop(key, DF0.format(value))); + properties.add(new Prop(key, formatter().format(value))); return this; } @@ -92,7 +110,7 @@ public class PropertyPanel { * @return self, for chaining */ public PropertyPanel addProp(String key, long value) { - properties.add(new Prop(key, DF0.format(value))); + properties.add(new Prop(key, formatter().format(value))); return this; } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationEventTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationEventTest.java index d31cc268..34c593c4 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationEventTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationEventTest.java @@ -33,7 +33,7 @@ public class ApplicationEventTest extends AbstractEventTest { private Application createApp() { return new DefaultApplication(APP_ID, VER, DESC, ORIGIN, ROLE, - PERMS, Optional.of(FURL), FEATURES); + PERMS, Optional.of(FURL), FEATURES, APPS); } @Test diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationServiceAdapter.java b/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationServiceAdapter.java index 479cc59a..96324a91 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationServiceAdapter.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/app/ApplicationServiceAdapter.java @@ -51,6 +51,10 @@ public class ApplicationServiceAdapter implements ApplicationService { } @Override + public void registerDeactivateHook(ApplicationId appId, Runnable hook) { + } + + @Override public void addListener(ApplicationListener listener) { } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/app/DefaultApplicationDescriptionTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/app/DefaultApplicationDescriptionTest.java index d40d3fea..0e93c1fe 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/app/DefaultApplicationDescriptionTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/app/DefaultApplicationDescriptionTest.java @@ -46,12 +46,13 @@ public class DefaultApplicationDescriptionTest { new Permission(AppPermission.class.getName(), "FLOWRULE_READ")); public static final URI FURL = URI.create("mvn:org.foo-features/1.2a/xml/features"); public static final List<String> FEATURES = ImmutableList.of("foo", "bar"); + public static final List<String> APPS = ImmutableList.of("fifi"); @Test public void basics() { ApplicationDescription app = new DefaultApplicationDescription(APP_NAME, VER, DESC, ORIGIN, - ROLE, PERMS, FURL, FEATURES); + ROLE, PERMS, FURL, FEATURES, APPS); assertEquals("incorrect id", APP_NAME, app.name()); assertEquals("incorrect version", VER, app.version()); assertEquals("incorrect description", DESC, app.description()); @@ -60,6 +61,7 @@ public class DefaultApplicationDescriptionTest { assertEquals("incorrect permissions", PERMS, app.permissions()); assertEquals("incorrect features repo", FURL, app.featuresRepo().get()); assertEquals("incorrect features", FEATURES, app.features()); + assertEquals("incorrect apps", APPS, app.requiredApps()); assertTrue("incorrect toString", app.toString().contains(APP_NAME)); } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/core/CoreServiceAdapter.java b/framework/src/onos/core/api/src/test/java/org/onosproject/core/CoreServiceAdapter.java index 0f6abd68..6d45e8c5 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/core/CoreServiceAdapter.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/core/CoreServiceAdapter.java @@ -43,7 +43,12 @@ public class CoreServiceAdapter implements CoreService { } @Override - public ApplicationId registerApplication(String identifier) { + public ApplicationId registerApplication(String name) { + return null; + } + + @Override + public ApplicationId registerApplication(String name, Runnable preDeactivate) { return null; } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/core/DefaultApplicationTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/core/DefaultApplicationTest.java index cbedb79c..77b3812b 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/core/DefaultApplicationTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/core/DefaultApplicationTest.java @@ -34,7 +34,7 @@ public class DefaultApplicationTest { @Test public void basics() { Application app = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, ROLE, - PERMS, Optional.of(FURL), FEATURES); + PERMS, Optional.of(FURL), FEATURES, APPS); assertEquals("incorrect id", APP_ID, app.id()); assertEquals("incorrect version", VER, app.version()); assertEquals("incorrect description", DESC, app.description()); @@ -43,19 +43,20 @@ public class DefaultApplicationTest { assertEquals("incorrect permissions", PERMS, app.permissions()); assertEquals("incorrect features repo", FURL, app.featuresRepo().get()); assertEquals("incorrect features", FEATURES, app.features()); + assertEquals("incorrect apps", APPS, app.requiredApps()); assertTrue("incorrect toString", app.toString().contains(APP_NAME)); } @Test public void testEquality() { Application a1 = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, ROLE, - PERMS, Optional.of(FURL), FEATURES); + PERMS, Optional.of(FURL), FEATURES, APPS); Application a2 = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, ROLE, - PERMS, Optional.of(FURL), FEATURES); + PERMS, Optional.of(FURL), FEATURES, APPS); Application a3 = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, ROLE, - PERMS, Optional.empty(), FEATURES); + PERMS, Optional.empty(), FEATURES, APPS); Application a4 = new DefaultApplication(APP_ID, VER, DESC, ORIGIN + "asd", ROLE, - PERMS, Optional.of(FURL), FEATURES); + PERMS, Optional.of(FURL), FEATURES, APPS); new EqualsTester().addEqualityGroup(a1, a2) .addEqualityGroup(a3).addEqualityGroup(a4).testEquals(); } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/PortNumberTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/PortNumberTest.java index 6f7b2c2d..de153dc2 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/PortNumberTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/PortNumberTest.java @@ -15,12 +15,17 @@ */ package org.onosproject.net; +import com.google.common.collect.ImmutableList; import com.google.common.testing.EqualsTester; import org.junit.Test; +import org.onosproject.net.PortNumber.Logical; +import static java.util.stream.Collectors.toList; import static org.junit.Assert.assertEquals; import static org.onosproject.net.PortNumber.portNumber; +import java.util.List; + /** * Test of the port number. */ @@ -39,5 +44,37 @@ public class PortNumberTest { assertEquals("incorrect long value", 12345, portNumber(12345).toLong()); } + @Test + public void decimalPortNumberIsReconstructableFromString() { + List<PortNumber> ps = ImmutableList.<PortNumber>builder() + .add(portNumber(0)) + .add(portNumber(1)) + .add(portNumber(6653)) + .add(portNumber(PortNumber.MAX_NUMBER)) + .build(); + ps.forEach(p -> assertEquals(p, PortNumber.fromString(p.toString()))); + } + + @Test + public void logicalPortNumberIsReconstructableFromString() { + List<PortNumber> ps = ImmutableList.copyOf(Logical.values()) + .stream().map(Logical::instance).collect(toList()); + + ps.forEach(p -> assertEquals(p, PortNumber.fromString(p.toString()))); + + PortNumber unknown = portNumber(-42); + assertEquals(unknown, PortNumber.fromString(unknown.toString())); + } + + @Test + public void namedPortNumberIsReconstructableFromString() { + List<PortNumber> ps = ImmutableList.<PortNumber>builder() + .add(portNumber(0, "Zero")) + .add(portNumber(1, "[ONE]")) + .add(portNumber(6653, "OpenFlow (1.3+)")) + .add(portNumber(PortNumber.MAX_NUMBER, "(大)")) + .build(); + ps.forEach(p -> assertEquals(p, PortNumber.fromString(p.toString()))); + } } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/device/DefaultDeviceDescriptionTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/device/DefaultDeviceDescriptionTest.java index 3dcdc22d..c00a6de0 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/device/DefaultDeviceDescriptionTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/device/DefaultDeviceDescriptionTest.java @@ -41,7 +41,7 @@ public class DefaultDeviceDescriptionTest { public void basics() { DeviceDescription device = new DefaultDeviceDescription(DURI, SWITCH, MFR, HW, SW, SN, CID); - assertEquals("incorrect uri", DURI, device.deviceURI()); + assertEquals("incorrect uri", DURI, device.deviceUri()); assertEquals("incorrect type", SWITCH, device.type()); assertEquals("incorrect manufacturer", MFR, device.manufacturer()); assertEquals("incorrect hw", HW, device.hwVersion()); diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java index f54e7411..15abc2bf 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java @@ -57,7 +57,7 @@ public class XmlDriverLoaderTest { } @Test(expected = IOException.class) - public void badXML() throws IOException { + public void badXml() throws IOException { XmlDriverLoader loader = new XmlDriverLoader(getClass().getClassLoader()); loader.loadDrivers(getClass().getResourceAsStream("drivers.bad.xml"), null); } @@ -77,4 +77,4 @@ public class XmlDriverLoaderTest { driver.createBehaviour(new DefaultDriverData(driver, DEVICE_ID), TestBehaviour.class); } -}
\ No newline at end of file +} diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java index e03ed850..c510b60a 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/ConnectivityIntentTest.java @@ -33,6 +33,7 @@ import org.onosproject.net.flow.TrafficTreatment; public abstract class ConnectivityIntentTest extends IntentTest { public static final ApplicationId APPID = new TestApplicationId("foo"); + public static final Key KEY = Key.of(1L, APPID); public static final IntentId IID = new IntentId(123); public static final TrafficSelector MATCH = DefaultTrafficSelector.emptySelector(); diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java index d42e22fa..14201472 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/IntentTestsMocks.java @@ -192,14 +192,17 @@ public class IntentTestsMocks { new MplsLabelResourceAllocation(MplsLabel.valueOf(10))); } + @Override public IntentId intentId() { return null; } + @Override public Collection<Link> links() { return null; } + @Override public Set<ResourceRequest> resources() { return null; } @@ -408,7 +411,7 @@ public class IntentTestsMocks { @Override public int hashCode() { - return Objects.hash(priority); + return priority; } @Override diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java index 196d6ad4..7fbdf232 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java @@ -112,6 +112,5 @@ public class MplsIntentTest extends AbstractIntentTest { assertThat(intent1.selector(), equalTo(intent2.selector())); assertThat(intent1.treatment(), equalTo(intent2.treatment())); assertThat(intent1.priority(), is(PRIORITY)); - } } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java index 551f19eb..64528cb9 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java @@ -47,6 +47,7 @@ public class MplsPathIntentTest extends AbstractIntentTest { Optional<MplsLabel> label2; TrafficSelector selector; TrafficTreatment treatment; + static final Key KEY1 = Key.of(5L, APP_ID); @Before public void mplsPathIntentTestSetUp() { @@ -58,6 +59,7 @@ public class MplsPathIntentTest extends AbstractIntentTest { label2 = Optional.of(MplsLabel.mplsLabel(2)); intent1 = MplsPathIntent.builder() .appId(APP_ID) + .key(KEY1) .ingressLabel(label1) .egressLabel(label2) .path(defaultPath) @@ -105,6 +107,7 @@ public class MplsPathIntentTest extends AbstractIntentTest { assertThat(intent1.treatment(), equalTo(intent2.treatment())); assertThat(intent1.priority(), is(PRIORITY)); assertThat(intent1.path(), is(defaultPath)); + assertThat(intent1.key(), equalTo(KEY1)); } } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java index dfbc1846..9e675347 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/intent/PathIntentTest.java @@ -62,12 +62,14 @@ public class PathIntentTest extends ConnectivityIntentTest { assertEquals("incorrect match", MATCH, intent.selector()); assertEquals("incorrect action", NOP, intent.treatment()); assertEquals("incorrect path", PATH1, intent.path()); + assertEquals("incorrect key", KEY, intent.key()); } @Override protected PathIntent createOne() { return PathIntent.builder() .appId(APPID) + .key(KEY) .selector(MATCH) .treatment(NOP) .path(PATH1) diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourceAllocationTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourceAllocationTest.java index a84927a0..5f448221 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourceAllocationTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourceAllocationTest.java @@ -38,9 +38,9 @@ public class ResourceAllocationTest { @Test public void testEquals() { - ResourceAllocation alloc1 = new ResourceAllocation(new ResourcePath(LK1, VLAN1), IID1); - ResourceAllocation sameAsAlloc1 = new ResourceAllocation(new ResourcePath(LK1, VLAN1), IID1); - ResourceAllocation alloc2 = new ResourceAllocation(new ResourcePath(LK2, VLAN1), IID1); + ResourceAllocation alloc1 = new ResourceAllocation(ResourcePath.discrete(LK1, VLAN1), IID1); + ResourceAllocation sameAsAlloc1 = new ResourceAllocation(ResourcePath.discrete(LK1, VLAN1), IID1); + ResourceAllocation alloc2 = new ResourceAllocation(ResourcePath.discrete(LK2, VLAN1), IID1); new EqualsTester() .addEqualityGroup(alloc1, sameAsAlloc1) diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java index 4a8886a4..35dcf1ec 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/net/newresource/ResourcePathTest.java @@ -18,6 +18,7 @@ package org.onosproject.net.newresource; import com.google.common.testing.EqualsTester; import org.junit.Test; import org.onlab.packet.VlanId; +import org.onlab.util.Bandwidth; import org.onosproject.net.ConnectPoint; import org.onosproject.net.DeviceId; import org.onosproject.net.LinkKey; @@ -25,6 +26,7 @@ import org.onosproject.net.PortNumber; import java.util.Optional; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -36,37 +38,49 @@ public class ResourcePathTest { private static final ConnectPoint CP1_1 = new ConnectPoint(D1, P1); private static final ConnectPoint CP2_1 = new ConnectPoint(D2, P1); private static final VlanId VLAN1 = VlanId.vlanId((short) 100); + private static final Bandwidth BW1 = Bandwidth.gbps(2); + private static final Bandwidth BW2 = Bandwidth.gbps(1); @Test public void testEquals() { - ResourcePath resource1 = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); - ResourcePath sameAsResource1 = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); - ResourcePath resource2 = new ResourcePath(LinkKey.linkKey(CP2_1, CP1_1), VLAN1); + ResourcePath resource1 = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); + ResourcePath sameAsResource1 = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); + ResourcePath resource2 = ResourcePath.discrete(LinkKey.linkKey(CP2_1, CP1_1), VLAN1); + ResourcePath resource3 = ResourcePath.continuous(BW1.bps(), LinkKey.linkKey(CP1_1, CP2_1), BW1); + ResourcePath sameAsResource3 = ResourcePath.continuous(BW2.bps(), LinkKey.linkKey(CP1_1, CP2_1), BW1); new EqualsTester() .addEqualityGroup(resource1, sameAsResource1) .addEqualityGroup(resource2) + .addEqualityGroup(resource3, sameAsResource3) // this is intentional .testEquals(); } @Test public void testCreateWithZeroComponent() { - ResourcePath path = new ResourcePath(); + ResourcePath path = ResourcePath.discrete(); assertThat(path, is(ResourcePath.ROOT)); } @Test + public void testComponents() { + ResourcePath port = ResourcePath.discrete(D1, P1); + + assertThat(port.components(), contains(D1, P1)); + } + + @Test public void testThereIsParent() { - ResourcePath path = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); - ResourcePath parent = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1)); + ResourcePath path = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1), VLAN1); + ResourcePath parent = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1)); assertThat(path.parent(), is(Optional.of(parent))); } @Test public void testNoParent() { - ResourcePath path = new ResourcePath(LinkKey.linkKey(CP1_1, CP2_1)); + ResourcePath path = ResourcePath.discrete(LinkKey.linkKey(CP1_1, CP2_1)); assertThat(path.parent(), is(Optional.of(ResourcePath.ROOT))); } @@ -74,9 +88,9 @@ public class ResourcePathTest { @Test public void testBase() { LinkKey linkKey = LinkKey.linkKey(CP1_1, CP2_1); - ResourcePath path = new ResourcePath(linkKey); + ResourcePath path = ResourcePath.discrete(linkKey); - LinkKey child = (LinkKey) path.lastComponent(); + LinkKey child = (LinkKey) path.last(); assertThat(child, is(linkKey)); } } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/store/service/TestEventuallyConsistentMap.java b/framework/src/onos/core/api/src/test/java/org/onosproject/store/service/TestEventuallyConsistentMap.java index 4f612de2..02462e85 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/store/service/TestEventuallyConsistentMap.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/store/service/TestEventuallyConsistentMap.java @@ -30,7 +30,8 @@ import org.onlab.util.KryoNamespace; import org.onosproject.cluster.NodeId; import org.onosproject.store.Timestamp; -import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.*; +import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT; +import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE; /** * Testing version of an Eventually Consistent Map. diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java index d77c1b2b..b870d483 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/table/cell/DefaultCellComparatorTest.java @@ -115,19 +115,19 @@ public class DefaultCellComparatorTest { } @Test - public void swEpisodeII() { + public void swEpisodeIi() { assertTrue("r2d2 c3po", cmp.compare(SmallStarWars.R2D2, SmallStarWars.C3PO) > 0); } @Test - public void swEpisodeIII() { + public void swEpisodeIii() { assertTrue("luke c3po", cmp.compare(SmallStarWars.LUKE, SmallStarWars.C3PO) > 0); } @Test - public void swEpisodeIV() { + public void swEpisodeIv() { assertTrue("c3po luke", cmp.compare(SmallStarWars.C3PO, SmallStarWars.LUKE) < 0); } @@ -139,7 +139,7 @@ public class DefaultCellComparatorTest { } @Test - public void swEpisodeVI() { + public void swEpisodeVi() { assertTrue("r2d2 luke", cmp.compare(SmallStarWars.R2D2, SmallStarWars.LUKE) < 0); } diff --git a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java index 7e6cc227..b6d32bed 100644 --- a/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java +++ b/framework/src/onos/core/api/src/test/java/org/onosproject/ui/topo/PropertyPanelTest.java @@ -20,17 +20,38 @@ import org.junit.BeforeClass; import org.junit.Test; import org.onosproject.ui.topo.PropertyPanel.Prop; +import java.text.NumberFormat; import java.util.HashMap; import java.util.Iterator; +import java.util.Locale; import java.util.Map; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; /** * Unit tests for {@link PropertyPanel}. */ public class PropertyPanelTest { + // Modified property panel subclass to use ENGLISH locale formatter so + // we know formatted numbers will use comma for the thousand separator. + private static final class EnglishPropertyPanel extends PropertyPanel { + private static final NumberFormat ENGLISH_FORMATTER = + NumberFormat.getInstance(Locale.ENGLISH); + + public EnglishPropertyPanel(String title, String typeId) { + super(title, typeId); + } + + @Override + protected NumberFormat formatter() { + return ENGLISH_FORMATTER; + } + } + private static final String TITLE_ORIG = "Original Title"; private static final String TYPE_ORIG = "Original type ID"; private static final String TITLE_NEW = "New Title"; @@ -42,6 +63,7 @@ public class PropertyPanelTest { private static final String KEY_C = "C"; private static final String SEP = "-"; private static final String KEY_Z = "Z"; + private static final String VALUE_A = "Hay"; private static final String VALUE_B = "Bee"; private static final String VALUE_C = "Sea"; @@ -76,7 +98,7 @@ public class PropertyPanelTest { @Test public void basic() { - pp = new PropertyPanel(TITLE_ORIG, TYPE_ORIG); + pp = new EnglishPropertyPanel(TITLE_ORIG, TYPE_ORIG); assertEquals("wrong title", TITLE_ORIG, pp.title()); assertEquals("wrong type", TYPE_ORIG, pp.typeId()); assertNull("id?", pp.id()); @@ -134,8 +156,8 @@ public class PropertyPanelTest { public void props() { basic(); pp.addProp(KEY_A, VALUE_A) - .addProp(KEY_B, VALUE_B) - .addProp(KEY_C, VALUE_C); + .addProp(KEY_B, VALUE_B) + .addProp(KEY_C, VALUE_C); assertEquals("bad props", 3, pp.properties().size()); validateProps(KEY_A, KEY_B, KEY_C); } @@ -144,7 +166,7 @@ public class PropertyPanelTest { public void separator() { props(); pp.addSeparator() - .addProp(KEY_Z, VALUE_Z); + .addProp(KEY_Z, VALUE_Z); assertEquals("bad props", 5, pp.properties().size()); validateProps(KEY_A, KEY_B, KEY_C, SEP, KEY_Z); @@ -170,8 +192,8 @@ public class PropertyPanelTest { public void intValues() { basic(); pp.addProp(KEY_A, 200) - .addProp(KEY_B, 2000) - .addProp(KEY_C, 1234567); + .addProp(KEY_B, 2000) + .addProp(KEY_C, 1234567); validateProp(KEY_A, "200"); validateProp(KEY_B, "2,000"); @@ -182,9 +204,9 @@ public class PropertyPanelTest { public void longValues() { basic(); pp.addProp(KEY_A, 200L) - .addProp(KEY_B, 2000L) - .addProp(KEY_C, 1234567L) - .addProp(KEY_Z, Long.MAX_VALUE); + .addProp(KEY_B, 2000L) + .addProp(KEY_C, 1234567L) + .addProp(KEY_Z, Long.MAX_VALUE); validateProp(KEY_A, "200"); validateProp(KEY_B, "2,000"); @@ -196,7 +218,7 @@ public class PropertyPanelTest { public void objectValue() { basic(); pp.addProp(KEY_A, new FooClass("a")) - .addProp(KEY_B, new FooClass("bxyyzy"), "[xz]"); + .addProp(KEY_B, new FooClass("bxyyzy"), "[xz]"); validateProp(KEY_A, ">a<"); validateProp(KEY_B, ">byyy<"); diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ApplicationCodec.java b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ApplicationCodec.java index b2cab094..a09c0bdb 100644 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ApplicationCodec.java +++ b/framework/src/onos/core/common/src/main/java/org/onosproject/codec/impl/ApplicationCodec.java @@ -32,18 +32,18 @@ public final class ApplicationCodec extends JsonCodec<Application> { public ObjectNode encode(Application app, CodecContext context) { checkNotNull(app, "Application cannot be null"); ApplicationService service = context.getService(ApplicationService.class); - ObjectNode result = context.mapper().createObjectNode() + return context.mapper().createObjectNode() .put("name", app.id().name()) .put("id", app.id().id()) .put("version", app.version().toString()) .put("description", app.description()) .put("origin", app.origin()) - .put("permissions", app.permissions().toString()) + .put("permissions", app.permissions().toString()) // FIXME: change to an array .put("featuresRepo", app.featuresRepo().isPresent() ? app.featuresRepo().get().toString() : "") - .put("features", app.features().toString()) + .put("features", app.features().toString()) // FIXME: change to an array + .put("requiredApps", app.requiredApps().toString()) // FIXME: change to an array .put("state", service.getState(app.id()).toString()); - return result; } } diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/common/DefaultTopology.java b/framework/src/onos/core/common/src/main/java/org/onosproject/common/DefaultTopology.java index 3c5c540d..84cde424 100644 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/common/DefaultTopology.java +++ b/framework/src/onos/core/common/src/main/java/org/onosproject/common/DefaultTopology.java @@ -26,10 +26,10 @@ import org.onlab.graph.DijkstraGraphSearch; import org.onlab.graph.DisjointPathPair; import org.onlab.graph.GraphPathSearch; import org.onlab.graph.GraphPathSearch.Result; -import org.onlab.graph.SRLGGraphSearch; +import org.onlab.graph.SrlgGraphSearch; import org.onlab.graph.SuurballeGraphSearch; import org.onlab.graph.TarjanGraphSearch; -import org.onlab.graph.TarjanGraphSearch.SCCResult; +import org.onlab.graph.TarjanGraphSearch.SccResult; import org.onosproject.net.AbstractModel; import org.onosproject.net.ConnectPoint; import org.onosproject.net.DefaultDisjointPath; @@ -83,7 +83,7 @@ public class DefaultTopology extends AbstractModel implements Topology { private final TopologyGraph graph; private final LinkWeight weight; - private final Supplier<SCCResult<TopologyVertex, TopologyEdge>> clusterResults; + private final Supplier<SccResult<TopologyVertex, TopologyEdge>> clusterResults; private final Supplier<ImmutableMap<ClusterId, TopologyCluster>> clusters; private final Supplier<ImmutableSet<ConnectPoint>> infrastructurePoints; private final Supplier<ImmutableSetMultimap<ClusterId, ConnectPoint>> broadcastSets; @@ -385,7 +385,7 @@ public class DefaultTopology extends AbstractModel implements Topology { return ImmutableSet.of(); } - SRLGGraphSearch<TopologyVertex, TopologyEdge> srlg = new SRLGGraphSearch<>(riskProfile); + SrlgGraphSearch<TopologyVertex, TopologyEdge> srlg = new SrlgGraphSearch<>(riskProfile); GraphPathSearch.Result<TopologyVertex, TopologyEdge> result = srlg.search(graph, srcV, dstV, weight, ALL_PATHS); ImmutableSet.Builder<DisjointPath> builder = ImmutableSet.builder(); @@ -455,14 +455,14 @@ public class DefaultTopology extends AbstractModel implements Topology { // Searches for SCC clusters in the network topology graph using Tarjan // algorithm. - private SCCResult<TopologyVertex, TopologyEdge> searchForClusters() { + private SccResult<TopologyVertex, TopologyEdge> searchForClusters() { return TARJAN.search(graph, new NoIndirectLinksWeight()); } // Builds the topology clusters and returns the id-cluster bindings. private ImmutableMap<ClusterId, TopologyCluster> buildTopologyClusters() { ImmutableMap.Builder<ClusterId, TopologyCluster> clusterBuilder = ImmutableMap.builder(); - SCCResult<TopologyVertex, TopologyEdge> results = clusterResults.get(); + SccResult<TopologyVertex, TopologyEdge> results = clusterResults.get(); // Extract both vertexes and edges from the results; the lists form // pairs along the same index. diff --git a/framework/src/onos/core/common/src/main/java/org/onosproject/common/app/ApplicationArchive.java b/framework/src/onos/core/common/src/main/java/org/onosproject/common/app/ApplicationArchive.java index 54f0fb89..37cdbdfc 100644 --- a/framework/src/onos/core/common/src/main/java/org/onosproject/common/app/ApplicationArchive.java +++ b/framework/src/onos/core/common/src/main/java/org/onosproject/common/app/ApplicationArchive.java @@ -17,6 +17,7 @@ package org.onosproject.common.app; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; import com.google.common.io.ByteStreams; import com.google.common.io.Files; import org.apache.commons.configuration.ConfigurationException; @@ -33,7 +34,6 @@ import org.onosproject.core.Version; import org.onosproject.security.AppPermission; import org.onosproject.security.Permission; import org.onosproject.store.AbstractStore; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,7 +46,6 @@ import java.io.InputStream; import java.net.URI; import java.nio.charset.Charset; import java.nio.file.NoSuchFileException; -import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.Set; @@ -79,6 +78,7 @@ public class ApplicationArchive private static final String VERSION = "[@version]"; private static final String FEATURES_REPO = "[@featuresRepo]"; private static final String FEATURES = "[@features]"; + private static final String APPS = "[@apps]"; private static final String DESCRIPTION = "description"; private static final String ROLE = "security.role"; @@ -291,8 +291,13 @@ public class ApplicationArchive URI featuresRepo = featRepo != null ? URI.create(featRepo) : null; List<String> features = ImmutableList.copyOf(cfg.getString(FEATURES).split(",")); + String apps = cfg.getString(APPS, ""); + List<String> requiredApps = apps.isEmpty() ? + ImmutableList.of() : ImmutableList.copyOf(apps.split(",")); + return new DefaultApplicationDescription(name, version, desc, origin, role, - perms, featuresRepo, features); + perms, featuresRepo, features, + requiredApps); } // Expands the specified ZIP stream into app-specific directory. @@ -390,7 +395,7 @@ public class ApplicationArchive // Returns the set of Permissions specified in the app.xml file private ImmutableSet<Permission> getPermissions(XMLConfiguration cfg) { - List<Permission> permissionList = new ArrayList(); + List<Permission> permissionList = Lists.newArrayList(); for (Object o : cfg.getList(APP_PERMISSIONS)) { String name = (String) o; diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java b/framework/src/onos/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java index 7cbce4d1..2f933966 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/codec/impl/IntentCodecTest.java @@ -217,7 +217,7 @@ public class IntentCodecTest extends AbstractIntentTest { * @throws IOException if processing the resource fails */ private Intent getIntent(String resourceName, JsonCodec intentCodec) throws IOException { - InputStream jsonStream = FlowRuleCodecTest.class + InputStream jsonStream = IntentCodecTest.class .getResourceAsStream(resourceName); JsonNode json = context.mapper().readTree(jsonStream); assertThat(json, notNullValue()); diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleApplicationStore.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleApplicationStore.java index ea9a773e..d9f5285c 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleApplicationStore.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleApplicationStore.java @@ -75,7 +75,8 @@ public class SimpleApplicationStore extends ApplicationArchive implements Applic new DefaultApplication(appId, appDesc.version(), appDesc.description(), appDesc.origin(), appDesc.role(), appDesc.permissions(), - appDesc.featuresRepo(), appDesc.features()); + appDesc.featuresRepo(), appDesc.features(), + appDesc.requiredApps()); apps.put(appId, app); states.put(appId, isActive(name) ? INSTALLED : ACTIVE); // load app permissions @@ -117,7 +118,8 @@ public class SimpleApplicationStore extends ApplicationArchive implements Applic DefaultApplication app = new DefaultApplication(appId, appDesc.version(), appDesc.description(), appDesc.origin(), appDesc.role(), appDesc.permissions(), - appDesc.featuresRepo(), appDesc.features()); + appDesc.featuresRepo(), appDesc.features(), + appDesc.requiredApps()); apps.put(appId, app); states.put(appId, INSTALLED); delegate.notify(new ApplicationEvent(APP_INSTALLED, app)); diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStore.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStore.java index 72fc1b05..11a12040 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStore.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleDeviceStore.java @@ -532,7 +532,7 @@ public class SimpleDeviceStore checkArgument(!providerDescs.isEmpty(), "No Device descriptions supplied"); - ProviderId primary = pickPrimaryPID(providerDescs); + ProviderId primary = pickPrimaryPid(providerDescs); DeviceDescriptions desc = providerDescs.get(primary); @@ -575,7 +575,7 @@ public class SimpleDeviceStore private Port composePort(Device device, PortNumber number, Map<ProviderId, DeviceDescriptions> descsMap) { - ProviderId primary = pickPrimaryPID(descsMap); + ProviderId primary = pickPrimaryPid(descsMap); DeviceDescriptions primDescs = descsMap.get(primary); // if no primary, assume not enabled // TODO: revisit this default port enabled/disabled behavior @@ -613,7 +613,7 @@ public class SimpleDeviceStore /** * @return primary ProviderID, or randomly chosen one if none exists */ - private ProviderId pickPrimaryPID(Map<ProviderId, DeviceDescriptions> descsMap) { + private ProviderId pickPrimaryPid(Map<ProviderId, DeviceDescriptions> descsMap) { ProviderId fallBackPrimary = null; for (Entry<ProviderId, DeviceDescriptions> e : descsMap.entrySet()) { if (!e.getKey().isAncillary()) { diff --git a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleHostStore.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleHostStore.java index 72ec98ca..a56daab1 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleHostStore.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SimpleHostStore.java @@ -88,10 +88,14 @@ public class SimpleHostStore boolean replaceIps) { //TODO We need a way to detect conflicting changes and abort update. StoredHost host = hosts.get(hostId); + HostEvent hostEvent; if (host == null) { - return createHost(providerId, hostId, hostDescription); + hostEvent = createHost(providerId, hostId, hostDescription); + } else { + hostEvent = updateHost(providerId, host, hostDescription, replaceIps); } - return updateHost(providerId, host, hostDescription, replaceIps); + notifyDelegate(hostEvent); + return hostEvent; } // creates a new host and sends HOST_ADDED @@ -153,7 +157,9 @@ public class SimpleHostStore Host host = hosts.remove(hostId); if (host != null) { locations.remove((host.location()), host); - return new HostEvent(HOST_REMOVED, host); + HostEvent hostEvent = new HostEvent(HOST_REMOVED, host); + notifyDelegate(hostEvent); + return hostEvent; } return null; } 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/common/src/test/java/org/onosproject/store/trivial/SystemClockTimestamp.java b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SystemClockTimestamp.java index 2ee41945..500a09c7 100644 --- a/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SystemClockTimestamp.java +++ b/framework/src/onos/core/common/src/test/java/org/onosproject/store/trivial/SystemClockTimestamp.java @@ -51,7 +51,7 @@ public class SystemClockTimestamp implements Timestamp { } @Override public int hashCode() { - return Objects.hash(nanoTimestamp); + return Long.hashCode(nanoTimestamp); } @Override diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java index 161659f9..d09eb1f1 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/app/impl/ApplicationManager.java @@ -15,6 +15,7 @@ */ package org.onosproject.app.impl; +import com.google.common.collect.Maps; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; @@ -30,20 +31,21 @@ import org.onosproject.app.ApplicationService; import org.onosproject.app.ApplicationState; import org.onosproject.app.ApplicationStore; import org.onosproject.app.ApplicationStoreDelegate; -import org.onosproject.event.AbstractListenerManager; import org.onosproject.core.Application; import org.onosproject.core.ApplicationId; +import org.onosproject.event.AbstractListenerManager; import org.onosproject.security.Permission; import org.onosproject.security.SecurityUtil; import org.slf4j.Logger; import java.io.InputStream; +import java.util.Map; import java.util.Set; import static com.google.common.base.Preconditions.checkNotNull; import static org.onosproject.app.ApplicationEvent.Type.*; -import static org.onosproject.security.AppPermission.Type.*; import static org.onosproject.security.AppGuard.checkPermission; +import static org.onosproject.security.AppPermission.Type.APP_READ; import static org.slf4j.LoggerFactory.getLogger; /** @@ -69,6 +71,9 @@ public class ApplicationManager private boolean initializing; + // Application supplied hooks for pre-activation processing. + private final Map<String, Runnable> deactivateHooks = Maps.newConcurrentMap(); + @Activate public void activate() { eventDispatcher.addSink(ApplicationEvent.class, listenerRegistry); @@ -122,6 +127,14 @@ public class ApplicationManager } @Override + public void registerDeactivateHook(ApplicationId appId, Runnable hook) { + checkPermission(APP_READ); + checkNotNull(appId, APP_ID_NULL); + checkNotNull(hook, "Hook cannot be null"); + deactivateHooks.put(appId.name(), hook); + } + + @Override public Application install(InputStream appDescStream) { checkNotNull(appDescStream, "Application archive stream cannot be null"); Application app = store.create(appDescStream); @@ -199,6 +212,7 @@ public class ApplicationManager // The following methods are fully synchronized to guard against remote vs. // locally induced feature service interactions. + // Installs all feature repositories required by the specified app. private synchronized boolean installAppArtifacts(Application app) throws Exception { if (app.featuresRepo().isPresent() && featuresService.getRepository(app.featuresRepo().get()) == null) { @@ -208,6 +222,7 @@ public class ApplicationManager return false; } + // Uninstalls all the feature repositories required by the specified app. private synchronized boolean uninstallAppArtifacts(Application app) throws Exception { if (app.featuresRepo().isPresent() && featuresService.getRepository(app.featuresRepo().get()) != null) { @@ -217,6 +232,7 @@ public class ApplicationManager return false; } + // Installs all features that define the specified app. private synchronized boolean installAppFeatures(Application app) throws Exception { boolean changed = false; for (String name : app.features()) { @@ -233,8 +249,10 @@ public class ApplicationManager return changed; } + // Uninstalls all features that define the specified app. private synchronized boolean uninstallAppFeatures(Application app) throws Exception { boolean changed = false; + invokeHook(deactivateHooks.get(app.id().name()), app.id()); for (String name : app.features()) { Feature feature = featuresService.getFeature(name); if (feature != null && featuresService.isInstalled(feature)) { @@ -247,4 +265,16 @@ public class ApplicationManager return changed; } + // Invokes the specified function, if not null. + private void invokeHook(Runnable hook, ApplicationId appId) { + if (hook != null) { + try { + hook.run(); + } catch (Exception e) { + log.warn("Deactivate hook for application {} encountered an error", + appId.name(), e); + } + } + } + } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java index f4d560a4..ec99c18b 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java @@ -24,6 +24,7 @@ import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.ReferenceCardinality; import org.apache.felix.scr.annotations.Service; import org.onlab.util.SharedExecutors; +import org.onosproject.app.ApplicationService; import org.onosproject.cfg.ComponentConfigService; import org.onosproject.core.ApplicationId; import org.onosproject.core.ApplicationIdStore; @@ -48,7 +49,7 @@ import java.util.Set; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Strings.isNullOrEmpty; import static org.onosproject.security.AppGuard.checkPermission; -import static org.onosproject.security.AppPermission.Type.*; +import static org.onosproject.security.AppPermission.Type.APP_READ; @@ -71,6 +72,9 @@ public class CoreManager implements CoreService { protected IdBlockStore idBlockStore; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected ApplicationService appService; + + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected ComponentConfigService cfgService; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) @@ -111,28 +115,24 @@ public class CoreManager implements CoreService { @Override public Version version() { checkPermission(APP_READ); - return version; } @Override public Set<ApplicationId> getAppIds() { checkPermission(APP_READ); - return applicationIdStore.getAppIds(); } @Override public ApplicationId getAppId(Short id) { checkPermission(APP_READ); - return applicationIdStore.getAppId(id); } @Override public ApplicationId getAppId(String name) { checkPermission(APP_READ); - return applicationIdStore.getAppId(name); } @@ -144,6 +144,13 @@ public class CoreManager implements CoreService { } @Override + public ApplicationId registerApplication(String name, Runnable preDeactivate) { + ApplicationId id = registerApplication(name); + appService.registerDeactivateHook(id, preDeactivate); + return id; + } + + @Override public IdGenerator getIdGenerator(String topic) { IdBlockAllocator allocator = new StoreBasedIdBlockAllocator(topic, idBlockStore); return new BlockAllocatorBasedIdGenerator(allocator); @@ -185,10 +192,10 @@ public class CoreManager implements CoreService { */ private static Integer getIntegerProperty(Dictionary<?, ?> properties, String propertyName) { - Integer value = null; + Integer value; try { String s = (String) properties.get(propertyName); - value = isNullOrEmpty(s) ? value : Integer.parseInt(s.trim()); + value = isNullOrEmpty(s) ? null : Integer.parseInt(s.trim()); } catch (NumberFormatException | ClassCastException e) { value = null; } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java index fa90eb65..a498b3f4 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java @@ -51,7 +51,7 @@ public final class BasicDeviceOperator implements ConfigOperator { * @return DeviceDescription based on both sources */ public static DeviceDescription combine(BasicDeviceConfig bdc, DeviceDescription descr) { - if (bdc == null) { + if (bdc == null || descr == null) { return descr; } @@ -61,7 +61,7 @@ public final class BasicDeviceOperator implements ConfigOperator { } SparseAnnotations sa = combine(bdc, descr.annotations()); - return new DefaultDeviceDescription(descr.deviceURI(), type, descr.manufacturer(), + return new DefaultDeviceDescription(descr.deviceUri(), type, descr.manufacturer(), descr.hwVersion(), descr.swVersion(), descr.serialNumber(), descr.chassisId(), sa); } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java index 9215d3a0..03281bef 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java @@ -740,7 +740,7 @@ public class DeviceManager Device dev = getDevice(did); DeviceDescription desc = (dev == null) ? null : BasicDeviceOperator.descriptionOf(dev); desc = BasicDeviceOperator.combine(cfg, desc); - if (getProvider(did) != null) { + if (desc != null && getProvider(did) != null) { de = store.createOrUpdateDevice(getProvider(did).id(), did, desc); } } @@ -754,7 +754,7 @@ public class DeviceManager OpticalPortConfig opc = networkConfigService.getConfig(cpt, OpticalPortConfig.class); PortDescription desc = OpticalPortOperator.descriptionOf(dpt); desc = OpticalPortOperator.combine(opc, desc); - if (getProvider(did) != null) { + if (desc != null && getProvider(did) != null) { de = store.updatePortStatus(getProvider(did).id(), did, desc); } } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java index 1473f33f..f48b8366 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java @@ -192,10 +192,7 @@ public class HostManager @Override public void removeHost(HostId hostId) { checkNotNull(hostId, HOST_ID_NULL); - HostEvent event = store.removeHost(hostId); - if (event != null) { - post(event); - } + store.removeHost(hostId); } // Personalized host provider service issued to the supplied provider. @@ -211,11 +208,8 @@ public class HostManager checkNotNull(hostId, HOST_ID_NULL); checkValidity(); hostDescription = validateHost(hostDescription, hostId); - HostEvent event = store.createOrUpdateHost(provider().id(), hostId, + store.createOrUpdateHost(provider().id(), hostId, hostDescription, replaceIps); - if (event != null) { - post(event); - } } // returns a HostDescription made from the union of the BasicHostConfig @@ -231,20 +225,14 @@ public class HostManager public void hostVanished(HostId hostId) { checkNotNull(hostId, HOST_ID_NULL); checkValidity(); - HostEvent event = store.removeHost(hostId); - if (event != null) { - post(event); - } + store.removeHost(hostId); } @Override public void removeIpFromHost(HostId hostId, IpAddress ipAddress) { checkNotNull(hostId, HOST_ID_NULL); checkValidity(); - HostEvent event = store.removeIp(hostId, ipAddress); - if (event != null) { - post(event); - } + store.removeIp(hostId, ipAddress); } } 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<Class<?>> 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/intent/impl/compiler/MplsPathIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java index acc5a5d5..718c7bbf 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsPathIntentCompiler.java @@ -121,7 +121,7 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { } List<ResourcePath> resources = labels.entrySet().stream() - .map(x -> new ResourcePath(linkKey(x.getKey().src(), x.getKey().src()), x.getValue())) + .map(x -> ResourcePath.discrete(linkKey(x.getKey().src(), x.getKey().src()), x.getValue())) .collect(Collectors.toList()); List<org.onosproject.net.newresource.ResourceAllocation> allocations = resourceService.allocate(intent.id(), resources); @@ -145,9 +145,9 @@ public class MplsPathIntentCompiler implements IntentCompiler<MplsPathIntent> { } private Optional<MplsLabel> findMplsLabel(LinkKey link) { - return resourceService.getAvailableResources(new ResourcePath(link)).stream() - .filter(x -> x.lastComponent() instanceof MplsLabel) - .map(x -> (MplsLabel) x.lastComponent()) + return resourceService.getAvailableResources(ResourcePath.discrete(link)).stream() + .filter(x -> x.last() instanceof MplsLabel) + .map(x -> (MplsLabel) x.last()) .findFirst(); } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java index fce8498c..ee04aab5 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalCircuitIntentCompiler.java @@ -160,8 +160,8 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu log.debug("Compiling optical circuit intent between {} and {}", src, dst); // Reserve OduClt ports - ResourcePath srcPortPath = new ResourcePath(src.deviceId(), src.port()); - ResourcePath dstPortPath = new ResourcePath(dst.deviceId(), dst.port()); + ResourcePath srcPortPath = ResourcePath.discrete(src.deviceId(), src.port()); + ResourcePath dstPortPath = ResourcePath.discrete(dst.deviceId(), dst.port()); List<ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortPath, dstPortPath); if (allocation.isEmpty()) { throw new IntentCompilationException("Unable to reserve ports for intent " + intent); @@ -312,7 +312,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu if (ochCP != null) { OchPort ochPort = (OchPort) deviceService.getPort(ochCP.deviceId(), ochCP.port()); Optional<IntentId> intentId = - resourceService.getResourceAllocation(new ResourcePath(ochCP.deviceId(), ochCP.port())) + resourceService.getResourceAllocation(ResourcePath.discrete(ochCP.deviceId(), ochCP.port())) .map(ResourceAllocation::consumer) .filter(x -> x instanceof IntentId) .map(x -> (IntentId) x); @@ -331,7 +331,7 @@ public class OpticalCircuitIntentCompiler implements IntentCompiler<OpticalCircu } Optional<IntentId> intentId = - resourceService.getResourceAllocation(new ResourcePath(oduPort.deviceId(), port.number())) + resourceService.getResourceAllocation(ResourcePath.discrete(oduPort.deviceId(), port.number())) .map(ResourceAllocation::consumer) .filter(x -> x instanceof IntentId) .map(x -> (IntentId) x); diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java index d6725b7c..a4ed551a 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/OpticalConnectivityIntentCompiler.java @@ -107,8 +107,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical log.debug("Compiling optical connectivity intent between {} and {}", src, dst); // Reserve OCh ports - ResourcePath srcPortPath = new ResourcePath(src.deviceId(), src.port()); - ResourcePath dstPortPath = new ResourcePath(dst.deviceId(), dst.port()); + ResourcePath srcPortPath = ResourcePath.discrete(src.deviceId(), src.port()); + ResourcePath dstPortPath = ResourcePath.discrete(dst.deviceId(), dst.port()); List<org.onosproject.net.newresource.ResourceAllocation> allocation = resourceService.allocate(intent.id(), srcPortPath, dstPortPath); if (allocation.isEmpty()) { @@ -182,8 +182,8 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical IndexedLambda minLambda = findFirstLambda(lambdas); List<ResourcePath> lambdaResources = path.links().stream() - .map(x -> new ResourcePath(linkKey(x.src(), x.dst()))) - .map(x -> ResourcePath.child(x, minLambda)) + .map(x -> ResourcePath.discrete(linkKey(x.src(), x.dst()))) + .map(x -> x.child(minLambda)) .collect(Collectors.toList()); List<ResourceAllocation> allocations = resourceService.allocate(intent.id(), lambdaResources); @@ -196,10 +196,10 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical private Set<IndexedLambda> findCommonLambdasOverLinks(List<Link> links) { return links.stream() - .map(x -> new ResourcePath(linkKey(x.src(), x.dst()))) + .map(x -> ResourcePath.discrete(linkKey(x.src(), x.dst()))) .map(resourceService::getAvailableResources) - .map(x -> Iterables.filter(x, r -> r.lastComponent() instanceof IndexedLambda)) - .map(x -> Iterables.transform(x, r -> (IndexedLambda) r.lastComponent())) + .map(x -> Iterables.filter(x, r -> r.last() instanceof IndexedLambda)) + .map(x -> Iterables.transform(x, r -> (IndexedLambda) r.last())) .map(x -> (Set<IndexedLambda>) ImmutableSet.copyOf(x)) .reduce(Sets::intersection) .orElse(Collections.emptySet()); diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java index e6d92253..066dd33e 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceDeviceListener.java @@ -75,12 +75,12 @@ final class ResourceDeviceListener implements DeviceListener { } private void registerPortResource(Device device, Port port) { - ResourcePath parent = new ResourcePath(device.id()); + ResourcePath parent = ResourcePath.discrete(device.id()); executor.submit(() -> adminService.registerResources(parent, port.number())); } private void unregisterPortResource(Device device, Port port) { - ResourcePath parent = new ResourcePath(device.id()); + ResourcePath parent = ResourcePath.discrete(device.id()); executor.submit(() -> adminService.unregisterResources(parent, port.number())); } } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceLinkListener.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceLinkListener.java index f04c78b9..68fd6612 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceLinkListener.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceLinkListener.java @@ -87,7 +87,7 @@ final class ResourceLinkListener implements LinkListener { LinkKey linkKey = LinkKey.linkKey(link); adminService.registerResources(ResourcePath.ROOT, linkKey); - ResourcePath linkPath = new ResourcePath(linkKey); + ResourcePath linkPath = ResourcePath.discrete(linkKey); // register VLAN IDs against the link if (isEnabled(link, this::isVlanEnabled)) { adminService.registerResources(linkPath, ENTIRE_VLAN_IDS); 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 10fe75ea..1c6930bb 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,20 +50,32 @@ 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<ResourceEvent, ResourceListener> + 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.removeSink(ResourceEvent.class); + } + @Override public List<ResourceAllocation> allocate(ResourceConsumer consumer, List<ResourcePath> resources) { checkNotNull(consumer); checkNotNull(resources); - // TODO: implement support of resource hierarchy - // allocation for a particular resource implies allocations for all of the sub-resources need to be done - boolean success = store.allocate(resources, consumer); if (!success) { return ImmutableList.of(); @@ -151,7 +169,7 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ checkNotNull(children); checkArgument(!children.isEmpty()); - List<ResourcePath> resources = Lists.transform(children, x -> ResourcePath.child(parent, x)); + List<ResourcePath> resources = Lists.transform(children, parent::child); return store.register(resources); } @@ -161,7 +179,14 @@ public final class ResourceManager implements ResourceService, ResourceAdminServ checkNotNull(children); checkArgument(!children.isEmpty()); - List<ResourcePath> resources = Lists.transform(children, x -> ResourcePath.child(parent, x)); + List<ResourcePath> resources = Lists.transform(children, parent::child); 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/main/java/org/onosproject/net/newresource/impl/ResourceRegistrar.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceRegistrar.java index 4067d017..143f8c2b 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceRegistrar.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/newresource/impl/ResourceRegistrar.java @@ -36,7 +36,7 @@ import static org.onlab.util.Tools.groupedThreads; /** * A class registering resources when they are detected. */ -@Component(immediate = true, enabled = false) +@Component(immediate = true) @Beta public final class ResourceRegistrar { diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java index 8e87a07d..793030f2 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/packet/impl/PacketManager.java @@ -312,9 +312,13 @@ public class PacketManager public void processPacket(PacketContext context) { // TODO filter packets sent to processors based on registrations for (ProcessorEntry entry : processors) { - long start = System.nanoTime(); - entry.processor().process(context); - entry.addNanos(System.nanoTime() - start); + try { + long start = System.nanoTime(); + entry.processor().process(context); + entry.addNanos(System.nanoTime() - start); + } catch (Exception e) { + log.warn("Packet processor {} threw an exception", entry.processor(), e); + } } } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/proxyarp/impl/ProxyArpManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/proxyarp/impl/ProxyArpManager.java index 25a2640d..5ecf2806 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/proxyarp/impl/ProxyArpManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/proxyarp/impl/ProxyArpManager.java @@ -53,6 +53,7 @@ import org.slf4j.Logger; import java.nio.ByteBuffer; import java.util.Set; +import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @@ -199,11 +200,49 @@ public class ProxyArpManager implements ProxyArpService { return; } + // If the packets has a vlanId look if there are some other + // interfaces in the configuration on the same vlan and broadcast + // the packet out just of through those interfaces. + VlanId vlanId = context.vlan(); + + Set<Interface> filteredVlanInterfaces = + filterVlanInterfacesNoIp(interfaceService.getInterfacesByVlan(vlanId)); + + if (vlanId != null + && !vlanId.equals(VlanId.NONE) + && confContainsVlans(vlanId, context.inPort())) { + vlanFlood(context.packet(), filteredVlanInterfaces, context.inPort); + return; + } + // The request couldn't be resolved. // Flood the request on all ports except the incoming port. flood(context.packet(), context.inPort()); } + private Set<Interface> filterVlanInterfacesNoIp(Set<Interface> vlanInterfaces) { + return vlanInterfaces + .stream() + .filter(intf -> intf.ipAddresses().isEmpty()) + .collect(Collectors.toSet()); + } + + /** + * States if the interface configuration contains more than one interface configured + * on a specific vlan, including the interface passed as argument. + * + * @param vlanId the vlanid to look for in the interface configuration + * @param connectPoint the connect point to exclude from the search + * @return true if interfaces are found. False otherwise + */ + private boolean confContainsVlans(VlanId vlanId, ConnectPoint connectPoint) { + Set<Interface> vlanInterfaces = interfaceService.getInterfacesByVlan(vlanId); + return interfaceService.getInterfacesByVlan(vlanId) + .stream() + .anyMatch(intf -> intf.connectPoint().equals(connectPoint) && intf.ipAddresses().isEmpty()) + && vlanInterfaces.size() > 1; + } + /** * Builds and sends a reply message given a request context and the resolved * MAC address to answer with. @@ -259,14 +298,29 @@ public class ProxyArpManager implements ProxyArpService { /** * Returns whether the given port has any IP addresses configured or not. * - * @param port the port to check + * @param connectPoint the port to check * @return true if the port has at least one IP address configured, - * otherwise false + * false otherwise + */ + private boolean hasIpAddress(ConnectPoint connectPoint) { + return interfaceService.getInterfacesByPort(connectPoint) + .stream() + .flatMap(intf -> intf.ipAddresses().stream()) + .findAny() + .isPresent(); + } + + /** + * Returns whether the given port has any VLAN configured or not. + * + * @param connectPoint the port to check + * @return true if the port has at least one VLAN configured, + * false otherwise */ - private boolean hasIpAddress(ConnectPoint port) { - return interfaceService.getInterfacesByPort(port) + private boolean hasVlan(ConnectPoint connectPoint) { + return interfaceService.getInterfacesByPort(connectPoint) .stream() - .map(intf -> intf.ipAddresses()) + .filter(intf -> !intf.vlan().equals(VlanId.NONE)) .findAny() .isPresent(); } @@ -322,6 +376,30 @@ public class ProxyArpManager implements ProxyArpService { } /** + * Flood the arp request at all edges on a specifc VLAN. + * + * @param request the arp request + * @param dsts the destination interfaces + * @param inPort the connect point the arp request was received on + */ + private void vlanFlood(Ethernet request, Set<Interface> dsts, ConnectPoint inPort) { + TrafficTreatment.Builder builder = null; + ByteBuffer buf = ByteBuffer.wrap(request.serialize()); + + for (Interface intf : dsts) { + ConnectPoint cPoint = intf.connectPoint(); + if (cPoint.equals(inPort)) { + continue; + } + + builder = DefaultTrafficTreatment.builder(); + builder.setOutput(cPoint.port()); + packetService.emit(new DefaultOutboundPacket(cPoint.deviceId(), + builder.build(), buf)); + } + } + + /** * Flood the arp request at all edges in the network. * * @param request the arp request @@ -332,7 +410,9 @@ public class ProxyArpManager implements ProxyArpService { ByteBuffer buf = ByteBuffer.wrap(request.serialize()); for (ConnectPoint connectPoint : edgeService.getEdgePoints()) { - if (hasIpAddress(connectPoint) || connectPoint.equals(inPort)) { + if (hasIpAddress(connectPoint) + || hasVlan(connectPoint) + || connectPoint.equals(inPort)) { continue; } diff --git a/framework/src/onos/core/net/src/main/java/org/onosproject/net/statistic/impl/FlowStatisticManager.java b/framework/src/onos/core/net/src/main/java/org/onosproject/net/statistic/impl/FlowStatisticManager.java index 6515ef31..f18c56dc 100644 --- a/framework/src/onos/core/net/src/main/java/org/onosproject/net/statistic/impl/FlowStatisticManager.java +++ b/framework/src/onos/core/net/src/main/java/org/onosproject/net/statistic/impl/FlowStatisticManager.java @@ -255,7 +255,7 @@ public class FlowStatisticManager implements FlowStatisticService { Instruction.Type instType) {
checkPermission(STATISTIC_READ);
- List<TypedFlowEntryWithLoad> retTFEL = new ArrayList<>();
+ List<TypedFlowEntryWithLoad> retTfel = new ArrayList<>();
Set<FlowEntry> currentStats;
Set<FlowEntry> previousStats;
@@ -264,11 +264,11 @@ public class FlowStatisticManager implements FlowStatisticService { synchronized (flowStatisticStore) {
currentStats = flowStatisticStore.getCurrentFlowStatistic(cp);
if (currentStats == null) {
- return retTFEL;
+ return retTfel;
}
previousStats = flowStatisticStore.getPreviousFlowStatistic(cp);
if (previousStats == null) {
- return retTFEL;
+ return retTfel;
}
// copy to local flow entry set
typedStatistics = new TypedStatistics(currentStats, previousStats);
@@ -291,7 +291,7 @@ public class FlowStatisticManager implements FlowStatisticService { List<TypedFlowEntryWithLoad> fel = typedFlowEntryLoadByInstInternal(cp, currentMap, previousMap,
isAllInstType, instType, TypedFlowEntryWithLoad.shortPollInterval());
if (fel.size() > 0) {
- retTFEL.addAll(fel);
+ retTfel.addAll(fel);
}
}
@@ -302,7 +302,7 @@ public class FlowStatisticManager implements FlowStatisticService { List<TypedFlowEntryWithLoad> fel = typedFlowEntryLoadByInstInternal(cp, currentMap, previousMap,
isAllInstType, instType, TypedFlowEntryWithLoad.shortPollInterval());
if (fel.size() > 0) {
- retTFEL.addAll(fel);
+ retTfel.addAll(fel);
}
}
@@ -313,7 +313,7 @@ public class FlowStatisticManager implements FlowStatisticService { List<TypedFlowEntryWithLoad> fel = typedFlowEntryLoadByInstInternal(cp, currentMap, previousMap,
isAllInstType, instType, TypedFlowEntryWithLoad.midPollInterval());
if (fel.size() > 0) {
- retTFEL.addAll(fel);
+ retTfel.addAll(fel);
}
}
@@ -324,7 +324,7 @@ public class FlowStatisticManager implements FlowStatisticService { List<TypedFlowEntryWithLoad> fel = typedFlowEntryLoadByInstInternal(cp, currentMap, previousMap,
isAllInstType, instType, TypedFlowEntryWithLoad.longPollInterval());
if (fel.size() > 0) {
- retTFEL.addAll(fel);
+ retTfel.addAll(fel);
}
}
@@ -335,11 +335,11 @@ public class FlowStatisticManager implements FlowStatisticService { List<TypedFlowEntryWithLoad> fel = typedFlowEntryLoadByInstInternal(cp, currentMap, previousMap,
isAllInstType, instType, TypedFlowEntryWithLoad.avgPollInterval());
if (fel.size() > 0) {
- retTFEL.addAll(fel);
+ retTfel.addAll(fel);
}
}
- return retTFEL;
+ return retTfel;
}
private List<TypedFlowEntryWithLoad> typedFlowEntryLoadByInstInternal(ConnectPoint cp,
diff --git a/framework/src/onos/core/net/src/test/java/org/onosproject/app/impl/ApplicationManagerTest.java b/framework/src/onos/core/net/src/test/java/org/onosproject/app/impl/ApplicationManagerTest.java index 1ce31ac3..a99fd216 100644 --- a/framework/src/onos/core/net/src/test/java/org/onosproject/app/impl/ApplicationManagerTest.java +++ b/framework/src/onos/core/net/src/test/java/org/onosproject/app/impl/ApplicationManagerTest.java @@ -15,6 +15,7 @@ */ package org.onosproject.app.impl; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import org.junit.After; import org.junit.Before; @@ -24,11 +25,11 @@ import org.onosproject.app.ApplicationListener; import org.onosproject.app.ApplicationState; import org.onosproject.app.ApplicationStoreAdapter; import org.onosproject.common.app.ApplicationArchive; +import org.onosproject.common.event.impl.TestEventDispatcher; import org.onosproject.core.Application; import org.onosproject.core.ApplicationId; import org.onosproject.core.DefaultApplication; import org.onosproject.core.DefaultApplicationId; -import org.onosproject.common.event.impl.TestEventDispatcher; import java.io.InputStream; import java.net.URI; @@ -36,7 +37,7 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; import static org.onosproject.app.ApplicationEvent.Type.*; import static org.onosproject.app.ApplicationState.ACTIVE; import static org.onosproject.app.ApplicationState.INSTALLED; @@ -53,6 +54,8 @@ public class ApplicationManagerTest { private ApplicationManager mgr = new ApplicationManager(); private ApplicationListener listener = new TestListener(); + private boolean deactivated = false; + @Before public void setUp() { injectEventDispatcher(mgr, new TestEventDispatcher()); @@ -88,6 +91,11 @@ public class ApplicationManagerTest { assertEquals("incorrect app count", 1, mgr.getApplications().size()); assertEquals("incorrect app", app, mgr.getApplication(APP_ID)); assertEquals("incorrect app state", INSTALLED, mgr.getState(APP_ID)); + mgr.registerDeactivateHook(app.id(), this::deactivateHook); + } + + private void deactivateHook() { + deactivated = true; } @Test @@ -102,6 +110,7 @@ public class ApplicationManagerTest { install(); mgr.activate(APP_ID); assertEquals("incorrect app state", ACTIVE, mgr.getState(APP_ID)); + assertFalse("preDeactivate hook wrongly called", deactivated); } @Test @@ -109,6 +118,7 @@ public class ApplicationManagerTest { activate(); mgr.deactivate(APP_ID); assertEquals("incorrect app state", INSTALLED, mgr.getState(APP_ID)); + assertTrue("preDeactivate hook not called", deactivated); } @@ -129,7 +139,7 @@ public class ApplicationManagerTest { @Override public Application create(InputStream appDescStream) { app = new DefaultApplication(APP_ID, VER, DESC, ORIGIN, ROLE, PERMS, - Optional.of(FURL), FEATURES); + Optional.of(FURL), FEATURES, ImmutableList.of()); state = INSTALLED; delegate.notify(new ApplicationEvent(APP_INSTALLED, app)); return app; @@ -168,6 +178,11 @@ public class ApplicationManagerTest { state = INSTALLED; delegate.notify(new ApplicationEvent(APP_DEACTIVATED, app)); } + + @Override + public ApplicationId getId(String name) { + return new DefaultApplicationId(0, name); + } } private class TestFeaturesService extends FeaturesServiceAdapter { diff --git a/framework/src/onos/core/net/src/test/java/org/onosproject/net/host/impl/HostManagerTest.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/host/impl/HostManagerTest.java index 92c6c931..c5a6cabd 100644 --- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/host/impl/HostManagerTest.java +++ b/framework/src/onos/core/net/src/test/java/org/onosproject/net/host/impl/HostManagerTest.java @@ -20,6 +20,7 @@ import com.google.common.collect.Sets; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.onlab.junit.TestTools; import org.onlab.packet.IpAddress; import org.onlab.packet.MacAddress; import org.onlab.packet.VlanId; @@ -129,13 +130,15 @@ public class HostManagerTest { } private void validateEvents(Enum... types) { - int i = 0; - assertEquals("wrong events received", types.length, listener.events.size()); - for (Event event : listener.events) { - assertEquals("incorrect event type", types[i], event.type()); - i++; - } - listener.events.clear(); + TestTools.assertAfter(100, () -> { + int i = 0; + assertEquals("wrong events received", types.length, listener.events.size()); + for (Event event : listener.events) { + assertEquals("incorrect event type", types[i], event.type()); + i++; + } + listener.events.clear(); + }); } @Test 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..eb7f2ccd 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<Event> 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, + ResourcePath.discrete(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..f5d3d0f3 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; @@ -89,7 +90,7 @@ class MockResourceService implements ResourceService { @Override public Collection<ResourcePath> getAvailableResources(ResourcePath parent) { - ResourcePath resource = ResourcePath.child(parent, MplsLabel.mplsLabel(10)); + ResourcePath resource = parent.child(MplsLabel.mplsLabel(10)); return ImmutableList.of(resource); } @@ -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/net/src/test/java/org/onosproject/net/proxyarp/impl/ProxyArpManagerTest.java b/framework/src/onos/core/net/src/test/java/org/onosproject/net/proxyarp/impl/ProxyArpManagerTest.java index 3e806a73..70fdb406 100644 --- a/framework/src/onos/core/net/src/test/java/org/onosproject/net/proxyarp/impl/ProxyArpManagerTest.java +++ b/framework/src/onos/core/net/src/test/java/org/onosproject/net/proxyarp/impl/ProxyArpManagerTest.java @@ -15,7 +15,6 @@ */ package org.onosproject.net.proxyarp.impl; -import com.google.common.collect.Lists; import com.google.common.collect.Sets; import org.junit.Before; import org.junit.Test; @@ -48,7 +47,7 @@ import org.onosproject.net.Port; import org.onosproject.net.PortNumber; import org.onosproject.net.device.DeviceListener; import org.onosproject.net.device.DeviceService; -import org.onosproject.net.edgeservice.impl.EdgeManager; +import org.onosproject.net.edge.EdgePortService; import org.onosproject.net.flow.DefaultTrafficTreatment; import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flow.instructions.Instruction; @@ -67,6 +66,7 @@ import org.onosproject.net.proxyarp.ProxyArpStoreDelegate; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -88,47 +88,65 @@ import static org.junit.Assert.assertTrue; */ public class ProxyArpManagerTest { - private static final int NUM_DEVICES = 6; + private static final int NUM_DEVICES = 10; private static final int NUM_PORTS_PER_DEVICE = 3; - private static final int NUM_ADDRESS_PORTS = NUM_DEVICES / 2; - private static final int NUM_FLOOD_PORTS = 3; + private static final int LAST_CONF_DEVICE_INTF_VLAN_IP = 3; + private static final int LAST_CONF_DEVICE_INTF_VLAN = 6; private static final Ip4Address IP1 = Ip4Address.valueOf("192.168.1.1"); private static final Ip4Address IP2 = Ip4Address.valueOf("192.168.1.2"); - private static final Ip6Address IP3 = Ip6Address.valueOf("1000::1"); - private static final Ip6Address IP4 = Ip6Address.valueOf("1000::2"); + private static final Ip6Address IP3 = Ip6Address.valueOf("1000:ffff::1"); + private static final Ip6Address IP4 = Ip6Address.valueOf("1000:ffff::2"); private static final ProviderId PID = new ProviderId("of", "foo"); private static final VlanId VLAN1 = VlanId.vlanId((short) 1); private static final VlanId VLAN2 = VlanId.vlanId((short) 2); - private static final MacAddress MAC1 = MacAddress.valueOf("00:00:11:00:00:01"); - private static final MacAddress MAC2 = MacAddress.valueOf("00:00:22:00:00:02"); - private static final MacAddress MAC3 = MacAddress.valueOf("00:00:33:00:00:03"); - private static final MacAddress MAC4 = MacAddress.valueOf("00:00:44:00:00:04"); + private static final VlanId VLAN10 = VlanId.vlanId((short) 10); + + private static final MacAddress MAC1 = MacAddress.valueOf("00:00:00:00:00:01"); + private static final MacAddress MAC2 = MacAddress.valueOf("00:00:00:00:00:02"); + private static final MacAddress MAC3 = MacAddress.valueOf("00:00:00:00:00:03"); + private static final MacAddress MAC4 = MacAddress.valueOf("00:00:00:00:00:04"); + private static final MacAddress MAC10 = MacAddress.valueOf("00:00:00:00:00:0A"); + private static final MacAddress SOLICITED_MAC3 = MacAddress.valueOf("33:33:FF:00:00:01"); + private static final HostId HID1 = HostId.hostId(MAC1, VLAN1); private static final HostId HID2 = HostId.hostId(MAC2, VLAN1); private static final HostId HID3 = HostId.hostId(MAC3, VLAN1); private static final HostId HID4 = HostId.hostId(MAC4, VLAN1); + private static final HostId HID10 = HostId.hostId(MAC10, VLAN10); + private static final HostId SOLICITED_HID3 = HostId.hostId(SOLICITED_MAC3, VLAN1); private static final DeviceId DID1 = getDeviceId(1); private static final DeviceId DID2 = getDeviceId(2); + private static final PortNumber P1 = PortNumber.portNumber(1); + private static final HostLocation LOC1 = new HostLocation(DID1, P1, 123L); private static final HostLocation LOC2 = new HostLocation(DID2, P1, 123L); - private static final byte[] ZERO_MAC_ADDRESS = MacAddress.ZERO.toBytes(); - //Return values used for various functions of the TestPacketService inner class. - private boolean isEdgePointReturn; - private List<ConnectPoint> getEdgePointsNoArg; + private final byte[] zeroMacAddress = MacAddress.ZERO.toBytes(); + + // The first three devices in the topology have interfaces configured + // with VLANs and IPs + private final List<ConnectPoint> configIpCPoints = new ArrayList<>(); + // Other three devices in the topology (from 4 to 6) have interfaces + // configured only with VLANs + private final List<ConnectPoint> configVlanCPoints = new ArrayList<>(); + + // Remaining devices in the network (id > 6) don't have any interface + // configured. + private final List<ConnectPoint> noConfigCPoints = new ArrayList<>(); private ProxyArpManager proxyArp; private TestPacketService packetService; private DeviceService deviceService; + private EdgePortService edgePortService; private LinkService linkService; private HostService hostService; private InterfaceService interfaceService; @@ -140,20 +158,27 @@ public class ProxyArpManagerTest { proxyArp.packetService = packetService; proxyArp.store = new TestProxyArpStoreAdapter(); - proxyArp.edgeService = new TestEdgePortService(); - - // Create a host service mock here. Must be replayed by tests once the - // expectations have been set up + // Create a host service mock here. hostService = createMock(HostService.class); proxyArp.hostService = hostService; + // Create an edge port service. + edgePortService = createMock(EdgePortService.class); + proxyArp.edgeService = edgePortService; + + // Create interface service interfaceService = createMock(InterfaceService.class); proxyArp.interfaceService = interfaceService; + // Create the topology createTopology(); proxyArp.deviceService = deviceService; proxyArp.linkService = linkService; + setupNoConfigCPoints(); + setupconfigIpCPoints(); + setupconfigVlanCPoints(); + proxyArp.activate(); } @@ -176,7 +201,8 @@ public class ProxyArpManagerTest { createDevices(NUM_DEVICES, NUM_PORTS_PER_DEVICE); createLinks(NUM_DEVICES); - addAddressBindings(); + addIntfConfig(); + popluateEdgePortService(); } /** @@ -237,13 +263,22 @@ public class ProxyArpManagerTest { replay(linkService); } - private void addAddressBindings() { + /** + * On the first three devices two config interfaces are binded on port 1. + * The first one with VLAN1, the second one with VLAN equals to none. + * Both interfaces have an IP. + * On devices 4, 5 and 6 it's binded a config interface on port 1. + * The interface is configured with VLAN 1 and no IP. + */ + private void addIntfConfig() { Set<Interface> interfaces = Sets.newHashSet(); - for (int i = 1; i <= NUM_ADDRESS_PORTS; i++) { + Set<Interface> vlanOneSet = new HashSet<>(); + + for (int i = 1; i <= LAST_CONF_DEVICE_INTF_VLAN_IP; i++) { ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); - // Interface address for IPv4 + // Interface addresses for IPv4 Ip4Prefix prefix1 = Ip4Prefix.valueOf("10.0." + (2 * i - 1) + ".0/24"); Ip4Address addr1 = Ip4Address.valueOf("10.0." + (2 * i - 1) + ".1"); Ip4Prefix prefix2 = Ip4Prefix.valueOf("10.0." + (2 * i) + ".0/24"); @@ -251,39 +286,131 @@ public class ProxyArpManagerTest { InterfaceIpAddress ia1 = new InterfaceIpAddress(addr1, prefix1); InterfaceIpAddress ia2 = new InterfaceIpAddress(addr2, prefix2); - // Interface address for IPv6 + // Interface addresses for IPv6 Ip6Prefix prefix3 = Ip6Prefix.valueOf((2 * i - 1) + "000::0/64"); Ip6Address addr3 = Ip6Address.valueOf((2 * i - 1) + "000::1"); Ip6Prefix prefix4 = Ip6Prefix.valueOf((2 * i) + "000::0/64"); - Ip6Address addr4 = Ip6Address.valueOf((2 * i) + "000::1"); + Ip6Address addr4 = Ip6Address.valueOf((2 * i) + "000::2"); InterfaceIpAddress ia3 = new InterfaceIpAddress(addr3, prefix3); InterfaceIpAddress ia4 = new InterfaceIpAddress(addr4, prefix4); + // Setting up interfaces Interface intf1 = new Interface(cp, Sets.newHashSet(ia1, ia3), MacAddress.valueOf(2 * i - 1), VlanId.vlanId((short) 1)); Interface intf2 = new Interface(cp, Sets.newHashSet(ia2, ia4), MacAddress.valueOf(2 * i), VlanId.NONE); + interfaces.add(intf1); interfaces.add(intf2); + vlanOneSet.add(intf1); + expect(interfaceService.getInterfacesByPort(cp)) .andReturn(Sets.newHashSet(intf1, intf2)).anyTimes(); } + for (int i = LAST_CONF_DEVICE_INTF_VLAN_IP + 1; i <= LAST_CONF_DEVICE_INTF_VLAN; i++) { + ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); + Interface intf1 = new Interface(cp, null, + MacAddress.NONE, + VlanId.vlanId((short) 1)); + + interfaces.add(intf1); + vlanOneSet.add(intf1); + expect(interfaceService.getInterfacesByPort(cp)) + .andReturn(Sets.newHashSet(intf1)).anyTimes(); + } + expect(interfaceService.getInterfacesByVlan(VLAN1)) + .andReturn(vlanOneSet).anyTimes(); + expect(interfaceService.getInterfacesByVlan(VLAN10)) + .andReturn(Collections.emptySet()).anyTimes(); expect(interfaceService.getInterfaces()).andReturn(interfaces).anyTimes(); - for (int i = 1; i <= NUM_FLOOD_PORTS; i++) { - ConnectPoint cp = new ConnectPoint(getDeviceId(i + NUM_ADDRESS_PORTS), + for (int i = LAST_CONF_DEVICE_INTF_VLAN + 1; i <= NUM_DEVICES; i++) { + ConnectPoint cp = new ConnectPoint(getDeviceId(i), P1); - expect(interfaceService.getInterfacesByPort(cp)) .andReturn(Collections.emptySet()).anyTimes(); } } /** + * Populates edge ports in the EdgePortService to return all port 1 + * as edge ports. + */ + private void popluateEdgePortService() { + Set<ConnectPoint> edgeConnectPoints = new HashSet<>(); + + for (int i = 1; i <= NUM_DEVICES; i++) { + for (int j = 1; j <= NUM_PORTS_PER_DEVICE; j++) { + ConnectPoint edgeConnectPoint = new ConnectPoint( + getDeviceId(i), + PortNumber.portNumber(1)); + ConnectPoint noEdgeConnectPointOne = new ConnectPoint( + getDeviceId(i), + PortNumber.portNumber(2)); + ConnectPoint noEdgeConnectPointTwo = new ConnectPoint( + getDeviceId(i), + PortNumber.portNumber(3)); + + edgeConnectPoints.add(edgeConnectPoint); + + expect(edgePortService.isEdgePoint(edgeConnectPoint)) + .andReturn(true).anyTimes(); + expect(edgePortService.isEdgePoint(noEdgeConnectPointOne)) + .andReturn(false).anyTimes(); + expect(edgePortService.isEdgePoint(noEdgeConnectPointTwo)) + .andReturn(false).anyTimes(); + } + } + expect(edgePortService.getEdgePoints()) + .andReturn(edgeConnectPoints).anyTimes(); + + replay(edgePortService); + } + + /** + * Creates a list of connect points used to verify floodling on ports + * with no interfaces configured (all ports without interface config). + */ + private void setupNoConfigCPoints() { + for (int i = NUM_DEVICES / 2 + 2; i <= NUM_DEVICES; i++) { + ConnectPoint connectPoint = new ConnectPoint( + getDeviceId(i), + PortNumber.portNumber(1)); + noConfigCPoints.add(connectPoint); + } + } + + /** + * Creates a list of connect points used to verify floodling on ports + * with interfaces configured (both VLAN and IP). + */ + private void setupconfigIpCPoints() { + for (int i = 1; i <= 3; i++) { + ConnectPoint connectPoint = new ConnectPoint( + getDeviceId(i), + PortNumber.portNumber(1)); + configIpCPoints.add(connectPoint); + } + } + + /** + * Creates a list of connect points used to verify floodling on ports + * with interfaces configured (both VLAN and IP). + */ + private void setupconfigVlanCPoints() { + for (int i = LAST_CONF_DEVICE_INTF_VLAN_IP + 1; i <= LAST_CONF_DEVICE_INTF_VLAN; i++) { + ConnectPoint connectPoint = new ConnectPoint( + getDeviceId(i), + PortNumber.portNumber(1)); + configVlanCPoints.add(connectPoint); + } + } + + /** * Tests {@link ProxyArpManager#isKnown(org.onlab.packet.IpAddress)} in the * case where the IP address is not known. * Verifies the method returns false. @@ -318,33 +445,34 @@ public class ProxyArpManagerTest { /** * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the * destination host is known. - * Verifies the correct ARP reply is sent out the correct port. + * Two host using the same VLAN are registered on the host service on devices 5 and 6. + * Host on port 6 asks for the MAC of the device on port 5. + * Since the destination mac address is known, the request is not flooded to anywhere + * and ONOS directly builds an ARP reply, sended back to the requester on device 6. + * It's verified that a proper ARP reply is received on port 1 of device 6. */ @Test public void testReplyKnown() { - //Set the return value of isEdgePoint from the edgemanager. - isEdgePointReturn = true; - - Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(4), + Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(NUM_DEVICES), Collections.singleton(IP1)); - Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), + Host replyer = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(NUM_DEVICES - 1), Collections.singleton(IP2)); - expect(hostService.getHostsByIp(IP1)) + expect(hostService.getHostsByIp(IP2)) .andReturn(Collections.singleton(replyer)); - expect(hostService.getHost(HID2)).andReturn(requestor); + expect(hostService.getHost(HID1)).andReturn(requestor); replay(hostService); replay(interfaceService); - Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2); - proxyArp.reply(arpRequest, getLocation(5)); + proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); assertEquals(1, packetService.packets.size()); - Ethernet arpReply = buildArp(ARP.OP_REPLY, MAC1, MAC2, IP1, IP2); - verifyPacketOut(arpReply, getLocation(5), packetService.packets.get(0)); + Ethernet arpReply = buildArp(ARP.OP_REPLY, VLAN1, MAC2, MAC1, IP2, IP1); + verifyPacketOut(arpReply, getLocation(NUM_DEVICES), packetService.packets.get(0)); } /** @@ -354,9 +482,6 @@ public class ProxyArpManagerTest { */ @Test public void testReplyKnownIpv6() { - //Set the return value of isEdgePoint from the edgemanager. - isEdgePointReturn = true; - Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN1, getLocation(4), Collections.singleton(IP3)); @@ -370,49 +495,46 @@ public class ProxyArpManagerTest { replay(hostService); replay(interfaceService); - Ethernet ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, - MAC4, SOLICITED_MAC3, - IP4, IP3); + Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, + MAC4, SOLICITED_MAC3, + IP4, IP3); proxyArp.reply(ndpRequest, getLocation(5)); assertEquals(1, packetService.packets.size()); - Ethernet ndpReply = buildNDP(ICMP6.NEIGHBOR_ADVERTISEMENT, - MAC3, MAC4, IP3, IP4); + Ethernet ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT, + MAC3, MAC4, IP3, IP4); verifyPacketOut(ndpReply, getLocation(5), packetService.packets.get(0)); } /** * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the * destination host is not known. + * Only a requestor is present (on device 6, port 1). The device has a VLAN configured + * which is not configured anywhere in the system. + * Since the destination is not known, and since the ARP request can't be sent out of + * interfaces configured, the ARP request is flooded out of ports 4 and 5. * Verifies the ARP request is flooded out the correct edge ports. */ @Test public void testReplyUnknown() { - isEdgePointReturn = true; - - Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), - Collections.singleton(IP2)); + Host requestor = new DefaultHost(PID, HID10, MAC10, VLAN10, getLocation(NUM_DEVICES), + Collections.singleton(IP1)); - expect(hostService.getHostsByIp(IP1)) + expect(hostService.getHostsByIp(IP2)) .andReturn(Collections.emptySet()); - expect(interfaceService.getInterfacesByIp(IP2)) + expect(interfaceService.getInterfacesByIp(IP1)) .andReturn(Collections.emptySet()); - expect(hostService.getHost(HID2)).andReturn(requestor); + expect(hostService.getHost(HID10)).andReturn(requestor); replay(hostService); replay(interfaceService); - Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); - - //Setup the set of edge ports to be used in the reply method - getEdgePointsNoArg = Lists.newLinkedList(); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN10, MAC10, null, IP1, IP2); - proxyArp.reply(arpRequest, getLocation(6)); + proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); - verifyFlood(arpRequest); + verifyFlood(arpRequest, noConfigCPoints); } /** @@ -422,9 +544,7 @@ public class ProxyArpManagerTest { */ @Test public void testReplyUnknownIpv6() { - isEdgePointReturn = true; - - Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(5), + Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(NUM_DEVICES), Collections.singleton(IP4)); expect(hostService.getHostsByIp(IP3)) @@ -436,53 +556,111 @@ public class ProxyArpManagerTest { replay(hostService); replay(interfaceService); - Ethernet ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, - MAC4, SOLICITED_MAC3, - IP4, IP3); - - //Setup the set of edge ports to be used in the reply method - getEdgePointsNoArg = Lists.newLinkedList(); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); + Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, + MAC4, SOLICITED_MAC3, + IP4, IP3); - proxyArp.reply(ndpRequest, getLocation(6)); + proxyArp.reply(ndpRequest, getLocation(NUM_DEVICES)); - verifyFlood(ndpRequest); + verifyFlood(ndpRequest, noConfigCPoints); } /** * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the * destination host is known for that IP address, but is not on the same * VLAN as the source host. + * An host is connected on device 6, port 1 where no interfaces are defined. It sends + * ARP requests from VLAN10, not configured anywhere in the network. Another host with + * the IP address requested lives on device 5, port 1 in the network. Anyway, since the + * host uses another VLAN it's not found and the ARP packet is flooded out of port + * 4 and 5. + * * Verifies the ARP request is flooded out the correct edge ports. */ @Test public void testReplyDifferentVlan() { - - Host replyer = new DefaultHost(PID, HID1, MAC1, VLAN2, getLocation(4), + Host requestor = new DefaultHost(PID, HID10, MAC10, VLAN10, getLocation(NUM_DEVICES), Collections.singleton(IP1)); - Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, getLocation(5), + Host replyer = new DefaultHost(PID, HID2, MAC2, VLAN2, getLocation(NUM_DEVICES - 1), Collections.singleton(IP2)); - expect(hostService.getHostsByIp(IP1)) + expect(hostService.getHostsByIp(IP2)) .andReturn(Collections.singleton(replyer)); - expect(interfaceService.getInterfacesByIp(IP2)) + expect(interfaceService.getInterfacesByIp(IP1)) .andReturn(Collections.emptySet()); - expect(hostService.getHost(HID2)).andReturn(requestor); + expect(hostService.getHost(HID10)).andReturn(requestor); + + replay(hostService); + replay(interfaceService); + + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN10, MAC10, null, IP1, IP2); + + proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); + + verifyFlood(arpRequest, noConfigCPoints); + } + + /** + * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the + * a vlan packet comes in from a port without interfaces configured. The destination + * host is unknown for that IP address and there are some interfaces configured on + * the same vlan. + * It's expected to see the ARP request going out through ports with no interfaces + * configured, devices 4 and 5, port 1. + * + * Verifies the ARP request is flooded out the correct edge ports. + */ + @Test + public void testConfiguredVlan() { + Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(NUM_DEVICES), + Collections.singleton(IP1)); + + expect(hostService.getHostsByIp(IP2)) + .andReturn(Collections.emptySet()); + expect(interfaceService.getInterfacesByIp(IP1)) + .andReturn(Collections.emptySet()); + expect(hostService.getHost(HID1)).andReturn(requestor); + + replay(hostService); + replay(interfaceService); + + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2); + + proxyArp.reply(arpRequest, getLocation(NUM_DEVICES)); + + verifyFlood(arpRequest, noConfigCPoints); + } + + /** + * Tests {@link ProxyArpManager#reply(Ethernet, ConnectPoint)} in the case where the + * a vlan packet comes in from a port without interfaces configured. The destination + * host is not known for that IP address and there are some interfaces configured on + * the same vlan. + * It's expected to see the ARP request going out through ports with no interfaces + * configured, devices 4 and 5, port 1. + * + * Verifies the ARP request is flooded out the correct edge ports. + */ + @Test + public void testConfiguredVlanOnInterfaces() { + Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, getLocation(6), + Collections.singleton(IP1)); + + expect(hostService.getHostsByIp(IP2)) + .andReturn(Collections.emptySet()); + expect(interfaceService.getInterfacesByIp(IP1)) + .andReturn(Collections.emptySet()); + expect(hostService.getHost(HID1)).andReturn(requestor); replay(hostService); replay(interfaceService); - Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, IP2, IP1); + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, IP1, IP2); - //Setup for flood test - getEdgePointsNoArg = Lists.newLinkedList(); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); proxyArp.reply(arpRequest, getLocation(6)); - verifyFlood(arpRequest); + verifyFlood(arpRequest, configVlanCPoints); } /** @@ -493,13 +671,12 @@ public class ProxyArpManagerTest { */ @Test public void testReplyDifferentVlanIpv6() { - - Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN2, getLocation(4), - Collections.singleton(IP3)); - - Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(5), + Host requestor = new DefaultHost(PID, HID4, MAC4, VLAN1, getLocation(NUM_DEVICES), Collections.singleton(IP4)); + Host replyer = new DefaultHost(PID, HID3, MAC3, VLAN2, getLocation(NUM_DEVICES - 1), + Collections.singleton(IP3)); + expect(hostService.getHostsByIp(IP3)) .andReturn(Collections.singleton(replyer)); expect(interfaceService.getInterfacesByIp(IP4)) @@ -509,17 +686,13 @@ public class ProxyArpManagerTest { replay(hostService); replay(interfaceService); - Ethernet ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, - MAC4, SOLICITED_MAC3, - IP4, IP3); + Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, + MAC4, SOLICITED_MAC3, + IP4, IP3); - //Setup for flood test - getEdgePointsNoArg = Lists.newLinkedList(); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); - proxyArp.reply(ndpRequest, getLocation(6)); + proxyArp.reply(ndpRequest, getLocation(NUM_DEVICES)); - verifyFlood(ndpRequest); + verifyFlood(ndpRequest, noConfigCPoints); } /** @@ -533,29 +706,29 @@ public class ProxyArpManagerTest { MacAddress firstMac = MacAddress.valueOf(1L); MacAddress secondMac = MacAddress.valueOf(2L); - Host requestor = new DefaultHost(PID, HID2, MAC2, VLAN1, LOC1, + Host requestor = new DefaultHost(PID, HID1, MAC1, VLAN1, LOC1, Collections.singleton(theirIp)); - expect(hostService.getHost(HID2)).andReturn(requestor); + expect(hostService.getHost(HID1)).andReturn(requestor); replay(hostService); replay(interfaceService); - Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, theirIp, ourFirstIp); - isEdgePointReturn = true; + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourFirstIp); + proxyArp.reply(arpRequest, LOC1); assertEquals(1, packetService.packets.size()); - Ethernet arpReply = buildArp(ARP.OP_REPLY, firstMac, MAC2, ourFirstIp, theirIp); + Ethernet arpReply = buildArp(ARP.OP_REPLY, VLAN1, firstMac, MAC1, ourFirstIp, theirIp); verifyPacketOut(arpReply, LOC1, packetService.packets.get(0)); // Test a request for the second address on that port packetService.packets.clear(); - arpRequest = buildArp(ARP.OP_REQUEST, MAC2, null, theirIp, ourSecondIp); + arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, ourSecondIp); proxyArp.reply(arpRequest, LOC1); assertEquals(1, packetService.packets.size()); - arpReply = buildArp(ARP.OP_REPLY, secondMac, MAC2, ourSecondIp, theirIp); + arpReply = buildArp(ARP.OP_REPLY, VLAN1, secondMac, MAC1, ourSecondIp, theirIp); verifyPacketOut(arpReply, LOC1, packetService.packets.get(0)); } @@ -566,7 +739,7 @@ public class ProxyArpManagerTest { public void testReplyToRequestForUsIpv6() { Ip6Address theirIp = Ip6Address.valueOf("1000::ffff"); Ip6Address ourFirstIp = Ip6Address.valueOf("1000::1"); - Ip6Address ourSecondIp = Ip6Address.valueOf("2000::1"); + Ip6Address ourSecondIp = Ip6Address.valueOf("2000::2"); MacAddress firstMac = MacAddress.valueOf(1L); MacAddress secondMac = MacAddress.valueOf(2L); @@ -579,37 +752,37 @@ public class ProxyArpManagerTest { replay(hostService); replay(interfaceService); - Ethernet ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, - MAC2, - MacAddress.valueOf("33:33:ff:00:00:01"), - theirIp, - ourFirstIp); - isEdgePointReturn = true; + Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, + MAC2, + MacAddress.valueOf("33:33:ff:00:00:01"), + theirIp, + ourFirstIp); + proxyArp.reply(ndpRequest, LOC1); assertEquals(1, packetService.packets.size()); - Ethernet ndpReply = buildNDP(ICMP6.NEIGHBOR_ADVERTISEMENT, - firstMac, - MAC2, - ourFirstIp, - theirIp); + Ethernet ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT, + firstMac, + MAC2, + ourFirstIp, + theirIp); verifyPacketOut(ndpReply, LOC1, packetService.packets.get(0)); // Test a request for the second address on that port packetService.packets.clear(); - ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, - MAC2, - MacAddress.valueOf("33:33:ff:00:00:01"), - theirIp, - ourSecondIp); + ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, + MAC2, + MacAddress.valueOf("33:33:ff:00:00:01"), + theirIp, + ourSecondIp); proxyArp.reply(ndpRequest, LOC1); assertEquals(1, packetService.packets.size()); - ndpReply = buildNDP(ICMP6.NEIGHBOR_ADVERTISEMENT, - secondMac, - MAC2, - ourSecondIp, - theirIp); + ndpReply = buildNdp(ICMP6.NEIGHBOR_ADVERTISEMENT, + secondMac, + MAC2, + ourSecondIp, + theirIp); verifyPacketOut(ndpReply, LOC1, packetService.packets.get(0)); } @@ -624,14 +797,14 @@ public class ProxyArpManagerTest { Ip4Address theirIp = Ip4Address.valueOf("10.0.1.254"); // Request for a valid external IP address but coming in the wrong port - Ethernet arpRequest = buildArp(ARP.OP_REQUEST, MAC1, null, theirIp, + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, Ip4Address.valueOf("10.0.3.1")); proxyArp.reply(arpRequest, LOC1); assertEquals(0, packetService.packets.size()); // Request for a valid internal IP address but coming in an external port packetService.packets.clear(); - arpRequest = buildArp(ARP.OP_REQUEST, MAC1, null, theirIp, IP1); + arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, MAC1, null, theirIp, IP1); proxyArp.reply(arpRequest, LOC1); assertEquals(0, packetService.packets.size()); } @@ -646,21 +819,21 @@ public class ProxyArpManagerTest { Ip6Address theirIp = Ip6Address.valueOf("1000::ffff"); - Ethernet ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, - MAC1, - MacAddress.valueOf("33:33:ff:00:00:01"), - theirIp, - Ip6Address.valueOf("3000::1")); + Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, + MAC1, + MacAddress.valueOf("33:33:ff:00:00:01"), + theirIp, + Ip6Address.valueOf("3000::1")); proxyArp.reply(ndpRequest, LOC1); assertEquals(0, packetService.packets.size()); // Request for a valid internal IP address but coming in an external port packetService.packets.clear(); - ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, - MAC1, - MacAddress.valueOf("33:33:ff:00:00:01"), - theirIp, - IP3); + ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, + MAC1, + MacAddress.valueOf("33:33:ff:00:00:01"), + theirIp, + IP3); proxyArp.reply(ndpRequest, LOC1); assertEquals(0, packetService.packets.size()); } @@ -685,9 +858,8 @@ public class ProxyArpManagerTest { // This is a request from something inside our network (like a BGP // daemon) to an external host. - Ethernet arpRequest = buildArp(ARP.OP_REQUEST, ourMac, null, ourIp, theirIp); + Ethernet arpRequest = buildArp(ARP.OP_REQUEST, VLAN1, ourMac, null, ourIp, theirIp); //Ensure the packet is allowed through (it is not to an internal port) - isEdgePointReturn = true; proxyArp.reply(arpRequest, getLocation(5)); assertEquals(1, packetService.packets.size()); @@ -722,14 +894,11 @@ public class ProxyArpManagerTest { // This is a request from something inside our network (like a BGP // daemon) to an external host. - Ethernet ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, - ourMac, - MacAddress.valueOf("33:33:ff:00:00:01"), - ourIp, - theirIp); - - //Ensure the packet is allowed through (it is not to an internal port) - isEdgePointReturn = true; + Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, + ourMac, + MacAddress.valueOf("33:33:ff:00:00:01"), + ourIp, + theirIp); proxyArp.reply(ndpRequest, getLocation(5)); assertEquals(1, packetService.packets.size()); @@ -758,7 +927,7 @@ public class ProxyArpManagerTest { replay(hostService); replay(interfaceService); - Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1); + Ethernet arpRequest = buildArp(ARP.OP_REPLY, VLAN1, MAC2, MAC1, IP2, IP1); proxyArp.forward(arpRequest, LOC2); @@ -785,9 +954,9 @@ public class ProxyArpManagerTest { replay(hostService); replay(interfaceService); - Ethernet ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, - MAC4, SOLICITED_MAC3, - IP4, IP3); + Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, + MAC4, SOLICITED_MAC3, + IP4, IP3); proxyArp.forward(ndpRequest, LOC2); @@ -804,22 +973,15 @@ public class ProxyArpManagerTest { */ @Test public void testForwardFlood() { - expect(hostService.getHost(HID1)).andReturn(null); + expect(hostService.getHost(HID2)).andReturn(null); replay(hostService); replay(interfaceService); - Ethernet arpRequest = buildArp(ARP.OP_REPLY, MAC2, MAC1, IP2, IP1); - - //populate the list of edges when so that when forward hits flood in the manager it contains the values - //that should continue on - getEdgePointsNoArg = Lists.newLinkedList(); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("3"), PortNumber.portNumber(1))); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); + Ethernet arpRequest = buildArp(ARP.OP_REPLY, VLAN1, MAC1, MAC2, IP1, IP2); - proxyArp.forward(arpRequest, getLocation(6)); + proxyArp.forward(arpRequest, getLocation(NUM_DEVICES)); - verifyFlood(arpRequest); + verifyFlood(arpRequest, noConfigCPoints); } /** @@ -833,20 +995,13 @@ public class ProxyArpManagerTest { replay(hostService); replay(interfaceService); - Ethernet ndpRequest = buildNDP(ICMP6.NEIGHBOR_SOLICITATION, - MAC4, SOLICITED_MAC3, - IP4, IP3); + Ethernet ndpRequest = buildNdp(ICMP6.NEIGHBOR_SOLICITATION, + MAC4, SOLICITED_MAC3, + IP4, IP3); - //populate the list of edges when so that when forward hits flood in the manager it contains the values - //that should continue on - getEdgePointsNoArg = Lists.newLinkedList(); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("3"), PortNumber.portNumber(1))); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("5"), PortNumber.portNumber(1))); - getEdgePointsNoArg.add(new ConnectPoint(DeviceId.deviceId("4"), PortNumber.portNumber(1))); + proxyArp.forward(ndpRequest, getLocation(NUM_DEVICES)); - proxyArp.forward(ndpRequest, getLocation(6)); - - verifyFlood(ndpRequest); + verifyFlood(ndpRequest, noConfigCPoints); } /** @@ -854,21 +1009,20 @@ public class ProxyArpManagerTest { * except for the input port. * * @param packet the packet that was expected to be flooded + * @param connectPoints the connectPoints where the outpacket should be + * observed */ - private void verifyFlood(Ethernet packet) { + private void verifyFlood(Ethernet packet, List<ConnectPoint> connectPoints) { + // There should be 1 less than NUM_FLOOD_PORTS; the inPort should be excluded. - assertEquals(NUM_FLOOD_PORTS - 1, packetService.packets.size()); + assertEquals(connectPoints.size() - 1, packetService.packets.size()); Collections.sort(packetService.packets, (o1, o2) -> o1.sendThrough().uri().compareTo(o2.sendThrough().uri())); - - for (int i = 0; i < NUM_FLOOD_PORTS - 1; i++) { - ConnectPoint cp = new ConnectPoint(getDeviceId(NUM_ADDRESS_PORTS + i + 1), - PortNumber.portNumber(1)); - + for (int i = 0; i < connectPoints.size() - 1; i++) { OutboundPacket outboundPacket = packetService.packets.get(i); - verifyPacketOut(packet, cp, outboundPacket); + verifyPacketOut(packet, connectPoints.get(i), outboundPacket); } } @@ -913,8 +1067,8 @@ public class ProxyArpManagerTest { * @param dstIp destination IP address * @return the ARP packet */ - private Ethernet buildArp(short opcode, MacAddress srcMac, MacAddress dstMac, - Ip4Address srcIp, Ip4Address dstIp) { + private Ethernet buildArp(short opcode, VlanId vlanId, MacAddress srcMac, + MacAddress dstMac, Ip4Address srcIp, Ip4Address dstIp) { Ethernet eth = new Ethernet(); if (dstMac == null) { @@ -925,7 +1079,7 @@ public class ProxyArpManagerTest { eth.setSourceMACAddress(srcMac); eth.setEtherType(Ethernet.TYPE_ARP); - eth.setVlanID(VLAN1.toShort()); + eth.setVlanID(vlanId.toShort()); ARP arp = new ARP(); arp.setOpCode(opcode); @@ -937,7 +1091,7 @@ public class ProxyArpManagerTest { arp.setSenderHardwareAddress(srcMac.toBytes()); if (dstMac == null) { - arp.setTargetHardwareAddress(ZERO_MAC_ADDRESS); + arp.setTargetHardwareAddress(zeroMacAddress); } else { arp.setTargetHardwareAddress(dstMac.toBytes()); } @@ -959,7 +1113,7 @@ public class ProxyArpManagerTest { * @param dstIp destination IP address * @return the NDP packet */ - private Ethernet buildNDP(byte type, MacAddress srcMac, MacAddress dstMac, + private Ethernet buildNdp(byte type, MacAddress srcMac, MacAddress dstMac, Ip6Address srcIp, Ip6Address dstIp) { assertThat(type, anyOf( is(ICMP6.NEIGHBOR_SOLICITATION), @@ -1019,19 +1173,6 @@ public class ProxyArpManagerTest { } - class TestEdgePortService extends EdgeManager { - - @Override - public boolean isEdgePoint(ConnectPoint connectPoint) { - return isEdgePointReturn; - } - - @Override - public Iterable<ConnectPoint> getEdgePoints() { - return getEdgePointsNoArg; - } - } - private class TestProxyArpStoreAdapter implements ProxyArpStore { @Override public void forward(ConnectPoint outPort, Host subject, ByteBuffer packet) { diff --git a/framework/src/onos/core/store/dist/pom.xml b/framework/src/onos/core/store/dist/pom.xml index f2ec2a71..0b8b72bc 100644 --- a/framework/src/onos/core/store/dist/pom.xml +++ b/framework/src/onos/core/store/dist/pom.xml @@ -69,6 +69,12 @@ </dependency> <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-core-persistence</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> <groupId>org.mapdb</groupId> <artifactId>mapdb</artifactId> <version>1.0.8</version> @@ -110,5 +116,4 @@ <artifactId>onlab-thirdparty</artifactId> </dependency> </dependencies> - </project> diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/app/GossipApplicationStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/app/GossipApplicationStore.java index 6764c222..fe4aa0be 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/app/GossipApplicationStore.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/app/GossipApplicationStore.java @@ -17,7 +17,9 @@ package org.onosproject.store.app; import com.google.common.base.Charsets; import com.google.common.collect.ImmutableSet; - +import com.google.common.collect.Maps; +import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; @@ -37,6 +39,7 @@ import org.onosproject.common.app.ApplicationArchive; import org.onosproject.core.Application; import org.onosproject.core.ApplicationId; import org.onosproject.core.ApplicationIdStore; +import org.onosproject.core.CoreService; import org.onosproject.core.DefaultApplication; import org.onosproject.security.Permission; import org.onosproject.store.cluster.messaging.ClusterCommunicationService; @@ -61,6 +64,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.function.Function; +import static com.google.common.collect.Multimaps.newSetMultimap; +import static com.google.common.collect.Multimaps.synchronizedSetMultimap; import static com.google.common.io.ByteStreams.toByteArray; import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.onlab.util.Tools.groupedThreads; @@ -115,6 +120,14 @@ public class GossipApplicationStore extends ApplicationArchive @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected ApplicationIdStore idStore; + // Multimap to track which apps are required by others apps + // app -> { required-by, ... } + // Apps explicitly activated will be required by the CORE app + private final Multimap<ApplicationId, ApplicationId> requiredBy = + synchronizedSetMultimap(newSetMultimap(Maps.newHashMap(), Sets::newHashSet)); + + private ApplicationId coreAppId; + @Activate public void activate() { KryoNamespace.Builder serializer = KryoNamespace.newBuilder() @@ -128,16 +141,16 @@ public class GossipApplicationStore extends ApplicationArchive groupedThreads("onos/store/app", "message-handler")); clusterCommunicator.<String, byte[]>addSubscriber(APP_BITS_REQUEST, - bytes -> new String(bytes, Charsets.UTF_8), - name -> { - try { - return toByteArray(getApplicationInputStream(name)); - } catch (IOException e) { - throw new StorageException(e); - } - }, - Function.identity(), - messageHandlingExecutor); + bytes -> new String(bytes, Charsets.UTF_8), + name -> { + try { + return toByteArray(getApplicationInputStream(name)); + } catch (IOException e) { + throw new StorageException(e); + } + }, + Function.identity(), + messageHandlingExecutor); // FIXME: Consider consolidating into a single map. @@ -161,6 +174,7 @@ public class GossipApplicationStore extends ApplicationArchive .withTimestampProvider((k, v) -> clockService.getTimestamp()) .build(); + coreAppId = getId(CoreService.CORE_APP_NAME); log.info("Started"); } @@ -169,20 +183,34 @@ public class GossipApplicationStore extends ApplicationArchive * they are marked to be active. */ private void loadFromDisk() { - for (String name : getApplicationNames()) { - for (int i = 0; i < MAX_LOAD_RETRIES; i++) { - try { - Application app = create(getApplicationDescription(name), false); - if (app != null && isActive(app.id().name())) { - activate(app.id(), false); - // load app permissions - } - } catch (Exception e) { - log.warn("Unable to load application {} from disk; retrying", name); - randomDelay(RETRY_DELAY_MS); // FIXME: This is a deliberate hack; fix in Drake + getApplicationNames().forEach(appName -> { + Application app = loadFromDisk(appName); + if (app != null && isActive(app.id().name())) { + activate(app.id(), false); + // TODO Load app permissions + } + }); + } + + private Application loadFromDisk(String appName) { + for (int i = 0; i < MAX_LOAD_RETRIES; i++) { + try { + // Directly return if app already exists + ApplicationId appId = getId(appName); + if (appId != null) { + return getApplication(appId); } + + ApplicationDescription appDesc = getApplicationDescription(appName); + boolean success = appDesc.requiredApps().stream() + .noneMatch(requiredApp -> loadFromDisk(requiredApp) == null); + return success ? create(appDesc, false) : null; + } catch (Exception e) { + log.warn("Unable to load application {} from disk; retrying", appName); + randomDelay(RETRY_DELAY_MS); //FIXME: This is a deliberate hack; fix in Falcon } } + return null; } @Deactivate @@ -200,7 +228,6 @@ public class GossipApplicationStore extends ApplicationArchive public void setDelegate(ApplicationStoreDelegate delegate) { super.setDelegate(delegate); loadFromDisk(); -// executor.schedule(this::pruneUninstalledApps, LOAD_TIMEOUT_MS, MILLISECONDS); } @Override @@ -229,7 +256,15 @@ public class GossipApplicationStore extends ApplicationArchive @Override public Application create(InputStream appDescStream) { ApplicationDescription appDesc = saveApplication(appDescStream); - return create(appDesc, true); + if (hasPrerequisites(appDesc)) { + return create(appDesc, true); + } + throw new ApplicationException("Missing dependencies for app " + appDesc.name()); + } + + private boolean hasPrerequisites(ApplicationDescription app) { + return !app.requiredApps().stream().map(n -> getId(n)) + .anyMatch(id -> id == null || getApplication(id) == null); } private Application create(ApplicationDescription appDesc, boolean updateTime) { @@ -246,36 +281,80 @@ public class GossipApplicationStore extends ApplicationArchive public void remove(ApplicationId appId) { Application app = apps.get(appId); if (app != null) { + uninstallDependentApps(app); apps.remove(appId); states.remove(app); permissions.remove(app); } } + // Uninstalls all apps that depend on the given app. + private void uninstallDependentApps(Application app) { + getApplications().stream() + .filter(a -> a.requiredApps().contains(app.id().name())) + .forEach(a -> remove(a.id())); + } + @Override public void activate(ApplicationId appId) { + activate(appId, coreAppId); + } + + private void activate(ApplicationId appId, ApplicationId forAppId) { + requiredBy.put(appId, forAppId); activate(appId, true); } + private void activate(ApplicationId appId, boolean updateTime) { Application app = apps.get(appId); if (app != null) { if (updateTime) { updateTime(appId.name()); } + activateRequiredApps(app); states.put(app, ACTIVATED); } } + // Activates all apps required by this application. + private void activateRequiredApps(Application app) { + app.requiredApps().stream().map(this::getId).forEach(id -> activate(id, app.id())); + } + @Override public void deactivate(ApplicationId appId) { - Application app = apps.get(appId); - if (app != null) { - updateTime(appId.name()); - states.put(app, DEACTIVATED); + deactivateDependentApps(getApplication(appId)); + deactivate(appId, coreAppId); + } + + private void deactivate(ApplicationId appId, ApplicationId forAppId) { + requiredBy.remove(appId, forAppId); + if (requiredBy.get(appId).isEmpty()) { + Application app = apps.get(appId); + if (app != null) { + updateTime(appId.name()); + states.put(app, DEACTIVATED); + deactivateRequiredApps(app); + } } } + // Deactivates all apps that require this application. + private void deactivateDependentApps(Application app) { + getApplications().stream() + .filter(a -> states.get(a) == ACTIVATED) + .filter(a -> a.requiredApps().contains(app.id().name())) + .forEach(a -> deactivate(a.id())); + } + + // Deactivates all apps required by this application. + private void deactivateRequiredApps(Application app) { + app.requiredApps().stream().map(this::getId).map(this::getApplication) + .filter(a -> states.get(a) == ACTIVATED) + .forEach(a -> deactivate(a.id(), app.id())); + } + @Override public Set<Permission> getPermissions(ApplicationId appId) { Application app = apps.get(appId); @@ -424,6 +503,7 @@ public class GossipApplicationStore extends ApplicationArchive ApplicationId appId = idStore.registerApplication(appDesc.name()); return new DefaultApplication(appId, appDesc.version(), appDesc.description(), appDesc.origin(), appDesc.role(), appDesc.permissions(), - appDesc.featuresRepo(), appDesc.features()); + appDesc.featuresRepo(), appDesc.features(), + appDesc.requiredApps()); } } 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..3cd992bb 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 @@ -7,6 +7,7 @@ import static org.slf4j.LoggerFactory.getLogger; import java.io.File; import java.io.IOException; import java.net.InetAddress; +import java.net.Inet4Address; import java.net.NetworkInterface; import java.util.Arrays; import java.util.Collection; @@ -55,6 +56,11 @@ 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 ONOS_ALLOW_IPV6 = "ONOS_ALLOW_IPV6"; + 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,28 +200,59 @@ 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; + } + + // Capture if they want to limit IP address selection to only IPv4 (default). + boolean allowIPv6 = (System.getenv(ONOS_ALLOW_IPV6) != null); + Function<NetworkInterface, IpAddress> ipLookup = nif -> { - for (InetAddress address : Collections.list(nif.getInetAddresses())) { - if (address.isSiteLocalAddress()) { - return IpAddress.valueOf(address); + IpAddress fallback = null; + + // nif can be null if the interface name specified doesn't exist on the node's host + if (nif != null) { + for (InetAddress address : Collections.list(nif.getInetAddresses())) { + if (address.isSiteLocalAddress() && (allowIPv6 || address instanceof Inet4Address)) { + return IpAddress.valueOf(address); + } + if (fallback == null && !address.isLoopbackAddress() && !address.isMulticastAddress() + && (allowIPv6 || address instanceof Inet4Address)) { + fallback = IpAddress.valueOf(address); + } } } - return null; + return fallback; }; try { - IpAddress ip = ipLookup.apply(NetworkInterface.getByName("eth0")); + IpAddress ip = ipLookup.apply(NetworkInterface.getByName(useOnosInterface)); if (ip != null) { return ip.toString(); } for (NetworkInterface nif : Collections.list(getNetworkInterfaces())) { - ip = ipLookup.apply(nif); - if (ip != null) { - return ip.toString(); + if (!nif.getName().equals(useOnosInterface)) { + ip = ipLookup.apply(nif); + if (ip != null) { + return ip.toString(); + } } } } catch (Exception e) { throw new IllegalStateException("Unable to get network interfaces", e); } + 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/cluster/messaging/impl/NettyMessagingManager.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/NettyMessagingManager.java index 23c81869..d61d7dcf 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/NettyMessagingManager.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/cluster/messaging/impl/NettyMessagingManager.java @@ -47,7 +47,7 @@ public class NettyMessagingManager extends NettyMessaging { @Activate public void activate() throws Exception { ControllerNode localNode = clusterMetadataService.getLocalNode(); - getTLSParameters(); + getTlsParameters(); super.start(new Endpoint(localNode.ip(), localNode.tcpPort())); log.info("Started"); } @@ -58,29 +58,29 @@ public class NettyMessagingManager extends NettyMessaging { log.info("Stopped"); } - private void getTLSParameters() { + private void getTlsParameters() { String tempString = System.getProperty("enableNettyTLS"); - enableNettyTLS = Strings.isNullOrEmpty(tempString) ? TLS_DISABLED : Boolean.parseBoolean(tempString); - log.info("enableNettyTLS = {}", enableNettyTLS); - if (enableNettyTLS) { + enableNettyTls = Strings.isNullOrEmpty(tempString) ? TLS_DISABLED : Boolean.parseBoolean(tempString); + log.info("enableNettyTLS = {}", enableNettyTls); + if (enableNettyTls) { ksLocation = System.getProperty("javax.net.ssl.keyStore"); if (Strings.isNullOrEmpty(ksLocation)) { - enableNettyTLS = TLS_DISABLED; + enableNettyTls = TLS_DISABLED; return; } tsLocation = System.getProperty("javax.net.ssl.trustStore"); if (Strings.isNullOrEmpty(tsLocation)) { - enableNettyTLS = TLS_DISABLED; + enableNettyTls = TLS_DISABLED; return; } ksPwd = System.getProperty("javax.net.ssl.keyStorePassword").toCharArray(); if (MIN_KS_LENGTH > ksPwd.length) { - enableNettyTLS = TLS_DISABLED; + enableNettyTls = TLS_DISABLED; return; } tsPwd = System.getProperty("javax.net.ssl.trustStorePassword").toCharArray(); if (MIN_KS_LENGTH > tsPwd.length) { - enableNettyTLS = TLS_DISABLED; + enableNettyTls = TLS_DISABLED; return; } } diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java index 3e73d8f4..ca8eea37 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java @@ -60,6 +60,7 @@ import java.util.Map; import java.util.Objects; import java.util.Set; +import static com.google.common.base.Preconditions.checkArgument; import static org.onosproject.net.config.NetworkConfigEvent.Type.*; /** @@ -71,10 +72,12 @@ public class DistributedNetworkConfigStore extends AbstractStore<NetworkConfigEvent, NetworkConfigStoreDelegate> implements NetworkConfigStore { - private static final int MAX_BACKOFF = 10; - private final Logger log = LoggerFactory.getLogger(getClass()); + private static final int MAX_BACKOFF = 10; + private static final String INVALID_CONFIG_JSON = + "JSON node does not contain valid configuration"; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected StorageService storageService; @@ -187,8 +190,17 @@ public class DistributedNetworkConfigStore @Override public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, JsonNode json) { - return createConfig(subject, configClass, - configs.putAndGet(key(subject, configClass), json).value()); + // Create the configuration and validate it. + C config = createConfig(subject, configClass, json); + checkArgument(config.isValid(), INVALID_CONFIG_JSON); + + // Insert the validated configuration and get it back. + Versioned<JsonNode> versioned = configs.putAndGet(key(subject, configClass), json); + + // Re-create the config if for some reason what we attempted to put + // was supplanted by someone else already. + return versioned.value() == json ? config : + createConfig(subject, configClass, versioned.value()); } @Override diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/AsyncCachingConsistentMap.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/AsyncCachingConsistentMap.java index 7e575b01..92db5b44 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/AsyncCachingConsistentMap.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/AsyncCachingConsistentMap.java @@ -26,8 +26,12 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; /** - * Extension of DefaultAsyncConsistentMap that provides a weaker read consistency + * Extension of {@link DefaultAsyncConsistentMap} that provides a weaker read consistency * guarantee in return for better read performance. + * <p> + * For read/write operations that are local to a node this map implementation provides + * guarantees similar to a ConsistentMap. However for read/write operations executed + * across multiple nodes this implementation only provides eventual consistency. * * @param <K> key type * @param <V> value type @@ -68,4 +72,10 @@ public class AsyncCachingConsistentMap<K, V> extends DefaultAsyncConsistentMap<K } return cache.getUnchecked(key); } + + @Override + protected void beforeUpdate(K key) { + super.beforeUpdate(key); + cache.invalidate(key); + } }
\ No newline at end of file diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DatabaseManager.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DatabaseManager.java index 3e89635a..90d81ee7 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DatabaseManager.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DatabaseManager.java @@ -55,6 +55,7 @@ import org.onosproject.cluster.ControllerNode; import org.onosproject.cluster.NodeId; import org.onosproject.core.ApplicationId; import org.onosproject.core.IdGenerator; +import org.onosproject.persistence.PersistenceService; import org.onosproject.store.cluster.messaging.ClusterCommunicationService; import org.onosproject.store.ecmap.EventuallyConsistentMapBuilderImpl; import org.onosproject.store.service.AtomicCounterBuilder; @@ -128,6 +129,9 @@ public class DatabaseManager implements StorageService, StorageAdminService { @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected ClusterCommunicationService clusterCommunicator; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected PersistenceService persistenceService; + protected String nodeIdToUri(NodeId nodeId) { ControllerNode node = clusterService.getNode(nodeId); return String.format("onos://%s:%d", node.ip(), node.tcpPort()); @@ -312,7 +316,8 @@ public class DatabaseManager implements StorageService, StorageAdminService { @Override public <K, V> EventuallyConsistentMapBuilder<K, V> eventuallyConsistentMapBuilder() { return new EventuallyConsistentMapBuilderImpl<>(clusterService, - clusterCommunicator); + clusterCommunicator, + persistenceService); } @Override diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DefaultAsyncConsistentMap.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DefaultAsyncConsistentMap.java index 0ea66861..c6d300c9 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DefaultAsyncConsistentMap.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DefaultAsyncConsistentMap.java @@ -405,6 +405,14 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V .thenApply(v -> v.updated()); } + /** + * Pre-update hook for performing required checks/actions before going forward with an update operation. + * @param key map key. + */ + protected void beforeUpdate(K key) { + checkIfUnmodifiable(); + } + private Map.Entry<K, Versioned<V>> mapRawEntry(Map.Entry<String, Versioned<byte[]>> e) { return Maps.immutableEntry(dK(e.getKey()), e.getValue().<V>map(serializer::decode)); } @@ -413,7 +421,7 @@ public class DefaultAsyncConsistentMap<K, V> implements AsyncConsistentMap<K, V Match<V> oldValueMatch, Match<Long> oldVersionMatch, V value) { - checkIfUnmodifiable(); + beforeUpdate(key); return database.mapUpdate(name, keyCache.getUnchecked(key), oldValueMatch.map(serializer::encode), diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java index 687762e0..a9a9098e 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/device/impl/GossipDeviceStore.java @@ -986,6 +986,10 @@ public class GossipDeviceStore // accept removal request if given timestamp is newer than // the latest Timestamp from Primary provider DeviceDescriptions primDescs = getPrimaryDescriptions(descs); + if (primDescs == null) { + return null; + } + Timestamp lastTimestamp = primDescs.getLatestTimestamp(); if (timestamp.compareTo(lastTimestamp) <= 0) { // outdated event ignore @@ -1036,7 +1040,7 @@ public class GossipDeviceStore checkArgument(!providerDescs.isEmpty(), "No device descriptions supplied"); - ProviderId primary = pickPrimaryPID(providerDescs); + ProviderId primary = pickPrimaryPid(providerDescs); DeviceDescriptions desc = providerDescs.get(primary); @@ -1099,7 +1103,7 @@ public class GossipDeviceStore private Port composePort(Device device, PortNumber number, Map<ProviderId, DeviceDescriptions> descsMap) { - ProviderId primary = pickPrimaryPID(descsMap); + ProviderId primary = pickPrimaryPid(descsMap); DeviceDescriptions primDescs = descsMap.get(primary); // if no primary, assume not enabled boolean isEnabled = false; @@ -1145,7 +1149,7 @@ public class GossipDeviceStore /** * @return primary ProviderID, or randomly chosen one if none exists */ - private ProviderId pickPrimaryPID( + private ProviderId pickPrimaryPid( Map<ProviderId, DeviceDescriptions> providerDescs) { ProviderId fallBackPrimary = null; for (Entry<ProviderId, DeviceDescriptions> e : providerDescs.entrySet()) { @@ -1161,7 +1165,7 @@ public class GossipDeviceStore private DeviceDescriptions getPrimaryDescriptions( Map<ProviderId, DeviceDescriptions> providerDescs) { - ProviderId pid = pickPrimaryPID(providerDescs); + ProviderId pid = pickPrimaryPid(providerDescs); return providerDescs.get(pid); } diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapBuilderImpl.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapBuilderImpl.java index a553ffff..eb98c829 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapBuilderImpl.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapBuilderImpl.java @@ -18,6 +18,7 @@ package org.onosproject.store.ecmap; import org.onlab.util.KryoNamespace; import org.onosproject.cluster.ClusterService; import org.onosproject.cluster.NodeId; +import org.onosproject.persistence.PersistenceService; import org.onosproject.store.Timestamp; import org.onosproject.store.cluster.messaging.ClusterCommunicationService; import org.onosproject.store.service.EventuallyConsistentMap; @@ -52,6 +53,8 @@ public class EventuallyConsistentMapBuilderImpl<K, V> private TimeUnit antiEntropyTimeUnit = TimeUnit.SECONDS; private boolean convergeFaster = false; private boolean persistent = false; + private boolean persistentMap = false; + private final PersistenceService persistenceService; /** * Creates a new eventually consistent map builder. @@ -60,7 +63,9 @@ public class EventuallyConsistentMapBuilderImpl<K, V> * @param clusterCommunicator cluster communication service */ public EventuallyConsistentMapBuilderImpl(ClusterService clusterService, - ClusterCommunicationService clusterCommunicator) { + ClusterCommunicationService clusterCommunicator, + PersistenceService persistenceService) { + this.persistenceService = persistenceService; this.clusterService = checkNotNull(clusterService); this.clusterCommunicator = checkNotNull(clusterCommunicator); } @@ -133,6 +138,7 @@ public class EventuallyConsistentMapBuilderImpl<K, V> @Override public EventuallyConsistentMapBuilder<K, V> withPersistence() { + checkNotNull(this.persistenceService); persistent = true; return this; } @@ -156,6 +162,7 @@ public class EventuallyConsistentMapBuilderImpl<K, V> antiEntropyPeriod, antiEntropyTimeUnit, convergeFaster, - persistent); + persistent, + persistenceService); } } diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapImpl.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapImpl.java index f1e0dbd4..b5ea52e0 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapImpl.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/ecmap/EventuallyConsistentMapImpl.java @@ -28,6 +28,7 @@ import org.onlab.util.SlidingWindowCounter; import org.onosproject.cluster.ClusterService; import org.onosproject.cluster.ControllerNode; import org.onosproject.cluster.NodeId; +import org.onosproject.persistence.PersistenceService; import org.onosproject.store.Timestamp; import org.onosproject.store.cluster.messaging.ClusterCommunicationService; import org.onosproject.store.cluster.messaging.MessageSubject; @@ -37,6 +38,7 @@ import org.onosproject.store.serializers.KryoSerializer; import org.onosproject.store.service.EventuallyConsistentMap; import org.onosproject.store.service.EventuallyConsistentMapEvent; import org.onosproject.store.service.EventuallyConsistentMapListener; +import org.onosproject.store.service.Serializer; import org.onosproject.store.service.WallClockTimestamp; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -81,6 +83,7 @@ public class EventuallyConsistentMapImpl<K, V> private final ClusterCommunicationService clusterCommunicator; private final KryoSerializer serializer; private final NodeId localNodeId; + private final PersistenceService persistenceService; private final BiFunction<K, V, Timestamp> timestampProvider; @@ -116,7 +119,9 @@ public class EventuallyConsistentMapImpl<K, V> private SlidingWindowCounter counter = new SlidingWindowCounter(WINDOW_SIZE); private final boolean persistent; - private final PersistentStore<K, V> persistentStore; + + private static final String PERSISTENT_LOCAL_MAP_NAME = "itemsMap"; + /** * Creates a new eventually consistent map shared amongst multiple instances. @@ -158,9 +163,32 @@ public class EventuallyConsistentMapImpl<K, V> long antiEntropyPeriod, TimeUnit antiEntropyTimeUnit, boolean convergeFaster, - boolean persistent) { + boolean persistent, + PersistenceService persistenceService) { this.mapName = mapName; - items = Maps.newConcurrentMap(); + this.serializer = createSerializer(serializerBuilder); + this.persistenceService = persistenceService; + this.persistent = + persistent; + if (persistent) { + items = this.persistenceService.<K, MapValue<V>>persistentMapBuilder() + .withName(PERSISTENT_LOCAL_MAP_NAME) + .withSerializer(new Serializer() { + + @Override + public <T> byte[] encode(T object) { + return EventuallyConsistentMapImpl.this.serializer.encode(object); + } + + @Override + public <T> T decode(byte[] bytes) { + return EventuallyConsistentMapImpl.this.serializer.decode(bytes); + } + }) + .build(); + } else { + items = Maps.newConcurrentMap(); + } senderPending = Maps.newConcurrentMap(); destroyedMessage = mapName + ERROR_DESTROYED; @@ -168,8 +196,6 @@ public class EventuallyConsistentMapImpl<K, V> this.clusterCommunicator = clusterCommunicator; this.localNodeId = clusterService.getLocalNode().id(); - this.serializer = createSerializer(serializerBuilder); - this.timestampProvider = timestampProvider; if (peerUpdateFunction != null) { @@ -198,20 +224,6 @@ public class EventuallyConsistentMapImpl<K, V> newFixedThreadPool(8, groupedThreads("onos/ecm", mapName + "-publish-%d")); } - this.persistent = persistent; - - if (this.persistent) { - String dataDirectory = System.getProperty("karaf.data", "./data"); - String filename = dataDirectory + "/" + "mapdb-ecm-" + mapName; - - ExecutorService dbExecutor = - newFixedThreadPool(1, groupedThreads("onos/ecm", mapName + "-dbwriter")); - - persistentStore = new MapDbPersistentStore<>(filename, dbExecutor, serializer); - persistentStore.readInto(items); - } else { - this.persistentStore = null; - } if (backgroundExecutor != null) { this.backgroundExecutor = backgroundExecutor; @@ -373,15 +385,6 @@ public class EventuallyConsistentMapImpl<K, V> return existing; } }); - if (updated.get()) { - if (persistent) { - if (tombstone.isPresent()) { - persistentStore.update(key, tombstone.get()); - } else { - persistentStore.remove(key); - } - } - } return previousValue.get(); } @@ -455,6 +458,7 @@ public class EventuallyConsistentMapImpl<K, V> /** * Returns true if newValue was accepted i.e. map is updated. + * * @param key key * @param newValue proposed new value * @return true if update happened; false if map already contains a more recent value for the key @@ -473,9 +477,6 @@ public class EventuallyConsistentMapImpl<K, V> } return existing; }); - if (updated.get() && persistent) { - persistentStore.update(key, newValue); - } return updated.get(); } diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/flow/impl/NewDistributedFlowRuleStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/flow/impl/NewDistributedFlowRuleStore.java index 8cd63e7d..1695e5ff 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/flow/impl/NewDistributedFlowRuleStore.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/flow/impl/NewDistributedFlowRuleStore.java @@ -59,6 +59,7 @@ import org.onosproject.net.flow.FlowRuleStore; import org.onosproject.net.flow.FlowRuleStoreDelegate; import org.onosproject.net.flow.StoredFlowEntry; import org.onosproject.net.flow.TableStatisticsEntry; +import org.onosproject.persistence.PersistenceService; import org.onosproject.store.AbstractStore; import org.onosproject.store.cluster.messaging.ClusterCommunicationService; import org.onosproject.store.cluster.messaging.ClusterMessage; @@ -74,6 +75,7 @@ import org.onosproject.store.serializers.custom.DistributedStoreSerializers; import org.onosproject.store.service.EventuallyConsistentMap; import org.onosproject.store.service.EventuallyConsistentMapEvent; import org.onosproject.store.service.EventuallyConsistentMapListener; +import org.onosproject.store.service.Serializer; import org.onosproject.store.service.StorageService; import org.onosproject.store.service.WallClockTimestamp; import org.osgi.service.component.ComponentContext; @@ -113,6 +115,7 @@ public class NewDistributedFlowRuleStore private static final int MESSAGE_HANDLER_THREAD_POOL_SIZE = 8; private static final boolean DEFAULT_BACKUP_ENABLED = true; + private static final boolean DEFAULT_PERSISTENCE_ENABLED = false; private static final int DEFAULT_BACKUP_PERIOD_MILLIS = 2000; private static final long FLOW_RULE_STORE_TIMEOUT_MILLIS = 5000; // number of devices whose flow entries will be backed up in one communication round @@ -129,6 +132,9 @@ public class NewDistributedFlowRuleStore @Property(name = "backupPeriod", intValue = DEFAULT_BACKUP_PERIOD_MILLIS, label = "Delay in ms between successive backup runs") private int backupPeriod = DEFAULT_BACKUP_PERIOD_MILLIS; + @Property(name = "persistenceEnabled", boolValue = false, + label = "Indicates whether or not changes in the flow table should be persisted to disk.") + private boolean persistenceEnabled = DEFAULT_PERSISTENCE_ENABLED; private InternalFlowTable flowTable = new InternalFlowTable(); @@ -153,6 +159,9 @@ public class NewDistributedFlowRuleStore @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected MastershipService mastershipService; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected PersistenceService persistenceService; + private Map<Long, NodeId> pendingResponses = Maps.newConcurrentMap(); private ExecutorService messageHandlingExecutor; @@ -716,7 +725,25 @@ public class NewDistributedFlowRuleStore * @return Map representing Flow Table of given device. */ private Map<FlowId, Set<StoredFlowEntry>> getFlowTable(DeviceId deviceId) { - return flowEntries.computeIfAbsent(deviceId, id -> Maps.newConcurrentMap()); + if (persistenceEnabled) { + return flowEntries.computeIfAbsent(deviceId, id -> persistenceService + .<FlowId, Set<StoredFlowEntry>>persistentMapBuilder() + .withName("FlowTable:" + deviceId.toString()) + .withSerializer(new Serializer() { + @Override + public <T> byte[] encode(T object) { + return SERIALIZER.encode(object); + } + + @Override + public <T> T decode(byte[] bytes) { + return SERIALIZER.decode(bytes); + } + }) + .build()); + } else { + return flowEntries.computeIfAbsent(deviceId, id -> Maps.newConcurrentMap()); + } } private Set<StoredFlowEntry> getFlowEntriesInternal(DeviceId deviceId, FlowId flowId) { diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/host/impl/ECHostStore.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/host/impl/ECHostStore.java index f9c96891..20124576 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/host/impl/ECHostStore.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/host/impl/ECHostStore.java @@ -19,8 +19,8 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static org.onosproject.net.DefaultAnnotations.merge; import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED; -import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED; import static org.onosproject.net.host.HostEvent.Type.HOST_MOVED; +import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED; import static org.onosproject.net.host.HostEvent.Type.HOST_UPDATED; import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.PUT; import static org.onosproject.store.service.EventuallyConsistentMapEvent.Type.REMOVE; @@ -28,9 +28,10 @@ import static org.slf4j.LoggerFactory.getLogger; import java.util.Collection; import java.util.HashSet; +import java.util.Map; import java.util.Objects; import java.util.Set; -import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -56,7 +57,6 @@ import org.onosproject.net.host.HostDescription; import org.onosproject.net.host.HostEvent; import org.onosproject.net.host.HostStore; import org.onosproject.net.host.HostStoreDelegate; -import org.onosproject.net.host.HostEvent.Type; import org.onosproject.net.provider.ProviderId; import org.onosproject.store.AbstractStore; import org.onosproject.store.serializers.KryoNamespaces; @@ -67,10 +67,7 @@ import org.onosproject.store.service.LogicalClockService; import org.onosproject.store.service.StorageService; import org.slf4j.Logger; -import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Multimaps; -import com.google.common.collect.SetMultimap; import com.google.common.collect.Sets; /** @@ -90,13 +87,11 @@ public class ECHostStore @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected LogicalClockService clockService; - // Hosts tracked by their location - private final SetMultimap<ConnectPoint, Host> locations = - Multimaps.synchronizedSetMultimap( - HashMultimap.<ConnectPoint, Host>create()); - private EventuallyConsistentMap<HostId, DefaultHost> hosts; + private final ConcurrentHashMap<HostId, DefaultHost> prevHosts = + new ConcurrentHashMap<>(); + private EventuallyConsistentMapListener<HostId, DefaultHost> hostLocationTracker = new HostLocationTracker(); @@ -120,11 +115,12 @@ public class ECHostStore public void deactivate() { hosts.removeListener(hostLocationTracker); hosts.destroy(); - locations.clear(); + prevHosts.clear(); log.info("Stopped"); } + // TODO No longer need to return HostEvent @Override public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, @@ -133,18 +129,7 @@ public class ECHostStore // TODO: We need a way to detect conflicting changes and abort update. // (BOC) Compute might do this for us. - final AtomicReference<Type> eventType = new AtomicReference<>(); - final AtomicReference<DefaultHost> oldHost = new AtomicReference<>(); - DefaultHost host = hosts.compute(hostId, (id, existingHost) -> { - if (existingHost != null) { - oldHost.set(existingHost); - checkState(Objects.equals(hostDescription.hwAddress(), existingHost.mac()), - "Existing and new MAC addresses differ."); - checkState(Objects.equals(hostDescription.vlan(), existingHost.vlan()), - "Existing and new VLANs differ."); - } - - // TODO do we ever want the existing location? + hosts.compute(hostId, (id, existingHost) -> { HostLocation location = hostDescription.location(); final Set<IpAddress> addresses; @@ -163,15 +148,6 @@ public class ECHostStore annotations = hostDescription.annotations(); } - if (existingHost == null) { - eventType.set(HOST_ADDED); - } else if (!Objects.equals(existingHost.location(), hostDescription.location())) { - eventType.set(HOST_MOVED); - } else if (!existingHost.ipAddresses().containsAll(hostDescription.ipAddress()) || - !hostDescription.annotations().keys().isEmpty()) { - eventType.set(HOST_UPDATED); - } // else, eventType == null; this means we don't send an event - return new DefaultHost(providerId, hostId, hostDescription.hwAddress(), @@ -181,24 +157,20 @@ public class ECHostStore annotations); }); - if (oldHost.get() != null) { - DefaultHost old = oldHost.get(); - locations.remove(old.location(), old); - } - locations.put(host.location(), host); - - return eventType.get() != null ? new HostEvent(eventType.get(), host) : null; + return null; } + // TODO No longer need to return HostEvent @Override public HostEvent removeHost(HostId hostId) { - Host host = hosts.remove(hostId); - return host != null ? new HostEvent(HOST_REMOVED, host) : null; + hosts.remove(hostId); + return null; } + // TODO No longer need to return HostEvent @Override public HostEvent removeIp(HostId hostId, IpAddress ipAddress) { - DefaultHost host = hosts.compute(hostId, (id, existingHost) -> { + hosts.compute(hostId, (id, existingHost) -> { if (existingHost != null) { checkState(Objects.equals(hostId.mac(), existingHost.mac()), "Existing and new MAC addresses differ."); @@ -222,7 +194,7 @@ public class ECHostStore } return null; }); - return host != null ? new HostEvent(HOST_UPDATED, host) : null; + return null; } @Override @@ -257,22 +229,19 @@ public class ECHostStore @Override public Set<Host> getConnectedHosts(ConnectPoint connectPoint) { - synchronized (locations) { - return ImmutableSet.copyOf(locations.get(connectPoint)); - } + Set<Host> filtered = hosts.entrySet().stream() + .filter(entry -> entry.getValue().location().equals(connectPoint)) + .map(Map.Entry::getValue) + .collect(Collectors.toSet()); + return ImmutableSet.copyOf(filtered); } @Override public Set<Host> getConnectedHosts(DeviceId deviceId) { - Set<Host> filtered; - synchronized (locations) { - filtered = locations - .entries() - .stream() - .filter(entry -> entry.getKey().deviceId().equals(deviceId)) - .map(entry -> entry.getValue()) - .collect(Collectors.toSet()); - } + Set<Host> filtered = hosts.entrySet().stream() + .filter(entry -> entry.getValue().location().deviceId().equals(deviceId)) + .map(Map.Entry::getValue) + .collect(Collectors.toSet()); return ImmutableSet.copyOf(filtered); } @@ -285,13 +254,18 @@ public class ECHostStore public void event(EventuallyConsistentMapEvent<HostId, DefaultHost> event) { DefaultHost host = checkNotNull(event.value()); if (event.type() == PUT) { - boolean isNew = locations.put(host.location(), host); - notifyDelegate(new HostEvent(isNew ? HOST_ADDED : HOST_UPDATED, host)); + Host prevHost = prevHosts.put(host.id(), host); + if (prevHost == null) { + notifyDelegate(new HostEvent(HOST_ADDED, host)); + } else if (!Objects.equals(prevHost.location(), host.location())) { + notifyDelegate(new HostEvent(HOST_MOVED, host, prevHost)); + } else if (!Objects.equals(prevHost, host)) { + notifyDelegate(new HostEvent(HOST_UPDATED, host, prevHost)); + } } else if (event.type() == REMOVE) { - if (locations.remove(host.location(), host)) { + if (prevHosts.remove(host.id()) != null) { notifyDelegate(new HostEvent(HOST_REMOVED, host)); } - } } } diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/impl/LogicalTimestamp.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/impl/LogicalTimestamp.java index 9382960f..dfee9980 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/impl/LogicalTimestamp.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/impl/LogicalTimestamp.java @@ -50,7 +50,7 @@ public class LogicalTimestamp implements Timestamp { @Override public int hashCode() { - return Objects.hash(value); + return Long.hashCode(value); } @Override diff --git a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/intent/impl/PartitionId.java b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/intent/impl/PartitionId.java index 885361f0..f6cd198f 100644 --- a/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/intent/impl/PartitionId.java +++ b/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/intent/impl/PartitionId.java @@ -56,7 +56,7 @@ public class PartitionId { @Override public int hashCode() { - return Objects.hash(id); + return id; } @Override 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 687576c3..0335ba5d 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,20 +16,23 @@ 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; import org.onosproject.store.service.StorageService; import org.onosproject.store.service.TransactionContext; -import org.onosproject.store.service.TransactionException; import org.onosproject.store.service.TransactionalMap; import org.onosproject.store.service.Versioned; import org.slf4j.Logger; @@ -48,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. @@ -55,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<ResourceEvent, ResourceStoreDelegate> + implements ResourceStore { private static final Logger log = LoggerFactory.getLogger(ConsistentResourceStore.class); private static final String CONSUMER_MAP = "onos-resource-consumers"; @@ -79,6 +84,8 @@ public class ConsistentResourceStore implements ResourceStore { .withName(CHILD_MAP) .withSerializer(SERIALIZER) .build(); + + childMap.put(ResourcePath.ROOT, ImmutableList.of()); } @Override @@ -100,29 +107,32 @@ public class ConsistentResourceStore implements ResourceStore { TransactionContext tx = service.transactionContextBuilder().build(); tx.begin(); - try { - TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = - tx.getTransactionalMap(CHILD_MAP, SERIALIZER); + TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = + tx.getTransactionalMap(CHILD_MAP, SERIALIZER); - Map<ResourcePath, List<ResourcePath>> resourceMap = resources.stream() - .filter(x -> x.parent().isPresent()) - .collect(Collectors.groupingBy(x -> x.parent().get())); + Map<ResourcePath, List<ResourcePath>> resourceMap = resources.stream() + .filter(x -> x.parent().isPresent()) + .collect(Collectors.groupingBy(x -> x.parent().get())); - for (Map.Entry<ResourcePath, List<ResourcePath>> entry: resourceMap.entrySet()) { - if (!isRegistered(childTxMap, entry.getKey())) { - return abortTransaction(tx); - } + for (Map.Entry<ResourcePath, List<ResourcePath>> entry: resourceMap.entrySet()) { + if (!isRegistered(childTxMap, entry.getKey())) { + return abortTransaction(tx); + } - if (!appendValues(childTxMap, entry.getKey(), entry.getValue())) { - return abortTransaction(tx); - } + if (!appendValues(childTxMap, entry.getKey(), entry.getValue())) { + return abortTransaction(tx); } + } - return commitTransaction(tx); - } catch (TransactionException e) { - log.error("Exception thrown, abort the transaction", e); - return abortTransaction(tx); + boolean success = tx.commit(); + if (success) { + List<ResourceEvent> events = resources.stream() + .filter(x -> x.parent().isPresent()) + .map(x -> new ResourceEvent(RESOURCE_ADDED, x)) + .collect(Collectors.toList()); + notifyDelegate(events); } + return success; } @Override @@ -132,33 +142,36 @@ public class ConsistentResourceStore implements ResourceStore { TransactionContext tx = service.transactionContextBuilder().build(); tx.begin(); - try { - TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = - tx.getTransactionalMap(CHILD_MAP, SERIALIZER); - TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = - tx.getTransactionalMap(CONSUMER_MAP, SERIALIZER); + TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = + tx.getTransactionalMap(CHILD_MAP, SERIALIZER); + TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = + tx.getTransactionalMap(CONSUMER_MAP, SERIALIZER); - Map<ResourcePath, List<ResourcePath>> resourceMap = resources.stream() - .filter(x -> x.parent().isPresent()) - .collect(Collectors.groupingBy(x -> x.parent().get())); - - // even if one of the resources is allocated to a consumer, - // all unregistrations are regarded as failure - for (Map.Entry<ResourcePath, List<ResourcePath>> entry: resourceMap.entrySet()) { - if (entry.getValue().stream().anyMatch(x -> consumerTxMap.get(x) != null)) { - return abortTransaction(tx); - } - - if (!removeValues(childTxMap, entry.getKey(), entry.getValue())) { - return abortTransaction(tx); - } + Map<ResourcePath, List<ResourcePath>> resourceMap = resources.stream() + .filter(x -> x.parent().isPresent()) + .collect(Collectors.groupingBy(x -> x.parent().get())); + + // even if one of the resources is allocated to a consumer, + // all unregistrations are regarded as failure + for (Map.Entry<ResourcePath, List<ResourcePath>> entry: resourceMap.entrySet()) { + if (entry.getValue().stream().anyMatch(x -> consumerTxMap.get(x) != null)) { + return abortTransaction(tx); } - return commitTransaction(tx); - } catch (TransactionException e) { - log.error("Exception thrown, abort the transaction", e); - return abortTransaction(tx); + if (!removeValues(childTxMap, entry.getKey(), entry.getValue())) { + return abortTransaction(tx); + } + } + + boolean success = tx.commit(); + if (success) { + List<ResourceEvent> events = resources.stream() + .filter(x -> x.parent().isPresent()) + .map(x -> new ResourceEvent(RESOURCE_REMOVED, x)) + .collect(Collectors.toList()); + notifyDelegate(events); } + return success; } @Override @@ -169,28 +182,23 @@ public class ConsistentResourceStore implements ResourceStore { TransactionContext tx = service.transactionContextBuilder().build(); tx.begin(); - try { - TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = - tx.getTransactionalMap(CHILD_MAP, SERIALIZER); - TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = - tx.getTransactionalMap(CONSUMER_MAP, SERIALIZER); - - for (ResourcePath resource: resources) { - if (!isRegistered(childTxMap, resource)) { - return abortTransaction(tx); - } - - ResourceConsumer oldValue = consumerTxMap.put(resource, consumer); - if (oldValue != null) { - return abortTransaction(tx); - } + TransactionalMap<ResourcePath, List<ResourcePath>> childTxMap = + tx.getTransactionalMap(CHILD_MAP, SERIALIZER); + TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = + tx.getTransactionalMap(CONSUMER_MAP, SERIALIZER); + + for (ResourcePath resource: resources) { + if (!isRegistered(childTxMap, resource)) { + return abortTransaction(tx); } - return commitTransaction(tx); - } catch (TransactionException e) { - log.error("Exception thrown, abort the transaction", e); - return abortTransaction(tx); + ResourceConsumer oldValue = consumerTxMap.put(resource, consumer); + if (oldValue != null) { + return abortTransaction(tx); + } } + + return tx.commit(); } @Override @@ -202,28 +210,23 @@ public class ConsistentResourceStore implements ResourceStore { TransactionContext tx = service.transactionContextBuilder().build(); tx.begin(); - try { - TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = - tx.getTransactionalMap(CONSUMER_MAP, SERIALIZER); - Iterator<ResourcePath> resourceIte = resources.iterator(); - Iterator<ResourceConsumer> consumerIte = consumers.iterator(); - - while (resourceIte.hasNext() && consumerIte.hasNext()) { - ResourcePath resource = resourceIte.next(); - ResourceConsumer consumer = consumerIte.next(); - - // if this single release fails (because the resource is allocated to another consumer, - // the whole release fails - if (!consumerTxMap.remove(resource, consumer)) { - return abortTransaction(tx); - } - } + TransactionalMap<ResourcePath, ResourceConsumer> consumerTxMap = + tx.getTransactionalMap(CONSUMER_MAP, SERIALIZER); + Iterator<ResourcePath> resourceIte = resources.iterator(); + Iterator<ResourceConsumer> consumerIte = consumers.iterator(); + + while (resourceIte.hasNext() && consumerIte.hasNext()) { + ResourcePath resource = resourceIte.next(); + ResourceConsumer consumer = consumerIte.next(); - return commitTransaction(tx); - } catch (TransactionException e) { - log.error("Exception thrown, abort the transaction", e); - return abortTransaction(tx); + // if this single release fails (because the resource is allocated to another consumer, + // the whole release fails + if (!consumerTxMap.remove(resource, consumer)) { + return abortTransaction(tx); + } } + + return tx.commit(); } @Override @@ -261,7 +264,7 @@ public class ConsistentResourceStore implements ResourceStore { } return children.value().stream() - .filter(x -> x.lastComponent().getClass().equals(cls)) + .filter(x -> x.last().getClass().equals(cls)) .filter(consumerMap::containsKey) .collect(Collectors.toList()); } @@ -278,17 +281,6 @@ public class ConsistentResourceStore implements ResourceStore { } /** - * Commit the transaction. - * - * @param tx transaction context - * @return always true - */ - private boolean commitTransaction(TransactionContext tx) { - tx.commit(); - return true; - } - - /** * Appends the values to the existing values associated with the specified key. * If the map already has all the given values, appending will not happen. * @@ -300,9 +292,9 @@ public class ConsistentResourceStore implements ResourceStore { * @return true if the operation succeeds, false otherwise. */ private <K, V> boolean appendValues(TransactionalMap<K, List<V>> map, K key, List<V> values) { - List<V> oldValues = map.get(key); + List<V> oldValues = map.putIfAbsent(key, new ArrayList<>(values)); if (oldValues == null) { - return map.replace(key, oldValues, new ArrayList<>(values)); + return true; } LinkedHashSet<V> oldSet = new LinkedHashSet<>(oldValues); @@ -329,7 +321,8 @@ public class ConsistentResourceStore implements ResourceStore { private <K, V> boolean removeValues(TransactionalMap<K, List<V>> map, K key, List<V> values) { List<V> oldValues = map.get(key); if (oldValues == null) { - return map.replace(key, oldValues, new ArrayList<>()); + map.put(key, new ArrayList<>()); + return true; } LinkedHashSet<V> oldSet = new LinkedHashSet<>(oldValues); @@ -351,7 +344,7 @@ public class ConsistentResourceStore implements ResourceStore { */ private boolean isRegistered(TransactionalMap<ResourcePath, List<ResourcePath>> map, ResourcePath resource) { // root is always regarded to be registered - if (resource.isRoot()) { + if (!resource.parent().isPresent()) { return true; } 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 c332ada5..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 @@ -59,7 +59,6 @@ import org.onosproject.store.service.ConsistentMap; import org.onosproject.store.service.Serializer; import org.onosproject.store.service.StorageService; import org.onosproject.store.service.TransactionContext; -import org.onosproject.store.service.TransactionException; import org.onosproject.store.service.TransactionalMap; import org.onosproject.store.service.Versioned; @@ -73,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 @@ -294,7 +296,7 @@ public class ConsistentLinkResourceStore extends intentAllocs.put(allocations.intentId(), allocations); allocations.links().forEach(link -> allocateLinkResource(tx, link, allocations)); tx.commit(); - } catch (TransactionException | ResourceAllocationException e) { + } catch (ResourceAllocationException e) { log.error("Exception thrown, rolling back", e); tx.abort(); } catch (Exception e) { @@ -407,12 +409,8 @@ public class ConsistentLinkResourceStore extends after.remove(allocations); linkAllocs.replace(linkId, before, after); }); - tx.commit(); - success = true; - } catch (TransactionException e) { - log.debug("Transaction failed, retrying", e); - tx.abort(); - } catch (Exception e) { + success = tx.commit(); + } catch (Exception e) { log.error("Exception thrown during releaseResource {}", allocations, e); tx.abort(); throw e; diff --git a/framework/src/onos/core/store/dist/src/test/java/org/onosproject/store/device/impl/GossipDeviceStoreTest.java b/framework/src/onos/core/store/dist/src/test/java/org/onosproject/store/device/impl/GossipDeviceStoreTest.java index 3a168936..5cbf360a 100644 --- a/framework/src/onos/core/store/dist/src/test/java/org/onosproject/store/device/impl/GossipDeviceStoreTest.java +++ b/framework/src/onos/core/store/dist/src/test/java/org/onosproject/store/device/impl/GossipDeviceStoreTest.java @@ -232,7 +232,7 @@ public class GossipDeviceStoreTest { if (expected == actual) { return; } - assertEquals(expected.deviceURI(), actual.deviceURI()); + assertEquals(expected.deviceUri(), actual.deviceUri()); assertEquals(expected.hwVersion(), actual.hwVersion()); assertEquals(expected.manufacturer(), actual.manufacturer()); assertEquals(expected.serialNumber(), actual.serialNumber()); @@ -247,7 +247,7 @@ public class GossipDeviceStoreTest { if (expected == actual) { return; } - assertEquals(expected.deviceURI(), actual.deviceURI()); + assertEquals(expected.deviceUri(), actual.deviceUri()); assertEquals(expected.hwVersion(), actual.hwVersion()); assertEquals(expected.manufacturer(), actual.manufacturer()); assertEquals(expected.serialNumber(), actual.serialNumber()); diff --git a/framework/src/onos/core/store/dist/src/test/java/org/onosproject/store/ecmap/EventuallyConsistentMapImplTest.java b/framework/src/onos/core/store/dist/src/test/java/org/onosproject/store/ecmap/EventuallyConsistentMapImplTest.java index ccf6ee71..ef8d9924 100644 --- a/framework/src/onos/core/store/dist/src/test/java/org/onosproject/store/ecmap/EventuallyConsistentMapImplTest.java +++ b/framework/src/onos/core/store/dist/src/test/java/org/onosproject/store/ecmap/EventuallyConsistentMapImplTest.java @@ -42,6 +42,7 @@ import org.onosproject.cluster.ControllerNode; import org.onosproject.cluster.DefaultControllerNode; import org.onosproject.cluster.NodeId; import org.onosproject.event.AbstractEvent; +import org.onosproject.persistence.impl.PersistenceManager; import org.onosproject.store.Timestamp; import org.onosproject.store.cluster.messaging.ClusterCommunicationService; import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter; @@ -81,6 +82,7 @@ public class EventuallyConsistentMapImplTest { private EventuallyConsistentMap<String, String> ecMap; + private PersistenceManager persistenceService; private ClusterService clusterService; private ClusterCommunicationService clusterCommunicator; private SequentialClockService<String, String> clockService; @@ -136,6 +138,8 @@ public class EventuallyConsistentMapImplTest { clusterCommunicator = createMock(ClusterCommunicationService.class); + persistenceService = new PersistenceManager(); + persistenceService.activate(); // Add expectation for adding cluster message subscribers which // delegate to our ClusterCommunicationService implementation. This // allows us to get a reference to the map's internal cluster message @@ -153,11 +157,12 @@ public class EventuallyConsistentMapImplTest { .register(TestTimestamp.class); ecMap = new EventuallyConsistentMapBuilderImpl<String, String>( - clusterService, clusterCommunicator) + clusterService, clusterCommunicator, persistenceService) .withName(MAP_NAME) .withSerializer(serializer) .withTimestampProvider((k, v) -> clockService.getTimestamp(k, v)) .withCommunicationExecutor(MoreExecutors.newDirectExecutorService()) + .withPersistence() .build(); // Reset ready for tests to add their own expectations diff --git a/framework/src/onos/core/store/persistence/pom.xml b/framework/src/onos/core/store/persistence/pom.xml index 555de11a..5692c531 100644 --- a/framework/src/onos/core/store/persistence/pom.xml +++ b/framework/src/onos/core/store/persistence/pom.xml @@ -50,7 +50,7 @@ <groupId>org.onosproject</groupId> <artifactId>onos-api</artifactId> </dependency>--> - <dependency> + <dependency> <groupId>org.onosproject</groupId> <artifactId>onos-api</artifactId> <classifier>tests</classifier> diff --git a/framework/src/onos/core/store/pom.xml b/framework/src/onos/core/store/pom.xml index 219ae5d0..94c077a4 100644 --- a/framework/src/onos/core/store/pom.xml +++ b/framework/src/onos/core/store/pom.xml @@ -34,7 +34,7 @@ <modules> <module>dist</module> <module>persistence</module> - <module>serializers</module> + <module>serializers</module> </modules> <dependencies> diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java index 0312bafd..6f96498f 100644 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/KryoNamespaces.java @@ -416,6 +416,8 @@ public final class KryoNamespaces { BandwidthResourceAllocation.class, LambdaResourceAllocation.class, ResourcePath.class, + ResourcePath.Discrete.class, + ResourcePath.Continuous.class, ResourceAllocation.class, // Constraints LambdaConstraint.class, @@ -438,7 +440,7 @@ public final class KryoNamespaces { DefaultTableStatisticsEntry.class ) .register(new DefaultApplicationIdSerializer(), DefaultApplicationId.class) - .register(new URISerializer(), URI.class) + .register(new UriSerializer(), URI.class) .register(new NodeIdSerializer(), NodeId.class) .register(new ProviderIdSerializer(), ProviderId.class) .register(new DeviceIdSerializer(), DeviceId.class) diff --git a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/URISerializer.java b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/UriSerializer.java index 43969666..1d146a55 100644 --- a/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/URISerializer.java +++ b/framework/src/onos/core/store/serializers/src/main/java/org/onosproject/store/serializers/UriSerializer.java @@ -15,22 +15,22 @@ */ package org.onosproject.store.serializers; -import java.net.URI; - import com.esotericsoftware.kryo.Kryo; import com.esotericsoftware.kryo.Serializer; import com.esotericsoftware.kryo.io.Input; import com.esotericsoftware.kryo.io.Output; +import java.net.URI; + /** * Serializer for {@link URI}. */ -public class URISerializer extends Serializer<URI> { +public class UriSerializer extends Serializer<URI> { /** * Creates {@link URI} serializer instance. */ - public URISerializer() { + public UriSerializer() { super(false); } diff --git a/framework/src/onos/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java b/framework/src/onos/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java index 97ccb836..11a62d4e 100644 --- a/framework/src/onos/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java +++ b/framework/src/onos/core/store/serializers/src/test/java/org/onosproject/store/serializers/KryoSerializerTest.java @@ -373,13 +373,13 @@ public class KryoSerializerTest { @Test public void testResourcePath() { - testSerializedEquals(new ResourcePath(LinkKey.linkKey(CP1, CP2), VLAN1)); + testSerializedEquals(ResourcePath.discrete(LinkKey.linkKey(CP1, CP2), VLAN1)); } @Test public void testResourceAllocation() { testSerializedEquals(new org.onosproject.net.newresource.ResourceAllocation( - new ResourcePath(LinkKey.linkKey(CP1, CP2), VLAN1), + ResourcePath.discrete(LinkKey.linkKey(CP1, CP2), VLAN1), IntentId.valueOf(30))); } diff --git a/framework/src/onos/docs/external.xml b/framework/src/onos/docs/external.xml index 69ac0577..f2c568a6 100644 --- a/framework/src/onos/docs/external.xml +++ b/framework/src/onos/docs/external.xml @@ -49,7 +49,8 @@ <version>2.10.1</version> <configuration> <show>package</show> - <excludePackageNames>@external-excludes</excludePackageNames> + <excludePackageNames>@external-excludes + </excludePackageNames> <docfilessubdirs>true</docfilessubdirs> <doctitle>ONOS Java API (1.4.0-SNAPSHOT)</doctitle> <groups> @@ -58,7 +59,8 @@ <packages>@external-apis</packages> </group> <group> - <title>Incubator for Network Model & Services</title> + <title>Incubator for Network Model & Services + </title> <packages>@external-incubator-apis</packages> </group> <group> @@ -66,6 +68,13 @@ <packages>@utils</packages> </group> </groups> + <tags> + <tag> + <name>rsModel</name> + <placement>m</placement> + <head>Json model for REST api:</head> + </tag> + </tags> </configuration> </plugin> </plugins> diff --git a/framework/src/onos/docs/internal.xml b/framework/src/onos/docs/internal.xml index 602479eb..e0ba3607 100644 --- a/framework/src/onos/docs/internal.xml +++ b/framework/src/onos/docs/internal.xml @@ -51,14 +51,16 @@ <show>package</show> <docfilessubdirs>true</docfilessubdirs> <doctitle>ONOS Java API (1.4.0-SNAPSHOT)</doctitle> - <excludePackageNames>@internal-excludes</excludePackageNames> + <excludePackageNames>@internal-excludes + </excludePackageNames> <groups> <group> <title>Network Model & Services</title> <packages>@internal-apis</packages> </group> <group> - <title>Incubator for Network Model & Services</title> + <title>Incubator for Network Model & Services + </title> <packages>@internal-incubator-apis</packages> </group> <group> @@ -70,7 +72,9 @@ <packages>@internal-stores</packages> </group> <group> - <title>Incubator for Core Subsystems & Distributed Stores</title> + <title>Incubator for Core Subsystems & + Distributed Stores + </title> <packages>@internal-incubator</packages> </group> <group> @@ -114,10 +118,18 @@ <packages>@internal-apps</packages> </group> <group> - <title>Test Instrumentation & Applications</title> + <title>Test Instrumentation & Applications + </title> <packages>@internal-test-apps</packages> </group> </groups> + <tags> + <tag> + <name>rsModel</name> + <placement>m</placement> + <head>Json model for REST api:</head> + </tag> + </tags> </configuration> </plugin> </plugins> diff --git a/framework/src/onos/drivers/features.xml b/framework/src/onos/drivers/features.xml index a7144492..e83f93fa 100644 --- a/framework/src/onos/drivers/features.xml +++ b/framework/src/onos/drivers/features.xml @@ -24,5 +24,7 @@ <bundle>mvn:${project.groupId}/onos-ovsdb-api/${project.version}</bundle> <bundle>mvn:${project.groupId}/onos-ovsdb-rfc/${project.version}</bundle> + + <bundle>mvn:${project.groupId}/onos-netconf-api/${project.version}</bundle> </feature> </features> diff --git a/framework/src/onos/drivers/pom.xml b/framework/src/onos/drivers/pom.xml index 56a39a8e..db0a3985 100644 --- a/framework/src/onos/drivers/pom.xml +++ b/framework/src/onos/drivers/pom.xml @@ -67,6 +67,11 @@ <artifactId>easymock</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-netconf-api</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>org.apache.felix</groupId> diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/extensions/NiciraExtensionInterpreter.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/extensions/NiciraExtensionInterpreter.java index 082c5a6d..b8f1fd91 100644 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/extensions/NiciraExtensionInterpreter.java +++ b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/extensions/NiciraExtensionInterpreter.java @@ -38,10 +38,12 @@ public class NiciraExtensionInterpreter extends AbstractHandlerBehaviour @Override public boolean supported(ExtensionType extensionType) { - if (extensionType.equals(ExtensionType.ExtensionTypes.NICIRA_SET_TUNNEL_DST)) { + if (extensionType.equals(ExtensionType.ExtensionTypes.NICIRA_SET_TUNNEL_DST.type())) { + return true; + } + if (extensionType.equals(ExtensionType.ExtensionTypes.NICIRA_RESUBMIT.type())) { return true; } - return false; } @@ -53,6 +55,9 @@ public class NiciraExtensionInterpreter extends AbstractHandlerBehaviour return factory.actions().setField(factory.oxms().tunnelIpv4Dst( IPv4Address.of(tunnelDst.tunnelDst().toInt()))); } + if (type.equals(ExtensionType.ExtensionTypes.NICIRA_RESUBMIT.type())) { + // TODO this will be implemented later + } return null; } @@ -78,6 +83,9 @@ public class NiciraExtensionInterpreter extends AbstractHandlerBehaviour if (type.equals(ExtensionType.ExtensionTypes.NICIRA_SET_TUNNEL_DST.type())) { return new NiciraSetTunnelDst(); } + if (type.equals(ExtensionType.ExtensionTypes.NICIRA_RESUBMIT.type())) { + return new NiciraResubmit(); + } throw new UnsupportedOperationException( "Driver does not support extension type " + type.toString()); } 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/handshaker/OFOpticalSwitchImplLINC13.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/OfOpticalSwitchImplLinc13.java index 7faee374..ff65e0c6 100644 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/OFOpticalSwitchImplLINC13.java +++ b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/handshaker/OfOpticalSwitchImplLinc13.java @@ -53,7 +53,7 @@ import java.util.concurrent.atomic.AtomicBoolean; * while it sends *all* ports (both tap and WDM ports, i.e., OCh and OMS) in the experimenter port desc stats reply. * */ -public class OFOpticalSwitchImplLINC13 +public class OfOpticalSwitchImplLinc13 extends AbstractOpenFlowSwitch implements OpenFlowOpticalSwitch { private final AtomicBoolean driverHandshakeComplete = new AtomicBoolean(false); diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/ovsdb/OvsdbBridgeConfig.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/ovsdb/OvsdbBridgeConfig.java index 77b48298..6451160a 100644 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/ovsdb/OvsdbBridgeConfig.java +++ b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/ovsdb/OvsdbBridgeConfig.java @@ -54,6 +54,13 @@ public class OvsdbBridgeConfig extends AbstractHandlerBehaviour } @Override + public void addBridge(BridgeName bridgeName, String dpid, String exPortName) { + DriverHandler handler = handler(); + OvsdbClientService clientService = getOvsdbClientService(handler); + clientService.createBridge(bridgeName.name(), dpid, exPortName); + } + + @Override public boolean addBridge(BridgeName bridgeName, String dpid, List<ControllerInfo> controllers) { DriverHandler handler = handler(); OvsdbClientService clientService = getOvsdbClientService(handler); 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 a830ed49..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 @@ -17,6 +17,16 @@ 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; +import org.onosproject.net.Port; +import org.onosproject.net.PortNumber; import org.onosproject.net.flow.DefaultFlowRule; import org.onosproject.net.flow.DefaultTrafficSelector; import org.onosproject.net.flow.DefaultTrafficTreatment; @@ -25,6 +35,8 @@ import org.onosproject.net.flow.FlowRuleOperations; import org.onosproject.net.flow.FlowRuleOperationsContext; import org.onosproject.net.flow.TrafficSelector; import org.onosproject.net.flow.TrafficTreatment; +import org.onosproject.net.flow.criteria.PortCriterion; +import org.onosproject.net.flow.criteria.VlanIdCriterion; import org.slf4j.Logger; @@ -37,16 +49,76 @@ public class CpqdOFDPA2Pipeline extends OFDPA2Pipeline { private final Logger log = getLogger(getClass()); @Override + protected List<FlowRule> processVlanIdFilter(PortCriterion portCriterion, + VlanIdCriterion vidCriterion, + VlanId assignedVlan, + ApplicationId applicationId) { + List<FlowRule> rules = new ArrayList<FlowRule>(); + 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(); + } + + // ofdpa cannot match on ALL portnumber, so we need to use separate + // rules for each port. + List<PortNumber> portnums = new ArrayList<PortNumber>(); + if (portCriterion.port() == PortNumber.ALL) { + for (Port port : deviceService.getPorts(deviceId)) { + if (port.number().toLong() > 0 && port.number().toLong() < OFPP_MAX) { + portnums.add(port.number()); + } + } + } else { + portnums.add(portCriterion.port()); + } + + for (PortNumber pnum : portnums) { + // update storage + port2Vlan.put(pnum, storeVlan); + Set<PortNumber> vlanPorts = vlan2Port.get(storeVlan); + if (vlanPorts == null) { + vlanPorts = Collections.newSetFromMap( + new ConcurrentHashMap<PortNumber, Boolean>()); + vlanPorts.add(pnum); + vlan2Port.put(storeVlan, vlanPorts); + } else { + vlanPorts.add(pnum); + } + // create rest of flowrule + selector.matchInPort(pnum); + FlowRule rule = DefaultFlowRule.builder() + .forDevice(deviceId) + .withSelector(selector.build()) + .withTreatment(treatment.build()) + .withPriority(DEFAULT_PRIORITY) + .fromApp(applicationId) + .makePermanent() + .forTable(VLAN_TABLE).build(); + rules.add(rule); + } + return rules; + } + + + @Override protected void initializePipeline() { processPortTable(); + // vlan table processing not required, as default is to drop packets + // which can be accomplished without a table-miss-entry. processTmacTable(); processIpTable(); + processMplsTable(); processBridgingTable(); processAclTable(); - // XXX implement table miss entries and default groups - //processVlanTable(); - //processMPLSTable(); - //processGroupTable(); } @Override @@ -140,6 +212,49 @@ public class CpqdOFDPA2Pipeline extends OFDPA2Pipeline { })); } + @Override + protected void processMplsTable() { + //table miss entry + FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); + TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); + TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder(); + selector = DefaultTrafficSelector.builder(); + treatment = DefaultTrafficTreatment.builder(); + treatment.transition(MPLS_TABLE_1); + FlowRule rule = DefaultFlowRule.builder() + .forDevice(deviceId) + .withSelector(selector.build()) + .withTreatment(treatment.build()) + .withPriority(LOWEST_PRIORITY) + .fromApp(driverId) + .makePermanent() + .forTable(MPLS_TABLE_0).build(); + ops = ops.add(rule); + + treatment.transition(ACL_TABLE); + rule = DefaultFlowRule.builder() + .forDevice(deviceId) + .withSelector(selector.build()) + .withTreatment(treatment.build()) + .withPriority(LOWEST_PRIORITY) + .fromApp(driverId) + .makePermanent() + .forTable(MPLS_TABLE_1).build(); + ops = ops.add(rule); + + flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { + @Override + public void onSuccess(FlowRuleOperations ops) { + log.info("Initialized MPLS tables"); + } + + @Override + public void onError(FlowRuleOperations ops) { + log.info("Failed to initialize MPLS tables"); + } + })); + } + private void processBridgingTable() { //table miss entry FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); 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 b1a1256a..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; @@ -122,7 +124,7 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline protected static final long OFPP_MAX = 0xffffff00L; private static final int HIGHEST_PRIORITY = 0xffff; - private static final int DEFAULT_PRIORITY = 0x8000; + protected static final int DEFAULT_PRIORITY = 0x8000; protected static final int LOWEST_PRIORITY = 0x0; /* @@ -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<IPCriterion> sentIpFilters = Collections.newSetFromMap( new ConcurrentHashMap<IPCriterion, Boolean>()); + // local stores for port-vlan mapping + Map<PortNumber, VlanId> port2Vlan = new ConcurrentHashMap<PortNumber, VlanId>(); + Map<VlanId, Set<PortNumber>> vlan2Port = new ConcurrentHashMap<VlanId, + Set<PortNumber>>(); + + + @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<TrafficTreatment> 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,13 +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 may require an additional vlan match on the assigned vlan - // and it may not require the push. + // 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. @@ -475,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<PortNumber> vlanPorts = vlan2Port.get(storeVlan); + if (vlanPorts == null) { + vlanPorts = Collections.newSetFromMap( + new ConcurrentHashMap<PortNumber, Boolean>()); + vlanPorts.add(pnum); + vlan2Port.put(storeVlan, vlanPorts); + } else { + vlanPorts.add(pnum); + } + // create rest of flowrule selector.matchInPort(pnum); FlowRule rule = DefaultFlowRule.builder() .forDevice(deviceId) @@ -707,10 +734,39 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline // Group handling ////////////////////////////////////// + private void addGroup(NextObjective nextObjective) { + switch (nextObjective.type()) { + case SIMPLE: + Collection<TrafficTreatment> 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. * @@ -769,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<GroupKey> gkeys = new ArrayList<GroupKey>(); @@ -796,27 +854,201 @@ public class OFDPA2Pipeline extends AbstractHandlerBehaviour implements Pipeline } /** + * 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<TrafficTreatment> buckets = nextObj.next(); + + // each treatment is converted to an L2 interface group + int indicator = 0; + VlanId vlanid = null; + List<GroupInfo> 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<TrafficTreatment> 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<GroupKey> gkeys = new ArrayList<GroupKey>(); + 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 * and this driver has received notification for it. A second assumption is * 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. + * <p> + * 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<GroupBucket> 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 @@ -836,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); @@ -865,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); @@ -889,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; @@ -924,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<TrafficTreatment> 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<TrafficTreatment> 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/drivers/src/main/java/org/onosproject/driver/pipeline/OLTPipeline.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/OLTPipeline.java deleted file mode 100644 index c735af3f..00000000 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/OLTPipeline.java +++ /dev/null @@ -1,238 +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.driver.pipeline; - -import org.onlab.osgi.ServiceDirectory; -import org.onlab.packet.EthType; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.MastershipRole; -import org.onosproject.net.PortNumber; -import org.onosproject.net.behaviour.Pipeliner; -import org.onosproject.net.behaviour.PipelinerContext; -import org.onosproject.net.device.DefaultDeviceDescription; -import org.onosproject.net.device.DeviceDescription; -import org.onosproject.net.device.DeviceProvider; -import org.onosproject.net.device.DeviceProviderRegistry; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.driver.AbstractHandlerBehaviour; -import org.onosproject.net.flow.DefaultFlowRule; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.DefaultTrafficTreatment; -import org.onosproject.net.flow.FlowRule; -import org.onosproject.net.flow.FlowRuleOperations; -import org.onosproject.net.flow.FlowRuleOperationsContext; -import org.onosproject.net.flow.FlowRuleService; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.flow.instructions.Instructions; -import org.onosproject.net.flowobjective.FilteringObjective; -import org.onosproject.net.flowobjective.ForwardingObjective; -import org.onosproject.net.flowobjective.NextObjective; -import org.onosproject.net.flowobjective.ObjectiveError; -import org.onosproject.net.packet.PacketPriority; -import org.onosproject.net.provider.AbstractProvider; -import org.onosproject.net.provider.ProviderId; -import org.slf4j.Logger; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * Pipeliner for OLT device. - */ -public class OLTPipeline extends AbstractHandlerBehaviour implements Pipeliner { - - private final Logger log = getLogger(getClass()); - - static final ProviderId PID = new ProviderId("olt", "org.onosproject.olt", true); - - static final String DEVICE = "isAccess"; - static final String OLT = "true"; - - private ServiceDirectory serviceDirectory; - private FlowRuleService flowRuleService; - private DeviceId deviceId; - private CoreService coreService; - - private ApplicationId appId; - - private DeviceProvider provider = new AnnotationProvider(); - - - @Override - public void init(DeviceId deviceId, PipelinerContext context) { - this.serviceDirectory = context.directory(); - this.deviceId = deviceId; - DeviceProviderRegistry registry = - serviceDirectory.get(DeviceProviderRegistry.class); - flowRuleService = serviceDirectory.get(FlowRuleService.class); - coreService = serviceDirectory.get(CoreService.class); - - /*try { - DeviceProviderService providerService = registry.register(provider); - providerService.deviceConnected(deviceId, - description(deviceId, DEVICE, OLT)); - } finally { - registry.unregister(provider); - }*/ - - appId = coreService.registerApplication( - "org.onosproject.driver.OLTPipeline"); - - TrafficSelector selector = DefaultTrafficSelector.builder() - .matchEthType(EthType.EtherType.EAPOL.ethType().toShort()) - .build(); - - TrafficTreatment treatment = DefaultTrafficTreatment.builder() - .punt() - .build(); - - FlowRule flowRule = new DefaultFlowRule(deviceId, selector, treatment, - PacketPriority.CONTROL.priorityValue(), - appId, 0, true, null); - - //flowRuleService.applyFlowRules(flowRule); - } - - @Override - public void filter(FilteringObjective filter) { - throw new UnsupportedOperationException("OLT does not filter."); - } - - @Override - public void forward(ForwardingObjective fwd) { - FlowRuleOperations.Builder flowBuilder = FlowRuleOperations.builder(); - - if (fwd.flag() != ForwardingObjective.Flag.VERSATILE) { - throw new UnsupportedOperationException( - "Only VERSATILE is supported."); - } - - boolean isPunt = fwd.treatment().immediate().stream().anyMatch(i -> { - if (i instanceof Instructions.OutputInstruction) { - Instructions.OutputInstruction out = (Instructions.OutputInstruction) i; - return out.port().equals(PortNumber.CONTROLLER); - } - return false; - }); - - if (isPunt) { - return; - } - - TrafficSelector selector = fwd.selector(); - TrafficTreatment treatment = fwd.treatment(); - - FlowRule.Builder ruleBuilder = DefaultFlowRule.builder() - .forDevice(deviceId) - .withSelector(selector) - .withTreatment(treatment) - .fromApp(fwd.appId()) - .withPriority(fwd.priority()); - - if (fwd.permanent()) { - ruleBuilder.makePermanent(); - } else { - ruleBuilder.makeTemporary(fwd.timeout()); - } - - switch (fwd.op()) { - case ADD: - flowBuilder.add(ruleBuilder.build()); - break; - case REMOVE: - flowBuilder.remove(ruleBuilder.build()); - break; - default: - log.warn("Unknown operation {}", fwd.op()); - } - - flowRuleService.apply(flowBuilder.build(new FlowRuleOperationsContext() { - @Override - public void onSuccess(FlowRuleOperations ops) { - if (fwd.context().isPresent()) { - fwd.context().get().onSuccess(fwd); - } - } - - @Override - public void onError(FlowRuleOperations ops) { - if (fwd.context().isPresent()) { - fwd.context().get().onError(fwd, ObjectiveError.FLOWINSTALLATIONFAILED); - } - } - })); - } - - @Override - public void next(NextObjective nextObjective) { - throw new UnsupportedOperationException("OLT does not next hop."); - } - - /** - * Build a device description. - * - * @param deviceId a deviceId - * @param key the key of the annotation - * @param value the value for the annotation - * @return a device description - */ - private DeviceDescription description(DeviceId deviceId, String key, String value) { - DeviceService deviceService = serviceDirectory.get(DeviceService.class); - Device device = deviceService.getDevice(deviceId); - - checkNotNull(device, "Device not found in device service."); - - DefaultAnnotations.Builder builder = DefaultAnnotations.builder(); - if (value != null) { - builder.set(key, value); - } else { - builder.remove(key); - } - return new DefaultDeviceDescription(device.id().uri(), device.type(), - device.manufacturer(), device.hwVersion(), - device.swVersion(), device.serialNumber(), - device.chassisId(), builder.build()); - } - - /** - * Simple ancillary provider used to annotate device. - */ - private static final class AnnotationProvider - extends AbstractProvider implements DeviceProvider { - private AnnotationProvider() { - super(PID); - } - - @Override - public void triggerProbe(DeviceId deviceId) { - } - - @Override - public void roleChanged(DeviceId deviceId, MastershipRole newRole) { - } - - @Override - public boolean isReachable(DeviceId deviceId) { - return false; - } - } - -} diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/PicaPipeline.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/PicaPipeline.java index 32d6b103..69d20835 100644 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/PicaPipeline.java +++ b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/PicaPipeline.java @@ -462,10 +462,10 @@ public class PicaPipeline extends AbstractHandlerBehaviour implements Pipeliner private void initializePipeline() { //processIpUnicastTable(true); - processACLTable(true); + processAclTable(true); } - private void processACLTable(boolean install) { + private void processAclTable(boolean install) { TrafficSelector.Builder selector; TrafficTreatment.Builder treatment; FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/SoftRouterPipeline.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/SoftRouterPipeline.java index 23ef5f2b..bd49e688 100644 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/SoftRouterPipeline.java +++ b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/SoftRouterPipeline.java @@ -15,13 +15,6 @@ */ package org.onosproject.driver.pipeline; -import static org.slf4j.LoggerFactory.getLogger; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.ConcurrentHashMap; - import org.onlab.osgi.ServiceDirectory; import org.onlab.packet.Ethernet; import org.onlab.packet.MacAddress; @@ -57,8 +50,15 @@ import org.onosproject.net.flowobjective.ForwardingObjective; import org.onosproject.net.flowobjective.NextObjective; import org.onosproject.net.flowobjective.Objective; import org.onosproject.net.flowobjective.ObjectiveError; -import org.slf4j.Logger; import org.onosproject.store.serializers.KryoNamespaces; +import org.slf4j.Logger; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.concurrent.ConcurrentHashMap; + +import static org.slf4j.LoggerFactory.getLogger; /** * Simple 2-Table Pipeline for Software/NPU based routers. This pipeline @@ -100,7 +100,7 @@ public class SoftRouterPipeline extends AbstractHandlerBehaviour implements Pipe flowRuleService = serviceDirectory.get(FlowRuleService.class); flowObjectiveStore = context.store(); driverId = coreService.registerApplication( - "org.onosproject.driver.OVSCorsaPipeline"); + "org.onosproject.driver.SoftRouterPipeline"); filters = Collections.newSetFromMap(new ConcurrentHashMap<Filter, Boolean>()); pendingVersatiles = Collections.newSetFromMap( new ConcurrentHashMap<ForwardingObjective, Boolean>()); diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/SpringOpenTTP.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/SpringOpenTTP.java index 31297ff4..b5541065 100644 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/SpringOpenTTP.java +++ b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/SpringOpenTTP.java @@ -25,6 +25,7 @@ import com.google.common.cache.RemovalNotification; import org.onlab.osgi.ServiceDirectory; import org.onlab.packet.Ethernet; +import org.onlab.packet.MacAddress; import org.onlab.packet.VlanId; import org.onlab.util.KryoNamespace; import org.onosproject.core.ApplicationId; @@ -54,6 +55,7 @@ import org.onosproject.net.flow.criteria.PortCriterion; import org.onosproject.net.flow.criteria.VlanIdCriterion; import org.onosproject.net.flow.instructions.Instruction; import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; +import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; import org.onosproject.net.flowobjective.FilteringObjective; import org.onosproject.net.flowobjective.FlowObjectiveStore; import org.onosproject.net.flowobjective.ForwardingObjective; @@ -94,7 +96,9 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour private static final int TABLE_TMAC = 1; private static final int TABLE_IPV4_UNICAST = 2; private static final int TABLE_MPLS = 3; + private static final int TABLE_DMAC = 4; private static final int TABLE_ACL = 5; + private static final int TABLE_SMAC = 6; /** * Set the default values. These variables will get overwritten based on the @@ -104,7 +108,9 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour protected int tmacTableId = TABLE_TMAC; protected int ipv4UnicastTableId = TABLE_IPV4_UNICAST; protected int mplsTableId = TABLE_MPLS; + protected int dstMacTableId = TABLE_DMAC; protected int aclTableId = TABLE_ACL; + protected int srcMacTableId = TABLE_SMAC; protected final Logger log = getLogger(getClass()); @@ -448,12 +454,14 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour fwd.treatment().allInstructions().get(0).type() == Instruction.Type.OUTPUT) { OutputInstruction o = (OutputInstruction) fwd.treatment().allInstructions().get(0); if (o.port() == PortNumber.CONTROLLER) { - log.warn("Punts to the controller are handled by misses in" - + " the TMAC, IP and MPLS tables."); - return Collections.emptySet(); + treatmentBuilder.punt(); + treatment = treatmentBuilder.build(); + } else { + treatment = fwd.treatment(); } + } else { + treatment = fwd.treatment(); } - treatment = fwd.treatment(); } else { log.warn("VERSATILE forwarding objective needs next objective ID " + "or treatment."); @@ -475,19 +483,52 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour return Collections.singletonList(ruleBuilder.build()); } - protected Collection<FlowRule> processSpecific(ForwardingObjective fwd) { - log.debug("Processing specific"); + private boolean isSupportedEthTypeObjective(ForwardingObjective fwd) { TrafficSelector selector = fwd.selector(); EthTypeCriterion ethType = (EthTypeCriterion) selector .getCriterion(Criterion.Type.ETH_TYPE); if ((ethType == null) || - (ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && - (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST)) { + ((ethType.ethType().toShort() != Ethernet.TYPE_IPV4) && + (ethType.ethType().toShort() != Ethernet.MPLS_UNICAST))) { + return false; + } + return true; + } + + private boolean isSupportedEthDstObjective(ForwardingObjective fwd) { + TrafficSelector selector = fwd.selector(); + EthCriterion ethDst = (EthCriterion) selector + .getCriterion(Criterion.Type.ETH_DST); + VlanIdCriterion vlanId = (VlanIdCriterion) selector + .getCriterion(Criterion.Type.VLAN_VID); + if (ethDst == null && vlanId == null) { + return false; + } + return true; + } + + protected Collection<FlowRule> processSpecific(ForwardingObjective fwd) { + log.debug("Processing specific"); + boolean isEthTypeObj = isSupportedEthTypeObjective(fwd); + boolean isEthDstObj = isSupportedEthDstObjective(fwd); + + if (isEthTypeObj) { + return processEthTypeSpecificObjective(fwd); + } else if (isEthDstObj) { + return processEthDstSpecificObjective(fwd); + } else { log.warn("processSpecific: Unsupported " + "forwarding objective criteraia"); fail(fwd, ObjectiveError.UNSUPPORTED); return Collections.emptySet(); } + } + + protected Collection<FlowRule> + processEthTypeSpecificObjective(ForwardingObjective fwd) { + TrafficSelector selector = fwd.selector(); + EthTypeCriterion ethType = (EthTypeCriterion) selector + .getCriterion(Criterion.Type.ETH_TYPE); TrafficSelector.Builder filteredSelectorBuilder = DefaultTrafficSelector.builder(); @@ -565,59 +606,167 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour } - protected List<FlowRule> processEthDstFilter(Criterion c, + protected Collection<FlowRule> + processEthDstSpecificObjective(ForwardingObjective fwd) { + List<FlowRule> rules = new ArrayList<>(); + + // Build filtered selector + TrafficSelector selector = fwd.selector(); + EthCriterion ethCriterion = (EthCriterion) selector + .getCriterion(Criterion.Type.ETH_DST); + VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) selector + .getCriterion(Criterion.Type.VLAN_VID); + TrafficSelector.Builder filteredSelectorBuilder = + DefaultTrafficSelector.builder(); + // Do not match MacAddress for subnet broadcast entry + if (!ethCriterion.mac().equals(MacAddress.NONE)) { + filteredSelectorBuilder.matchEthDst(ethCriterion.mac()); + } + filteredSelectorBuilder.matchVlanId(vlanIdCriterion.vlanId()); + TrafficSelector filteredSelector = filteredSelectorBuilder.build(); + + // Build filtered treatment + TrafficTreatment.Builder treatmentBuilder = + DefaultTrafficTreatment.builder(); + if (fwd.treatment() != null) { + treatmentBuilder.deferred(); + fwd.treatment().allInstructions().forEach(treatmentBuilder::add); + } + if (fwd.nextId() != null) { + NextGroup next = flowObjectiveStore.getNextGroup(fwd.nextId()); + if (next != null) { + GroupKey key = appKryo.deserialize(next.data()); + Group group = groupService.getGroup(deviceId, key); + if (group != null) { + treatmentBuilder.deferred().group(group.id()); + } else { + log.warn("Group Missing"); + fail(fwd, ObjectiveError.GROUPMISSING); + return Collections.emptySet(); + } + } + } + treatmentBuilder.immediate().transition(aclTableId); + TrafficTreatment filteredTreatment = treatmentBuilder.build(); + + // Build bridging table entries + FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder(); + flowRuleBuilder.fromApp(fwd.appId()) + .withPriority(fwd.priority()) + .forDevice(deviceId) + .withSelector(filteredSelector) + .withTreatment(filteredTreatment) + .forTable(dstMacTableId); + if (fwd.permanent()) { + flowRuleBuilder.makePermanent(); + } else { + flowRuleBuilder.makeTemporary(fwd.timeout()); + } + rules.add(flowRuleBuilder.build()); + + /* + // TODO Emulate source MAC table behavior + // Do not install source MAC table entry for subnet broadcast + if (!ethCriterion.mac().equals(MacAddress.NONE)) { + // Build filtered selector + selector = fwd.selector(); + ethCriterion = (EthCriterion) selector.getCriterion(Criterion.Type.ETH_DST); + filteredSelectorBuilder = DefaultTrafficSelector.builder(); + filteredSelectorBuilder.matchEthSrc(ethCriterion.mac()); + filteredSelector = filteredSelectorBuilder.build(); + + // Build empty treatment. Apply existing instruction if match. + treatmentBuilder = DefaultTrafficTreatment.builder(); + filteredTreatment = treatmentBuilder.build(); + + // Build bridging table entries + flowRuleBuilder = DefaultFlowRule.builder(); + flowRuleBuilder.fromApp(fwd.appId()) + .withPriority(fwd.priority()) + .forDevice(deviceId) + .withSelector(filteredSelector) + .withTreatment(filteredTreatment) + .forTable(srcMacTableId) + .makePermanent(); + rules.add(flowRuleBuilder.build()); + } + */ + + return rules; + } + + protected List<FlowRule> processEthDstFilter(EthCriterion ethCriterion, + VlanIdCriterion vlanIdCriterion, FilteringObjective filt, + VlanId assignedVlan, ApplicationId applicationId) { + //handling untagged packets via assigned VLAN + if (vlanIdCriterion.vlanId() == VlanId.NONE) { + vlanIdCriterion = (VlanIdCriterion) Criteria.matchVlanId(assignedVlan); + } + + /* + * Note: CpqD switches do not handle MPLS-related operation properly + * for a packet with VLAN tag. We pop VLAN here as a workaround. + * Side effect: HostService learns redundant hosts with same MAC but + * different VLAN. No known side effect on the network reachability. + */ List<FlowRule> rules = new ArrayList<>(); - EthCriterion e = (EthCriterion) c; TrafficSelector.Builder selectorIp = DefaultTrafficSelector .builder(); TrafficTreatment.Builder treatmentIp = DefaultTrafficTreatment .builder(); - selectorIp.matchEthDst(e.mac()); + selectorIp.matchEthDst(ethCriterion.mac()); selectorIp.matchEthType(Ethernet.TYPE_IPV4); + selectorIp.matchVlanId(vlanIdCriterion.vlanId()); + treatmentIp.popVlan(); treatmentIp.transition(ipv4UnicastTableId); FlowRule ruleIp = DefaultFlowRule.builder().forDevice(deviceId) .withSelector(selectorIp.build()) .withTreatment(treatmentIp.build()) .withPriority(filt.priority()).fromApp(applicationId) .makePermanent().forTable(tmacTableId).build(); - log.debug("adding IP ETH rule for MAC: {}", e.mac()); + log.debug("adding IP ETH rule for MAC: {}", ethCriterion.mac()); rules.add(ruleIp); TrafficSelector.Builder selectorMpls = DefaultTrafficSelector .builder(); TrafficTreatment.Builder treatmentMpls = DefaultTrafficTreatment .builder(); - selectorMpls.matchEthDst(e.mac()); + selectorMpls.matchEthDst(ethCriterion.mac()); selectorMpls.matchEthType(Ethernet.MPLS_UNICAST); + selectorMpls.matchVlanId(vlanIdCriterion.vlanId()); + treatmentMpls.popVlan(); treatmentMpls.transition(mplsTableId); FlowRule ruleMpls = DefaultFlowRule.builder() .forDevice(deviceId).withSelector(selectorMpls.build()) .withTreatment(treatmentMpls.build()) .withPriority(filt.priority()).fromApp(applicationId) .makePermanent().forTable(tmacTableId).build(); - log.debug("adding MPLS ETH rule for MAC: {}", e.mac()); + log.debug("adding MPLS ETH rule for MAC: {}", ethCriterion.mac()); rules.add(ruleMpls); return rules; } - protected List<FlowRule> processVlanIdFilter(Criterion c, + protected List<FlowRule> processVlanIdFilter(VlanIdCriterion vlanIdCriterion, FilteringObjective filt, + VlanId assignedVlan, ApplicationId applicationId) { List<FlowRule> rules = new ArrayList<>(); - VlanIdCriterion v = (VlanIdCriterion) c; - log.debug("adding rule for VLAN: {}", v.vlanId()); + log.debug("adding rule for VLAN: {}", vlanIdCriterion.vlanId()); TrafficSelector.Builder selector = DefaultTrafficSelector .builder(); TrafficTreatment.Builder treatment = DefaultTrafficTreatment .builder(); PortCriterion p = (PortCriterion) filt.key(); - if (v.vlanId() != VlanId.NONE) { - selector.matchVlanId(v.vlanId()); + if (vlanIdCriterion.vlanId() != VlanId.NONE) { + selector.matchVlanId(vlanIdCriterion.vlanId()); selector.matchInPort(p.port()); treatment.deferred().popVlan(); + } else { + selector.matchInPort(p.port()); + treatment.immediate().pushVlan().setVlanId(assignedVlan); } treatment.transition(tmacTableId); FlowRule rule = DefaultFlowRule.builder().forDevice(deviceId) @@ -641,30 +790,79 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour fail(filt, ObjectiveError.UNKNOWN); return; } + + EthCriterion ethCriterion = null; + VlanIdCriterion vlanIdCriterion = null; + // convert filtering conditions for switch-intfs into flowrules FlowRuleOperations.Builder ops = FlowRuleOperations.builder(); - for (Criterion c : filt.conditions()) { - if (c.type() == Criterion.Type.ETH_DST) { - for (FlowRule rule : processEthDstFilter(c, - filt, - applicationId)) { - ops = install ? ops.add(rule) : ops.remove(rule); - } - } else if (c.type() == Criterion.Type.VLAN_VID) { - for (FlowRule rule : processVlanIdFilter(c, - filt, - applicationId)) { - ops = install ? ops.add(rule) : ops.remove(rule); - } - } else if (c.type() == Criterion.Type.IPV4_DST) { + + for (Criterion criterion : filt.conditions()) { + if (criterion.type() == Criterion.Type.ETH_DST) { + ethCriterion = (EthCriterion) criterion; + } else if (criterion.type() == Criterion.Type.VLAN_VID) { + vlanIdCriterion = (VlanIdCriterion) criterion; + } else if (criterion.type() == Criterion.Type.IPV4_DST) { log.debug("driver does not process IP filtering rules as it " + "sends all misses in the IP table to the controller"); } else { log.warn("Driver does not currently process filtering condition" - + " of type: {}", c.type()); + + " of type: {}", criterion.type()); fail(filt, ObjectiveError.UNSUPPORTED); } } + + VlanId assignedVlan = null; + if (vlanIdCriterion != null && vlanIdCriterion.vlanId() == VlanId.NONE) { + // Assign a VLAN ID to untagged packets + if (filt.meta() == null) { + log.error("Missing metadata in filtering objective required " + + "for vlan assignment in dev {}", deviceId); + fail(filt, ObjectiveError.BADPARAMS); + return; + } + for (Instruction i : filt.meta().allInstructions()) { + if (i instanceof ModVlanIdInstruction) { + assignedVlan = ((ModVlanIdInstruction) i).vlanId(); + } + } + if (assignedVlan == null) { + log.error("Driver requires an assigned vlan-id to tag incoming " + + "untagged packets. Not processing vlan filters on " + + "device {}", deviceId); + fail(filt, ObjectiveError.BADPARAMS); + return; + } + } + + if (ethCriterion == null) { + log.debug("filtering objective missing dstMac, cannot program TMAC table"); + } else { + for (FlowRule tmacRule : processEthDstFilter(ethCriterion, + vlanIdCriterion, + filt, + assignedVlan, + applicationId)) { + log.debug("adding MAC filtering rules in TMAC table: {} for dev: {}", + tmacRule, deviceId); + ops = install ? ops.add(tmacRule) : ops.remove(tmacRule); + } + } + + if (ethCriterion == null || vlanIdCriterion == null) { + log.debug("filtering objective missing dstMac or vlan, cannot program" + + "Vlan Table"); + } else { + for (FlowRule vlanRule : processVlanIdFilter(vlanIdCriterion, + filt, + assignedVlan, + applicationId)) { + log.debug("adding VLAN filtering rule in VLAN table: {} for dev: {}", + vlanRule, deviceId); + ops = install ? ops.add(vlanRule) : ops.remove(vlanRule); + } + } + // apply filtering flow rules flowRuleService.apply(ops.build(new FlowRuleOperationsContext() { @Override @@ -686,10 +884,10 @@ public class SpringOpenTTP extends AbstractHandlerBehaviour protected void setTableMissEntries() { // set all table-miss-entries populateTableMissEntry(vlanTableId, true, false, false, -1); - populateTableMissEntry(tmacTableId, true, false, false, -1); - populateTableMissEntry(ipv4UnicastTableId, false, true, true, - aclTableId); + populateTableMissEntry(tmacTableId, false, false, true, dstMacTableId); + populateTableMissEntry(ipv4UnicastTableId, false, true, true, aclTableId); populateTableMissEntry(mplsTableId, false, true, true, aclTableId); + populateTableMissEntry(dstMacTableId, false, false, true, aclTableId); populateTableMissEntry(aclTableId, false, false, false, -1); } diff --git a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/SpringOpenTTPDell.java b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/SpringOpenTTPDell.java index 3267d550..91f2679c 100644 --- a/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/SpringOpenTTPDell.java +++ b/framework/src/onos/drivers/src/main/java/org/onosproject/driver/pipeline/SpringOpenTTPDell.java @@ -21,6 +21,7 @@ import java.util.List; import org.onlab.packet.Ethernet; import org.onlab.packet.MacAddress; +import org.onlab.packet.VlanId; import org.onosproject.core.ApplicationId; import org.onosproject.net.behaviour.NextGroup; import org.onosproject.net.flow.DefaultFlowRule; @@ -34,6 +35,7 @@ import org.onosproject.net.flow.criteria.EthCriterion; import org.onosproject.net.flow.criteria.EthTypeCriterion; import org.onosproject.net.flow.criteria.IPCriterion; import org.onosproject.net.flow.criteria.MplsCriterion; +import org.onosproject.net.flow.criteria.VlanIdCriterion; import org.onosproject.net.flow.instructions.Instruction; import org.onosproject.net.flowobjective.FilteringObjective; import org.onosproject.net.flowobjective.ForwardingObjective; @@ -175,12 +177,13 @@ public class SpringOpenTTPDell extends SpringOpenTTP { //Dell switches need ETH_DST based match condition in all IP table entries. //So while processing the ETH_DST based filtering objective, store //the device MAC to be used locally to use it while pushing the IP rules. - protected List<FlowRule> processEthDstFilter(Criterion c, + protected List<FlowRule> processEthDstFilter(EthCriterion ethCriterion, + VlanIdCriterion vlanIdCriterion, FilteringObjective filt, + VlanId assignedVlan, ApplicationId applicationId) { // Store device termination Mac to be used in IP flow entries - EthCriterion e = (EthCriterion) c; - deviceTMac = e.mac(); + deviceTMac = ethCriterion.mac(); log.debug("For now not adding any TMAC rules " + "into Dell switches as it is ignoring"); @@ -189,8 +192,9 @@ public class SpringOpenTTPDell extends SpringOpenTTP { } @Override - protected List<FlowRule> processVlanIdFilter(Criterion c, + protected List<FlowRule> processVlanIdFilter(VlanIdCriterion vlanIdCriterion, FilteringObjective filt, + VlanId assignedVlan, ApplicationId applicationId) { log.debug("For now not adding any VLAN rules " + "into Dell switches as it is ignoring"); diff --git a/framework/src/onos/drivers/src/main/resources/onos-drivers.xml b/framework/src/onos/drivers/src/main/resources/onos-drivers.xml index af498832..0349e1c2 100644 --- a/framework/src/onos/drivers/src/main/resources/onos-drivers.xml +++ b/framework/src/onos/drivers/src/main/resources/onos-drivers.xml @@ -37,6 +37,13 @@ <behaviour api="org.onosproject.net.behaviour.ExtensionResolver" impl="org.onosproject.driver.extensions.NiciraExtensionInterpreter" /> </driver> + <driver name="ovs-netconf" extends="default" + manufacturer="Nicira, Inc\." hwVersion="Open vSwitch" swVersion="2\..*"> + <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" + impl="org.onosproject.driver.handshaker.NiciraSwitchHandshaker"/> + <behaviour api="org.onosproject.net.behaviour.ControllerConfig" + impl="org.onosproject.driver.netconf.NetconfControllerConfig"/> + </driver> <driver name="ovs-corsa" extends="ovs" manufacturer="Corsa" hwVersion="emulation" swVersion="0.0.0"> <behaviour api="org.onosproject.net.behaviour.Pipeliner" @@ -61,7 +68,7 @@ manufacturer="FlowForwarding.org" hwVersion="Unknown" swVersion="LINC-OE OpenFlow Software Switch 1.1"> <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" - impl="org.onosproject.driver.handshaker.OFOpticalSwitchImplLINC13"/> + impl="org.onosproject.driver.handshaker.OfOpticalSwitchImplLinc13"/> </driver> <driver name="corsa" manufacturer="Corsa" hwVersion="Corsa Element" swVersion="2.3.1"> @@ -78,12 +85,12 @@ <driver name="pmc-olt" extends="default" manufacturer="Big Switch Networks" hwVersion="ivs 0.5" swVersion="ivs 0.5"> <behaviour api="org.onosproject.net.behaviour.Pipeliner" - impl="org.onosproject.driver.pipeline.OLTPipeline"/> + impl="org.onosproject.driver.pipeline.OltPipeline"/> </driver> <driver name="g.fast" extends="default" manufacturer="TEST1" hwVersion="TEST2" swVersion="TEST3"> <behaviour api="org.onosproject.net.behaviour.Pipeliner" - impl="org.onosproject.driver.pipeline.OLTPipeline"/> + impl="org.onosproject.driver.pipeline.OltPipeline"/> </driver> <!-- The SoftRouter driver is meant to be used by any software/NPU based ~ switch that wishes to implement a simple 2-table router. To use this @@ -124,7 +131,7 @@ <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" impl="org.onosproject.driver.handshaker.CalientFiberSwitchHandshaker"/> </driver> - <driver name="onosfw" extends="default" + <driver name="onosfw" extends="ovs" manufacturer="" hwVersion="" swVersion=""> <behaviour api="org.onosproject.net.behaviour.Pipeliner" impl="org.onosproject.driver.pipeline.OpenVSwitchPipeline"/> @@ -134,5 +141,8 @@ <behaviour api="org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver" impl="org.onosproject.driver.handshaker.OFOpticalSwitch13"/> </driver> + <driver name="aos" extends="ofdpa" + manufacturer="Accton" hwVersion=".*" swVersion="1.*"> + </driver> </drivers> diff --git a/framework/src/onos/features/features.xml b/framework/src/onos/features/features.xml index 1aae0f33..7d12d7b8 100644 --- a/framework/src/onos/features/features.xml +++ b/framework/src/onos/features/features.xml @@ -106,6 +106,7 @@ <feature>onos-core</feature> <bundle>mvn:org.onosproject/onos-incubator-net/@ONOS-VERSION</bundle> <bundle>mvn:org.onosproject/onos-incubator-store/@ONOS-VERSION</bundle> + <bundle>mvn:org.onosproject/onos-incubator-rpc/@ONOS-VERSION</bundle> </feature> <feature name="onos-rest" version="@FEATURE-VERSION" diff --git a/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/domain/DomainEdge.java b/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/domain/DomainEdge.java index 4a42a740..ad5e5d18 100644 --- a/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/domain/DomainEdge.java +++ b/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/domain/DomainEdge.java @@ -39,7 +39,7 @@ public class DomainEdge extends AbstractEdge<DomainVertex> { @Override public int hashCode() { - return 43 * super.hashCode() + Objects.hash(connectPoint); + return 43 * super.hashCode() + connectPoint.hashCode(); } @Override diff --git a/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalLogicId.java b/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalLogicId.java index 90f5eab6..d5994863 100644 --- a/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalLogicId.java +++ b/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/tunnel/OpticalLogicId.java @@ -63,7 +63,7 @@ public final class OpticalLogicId { @Override public int hashCode() { - return Objects.hash(logicId); + return Objects.hashCode(logicId); } @Override diff --git a/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/DefaultVirtualDevice.java b/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/DefaultVirtualDevice.java index 54a22a46..e3339a9a 100644 --- a/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/DefaultVirtualDevice.java +++ b/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/DefaultVirtualDevice.java @@ -53,7 +53,7 @@ public class DefaultVirtualDevice extends DefaultDevice implements VirtualDevice @Override public int hashCode() { - return 31 * super.hashCode() + Objects.hash(networkId); + return 31 * super.hashCode() + networkId.hashCode(); } @Override diff --git a/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/TenantId.java b/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/TenantId.java index a00f8807..196c17d4 100644 --- a/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/TenantId.java +++ b/framework/src/onos/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/TenantId.java @@ -59,7 +59,7 @@ public final class TenantId { @Override public int hashCode() { - return Objects.hash(id); + return id.hashCode(); } @Override 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/incubator/net/src/test/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManagerTest.java b/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManagerTest.java index 545e21d0..bec9cded 100644 --- a/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManagerTest.java +++ b/framework/src/onos/incubator/net/src/test/java/org/onosproject/incubator/net/mcast/impl/MulticastRouteManagerTest.java @@ -23,10 +23,8 @@ import org.onlab.junit.TestUtils; import org.onlab.packet.IpPrefix; import org.onosproject.common.event.impl.TestEventDispatcher; import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; +import org.onosproject.core.CoreServiceAdapter; import org.onosproject.core.DefaultApplicationId; -import org.onosproject.core.IdGenerator; -import org.onosproject.core.Version; import org.onosproject.net.ConnectPoint; import org.onosproject.net.PortNumber; import org.onosproject.net.mcast.McastEvent; @@ -35,7 +33,6 @@ import org.onosproject.net.mcast.McastRoute; import org.onosproject.store.service.TestStorageService; import java.util.List; -import java.util.Set; import static junit.framework.Assert.fail; import static junit.framework.TestCase.assertEquals; @@ -48,16 +45,16 @@ import static org.onosproject.net.NetTestTools.injectEventDispatcher; public class MulticastRouteManagerTest { McastRoute r1 = new McastRoute(IpPrefix.valueOf("1.1.1.1/8"), - IpPrefix.valueOf("1.1.1.2/8"), - McastRoute.Type.IGMP); + IpPrefix.valueOf("1.1.1.2/8"), + McastRoute.Type.IGMP); McastRoute r11 = new McastRoute(IpPrefix.valueOf("1.1.1.1/8"), - IpPrefix.valueOf("1.1.1.2/8"), - McastRoute.Type.STATIC); + IpPrefix.valueOf("1.1.1.2/8"), + McastRoute.Type.STATIC); McastRoute r2 = new McastRoute(IpPrefix.valueOf("2.2.2.1/8"), - IpPrefix.valueOf("2.2.2.2/8"), - McastRoute.Type.PIM); + IpPrefix.valueOf("2.2.2.2/8"), + McastRoute.Type.PIM); ConnectPoint cp1 = new ConnectPoint(did("1"), PortNumber.portNumber(1)); @@ -75,7 +72,7 @@ public class MulticastRouteManagerTest { injectEventDispatcher(manager, new TestEventDispatcher()); TestUtils.setField(manager, "storageService", new TestStorageService()); TestUtils.setField(manager, "coreService", new TestCoreService()); - events = Lists.newArrayList(); + events = Lists.newArrayList(); manager.activate(); manager.addListener(listener); } @@ -152,49 +149,23 @@ public class MulticastRouteManagerTest { for (int i = 0; i < evs.length; i++) { if (evs[i] != events.get(i).type()) { - fail(String.format("Mismtached events# obtained -> %s : expected %s", + fail(String.format("Mismatched events# obtained -> %s : expected %s", events, evs)); } } } class TestMulticastListener implements McastListener { - @Override public void event(McastEvent event) { events.add(event); } } - private class TestCoreService implements CoreService { - @Override - public Version version() { - return null; - } - - @Override - public Set<ApplicationId> getAppIds() { - return null; - } - - @Override - public ApplicationId getAppId(Short id) { - return null; - } - - @Override - public ApplicationId getAppId(String name) { - return null; - } - - @Override - public ApplicationId registerApplication(String identifier) { - return new DefaultApplicationId(0, identifier); - } - + private class TestCoreService extends CoreServiceAdapter { @Override - public IdGenerator getIdGenerator(String topic) { - return null; + public ApplicationId registerApplication(String name) { + return new DefaultApplicationId(0, name); } } } diff --git a/framework/src/onos/incubator/pom.xml b/framework/src/onos/incubator/pom.xml index c94243d2..5222fe98 100644 --- a/framework/src/onos/incubator/pom.xml +++ b/framework/src/onos/incubator/pom.xml @@ -35,6 +35,7 @@ <module>api</module> <module>net</module> <module>store</module> + <module>rpc</module> </modules> <dependencies> diff --git a/framework/src/onos/netconf/api/pom.xml b/framework/src/onos/netconf/api/pom.xml deleted file mode 100644 index d93b3be3..00000000 --- a/framework/src/onos/netconf/api/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ -<?xml version="1.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. - --> -<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" - xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-netconf</artifactId> - <version>1.4.0-SNAPSHOT</version> - </parent> - <artifactId>onos-netconf-api</artifactId> - <packaging>bundle</packaging> - - <description>ONOS NETCONF plugin API</description> - <dependencies> - <dependency> - <groupId>commons-pool</groupId> - <artifactId>commons-pool</artifactId> - </dependency> - <dependency> - <groupId>io.netty</groupId> - <artifactId>netty-transport</artifactId> - </dependency> - <dependency> - <groupId>io.netty</groupId> - <artifactId>netty-transport-native-epoll</artifactId> - <version>${netty4.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-netconf-rfc</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> - -</project> diff --git a/framework/src/onos/netconf/api/src/main/java/org/onosproject/netconf/Foo.java b/framework/src/onos/netconf/api/src/main/java/org/onosproject/netconf/Foo.java deleted file mode 100644 index ff688f45..00000000 --- a/framework/src/onos/netconf/api/src/main/java/org/onosproject/netconf/Foo.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.onosproject.netconf; - -/** - * Created by tom on 10/19/15. - */ -public class Foo { -} diff --git a/framework/src/onos/netconf/api/src/main/java/org/onosproject/netconf/package-info.java b/framework/src/onos/netconf/api/src/main/java/org/onosproject/netconf/package-info.java deleted file mode 100644 index 5562bd33..00000000 --- a/framework/src/onos/netconf/api/src/main/java/org/onosproject/netconf/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. - */ - -/** - * Created by ray on 10/30/15. - */ -package org.onosproject.netconf; diff --git a/framework/src/onos/netconf/ctl/pom.xml b/framework/src/onos/netconf/ctl/pom.xml deleted file mode 100644 index 56f17c90..00000000 --- a/framework/src/onos/netconf/ctl/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-netconf</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>onos-netconf-ctl</artifactId> - <packaging>bundle</packaging> - - <dependencies> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-netconf-api</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-netconf-rfc</artifactId> - <version>${project.version}</version> - </dependency> - </dependencies> -</project> diff --git a/framework/src/onos/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/Foo.java b/framework/src/onos/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/Foo.java deleted file mode 100644 index e0f6b3df..00000000 --- a/framework/src/onos/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/Foo.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.onosproject.netconf.ctl; - -/** - * Created by tom on 10/19/15. - */ -public class Foo { -} diff --git a/framework/src/onos/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/package-info.java b/framework/src/onos/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/package-info.java deleted file mode 100644 index 84992bf2..00000000 --- a/framework/src/onos/netconf/ctl/src/main/java/org/onosproject/netconf/ctl/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. - */ - -/** - * Created by ray on 10/30/15. - */ -package org.onosproject.netconf.ctl; diff --git a/framework/src/onos/netconf/pom.xml b/framework/src/onos/netconf/pom.xml deleted file mode 100644 index 7a36c227..00000000 --- a/framework/src/onos/netconf/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos</artifactId> - <version>1.4.0-SNAPSHOT</version> - </parent> - - <artifactId>onos-netconf</artifactId> - <packaging>pom</packaging> - - <description>ONOS NETCONF southbound libraries</description> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onlab-misc</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onlab-junit</artifactId> - </dependency> - <dependency> - <groupId>io.netty</groupId> - <artifactId>netty-buffer</artifactId> - </dependency> - <dependency> - <groupId>io.netty</groupId> - <artifactId>netty-handler</artifactId> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - </plugin> - </plugins> - </build> - - <modules> - <module>api</module> - <module>rfc</module> - <module>ctl</module> - </modules> -</project> diff --git a/framework/src/onos/netconf/rfc/pom.xml b/framework/src/onos/netconf/rfc/pom.xml deleted file mode 100644 index fa1e06e2..00000000 --- a/framework/src/onos/netconf/rfc/pom.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-netconf</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>onos-netconf-rfc</artifactId> - <packaging>bundle</packaging> - -</project> diff --git a/framework/src/onos/netconf/rfc/src/main/java/org/onosproject/netconf/rfc/Foo.java b/framework/src/onos/netconf/rfc/src/main/java/org/onosproject/netconf/rfc/Foo.java deleted file mode 100644 index 06963b0c..00000000 --- a/framework/src/onos/netconf/rfc/src/main/java/org/onosproject/netconf/rfc/Foo.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.onosproject.netconf.rfc; - -/** - * Created by tom on 10/19/15. - */ -public class Foo { -} diff --git a/framework/src/onos/netconf/rfc/src/main/java/org/onosproject/netconf/rfc/package-info.java b/framework/src/onos/netconf/rfc/src/main/java/org/onosproject/netconf/rfc/package-info.java deleted file mode 100644 index 616a7ce5..00000000 --- a/framework/src/onos/netconf/rfc/src/main/java/org/onosproject/netconf/rfc/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. - */ - -/** - * Created by ray on 10/30/15. - */ -package org.onosproject.netconf.rfc; diff --git a/framework/src/onos/openflow/api/pom.xml b/framework/src/onos/openflow/api/pom.xml deleted file mode 100644 index e535ac64..00000000 --- a/framework/src/onos/openflow/api/pom.xml +++ /dev/null @@ -1,93 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Copyright 2014 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-of</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>onos-of-api</artifactId> - <packaging>bundle</packaging> - - <description>ONOS OpenFlow controller subsystem API</description> - - <dependencies> - <dependency> - <!-- FIXME once experimenter gets merged to upstream --> - <groupId>org.onosproject</groupId> - <artifactId>openflowj</artifactId> - <version>${openflowj.version}</version> - </dependency> - <dependency> - <groupId>io.netty</groupId> - <artifactId>netty</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-api</artifactId> - </dependency> - - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>2.3</version> - <configuration> - <artifactSet> - <excludes> - <exclude>io.netty:netty</exclude> - <exclude>com.google.guava:guava</exclude> - <exclude>org.slf4j:slfj-api</exclude> - <exclude>ch.qos.logback:logback-core</exclude> - <exclude>ch.qos.logback:logback-classic</exclude> - <exclude>com.google.code.findbugs:annotations</exclude> - </excludes> - </artifactSet> - </configuration> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>shade</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <configuration> - <instructions> - <Export-Package> - org.onosproject.openflow.*,org.projectfloodlight.openflow.* - </Export-Package> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - -</project> diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/DefaultOpenFlowPacketContext.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/DefaultOpenFlowPacketContext.java deleted file mode 100644 index af92a1d0..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/DefaultOpenFlowPacketContext.java +++ /dev/null @@ -1,182 +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.openflow.controller; - -import org.onlab.packet.DeserializationException; -import org.onlab.packet.Ethernet; -import org.projectfloodlight.openflow.protocol.OFPacketIn; -import org.projectfloodlight.openflow.protocol.OFPacketOut; -import org.projectfloodlight.openflow.protocol.OFVersion; -import org.projectfloodlight.openflow.protocol.action.OFAction; -import org.projectfloodlight.openflow.protocol.action.OFActionOutput; -import org.projectfloodlight.openflow.protocol.match.MatchField; -import org.projectfloodlight.openflow.types.OFBufferId; -import org.projectfloodlight.openflow.types.OFPort; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.nio.BufferUnderflowException; -import java.util.Collections; -import java.util.concurrent.atomic.AtomicBoolean; - -import static org.onosproject.security.AppGuard.checkPermission; -import static org.onosproject.security.AppPermission.Type.*; - - -/** - * Default implementation of an OpenFlowPacketContext. - */ -public final class DefaultOpenFlowPacketContext implements OpenFlowPacketContext { - - private final AtomicBoolean free = new AtomicBoolean(true); - private final AtomicBoolean isBuilt = new AtomicBoolean(false); - private final OpenFlowSwitch sw; - private final OFPacketIn pktin; - private OFPacketOut pktout = null; - - private final boolean isBuffered; - - private DefaultOpenFlowPacketContext(OpenFlowSwitch s, OFPacketIn pkt) { - this.sw = s; - this.pktin = pkt; - this.isBuffered = pktin.getBufferId() != OFBufferId.NO_BUFFER; - } - - @Override - public void send() { - checkPermission(PACKET_WRITE); - - if (block() && isBuilt.get()) { - sw.sendMsg(pktout); - } - } - - @Override - public void build(OFPort outPort) { - if (isBuilt.getAndSet(true)) { - return; - } - OFPacketOut.Builder builder = sw.factory().buildPacketOut(); - OFAction act = buildOutput(outPort.getPortNumber()); - pktout = builder.setXid(pktin.getXid()) - .setInPort(pktinInPort()) - .setBufferId(OFBufferId.NO_BUFFER) - .setData(pktin.getData()) -// .setBufferId(pktin.getBufferId()) - .setActions(Collections.singletonList(act)) - .build(); - } - - @Override - public void build(Ethernet ethFrame, OFPort outPort) { - if (isBuilt.getAndSet(true)) { - return; - } - OFPacketOut.Builder builder = sw.factory().buildPacketOut(); - OFAction act = buildOutput(outPort.getPortNumber()); - pktout = builder.setXid(pktin.getXid()) - .setBufferId(OFBufferId.NO_BUFFER) - .setInPort(pktinInPort()) - .setActions(Collections.singletonList(act)) - .setData(ethFrame.serialize()) - .build(); - } - - @Override - public Ethernet parsed() { - checkPermission(PACKET_READ); - - try { - return Ethernet.deserializer().deserialize(pktin.getData(), 0, pktin.getData().length); - } catch (BufferUnderflowException | NullPointerException | - DeserializationException e) { - Logger log = LoggerFactory.getLogger(getClass()); - log.error("packet deserialization problem : {}", e.getMessage()); - return null; - } - } - - @Override - public Dpid dpid() { - checkPermission(PACKET_READ); - - return new Dpid(sw.getId()); - } - - /** - * Creates an OpenFlow packet context based on a packet-in. - * - * @param s OpenFlow switch - * @param pkt OpenFlow packet-in - * @return the OpenFlow packet context - */ - public static OpenFlowPacketContext packetContextFromPacketIn(OpenFlowSwitch s, - OFPacketIn pkt) { - return new DefaultOpenFlowPacketContext(s, pkt); - } - - @Override - public Integer inPort() { - checkPermission(PACKET_READ); - - return pktinInPort().getPortNumber(); - } - - private OFPort pktinInPort() { - if (pktin.getVersion() == OFVersion.OF_10) { - return pktin.getInPort(); - } - return pktin.getMatch().get(MatchField.IN_PORT); - } - - @Override - public byte[] unparsed() { - checkPermission(PACKET_READ); - - return pktin.getData().clone(); - - } - - private OFActionOutput buildOutput(Integer port) { - OFActionOutput act = sw.factory().actions() - .buildOutput() - .setPort(OFPort.of(port)) - .build(); - return act; - } - - @Override - public boolean block() { - checkPermission(PACKET_WRITE); - - return free.getAndSet(false); - } - - @Override - public boolean isHandled() { - checkPermission(PACKET_READ); - - return !free.get(); - } - - @Override - public boolean isBuffered() { - checkPermission(PACKET_READ); - - return isBuffered; - } - -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/Dpid.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/Dpid.java deleted file mode 100644 index 6e0f65be..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/Dpid.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2014 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; - -import org.projectfloodlight.openflow.util.HexString; - -import java.net.URI; -import java.net.URISyntaxException; - -import static com.google.common.base.Preconditions.checkArgument; -import static org.onlab.util.Tools.fromHex; -import static org.onlab.util.Tools.toHex; - -/** - * The class representing a network switch DPID. - * This class is immutable. - */ -public final class Dpid { - - private static final String SCHEME = "of"; - private static final long UNKNOWN = 0; - private final long value; - - /** - * Default constructor. - */ - public Dpid() { - this.value = Dpid.UNKNOWN; - } - - /** - * Constructor from a long value. - * - * @param value the value to use. - */ - public Dpid(long value) { - this.value = value; - } - - /** - * Constructor from a string. - * - * @param value the value to use. - */ - public Dpid(String value) { - this.value = HexString.toLong(value); - } - - /** - * Get the value of the DPID. - * - * @return the value of the DPID. - */ - public long value() { - return value; - } - - /** - * Convert the DPID value to a ':' separated hexadecimal string. - * - * @return the DPID value as a ':' separated hexadecimal string. - */ - @Override - public String toString() { - return HexString.toHexString(this.value); - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof Dpid)) { - return false; - } - - Dpid otherDpid = (Dpid) other; - - return value == otherDpid.value; - } - - @Override - public int hashCode() { - return Long.hashCode(value); - } - - /** - * Returns DPID created from the given device URI. - * - * @param uri device URI - * @return dpid - */ - public static Dpid dpid(URI uri) { - checkArgument(uri.getScheme().equals(SCHEME), "Unsupported URI scheme"); - return new Dpid(fromHex(uri.getSchemeSpecificPart())); - } - - /** - * Produces device URI from the given DPID. - * - * @param dpid device dpid - * @return device URI - */ - public static URI uri(Dpid dpid) { - return uri(dpid.value); - } - - /** - * Produces device URI from the given DPID long. - * - * @param value device dpid as long - * @return device URI - */ - public static URI uri(long value) { - try { - return new URI(SCHEME, toHex(value), null); - } catch (URISyntaxException e) { - return null; - } - } - -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/ExtensionInterpreter.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/ExtensionInterpreter.java deleted file mode 100644 index 44b121ac..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/ExtensionInterpreter.java +++ /dev/null @@ -1,58 +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.openflow.controller; - -import com.google.common.annotations.Beta; -import org.onosproject.net.driver.HandlerBehaviour; -import org.onosproject.net.flow.instructions.ExtensionInstruction; -import org.onosproject.net.flow.instructions.ExtensionType; -import org.projectfloodlight.openflow.protocol.OFFactory; -import org.projectfloodlight.openflow.protocol.action.OFAction; - -/** - * Interprets extension instructions and converts them to/from OpenFlow objects. - */ -@Beta -public interface ExtensionInterpreter extends HandlerBehaviour { - - /** - * Returns true if the given extension instruction is supported by this - * driver. - * - * @param extensionType extension instruction type - * @return true if the instruction is supported, otherwise false - */ - boolean supported(ExtensionType extensionType); - - /** - * Maps an extension instruction to an OpenFlow action. - * - * @param factory OpenFlow factory - * @param extensionInstruction extension instruction - * @return OpenFlow action - */ - OFAction mapInstruction(OFFactory factory, ExtensionInstruction extensionInstruction); - - /** - * Maps an OpenFlow action to an extension instruction. - * - * @param action OpenFlow action - * @return extension instruction - */ - ExtensionInstruction mapAction(OFAction action); - -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowController.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowController.java deleted file mode 100644 index 2c68fa0b..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowController.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2014 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; - -import org.projectfloodlight.openflow.protocol.OFMessage; - -/** - * Abstraction of an OpenFlow controller. Serves as a one stop - * shop for obtaining OpenFlow devices and (un)register listeners - * on OpenFlow events - */ -public interface OpenFlowController { - - /** - * Returns all switches known to this OF controller. - * @return Iterable of dpid elements - */ - Iterable<OpenFlowSwitch> getSwitches(); - - /** - * Returns all master switches known to this OF controller. - * @return Iterable of dpid elements - */ - Iterable<OpenFlowSwitch> getMasterSwitches(); - - /** - * Returns all equal switches known to this OF controller. - * @return Iterable of dpid elements - */ - Iterable<OpenFlowSwitch> getEqualSwitches(); - - - /** - * Returns the actual switch for the given Dpid. - * @param dpid the switch to fetch - * @return the interface to this switch - */ - OpenFlowSwitch getSwitch(Dpid dpid); - - /** - * Returns the actual master switch for the given Dpid, if one exists. - * @param dpid the switch to fetch - * @return the interface to this switch - */ - OpenFlowSwitch getMasterSwitch(Dpid dpid); - - /** - * Returns the actual equal switch for the given Dpid, if one exists. - * @param dpid the switch to fetch - * @return the interface to this switch - */ - OpenFlowSwitch getEqualSwitch(Dpid dpid); - - /** - * Register a listener for meta events that occur to OF - * devices. - * @param listener the listener to notify - */ - void addListener(OpenFlowSwitchListener listener); - - /** - * Unregister a listener. - * - * @param listener the listener to unregister - */ - void removeListener(OpenFlowSwitchListener listener); - - /** - * Register a listener for packet events. - * @param priority the importance of this listener, lower values are more important - * @param listener the listener to notify - */ - void addPacketListener(int priority, PacketListener listener); - - /** - * Unregister a listener. - * - * @param listener the listener to unregister - */ - void removePacketListener(PacketListener listener); - - /** - * Register a listener for OF msg events. - * - * @param listener the listener to notify - */ - void addEventListener(OpenFlowEventListener listener); - - /** - * Unregister a listener. - * - * @param listener the listener to unregister - */ - void removeEventListener(OpenFlowEventListener listener); - - /** - * Send a message to a particular switch. - * @param dpid the switch to send to. - * @param msg the message to send - */ - void write(Dpid dpid, OFMessage msg); - - /** - * Process a message and notify the appropriate listeners. - * - * @param dpid the dpid the message arrived on - * @param msg the message to process. - */ - void processPacket(Dpid dpid, OFMessage msg); - - /** - * Sets the role for a given switch. - * @param role the desired role - * @param dpid the switch to set the role for. - */ - void setRole(Dpid dpid, RoleState role); -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowPacketContext.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowPacketContext.java deleted file mode 100644 index 740d89d0..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowPacketContext.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2014 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; - -import org.onlab.packet.Ethernet; -import org.projectfloodlight.openflow.types.OFPort; - -/** - * A representation of a packet context which allows any provider - * to view a packet in event, but may block the response to the - * event if blocked has been called. This packet context can be used - * to react to the packet in event with a packet out. - */ -public interface OpenFlowPacketContext { - - /** - * Blocks further responses (ie. send() calls) on this - * packet in event. - * @return true if blocks - */ - boolean block(); - - /** - * Checks whether the packet has been handled. - * @return true if handled, false otherwise. - */ - boolean isHandled(); - - /** - * Provided build has been called send the packet - * out the switch it came in on. - */ - void send(); - - /** - * Build the packet out in response to this packet in event. - * @param outPort the out port to send to packet out of. - */ - void build(OFPort outPort); - - /** - * Build the packet out in response to this packet in event. - * @param ethFrame the actual packet to send out. - * @param outPort the out port to send to packet out of. - */ - void build(Ethernet ethFrame, OFPort outPort); - - /** - * Provided a handle onto the parsed payload. - * @return the parsed form of the payload. - */ - Ethernet parsed(); - - /** - * Provide an unparsed copy of the data. - * @return the unparsed form of the payload. - */ - byte[] unparsed(); - - /** - * Provide the dpid of the switch where the packet in arrived. - * @return the dpid of the switch. - */ - Dpid dpid(); - - /** - * Provide the port on which the packet arrived. - * @return the port - */ - Integer inPort(); - - /** - * Indicates that this packet is buffered at the switch. - * @return buffer indication - */ - boolean isBuffered(); -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowSwitch.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowSwitch.java deleted file mode 100644 index 51a2ce42..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowSwitch.java +++ /dev/null @@ -1,160 +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.openflow.controller; - -import org.onosproject.net.Device; -import org.projectfloodlight.openflow.protocol.OFFactory; -import org.projectfloodlight.openflow.protocol.OFMessage; -import org.projectfloodlight.openflow.protocol.OFPortDesc; - -import java.util.List; - -/** - * Represents to provider facing side of a switch. - */ -public interface OpenFlowSwitch { - - /** - * Writes the message to the driver. - * - * Note: - * Calling {@link #sendMsg(OFMessage)} does NOT guarantee the messages to be - * transmitted on the wire in order, especially during role transition. - * The messages may be reordered at the switch side. - * - * Calling {@link #sendMsg(List)} guarantee the messages inside the list - * to be transmitted on the wire in order. - * - * @param msg the message to write - */ - void sendMsg(OFMessage msg); - - /** - * Writes the OFMessage list to the driver. - * - * @param msgs the messages to be written - */ - void sendMsg(List<OFMessage> msgs); - - /** - * Handle a message from the switch. - * @param fromSwitch the message to handle - */ - void handleMessage(OFMessage fromSwitch); - - /** - * Sets the role for this switch. - * @param role the role to set. - */ - void setRole(RoleState role); - - /** - * Fetch the role for this switch. - * @return the role. - */ - RoleState getRole(); - - /** - * Fetches the ports of this switch. - * @return unmodifiable list of the ports. - */ - List<OFPortDesc> getPorts(); - - /** - * Provides the factory for this OF version. - * @return OF version specific factory. - */ - OFFactory factory(); - - /** - * Gets a string version of the ID for this switch. - * - * @return string version of the ID - */ - String getStringId(); - - /** - * Gets the datapathId of the switch. - * - * @return the switch dpid in long format - */ - long getId(); - - /** - * fetch the manufacturer description. - * @return the description - */ - String manufacturerDescription(); - - /** - * fetch the datapath description. - * @return the description - */ - String datapathDescription(); - - /** - * fetch the hardware description. - * @return the description - */ - String hardwareDescription(); - - /** - * fetch the software description. - * @return the description - */ - String softwareDescription(); - - /** - * fetch the serial number. - * @return the serial - */ - String serialNumber(); - - /** - * Checks if the switch is still connected. - * - * @return whether the switch is still connected - */ - boolean isConnected(); - - /** - * Disconnects the switch by closing the TCP connection. Results in a call - * to the channel handler's channelDisconnected method for cleanup - */ - void disconnectSwitch(); - - /** - * Notifies the controller that the device has responded to a set-role request. - * - * @param requested the role requested by the controller - * @param response the role set at the device - */ - void returnRoleReply(RoleState requested, RoleState response); - - /** - * Returns the switch device type. - * - * @return device type - */ - Device.Type deviceType(); - - /** - * Identifies the channel used to communicate with the switch. - * - * @return string representation of the connection to the device - */ - String channelId(); -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowSwitchListener.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowSwitchListener.java deleted file mode 100644 index 2da41335..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/OpenFlowSwitchListener.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2014 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; - -import org.projectfloodlight.openflow.protocol.OFPortStatus; - -/** - * Allows for providers interested in Switch events to be notified. - */ -public interface OpenFlowSwitchListener { - - /** - * Notify that the switch was added. - * @param dpid the switch where the event occurred - */ - void switchAdded(Dpid dpid); - - /** - * Notify that the switch was removed. - * @param dpid the switch where the event occurred. - */ - void switchRemoved(Dpid dpid); - - /** - * Notify that the switch has changed in some way. - * @param dpid the switch that changed - */ - void switchChanged(Dpid dpid); - - /** - * Notify that a port has changed. - * @param dpid the switch on which the change happened. - * @param status the new state of the port. - */ - void portChanged(Dpid dpid, OFPortStatus status); - - /** - * Notify that a role imposed on a switch failed to take hold. - * - * @param dpid the switch that failed role assertion - * @param requested the role controller requested - * @param response role reply from the switch - */ - void receivedRoleReply(Dpid dpid, RoleState requested, RoleState response); -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/PacketListener.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/PacketListener.java deleted file mode 100644 index 817a6cdf..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/PacketListener.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2014 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; - -/** - * Notifies providers about Packet in events. - */ -public interface PacketListener { - - /** - * Handles the packet. - * - * @param pktCtx the packet context - */ - void handlePacket(OpenFlowPacketContext pktCtx); -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/PortDescPropertyType.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/PortDescPropertyType.java deleted file mode 100644 index 3a0f1a0d..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/PortDescPropertyType.java +++ /dev/null @@ -1,39 +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.openflow.controller; - -/** - * Port description property types (OFPPDPT enums) in OF 1.3 <. - */ -public enum PortDescPropertyType { - ETHERNET(0), /* Ethernet port */ - OPTICAL(1), /* Optical port */ - OPTICAL_TRANSPORT(2), /* OF1.3 Optical transport extension */ - PIPELINE_INPUT(2), /* Ingress pipeline */ - PIPELINE_OUTPUT(3), /* Egress pipeline */ - RECIRCULATE(4), /* Recirculation */ - EXPERIMENTER(0xffff); /* Experimenter-implemented */ - - private final int value; - - PortDescPropertyType(int v) { - value = v; - } - - public int valueOf() { - return value; - } -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/RoleState.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/RoleState.java deleted file mode 100644 index b8304f39..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/RoleState.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2014 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; - -import org.projectfloodlight.openflow.protocol.OFControllerRole; - -/** - * The role of the controller as it pertains to a particular switch. - * Note that this definition of the role enum is different from the - * OF1.3 definition. It is maintained here to be backward compatible to - * earlier versions of the controller code. This enum is translated - * to the OF1.3 enum, before role messages are sent to the switch. - * See sendRoleRequestMessage method in OFSwitchImpl - */ -public enum RoleState { - EQUAL(OFControllerRole.ROLE_EQUAL), - MASTER(OFControllerRole.ROLE_MASTER), - SLAVE(OFControllerRole.ROLE_SLAVE); - - private RoleState(OFControllerRole nxRole) { - nxRole.ordinal(); - } - -} - - - diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/ThirdPartyMessage.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/ThirdPartyMessage.java deleted file mode 100644 index 59ef33cf..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/ThirdPartyMessage.java +++ /dev/null @@ -1,74 +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.openflow.controller; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.projectfloodlight.openflow.protocol.OFMessage; -import org.projectfloodlight.openflow.protocol.OFType; -import org.projectfloodlight.openflow.protocol.OFVersion; - -import com.google.common.hash.PrimitiveSink; -/** - * Used to support for the third party privacy flow rule. - * it implements OFMessage interface to use exist adapter API. - */ -public class ThirdPartyMessage implements OFMessage { - - private final byte[] payLoad; //privacy flow rule - - public ThirdPartyMessage(byte[] payLoad) { - this.payLoad = payLoad; - } - - public byte[] payLoad() { - return payLoad; - } - - @Override - public void putTo(PrimitiveSink sink) { - // Do nothing here for now. - } - - @Override - public OFVersion getVersion() { - // Do nothing here for now. - return null; - } - - @Override - public OFType getType() { - // Do nothing here for now. - return null; - } - - @Override - public long getXid() { - // Do nothing here for now. - return 0; - } - - @Override - public void writeTo(ChannelBuffer channelBuffer) { - // Do nothing here for now. - } - - @Override - public Builder createBuilder() { - // Do nothing here for now. - return null; - } - -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/WithTypedPorts.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/WithTypedPorts.java deleted file mode 100644 index 8b82b4a7..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/WithTypedPorts.java +++ /dev/null @@ -1,45 +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.openflow.controller; - -import java.util.List; -import java.util.Set; - -import org.projectfloodlight.openflow.protocol.OFObject; - -/** - * An interface implemented by OpenFlow devices that enables providers to - * retrieve ports based on port property. - */ -public interface WithTypedPorts { - - /** - * Return a list of interfaces (ports) of the type associated with this - * OpenFlow switch. - * - * @param type The port description property type of requested ports - * @return A potentially empty list of ports. - */ - List<? extends OFObject> getPortsOf(PortDescPropertyType type); - - /** - * Returns the port property types supported by the driver implementing this - * interface. - * - * @return A set of port property types - */ - Set<PortDescPropertyType> getPortTypes(); -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/AbstractOpenFlowSwitch.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/AbstractOpenFlowSwitch.java deleted file mode 100644 index 2c19837e..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/AbstractOpenFlowSwitch.java +++ /dev/null @@ -1,449 +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.openflow.controller.driver; - -import org.jboss.netty.channel.Channel; -import org.onlab.packet.IpAddress; -import org.onosproject.net.Device; -import org.onosproject.net.driver.AbstractHandlerBehaviour; -import org.onosproject.openflow.controller.Dpid; -import org.onosproject.openflow.controller.RoleState; -import org.projectfloodlight.openflow.protocol.OFDescStatsReply; -import org.projectfloodlight.openflow.protocol.OFErrorMsg; -import org.projectfloodlight.openflow.protocol.OFExperimenter; -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.OFNiciraControllerRoleRequest; -import org.projectfloodlight.openflow.protocol.OFPortDesc; -import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; -import org.projectfloodlight.openflow.protocol.OFPortStatus; -import org.projectfloodlight.openflow.protocol.OFRoleReply; -import org.projectfloodlight.openflow.protocol.OFRoleRequest; -import org.projectfloodlight.openflow.protocol.OFVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; - -/** - * An abstract representation of an OpenFlow switch. Can be extended by others - * to serve as a base for their vendor specific representation of a switch. - */ -public abstract class AbstractOpenFlowSwitch extends AbstractHandlerBehaviour - implements OpenFlowSwitchDriver { - - protected final Logger log = LoggerFactory.getLogger(getClass()); - - private Channel channel; - protected String channelId; - - private boolean connected; - protected boolean startDriverHandshakeCalled = false; - private Dpid dpid; - private OpenFlowAgent agent; - private final AtomicInteger xidCounter = new AtomicInteger(0); - - private OFVersion ofVersion; - - protected List<OFPortDescStatsReply> ports = new ArrayList<>(); - - protected boolean tableFull; - - private RoleHandler roleMan; - - protected RoleState role; - - protected OFFeaturesReply features; - protected OFDescStatsReply desc; - - List<OFMessage> messagesPendingMastership; - - @Override - public void init(Dpid dpid, OFDescStatsReply desc, OFVersion ofv) { - this.dpid = dpid; - this.desc = desc; - this.ofVersion = ofv; - } - - //************************ - // Channel related - //************************ - - @Override - public final void disconnectSwitch() { - this.channel.close(); - } - - @Override - public void sendMsg(OFMessage msg) { - this.sendMsg(Collections.singletonList(msg)); - } - - @Override - public final void sendMsg(List<OFMessage> msgs) { - if (role == RoleState.MASTER && channel.isConnected()) { - channel.write(msgs); - } else if (messagesPendingMastership != null) { - messagesPendingMastership.addAll(msgs); - log.debug("Enqueue message for switch {}. queue size after is {}", - dpid, messagesPendingMastership.size()); - } else { - log.warn("Dropping message for switch {} (role: {}, connected: {}): {}", - dpid, role, channel.isConnected(), msgs); - } - } - - @Override - public final void sendRoleRequest(OFMessage msg) { - if (msg instanceof OFRoleRequest || - msg instanceof OFNiciraControllerRoleRequest) { - channel.write(Collections.singletonList(msg)); - return; - } - throw new IllegalArgumentException("Someone is trying to send " + - "a non role request message"); - } - - @Override - public final void sendHandshakeMessage(OFMessage message) { - if (!this.isDriverHandshakeComplete()) { - channel.write(Collections.singletonList(message)); - } - } - - @Override - public final boolean isConnected() { - return this.connected; - } - - @Override - public final void setConnected(boolean connected) { - this.connected = connected; - } - - @Override - public final void setChannel(Channel channel) { - this.channel = channel; - final SocketAddress address = channel.getRemoteAddress(); - if (address instanceof InetSocketAddress) { - final InetSocketAddress inetAddress = (InetSocketAddress) address; - final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress()); - if (ipAddress.isIp4()) { - channelId = ipAddress.toString() + ':' + inetAddress.getPort(); - } else { - channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort(); - } - } - } - - @Override - public String channelId() { - return channelId; - } - - //************************ - // Switch features related - //************************ - - @Override - public final long getId() { - return this.dpid.value(); - } - - @Override - public final String getStringId() { - return this.dpid.toString(); - } - - @Override - public final void setOFVersion(OFVersion ofV) { - this.ofVersion = ofV; - } - - @Override - public void setTableFull(boolean full) { - this.tableFull = full; - } - - @Override - public void setFeaturesReply(OFFeaturesReply featuresReply) { - this.features = featuresReply; - } - - @Override - public abstract Boolean supportNxRole(); - - //************************ - // Message handling - //************************ - /** - * Handle the message coming from the dataplane. - * - * @param m the actual message - */ - @Override - public final void handleMessage(OFMessage m) { - if (this.role == RoleState.MASTER || m instanceof OFPortStatus) { - this.agent.processMessage(dpid, m); - } - } - - @Override - public RoleState getRole() { - return role; - } - - @Override - public final boolean connectSwitch() { - return this.agent.addConnectedSwitch(dpid, this); - } - - @Override - public final boolean activateMasterSwitch() { - return this.agent.addActivatedMasterSwitch(dpid, this); - } - - @Override - public final boolean activateEqualSwitch() { - return this.agent.addActivatedEqualSwitch(dpid, this); - } - - @Override - public final void transitionToEqualSwitch() { - this.agent.transitionToEqualSwitch(dpid); - } - - @Override - public final void transitionToMasterSwitch() { - this.agent.transitionToMasterSwitch(dpid); - if (messagesPendingMastership != null) { - this.sendMsg(messagesPendingMastership); - log.debug("Sending {} pending messages to switch {}", - messagesPendingMastership.size(), dpid); - messagesPendingMastership = null; - } - } - - @Override - public final void removeConnectedSwitch() { - this.agent.removeConnectedSwitch(dpid); - } - - @Override - public OFFactory factory() { - return OFFactories.getFactory(ofVersion); - } - - @Override - public void setPortDescReply(OFPortDescStatsReply portDescReply) { - this.ports.add(portDescReply); - } - - @Override - public void setPortDescReplies(List<OFPortDescStatsReply> portDescReplies) { - this.ports.addAll(portDescReplies); - } - - @Override - public void returnRoleReply(RoleState requested, RoleState response) { - this.agent.returnRoleReply(dpid, requested, response); - } - - @Override - public abstract void startDriverHandshake(); - - @Override - public abstract boolean isDriverHandshakeComplete(); - - @Override - public abstract void processDriverHandshakeMessage(OFMessage m); - - - // Role Handling - - @Override - public void setRole(RoleState role) { - try { - if (this.roleMan.sendRoleRequest(role, RoleRecvStatus.MATCHED_SET_ROLE)) { - log.debug("Sending role {} to switch {}", role, getStringId()); - if (role == RoleState.SLAVE || role == RoleState.EQUAL) { - this.role = role; - } else { - if (messagesPendingMastership == null) { - log.debug("Initializing new queue for switch {}", dpid); - messagesPendingMastership = new ArrayList<>(); - } - } - } else { - this.role = role; - } - } catch (IOException e) { - log.error("Unable to write to switch {}.", this.dpid); - } - } - - @Override - public void reassertRole() { - if (this.getRole() == RoleState.MASTER) { - log.warn("Received permission error from switch {} while " + - "being master. Reasserting master role.", - this.getStringId()); - this.setRole(RoleState.MASTER); - } - } - - - - @Override - public void handleRole(OFMessage m) throws SwitchStateException { - RoleReplyInfo rri = roleMan.extractOFRoleReply((OFRoleReply) m); - RoleRecvStatus rrs = roleMan.deliverRoleReply(rri); - if (rrs == RoleRecvStatus.MATCHED_SET_ROLE) { - if (rri.getRole() == RoleState.MASTER) { - this.role = rri.getRole(); - this.transitionToMasterSwitch(); - } else if (rri.getRole() == RoleState.EQUAL || - rri.getRole() == RoleState.SLAVE) { - this.transitionToEqualSwitch(); - } - } else { - log.warn("Failed to set role for {}", this.getStringId()); - } - } - - @Override - public void handleNiciraRole(OFMessage m) throws SwitchStateException { - RoleState r = this.roleMan.extractNiciraRoleReply((OFExperimenter) m); - if (r == null) { - // The message wasn't really a Nicira role reply. We just - // dispatch it to the OFMessage listeners in this case. - this.handleMessage(m); - return; - } - - RoleRecvStatus rrs = this.roleMan.deliverRoleReply( - new RoleReplyInfo(r, null, m.getXid())); - if (rrs == RoleRecvStatus.MATCHED_SET_ROLE) { - if (r == RoleState.MASTER) { - this.role = r; - this.transitionToMasterSwitch(); - } else if (r == RoleState.EQUAL || - r == RoleState.SLAVE) { - this.transitionToEqualSwitch(); - } - } else { - this.disconnectSwitch(); - } - } - - @Override - public boolean handleRoleError(OFErrorMsg error) { - try { - return RoleRecvStatus.OTHER_EXPECTATION != this.roleMan.deliverError(error); - } catch (SwitchStateException e) { - this.disconnectSwitch(); - } - return true; - } - - - - @Override - public final void setAgent(OpenFlowAgent ag) { - if (this.agent == null) { - this.agent = ag; - } - } - - @Override - public final void setRoleHandler(RoleHandler roleHandler) { - if (this.roleMan == null) { - this.roleMan = roleHandler; - } - } - - @Override - public void setSwitchDescription(OFDescStatsReply d) { - this.desc = d; - } - - @Override - public int getNextTransactionId() { - return this.xidCounter.getAndIncrement(); - } - - @Override - public List<OFPortDesc> getPorts() { - return this.ports.stream() - .flatMap((portReply) -> (portReply.getEntries().stream())) - .collect(Collectors.toList()); - //return Collections.unmodifiableList(ports.getEntries()); - } - - @Override - public String manufacturerDescription() { - return this.desc.getMfrDesc(); - } - - - @Override - public String datapathDescription() { - return this.desc.getDpDesc(); - } - - - @Override - public String hardwareDescription() { - return this.desc.getHwDesc(); - } - - @Override - public String softwareDescription() { - return this.desc.getSwDesc(); - } - - @Override - public String serialNumber() { - return this.desc.getSerialNum(); - } - - - @Override - public Device.Type deviceType() { - return Device.Type.SWITCH; - } - - - @Override - public String toString() { - return this.getClass().getName() + " [" + ((channel != null) - ? channel.getRemoteAddress() : "?") - + " DPID[" + ((getStringId() != null) ? getStringId() : "?") + "]]"; - } - - - -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/OpenFlowAgent.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/OpenFlowAgent.java deleted file mode 100644 index ad6dede1..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/OpenFlowAgent.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2014 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.driver; - -import org.onosproject.openflow.controller.Dpid; -import org.onosproject.openflow.controller.OpenFlowSwitch; -import org.onosproject.openflow.controller.RoleState; -import org.projectfloodlight.openflow.protocol.OFMessage; - -/** - * Responsible for keeping track of the current set of switches - * connected to the system. As well as whether they are in Master - * role or not. - * - */ -public interface OpenFlowAgent { - - /** - * Add a switch that has just connected to the system. - * @param dpid the dpid to add - * @param sw the actual switch object. - * @return true if added, false otherwise. - */ - boolean addConnectedSwitch(Dpid dpid, OpenFlowSwitch sw); - - /** - * Checks if the activation for this switch is valid. - * @param dpid the dpid to check - * @return true if valid, false otherwise - */ - boolean validActivation(Dpid dpid); - - /** - * Called when a switch is activated, with this controller's role as MASTER. - * @param dpid the dpid to add. - * @param sw the actual switch - * @return true if added, false otherwise. - */ - boolean addActivatedMasterSwitch(Dpid dpid, OpenFlowSwitch sw); - - /** - * Called when a switch is activated, with this controller's role as EQUAL. - * @param dpid the dpid to add. - * @param sw the actual switch - * @return true if added, false otherwise. - */ - boolean addActivatedEqualSwitch(Dpid dpid, OpenFlowSwitch sw); - - /** - * Called when this controller's role for a switch transitions from equal - * to master. For 1.0 switches, we internally refer to the role 'slave' as - * 'equal' - so this transition is equivalent to 'addActivatedMasterSwitch'. - * @param dpid the dpid to transistion. - */ - void transitionToMasterSwitch(Dpid dpid); - - /** - * Called when this controller's role for a switch transitions to equal. - * For 1.0 switches, we internally refer to the role 'slave' as - * 'equal'. - * @param dpid the dpid to transistion. - */ - void transitionToEqualSwitch(Dpid dpid); - - /** - * Clear all state in controller switch maps for a switch that has - * disconnected from the local controller. Also release control for - * that switch from the global repository. Notify switch listeners. - * @param dpid the dpid to remove. - */ - void removeConnectedSwitch(Dpid dpid); - - /** - * Process a message coming from a switch. - * - * @param dpid the dpid the message came on. - * @param m the message to process - */ - void processMessage(Dpid dpid, OFMessage m); - - /** - * Notifies the controller that role assertion has failed. - * - * @param dpid the switch that failed role assertion - * @param requested the role controller requested - * @param response role reply from the switch - */ - void returnRoleReply(Dpid dpid, RoleState requested, RoleState response); -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/OpenFlowSwitchDriver.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/OpenFlowSwitchDriver.java deleted file mode 100644 index b259388c..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/OpenFlowSwitchDriver.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright 2014 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.driver; - -import org.jboss.netty.channel.Channel; -import org.onosproject.net.driver.HandlerBehaviour; -import org.onosproject.openflow.controller.Dpid; -import org.onosproject.openflow.controller.OpenFlowSwitch; -import org.projectfloodlight.openflow.protocol.OFDescStatsReply; -import org.projectfloodlight.openflow.protocol.OFErrorMsg; -import org.projectfloodlight.openflow.protocol.OFFeaturesReply; -import org.projectfloodlight.openflow.protocol.OFMessage; -import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; -import org.projectfloodlight.openflow.protocol.OFVersion; - -import java.util.List; - -/** - * Represents the driver side of an OpenFlow switch. - * This interface should never be exposed to consumers. - * - */ -public interface OpenFlowSwitchDriver extends OpenFlowSwitch, HandlerBehaviour { - - /** - * Sets the OpenFlow agent to be used. This method - * can only be called once. - * @param agent the agent to set. - */ - void setAgent(OpenFlowAgent agent); - - /** - * Sets the Role handler object. - * This method can only be called once. - * @param roleHandler the roleHandler class - */ - void setRoleHandler(RoleHandler roleHandler); - - /** - * Reasserts this controllers role to the switch. - * Useful in cases where the switch no longer agrees - * that this controller has the role it claims. - */ - void reassertRole(); - - /** - * Handle the situation where the role request triggers an error. - * @param error the error to handle. - * @return true if handled, false if not. - */ - boolean handleRoleError(OFErrorMsg error); - - /** - * If this driver know of Nicira style role messages, these should - * be handled here. - * @param m the role message to handle. - * @throws SwitchStateException if the message received was - * not a nicira role or was malformed. - */ - void handleNiciraRole(OFMessage m) throws SwitchStateException; - - /** - * Handle OF 1.x (where x > 0) role messages. - * @param m the role message to handle - * @throws SwitchStateException if the message received was - * not a nicira role or was malformed. - */ - void handleRole(OFMessage m) throws SwitchStateException; - - /** - * Announce to the OpenFlow agent that this switch has connected. - * @return true if successful, false if duplicate switch. - */ - boolean connectSwitch(); - - /** - * Activate this MASTER switch-controller relationship in the OF agent. - * @return true is successful, false is switch has not - * connected or is unknown to the system. - */ - boolean activateMasterSwitch(); - - /** - * Activate this EQUAL switch-controller relationship in the OF agent. - * @return true is successful, false is switch has not - * connected or is unknown to the system. - */ - boolean activateEqualSwitch(); - - /** - * Transition this switch-controller relationship to an EQUAL state. - */ - void transitionToEqualSwitch(); - - /** - * Transition this switch-controller relationship to an Master state. - */ - void transitionToMasterSwitch(); - - /** - * Remove this switch from the openflow agent. - */ - void removeConnectedSwitch(); - - /** - * Sets the ports on this switch. - * @param portDescReply the port set and descriptions - */ - void setPortDescReply(OFPortDescStatsReply portDescReply); - - /** - * Sets the ports on this switch. - * @param portDescReplies list of port set and descriptions - */ - void setPortDescReplies(List<OFPortDescStatsReply> portDescReplies); - - /** - * Sets the features reply for this switch. - * @param featuresReply the features to set. - */ - void setFeaturesReply(OFFeaturesReply featuresReply); - - /** - * Sets the switch description. - * @param desc the descriptions - */ - void setSwitchDescription(OFDescStatsReply desc); - - /** - * Gets the next transaction id to use. - * @return the xid - */ - int getNextTransactionId(); - - - /** - * Sets the OF version for this switch. - * @param ofV the version to set. - */ - void setOFVersion(OFVersion ofV); - - /** - * Sets this switch has having a full flowtable. - * @param full true if full, false otherswise. - */ - void setTableFull(boolean full); - - /** - * Sets the associated Netty channel for this switch. - * @param channel the Netty channel - */ - void setChannel(Channel channel); - - /** - * Sets whether the switch is connected. - * - * @param connected whether the switch is connected - */ - void setConnected(boolean connected); - - /** - * Initialises the behaviour. - * @param dpid a dpid - * @param desc a switch description - * @param ofv OpenFlow version - */ - void init(Dpid dpid, OFDescStatsReply desc, OFVersion ofv); - - /** - * Does this switch support Nicira Role messages. - * @return true if supports, false otherwise. - */ - Boolean supportNxRole(); - - - /** - * Starts the driver specific handshake process. - */ - void startDriverHandshake(); - - /** - * Checks whether the driver specific handshake is complete. - * @return true is finished, false if not. - */ - boolean isDriverHandshakeComplete(); - - /** - * Process a message during the driver specific handshake. - * @param m the message to process. - */ - void processDriverHandshakeMessage(OFMessage m); - - /** - * Sends only role request messages. - * - * @param message a role request message. - */ - void sendRoleRequest(OFMessage message); - - /** - * Allows the handshaker behaviour to send messages during the - * handshake phase only. - * - * @param message an OpenFlow message - */ - void sendHandshakeMessage(OFMessage message); - -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/OpenFlowSwitchDriverFactory.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/OpenFlowSwitchDriverFactory.java deleted file mode 100644 index a0d8f18f..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/OpenFlowSwitchDriverFactory.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2014 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.driver; - -import org.onosproject.openflow.controller.Dpid; -import org.projectfloodlight.openflow.protocol.OFDescStatsReply; -import org.projectfloodlight.openflow.protocol.OFVersion; - -/** - * Switch factory which returns concrete switch objects for the - * physical openflow switch in use. - * - */ -public interface OpenFlowSwitchDriverFactory { - - - /** - * Constructs the real openflow switch representation. - * @param dpid the dpid for this switch. - * @param desc its description. - * @param ofv the OF version in use - * @return the openflow switch representation. - */ - OpenFlowSwitchDriver getOFSwitchImpl(Dpid dpid, - OFDescStatsReply desc, OFVersion ofv); -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/RoleHandler.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/RoleHandler.java deleted file mode 100644 index b4068886..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/RoleHandler.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2014 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.driver; - -import java.io.IOException; - -import org.onosproject.openflow.controller.RoleState; -import org.projectfloodlight.openflow.protocol.OFErrorMsg; -import org.projectfloodlight.openflow.protocol.OFExperimenter; -import org.projectfloodlight.openflow.protocol.OFRoleReply; - -/** - * Role handling. - * - */ -public interface RoleHandler { - - /** - * Extract the role from an OFVendor message. - * - * Extract the role from an OFVendor message if the message is a - * Nicira role reply. Otherwise return null. - * - * @param experimenterMsg The vendor message to parse. - * @return The role in the message if the message is a Nicira role - * reply, null otherwise. - * @throws SwitchStateException If the message is a Nicira role reply - * but the numeric role value is unknown. - */ - RoleState extractNiciraRoleReply(OFExperimenter experimenterMsg) - throws SwitchStateException; - - /** - * Send a role request with the given role to the switch and update - * the pending request and timestamp. - * Sends an OFPT_ROLE_REQUEST to an OF1.3 switch, OR - * Sends an NX_ROLE_REQUEST to an OF1.0 switch if configured to support it - * in the IOFSwitch driver. If not supported, this method sends nothing - * and returns 'false'. The caller should take appropriate action. - * - * One other optimization we do here is that for OF1.0 switches with - * Nicira role message support, we force the Role.EQUAL to become - * Role.SLAVE, as there is no defined behavior for the Nicira role OTHER. - * We cannot expect it to behave like SLAVE. We don't have this problem with - * OF1.3 switches, because Role.EQUAL is well defined and we can simulate - * SLAVE behavior by using ASYNC messages. - * - * @param role role to request - * @param exp expectation - * @throws IOException when I/O exception of some sort has occurred - * @return false if and only if the switch does not support role-request - * messages, according to the switch driver; true otherwise. - */ - boolean sendRoleRequest(RoleState role, RoleRecvStatus exp) - throws IOException; - - /** - * Extract the role information from an OF1.3 Role Reply Message. - * @param rrmsg role reply message - * @return RoleReplyInfo object - * @throws SwitchStateException If unknown role encountered - */ - RoleReplyInfo extractOFRoleReply(OFRoleReply rrmsg) - throws SwitchStateException; - - /** - * Deliver a received role reply. - * - * Check if a request is pending and if the received reply matches the - * the expected pending reply (we check both role and xid) we set - * the role for the switch/channel. - * - * If a request is pending but doesn't match the reply we ignore it, and - * return - * - * If no request is pending we disconnect with a SwitchStateException - * - * @param rri information about role-reply in format that - * controller can understand. - * @return result comparing expected and received reply - * @throws SwitchStateException if no request is pending - */ - RoleRecvStatus deliverRoleReply(RoleReplyInfo rri) - throws SwitchStateException; - - - /** - * Called if we receive an error message. If the xid matches the - * pending request we handle it otherwise we ignore it. - * - * Note: since we only keep the last pending request we might get - * error messages for earlier role requests that we won't be able - * to handle - * @param error error message - * @return result comparing expected and received reply - * @throws SwitchStateException if switch did not support requested role - */ - RoleRecvStatus deliverError(OFErrorMsg error) - throws SwitchStateException; - -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/RoleRecvStatus.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/RoleRecvStatus.java deleted file mode 100644 index 88c4cc70..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/RoleRecvStatus.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2014 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.driver; - -/** - * When we remove a pending role request we use this enum to indicate how we - * arrived at the decision. When we send a role request to the switch, we - * also use this enum to indicate what we expect back from the switch, so the - * role changer can match the reply to our expectation. - */ -public enum RoleRecvStatus { - /** The switch returned an error indicating that roles are not. - * supported*/ - UNSUPPORTED, - /** The request timed out. */ - NO_REPLY, - /** The reply was old, there is a newer request pending. */ - OLD_REPLY, - /** - * The reply's role matched the role that this controller set in the - * request message - invoked either initially at startup or to reassert - * current role. - */ - MATCHED_CURRENT_ROLE, - /** - * The reply's role matched the role that this controller set in the - * request message - this is the result of a callback from the - * global registry, followed by a role request sent to the switch. - */ - MATCHED_SET_ROLE, - /** - * The reply's role was a response to the query made by this controller. - */ - REPLY_QUERY, - /** We received a role reply message from the switch - * but the expectation was unclear, or there was no expectation. - */ - OTHER_EXPECTATION, -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/RoleReplyInfo.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/RoleReplyInfo.java deleted file mode 100644 index dc9b6bad..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/RoleReplyInfo.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2014 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.driver; - -import org.onosproject.openflow.controller.RoleState; -import org.projectfloodlight.openflow.types.U64; - -/** - * Helper class returns role reply information in the format understood - * by the controller. - */ -public class RoleReplyInfo { - private final RoleState role; - private final U64 genId; - private final long xid; - - public RoleReplyInfo(RoleState role, U64 genId, long xid) { - this.role = role; - this.genId = genId; - this.xid = xid; - } - public RoleState getRole() { - return role; - } - public U64 getGenId() { - return genId; - } - public long getXid() { - return xid; - } - @Override - public String toString() { - return "[Role:" + role + " GenId:" + genId + " Xid:" + xid + "]"; - } -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeAlreadyStarted.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeAlreadyStarted.java deleted file mode 100644 index 96b4bd73..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeAlreadyStarted.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2014 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.driver; - -/** - * Thrown when IOFSwitch.startDriverHandshake() is called more than once. - * - */ -public class SwitchDriverSubHandshakeAlreadyStarted extends - SwitchDriverSubHandshakeException { - private static final long serialVersionUID = -5491845708752443501L; - - public SwitchDriverSubHandshakeAlreadyStarted() { - super(); - } -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeCompleted.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeCompleted.java deleted file mode 100644 index b0f59fe5..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeCompleted.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2014 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.driver; - -import org.projectfloodlight.openflow.protocol.OFMessage; - - -/** - * Indicates that a message was passed to a switch driver's subhandshake - * handling code but the driver has already completed the sub-handshake. - * - */ -public class SwitchDriverSubHandshakeCompleted - extends SwitchDriverSubHandshakeException { - private static final long serialVersionUID = -8817822245846375995L; - - public SwitchDriverSubHandshakeCompleted(OFMessage m) { - super("Sub-Handshake is already complete but received message " - + m.getType()); - } -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeException.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeException.java deleted file mode 100644 index 1bc750ab..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeException.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2014 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.driver; - -/** - * Base class for exception thrown by switch driver sub-handshake processing. - * - */ -public class SwitchDriverSubHandshakeException extends RuntimeException { - private static final long serialVersionUID = -6257836781419604438L; - - protected SwitchDriverSubHandshakeException() { - super(); - } - - protected SwitchDriverSubHandshakeException(String arg0, Throwable arg1) { - super(arg0, arg1); - } - - protected SwitchDriverSubHandshakeException(String arg0) { - super(arg0); - } - - protected SwitchDriverSubHandshakeException(Throwable arg0) { - super(arg0); - } - -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeNotStarted.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeNotStarted.java deleted file mode 100644 index a073683c..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeNotStarted.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2014 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.driver; - -/** - * Thrown when a switch driver's sub-handshake has not been started but an - * operation requiring the sub-handshake has been attempted. - * - */ -public class SwitchDriverSubHandshakeNotStarted extends - SwitchDriverSubHandshakeException { - private static final long serialVersionUID = -5491845708752443501L; - - public SwitchDriverSubHandshakeNotStarted() { - super(); - } -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeStateException.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeStateException.java deleted file mode 100644 index 3f4be813..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchDriverSubHandshakeStateException.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2014 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.driver; - -/** - * Thrown when a switch driver's sub-handshake state-machine receives an - * unexpected OFMessage and/or is in an invald state. - * - */ -public class SwitchDriverSubHandshakeStateException extends - SwitchDriverSubHandshakeException { - private static final long serialVersionUID = -8249926069195147051L; - - public SwitchDriverSubHandshakeStateException(String msg) { - super(msg); - } -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchStateException.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchStateException.java deleted file mode 100644 index 30c4e917..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/SwitchStateException.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2014 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.driver; - -/** - * This exception indicates an error or unexpected message during - * message handling. E.g., if an OFMessage is received that is illegal or - * unexpected given the current handshake state. - * - * We don't allow wrapping other exception in a switch state exception. We - * only log the SwitchStateExceptions message so the causing exceptions - * stack trace is generally not available. - * - */ -public class SwitchStateException extends Exception { - - private static final long serialVersionUID = 9153954512470002631L; - - public SwitchStateException() { - super(); - } - - public SwitchStateException(String arg0, Throwable arg1) { - super(arg0, arg1); - } - - public SwitchStateException(String arg0) { - super(arg0); - } - - public SwitchStateException(Throwable arg0) { - super(arg0); - } - -} diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/package-info.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/package-info.java deleted file mode 100644 index c03a5840..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2014 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. - */ - -/** - * OpenFlow controller switch driver API. - */ -package org.onosproject.openflow.controller.driver; diff --git a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/package-info.java b/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/package-info.java deleted file mode 100644 index 54778426..00000000 --- a/framework/src/onos/openflow/api/src/main/java/org/onosproject/openflow/controller/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2014 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. - */ - -/** - * OpenFlow controller API. - */ -package org.onosproject.openflow.controller; diff --git a/framework/src/onos/openflow/api/src/test/java/org/onosproject/openflow/controller/OpenflowControllerAdapter.java b/framework/src/onos/openflow/api/src/test/java/org/onosproject/openflow/controller/OpenflowControllerAdapter.java deleted file mode 100644 index f4fe490f..00000000 --- a/framework/src/onos/openflow/api/src/test/java/org/onosproject/openflow/controller/OpenflowControllerAdapter.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2014 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; - -import org.projectfloodlight.openflow.protocol.OFMessage; - -/** - * Test adapter for the OpenFlow controller interface. - */ -public class OpenflowControllerAdapter implements OpenFlowController { - @Override - public Iterable<OpenFlowSwitch> getSwitches() { - return null; - } - - @Override - public Iterable<OpenFlowSwitch> getMasterSwitches() { - return null; - } - - @Override - public Iterable<OpenFlowSwitch> getEqualSwitches() { - return null; - } - - @Override - public OpenFlowSwitch getSwitch(Dpid dpid) { - return null; - } - - @Override - public OpenFlowSwitch getMasterSwitch(Dpid dpid) { - return null; - } - - @Override - public OpenFlowSwitch getEqualSwitch(Dpid dpid) { - return null; - } - - @Override - public void addListener(OpenFlowSwitchListener listener) { - } - - @Override - public void removeListener(OpenFlowSwitchListener listener) { - } - - @Override - public void addPacketListener(int priority, PacketListener listener) { - } - - @Override - public void removePacketListener(PacketListener listener) { - } - - @Override - public void write(Dpid dpid, OFMessage msg) { - } - - @Override - public void processPacket(Dpid dpid, OFMessage msg) { - } - - @Override - public void setRole(Dpid dpid, RoleState role) { - } - - @Override - public void addEventListener(OpenFlowEventListener listener) { - } - - @Override - public void removeEventListener(OpenFlowEventListener listener) { - } -} diff --git a/framework/src/onos/openflow/ctl/pom.xml b/framework/src/onos/openflow/ctl/pom.xml deleted file mode 100644 index 56d48550..00000000 --- a/framework/src/onos/openflow/ctl/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ -<!-- - ~ Copyright 2014 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-of</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>onos-of-ctl</artifactId> - <packaging>bundle</packaging> - - <description>ONOS OpenFlow controller subsystem API</description> - - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-of-api</artifactId> - </dependency> - <dependency> - <groupId>io.netty</groupId> - <artifactId>netty</artifactId> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.onosproject</groupId> - <artifactId>onos-maven-plugin</artifactId> - </plugin> - </plugins> - </build> - -</project> 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 deleted file mode 100644 index 9d355156..00000000 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/Controller.java +++ /dev/null @@ -1,341 +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.openflow.controller.impl; - -import com.google.common.base.Strings; -import com.google.common.collect.ImmutableList; -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipelineFactory; -import org.jboss.netty.channel.group.ChannelGroup; -import org.jboss.netty.channel.group.DefaultChannelGroup; -import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; -import org.onlab.util.ItemNotFoundException; -import org.onosproject.net.DeviceId; -import org.onosproject.net.driver.DefaultDriverData; -import org.onosproject.net.driver.DefaultDriverHandler; -import org.onosproject.net.driver.Driver; -import org.onosproject.net.driver.DriverService; -import org.onosproject.openflow.controller.Dpid; -import org.onosproject.openflow.controller.driver.OpenFlowAgent; -import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; -import org.projectfloodlight.openflow.protocol.OFDescStatsReply; -import org.projectfloodlight.openflow.protocol.OFFactories; -import org.projectfloodlight.openflow.protocol.OFFactory; -import org.projectfloodlight.openflow.protocol.OFVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLEngine; -import javax.net.ssl.TrustManagerFactory; -import java.io.FileInputStream; -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; -import java.net.InetSocketAddress; -import java.security.KeyStore; -import java.util.Dictionary; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.Executors; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.onlab.util.Tools.get; -import static org.onlab.util.Tools.groupedThreads; -import static org.onosproject.net.DeviceId.deviceId; -import static org.onosproject.openflow.controller.Dpid.uri; - - -/** - * The main controller class. Handles all setup and network listeners - * - Distributed ownership control of switch through IControllerRegistryService - */ -public class Controller { - - protected static final Logger log = LoggerFactory.getLogger(Controller.class); - - protected static final OFFactory FACTORY13 = OFFactories.getFactory(OFVersion.OF_13); - protected static final OFFactory FACTORY10 = OFFactories.getFactory(OFVersion.OF_10); - private static final boolean TLS_DISABLED = false; - private static final short MIN_KS_LENGTH = 6; - - protected HashMap<String, String> controllerNodeIPsCache; - - private ChannelGroup cg; - - // Configuration options - protected List<Integer> openFlowPorts = ImmutableList.of(6633, 6653); - protected int workerThreads = 16; - - // Start time of the controller - protected long systemStartTime; - - private OpenFlowAgent agent; - - private NioServerSocketChannelFactory execFactory; - - protected String ksLocation; - protected String tsLocation; - protected char[] ksPwd; - protected char[] tsPwd; - private SSLEngine serverSSLEngine; - - // Perf. related configuration - protected static final int SEND_BUFFER_SIZE = 4 * 1024 * 1024; - private DriverService driverService; - private boolean enableOFTLS = TLS_DISABLED; - - // *************** - // Getters/Setters - // *************** - - public OFFactory getOFMessageFactory10() { - return FACTORY10; - } - - - public OFFactory getOFMessageFactory13() { - return FACTORY13; - } - - - public Map<String, String> getControllerNodeIPs() { - // We return a copy of the mapping so we can guarantee that - // the mapping return is the same as one that will be (or was) - // dispatched to IHAListeners - HashMap<String, String> retval = new HashMap<>(); - synchronized (controllerNodeIPsCache) { - retval.putAll(controllerNodeIPsCache); - } - return retval; - } - - - public long getSystemStartTime() { - return (this.systemStartTime); - } - - // ************** - // Initialization - // ************** - - /** - * Tell controller that we're ready to accept switches loop. - */ - public void run() { - - try { - final ServerBootstrap bootstrap = createServerBootStrap(); - - bootstrap.setOption("reuseAddr", true); - bootstrap.setOption("child.keepAlive", true); - bootstrap.setOption("child.tcpNoDelay", true); - bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE); - - ChannelPipelineFactory pfact = - new OpenflowPipelineFactory(this, null, serverSSLEngine); - bootstrap.setPipelineFactory(pfact); - cg = new DefaultChannelGroup(); - openFlowPorts.forEach(port -> { - InetSocketAddress sa = new InetSocketAddress(port); - cg.add(bootstrap.bind(sa)); - log.info("Listening for switch connections on {}", sa); - }); - - } catch (Exception e) { - throw new RuntimeException(e); - } - - } - - private ServerBootstrap createServerBootStrap() { - - if (workerThreads == 0) { - execFactory = new NioServerSocketChannelFactory( - Executors.newCachedThreadPool(groupedThreads("onos/of", "boss-%d")), - Executors.newCachedThreadPool(groupedThreads("onos/of", "worker-%d"))); - return new ServerBootstrap(execFactory); - } else { - execFactory = new NioServerSocketChannelFactory( - Executors.newCachedThreadPool(groupedThreads("onos/of", "boss-%d")), - Executors.newCachedThreadPool(groupedThreads("onos/of", "worker-%d")), workerThreads); - return new ServerBootstrap(execFactory); - } - } - - public void setConfigParams(Dictionary<?, ?> properties) { - String ports = get(properties, "openflowPorts"); - if (!Strings.isNullOrEmpty(ports)) { - this.openFlowPorts = Stream.of(ports.split(",")) - .map(s -> Integer.parseInt(s)) - .collect(Collectors.toList()); - } - log.debug("OpenFlow ports set to {}", this.openFlowPorts); - - String threads = get(properties, "workerThreads"); - if (!Strings.isNullOrEmpty(threads)) { - this.workerThreads = Integer.parseInt(threads); - } - log.debug("Number of worker threads set to {}", this.workerThreads); - } - - /** - * Initialize internal data structures. - */ - public void init() { - // These data structures are initialized here because other - // module's startUp() might be called before ours - this.controllerNodeIPsCache = new HashMap<>(); - - this.systemStartTime = System.currentTimeMillis(); - - try { - getTLSParameters(); - if (enableOFTLS) { - initSSL(); - } - } catch (Exception ex) { - log.error("SSL init failed: {}", ex.getMessage()); - } - - } - - private void getTLSParameters() { - String tempString = System.getProperty("enableOFTLS"); - enableOFTLS = Strings.isNullOrEmpty(tempString) ? TLS_DISABLED : Boolean.parseBoolean(tempString); - log.info("OpenFlow Security is {}", enableOFTLS ? "enabled" : "disabled"); - if (enableOFTLS) { - ksLocation = System.getProperty("javax.net.ssl.keyStore"); - if (Strings.isNullOrEmpty(ksLocation)) { - enableOFTLS = TLS_DISABLED; - return; - } - tsLocation = System.getProperty("javax.net.ssl.trustStore"); - if (Strings.isNullOrEmpty(tsLocation)) { - enableOFTLS = TLS_DISABLED; - return; - } - ksPwd = System.getProperty("javax.net.ssl.keyStorePassword").toCharArray(); - if (MIN_KS_LENGTH > ksPwd.length) { - enableOFTLS = TLS_DISABLED; - return; - } - tsPwd = System.getProperty("javax.net.ssl.trustStorePassword").toCharArray(); - if (MIN_KS_LENGTH > tsPwd.length) { - enableOFTLS = TLS_DISABLED; - return; - } - } - } - - private void initSSL() throws Exception { - - TrustManagerFactory tmFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); - KeyStore ts = KeyStore.getInstance("JKS"); - ts.load(new FileInputStream(tsLocation), tsPwd); - tmFactory.init(ts); - - KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); - KeyStore ks = KeyStore.getInstance("JKS"); - ks.load(new FileInputStream(ksLocation), ksPwd); - kmf.init(ks, ksPwd); - - SSLContext serverContext = SSLContext.getInstance("TLS"); - serverContext.init(kmf.getKeyManagers(), tmFactory.getTrustManagers(), null); - - serverSSLEngine = serverContext.createSSLEngine(); - - serverSSLEngine.setNeedClientAuth(true); - serverSSLEngine.setUseClientMode(false); - serverSSLEngine.setEnabledProtocols(serverSSLEngine.getSupportedProtocols()); - serverSSLEngine.setEnabledCipherSuites(serverSSLEngine.getSupportedCipherSuites()); - serverSSLEngine.setEnableSessionCreation(true); - } - - // ************** - // Utility methods - // ************** - - public Map<String, Long> getMemory() { - Map<String, Long> m = new HashMap<>(); - Runtime runtime = Runtime.getRuntime(); - m.put("total", runtime.totalMemory()); - m.put("free", runtime.freeMemory()); - return m; - } - - - public Long getUptime() { - RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); - return rb.getUptime(); - } - - /** - * Forward to the driver-manager to get an IOFSwitch instance. - * - * @param dpid data path id - * @param desc switch description - * @param ofv OpenFlow version - * @return switch instance - */ - protected OpenFlowSwitchDriver getOFSwitchInstance(long dpid, - OFDescStatsReply desc, - OFVersion ofv) { - Dpid dpidObj = new Dpid(dpid); - - Driver driver; - try { - driver = driverService.getDriver(DeviceId.deviceId(Dpid.uri(dpidObj))); - } catch (ItemNotFoundException e) { - driver = driverService.getDriver(desc.getMfrDesc(), desc.getHwDesc(), desc.getSwDesc()); - } - - if (driver != null && driver.hasBehaviour(OpenFlowSwitchDriver.class)) { - Dpid did = new Dpid(dpid); - DefaultDriverHandler handler = - new DefaultDriverHandler(new DefaultDriverData(driver, deviceId(uri(did)))); - OpenFlowSwitchDriver ofSwitchDriver = - driver.createBehaviour(handler, OpenFlowSwitchDriver.class); - ofSwitchDriver.init(did, desc, ofv); - ofSwitchDriver.setAgent(agent); - ofSwitchDriver.setRoleHandler(new RoleManager(ofSwitchDriver)); - log.info("OpenFlow handshaker found for device {}: {}", dpid, ofSwitchDriver); - return ofSwitchDriver; - } - log.error("No OpenFlow driver for {} : {}", dpid, desc); - return null; - - } - - public void start(OpenFlowAgent ag, DriverService driverService) { - log.info("Starting OpenFlow IO"); - this.agent = ag; - this.driverService = driverService; - this.init(); - this.run(); - } - - - public void stop() { - log.info("Stopping OpenFlow IO"); - cg.close(); - execFactory.shutdown(); - } - -} diff --git a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/HandshakeTimeoutException.java b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/HandshakeTimeoutException.java deleted file mode 100644 index bbe307be..00000000 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/HandshakeTimeoutException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2014 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; - -/** - * Exception is thrown when the handshake fails to complete. - * before a specified time - * - */ -public class HandshakeTimeoutException extends Exception { - - private static final long serialVersionUID = 6859880268940337312L; - -} diff --git a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/HandshakeTimeoutHandler.java b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/HandshakeTimeoutHandler.java deleted file mode 100644 index fbbe3428..00000000 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/HandshakeTimeoutHandler.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2014 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.util.concurrent.TimeUnit; - -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.ChannelStateEvent; -import org.jboss.netty.channel.Channels; -import org.jboss.netty.channel.SimpleChannelUpstreamHandler; -import org.jboss.netty.util.Timeout; -import org.jboss.netty.util.Timer; -import org.jboss.netty.util.TimerTask; - -/** - * Trigger a timeout if a switch fails to complete handshake soon enough. - */ -public class HandshakeTimeoutHandler - extends SimpleChannelUpstreamHandler { - static final HandshakeTimeoutException EXCEPTION = - new HandshakeTimeoutException(); - - final OFChannelHandler channelHandler; - final Timer timer; - final long timeoutNanos; - volatile Timeout timeout; - - public HandshakeTimeoutHandler(OFChannelHandler channelHandler, - Timer timer, - long timeoutSeconds) { - super(); - this.channelHandler = channelHandler; - this.timer = timer; - this.timeoutNanos = TimeUnit.SECONDS.toNanos(timeoutSeconds); - - } - - @Override - public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - if (timeoutNanos > 0) { - timeout = timer.newTimeout(new HandshakeTimeoutTask(ctx), - timeoutNanos, TimeUnit.NANOSECONDS); - } - ctx.sendUpstream(e); - } - - @Override - public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) - throws Exception { - if (timeout != null) { - timeout.cancel(); - timeout = null; - } - } - - private final class HandshakeTimeoutTask implements TimerTask { - - private final ChannelHandlerContext ctx; - - HandshakeTimeoutTask(ChannelHandlerContext ctx) { - this.ctx = ctx; - } - - @Override - public void run(Timeout t) throws Exception { - if (t.isCancelled()) { - return; - } - - if (!ctx.getChannel().isOpen()) { - return; - } - if (!channelHandler.isHandshakeComplete()) { - Channels.fireExceptionCaught(ctx, EXCEPTION); - } - } - } -} 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 deleted file mode 100644 index 1a088ff7..00000000 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFChannelHandler.java +++ /dev/null @@ -1,1321 +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. - */ - -//CHECKSTYLE:OFF -package org.onosproject.openflow.controller.impl; - -import java.io.IOException; -import java.nio.channels.ClosedChannelException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.RejectedExecutionException; - -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.ChannelStateEvent; -import org.jboss.netty.channel.ExceptionEvent; -import org.jboss.netty.channel.MessageEvent; -import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler; -import org.jboss.netty.handler.timeout.IdleStateEvent; -import org.jboss.netty.handler.timeout.ReadTimeoutException; -import org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver; -import org.onosproject.openflow.controller.driver.SwitchStateException; -import org.projectfloodlight.openflow.exceptions.OFParseError; -import org.projectfloodlight.openflow.protocol.OFAsyncGetReply; -import org.projectfloodlight.openflow.protocol.OFBadRequestCode; -import org.projectfloodlight.openflow.protocol.OFBarrierReply; -import org.projectfloodlight.openflow.protocol.OFBarrierRequest; -import org.projectfloodlight.openflow.protocol.OFDescStatsReply; -import org.projectfloodlight.openflow.protocol.OFDescStatsRequest; -import org.projectfloodlight.openflow.protocol.OFEchoReply; -import org.projectfloodlight.openflow.protocol.OFEchoRequest; -import org.projectfloodlight.openflow.protocol.OFErrorMsg; -import org.projectfloodlight.openflow.protocol.OFErrorType; -import org.projectfloodlight.openflow.protocol.OFExperimenter; -import org.projectfloodlight.openflow.protocol.OFFactory; -import org.projectfloodlight.openflow.protocol.OFFeaturesReply; -import org.projectfloodlight.openflow.protocol.OFFlowModFailedCode; -import org.projectfloodlight.openflow.protocol.OFFlowRemoved; -import org.projectfloodlight.openflow.protocol.OFGetConfigReply; -import org.projectfloodlight.openflow.protocol.OFGetConfigRequest; -import org.projectfloodlight.openflow.protocol.OFHello; -import org.projectfloodlight.openflow.protocol.OFHelloElem; -import org.projectfloodlight.openflow.protocol.OFMessage; -import org.projectfloodlight.openflow.protocol.OFPacketIn; -import org.projectfloodlight.openflow.protocol.OFPortDescStatsReply; -import org.projectfloodlight.openflow.protocol.OFPortDescStatsRequest; -import org.projectfloodlight.openflow.protocol.OFPortStatus; -import org.projectfloodlight.openflow.protocol.OFQueueGetConfigReply; -import org.projectfloodlight.openflow.protocol.OFRoleReply; -import org.projectfloodlight.openflow.protocol.OFSetConfig; -import org.projectfloodlight.openflow.protocol.OFStatsReply; -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 org.projectfloodlight.openflow.protocol.errormsg.OFBadRequestErrorMsg; -import org.projectfloodlight.openflow.protocol.errormsg.OFFlowModFailedErrorMsg; -import org.projectfloodlight.openflow.types.U32; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Channel handler deals with the switch connection and dispatches - * switch messages to the appropriate locations. - */ -class OFChannelHandler extends IdleStateAwareChannelHandler { - private static final Logger log = LoggerFactory.getLogger(OFChannelHandler.class); - - private static final String RESET_BY_PEER = "Connection reset by peer"; - private static final String BROKEN_PIPE = "Broken pipe"; - - private final Controller controller; - private OpenFlowSwitchDriver sw; - private long thisdpid; // channelHandler cached value of connected switch id - private Channel channel; - // State needs to be volatile because the HandshakeTimeoutHandler - // needs to check if the handshake is complete - private volatile ChannelState state; - - // When a switch with a duplicate dpid is found (i.e we already have a - // connected switch with the same dpid), the new switch is immediately - // disconnected. At that point netty callsback channelDisconnected() which - // proceeds to cleaup switch state - we need to ensure that it does not cleanup - // switch state for the older (still connected) switch - private volatile Boolean duplicateDpidFound; - - // Temporary storage for switch-features and port-description - private OFFeaturesReply featuresReply; - private List<OFPortDescStatsReply> portDescReplies; - //private OFPortDescStatsReply portDescReply; - // a concurrent ArrayList to temporarily store port status messages - // before we are ready to deal with them - private final CopyOnWriteArrayList<OFPortStatus> pendingPortStatusMsg; - - //Indicates the openflow version used by this switch - protected OFVersion ofVersion; - protected OFFactory factory13; - protected OFFactory factory10; - - /** transaction Ids to use during handshake. Since only one thread - * calls into an OFChannelHandler instance, we don't need atomic. - * We will count down - */ - private int handshakeTransactionIds = -1; - - /** - * Create a new unconnected OFChannelHandler. - * @param controller parent controller - */ - OFChannelHandler(Controller controller) { - this.controller = controller; - this.state = ChannelState.INIT; - this.pendingPortStatusMsg = new CopyOnWriteArrayList<OFPortStatus>(); - this.portDescReplies = new ArrayList<OFPortDescStatsReply>(); - factory13 = controller.getOFMessageFactory13(); - factory10 = controller.getOFMessageFactory10(); - duplicateDpidFound = Boolean.FALSE; - } - - - - // XXX S consider if necessary - public void disconnectSwitch() { - sw.disconnectSwitch(); - } - - - - //************************* - // Channel State Machine - //************************* - - /** - * The state machine for handling the switch/channel state. All state - * transitions should happen from within the state machine (and not from other - * parts of the code) - */ - enum ChannelState { - /** - * Initial state before channel is connected. - */ - INIT(false) { - @Override - void processOFMessage(OFChannelHandler h, OFMessage m) - throws IOException, SwitchStateException { - illegalMessageReceived(h, m); - } - - @Override - void processOFError(OFChannelHandler h, OFErrorMsg m) - throws IOException { - // need to implement since its abstract but it will never - // be called - } - - @Override - void processOFPortStatus(OFChannelHandler h, OFPortStatus m) - throws IOException { - unhandledMessageReceived(h, m); - } - }, - - /** - * We send a OF 1.3 HELLO to the switch and wait for a Hello from the switch. - * Once we receive the reply, we decide on OF 1.3 or 1.0 switch - no other - * protocol version is accepted. - * We send an OFFeaturesRequest depending on the protocol version selected - * Next state is WAIT_FEATURES_REPLY - */ - WAIT_HELLO(false) { - @Override - void processOFHello(OFChannelHandler h, OFHello m) - throws IOException { - // TODO We could check for the optional bitmap, but for now - // we are just checking the version number. - if (m.getVersion().getWireVersion() >= OFVersion.OF_13.getWireVersion()) { - log.debug("Received {} Hello from {} - switching to OF " - + "version 1.3", m.getVersion(), - h.channel.getRemoteAddress()); - h.sendHandshakeHelloMessage(); - h.ofVersion = OFVersion.OF_13; - } else if (m.getVersion().getWireVersion() >= OFVersion.OF_10.getWireVersion()) { - log.debug("Received {} Hello from {} - switching to OF " - + "version 1.0", m.getVersion(), - h.channel.getRemoteAddress()); - OFHello hi = - h.factory10.buildHello() - .setXid(h.handshakeTransactionIds--) - .build(); - h.channel.write(Collections.singletonList(hi)); - h.ofVersion = OFVersion.OF_10; - } else { - log.error("Received Hello of version {} from switch at {}. " - + "This controller works with OF1.0 and OF1.3 " - + "switches. Disconnecting switch ...", - m.getVersion(), h.channel.getRemoteAddress()); - h.channel.disconnect(); - return; - } - h.sendHandshakeFeaturesRequestMessage(); - h.setState(WAIT_FEATURES_REPLY); - } - @Override - void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m) - throws IOException, SwitchStateException { - illegalMessageReceived(h, m); - } - @Override - void processOFStatisticsReply(OFChannelHandler h, - OFStatsReply m) - throws IOException, SwitchStateException { - illegalMessageReceived(h, m); - } - @Override - void processOFError(OFChannelHandler h, OFErrorMsg m) { - logErrorDisconnect(h, m); - } - - @Override - void processOFPortStatus(OFChannelHandler h, OFPortStatus m) - throws IOException { - unhandledMessageReceived(h, m); - } - }, - - - /** - * We are waiting for a features reply message. Once we receive it, the - * behavior depends on whether this is a 1.0 or 1.3 switch. For 1.0, - * we send a SetConfig request, barrier, and GetConfig request and the - * next state is WAIT_CONFIG_REPLY. For 1.3, we send a Port description - * request and the next state is WAIT_PORT_DESC_REPLY. - */ - WAIT_FEATURES_REPLY(false) { - @Override - void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m) - throws IOException { - h.thisdpid = m.getDatapathId().getLong(); - log.debug("Received features reply for switch at {} with dpid {}", - h.getSwitchInfoString(), h.thisdpid); - - h.featuresReply = m; //temp store - if (h.ofVersion == OFVersion.OF_10) { - h.sendHandshakeSetConfig(); - h.setState(WAIT_CONFIG_REPLY); - } else { - //version is 1.3, must get switchport information - h.sendHandshakeOFPortDescRequest(); - h.setState(WAIT_PORT_DESC_REPLY); - } - } - @Override - void processOFStatisticsReply(OFChannelHandler h, - OFStatsReply m) - throws IOException, SwitchStateException { - illegalMessageReceived(h, m); - } - @Override - void processOFError(OFChannelHandler h, OFErrorMsg m) { - logErrorDisconnect(h, m); - } - - @Override - void processOFPortStatus(OFChannelHandler h, OFPortStatus m) - throws IOException { - h.pendingPortStatusMsg.add(m); - } - }, - - /** - * We are waiting for a description of the 1.3 switch ports. - * Once received, we send a SetConfig request - * Next State is WAIT_CONFIG_REPLY - */ - WAIT_PORT_DESC_REPLY(false) { - - @Override - void processOFStatisticsReply(OFChannelHandler h, OFStatsReply m) - throws SwitchStateException { - // Read port description - if (m.getStatsType() != OFStatsType.PORT_DESC) { - log.warn("Expecting port description stats but received stats " - + "type {} from {}. Ignoring ...", m.getStatsType(), - h.channel.getRemoteAddress()); - return; - } - if (m.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { - log.debug("Stats reply indicates more stats from sw {} for " - + "port description", - h.getSwitchInfoString()); - h.portDescReplies.add((OFPortDescStatsReply)m); - return; - } - else { - h.portDescReplies.add((OFPortDescStatsReply)m); - } - //h.portDescReply = (OFPortDescStatsReply) m; // temp store - log.info("Received port desc reply for switch at {}", - h.getSwitchInfoString()); - try { - h.sendHandshakeSetConfig(); - } catch (IOException e) { - log.error("Unable to send setConfig after PortDescReply. " - + "Error: {}", e.getMessage()); - } - h.setState(WAIT_CONFIG_REPLY); - } - - @Override - void processOFError(OFChannelHandler h, OFErrorMsg m) - throws IOException, SwitchStateException { - logErrorDisconnect(h, m); - - } - - @Override - void processOFPortStatus(OFChannelHandler h, OFPortStatus m) - throws IOException, SwitchStateException { - h.pendingPortStatusMsg.add(m); - - } - }, - - /** - * We are waiting for a config reply message. Once we receive it - * we send a DescriptionStatsRequest to the switch. - * Next state: WAIT_DESCRIPTION_STAT_REPLY - */ - WAIT_CONFIG_REPLY(false) { - @Override - void processOFGetConfigReply(OFChannelHandler h, OFGetConfigReply m) - throws IOException { - if (m.getMissSendLen() == 0xffff) { - log.trace("Config Reply from switch {} confirms " - + "miss length set to 0xffff", - h.getSwitchInfoString()); - } else { - // FIXME: we can't really deal with switches that don't send - // full packets. Shouldn't we drop the connection here? - log.warn("Config Reply from switch {} has" - + "miss length set to {}", - h.getSwitchInfoString(), - m.getMissSendLen()); - } - h.sendHandshakeDescriptionStatsRequest(); - h.setState(WAIT_DESCRIPTION_STAT_REPLY); - } - - @Override - void processOFBarrierReply(OFChannelHandler h, OFBarrierReply m) { - // do nothing; - } - - @Override - void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m) - throws IOException, SwitchStateException { - illegalMessageReceived(h, m); - } - @Override - void processOFStatisticsReply(OFChannelHandler h, - OFStatsReply m) - throws IOException, SwitchStateException { - log.error("Received multipart(stats) message sub-type {}", - m.getStatsType()); - illegalMessageReceived(h, m); - } - - @Override - void processOFError(OFChannelHandler h, OFErrorMsg m) { - logErrorDisconnect(h, m); - } - - @Override - void processOFPortStatus(OFChannelHandler h, OFPortStatus m) - throws IOException { - h.pendingPortStatusMsg.add(m); - } - }, - - - /** - * We are waiting for a OFDescriptionStat message from the switch. - * Once we receive any stat message we try to parse it. If it's not - * a description stats message we disconnect. If its the expected - * description stats message, we: - * - use the switch driver to bind the switch and get an IOFSwitch instance - * - setup the IOFSwitch instance - * - add switch controller and send the initial role - * request to the switch. - * Next state: WAIT_INITIAL_ROLE - * In the typical case, where switches support role request messages - * the next state is where we expect the role reply message. - * In the special case that where the switch does not support any kind - * of role request messages, we don't send a role message, but we do - * request mastership from the registry service. This controller - * should become master once we hear back from the registry service. - * All following states will have a h.sw instance! - */ - WAIT_DESCRIPTION_STAT_REPLY(false) { - @Override - void processOFStatisticsReply(OFChannelHandler h, OFStatsReply m) - throws SwitchStateException { - // Read description, if it has been updated - if (m.getStatsType() != OFStatsType.DESC) { - log.warn("Expecting Description stats but received stats " - + "type {} from {}. Ignoring ...", m.getStatsType(), - h.channel.getRemoteAddress()); - return; - } - OFDescStatsReply drep = (OFDescStatsReply) m; - log.info("Received switch description reply {} from switch at {}", - drep, h.channel.getRemoteAddress()); - // Here is where we differentiate between different kinds of switches - h.sw = h.controller.getOFSwitchInstance(h.thisdpid, drep, h.ofVersion); - - h.sw.setOFVersion(h.ofVersion); - h.sw.setFeaturesReply(h.featuresReply); - //h.sw.setPortDescReply(h.portDescReply); - h.sw.setPortDescReplies(h.portDescReplies); - h.sw.setConnected(true); - h.sw.setChannel(h.channel); -// boolean success = h.sw.connectSwitch(); -// -// if (!success) { -// disconnectDuplicate(h); -// return; -// } - // set switch information - - - - log.debug("Switch {} bound to class {}, description {}", - new Object[] {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()); - //h.sw.activateEqualSwitch(); - //h.setSwitchRole(RoleState.EQUAL); - - h.sw.startDriverHandshake(); - if (h.sw.isDriverHandshakeComplete()) { - if (!h.sw.connectSwitch()) { - disconnectDuplicate(h); - } - handlePendingPortStatusMessages(h); - h.setState(ACTIVE); - } else { - h.setState(WAIT_SWITCH_DRIVER_SUB_HANDSHAKE); - } - - } - - @Override - void processOFError(OFChannelHandler h, OFErrorMsg m) { - logErrorDisconnect(h, m); - } - - @Override - void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m) - throws IOException, SwitchStateException { - illegalMessageReceived(h, m); - } - - @Override - void processOFPortStatus(OFChannelHandler h, OFPortStatus m) - throws IOException { - h.pendingPortStatusMsg.add(m); - } - }, - - - /** - * We are waiting for the respective switch driver to complete its - * configuration. Notice that we do not consider this to be part of the main - * switch-controller handshake. But we do consider it as a step that comes - * before we declare the switch as available to the controller. - * Next State: depends on the role of this controller for this switch - either - * MASTER or EQUAL. - */ - WAIT_SWITCH_DRIVER_SUB_HANDSHAKE(true) { - - @Override - void processOFError(OFChannelHandler h, OFErrorMsg m) - throws IOException { - // will never be called. We override processOFMessage - } - - - - @Override - void processOFMessage(OFChannelHandler h, OFMessage m) - throws IOException, SwitchStateException { - - if (h.sw.isDriverHandshakeComplete()) { - moveToActive(h); - h.state.processOFMessage(h, m); - return; - - } - - if (m.getType() == OFType.ECHO_REQUEST) { - processOFEchoRequest(h, (OFEchoRequest) m); - } else if (m.getType() == OFType.ECHO_REPLY) { - processOFEchoReply(h, (OFEchoReply) m); - } else if (m.getType() == OFType.ROLE_REPLY) { - h.sw.handleRole(m); - } else if (m.getType() == OFType.ERROR) { - if (!h.sw.handleRoleError((OFErrorMsg)m)) { - h.sw.processDriverHandshakeMessage(m); - if (h.sw.isDriverHandshakeComplete()) { - moveToActive(h); - } - } - } else { - if (m.getType() == OFType.EXPERIMENTER && - ((OFExperimenter) m).getExperimenter() == - RoleManager.NICIRA_EXPERIMENTER) { - h.sw.handleNiciraRole(m); - } else { - h.sw.processDriverHandshakeMessage(m); - if (h.sw.isDriverHandshakeComplete()) { - moveToActive(h); - } - } - } - } - - @Override - void processOFPortStatus(OFChannelHandler h, OFPortStatus m) - throws IOException, SwitchStateException { - h.pendingPortStatusMsg.add(m); - } - - private void moveToActive(OFChannelHandler h) { - boolean success = h.sw.connectSwitch(); - handlePendingPortStatusMessages(h); - h.setState(ACTIVE); - if (!success) { - disconnectDuplicate(h); - } - } - - }, - - - /** - * This controller is in MASTER role for this switch. We enter this state - * after requesting and winning control from the global registry. - * The main handshake as well as the switch-driver sub-handshake - * is complete at this point. - * // XXX S reconsider below - * In the (near) future we may deterministically assign controllers to - * switches at startup. - * We only leave this state if the switch disconnects or - * if we send a role request for SLAVE /and/ receive the role reply for - * SLAVE. - */ - ACTIVE(true) { - @Override - void processOFError(OFChannelHandler h, OFErrorMsg m) - throws IOException, SwitchStateException { - // if we get here, then the error message is for something else - if (m.getErrType() == OFErrorType.BAD_REQUEST && - ((OFBadRequestErrorMsg) m).getCode() == - OFBadRequestCode.EPERM) { - // We are the master controller and the switch returned - // a permission error. This is a likely indicator that - // the switch thinks we are slave. Reassert our - // role - // FIXME: this could be really bad during role transitions - // if two controllers are master (even if its only for - // a brief period). We might need to see if these errors - // persist before we reassert - - h.sw.reassertRole(); - } else if (m.getErrType() == OFErrorType.FLOW_MOD_FAILED && - ((OFFlowModFailedErrorMsg) m).getCode() == - OFFlowModFailedCode.ALL_TABLES_FULL) { - h.sw.setTableFull(true); - } else { - logError(h, m); - } - h.dispatchMessage(m); - } - - @Override - void processOFStatisticsReply(OFChannelHandler h, - OFStatsReply m) { - if (m.getStatsType().equals(OFStatsType.PORT_DESC)) { - h.sw.setPortDescReply((OFPortDescStatsReply) m); - } - h.dispatchMessage(m); - } - - @Override - void processOFExperimenter(OFChannelHandler h, OFExperimenter m) - throws SwitchStateException { - h.sw.handleNiciraRole(m); - } - - @Override - void processOFRoleReply(OFChannelHandler h, OFRoleReply m) - throws SwitchStateException { - h.sw.handleRole(m); - } - - @Override - void processOFPortStatus(OFChannelHandler h, OFPortStatus m) - throws SwitchStateException { - handlePortStatusMessage(h, m, true); - //h.dispatchMessage(m); - } - - @Override - void processOFPacketIn(OFChannelHandler h, OFPacketIn m) { -// OFPacketOut out = -// h.sw.factory().buildPacketOut() -// .setXid(m.getXid()) -// .setBufferId(m.getBufferId()).build(); -// h.sw.sendMsg(out); - h.dispatchMessage(m); - } - - @Override - void processOFFlowRemoved(OFChannelHandler h, - OFFlowRemoved m) { - h.dispatchMessage(m); - } - - @Override - void processOFBarrierReply(OFChannelHandler h, OFBarrierReply m) { - h.dispatchMessage(m); - } - - @Override - void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m) { - h.sw.setFeaturesReply(m); - h.dispatchMessage(m); - } - - }; - - private final boolean handshakeComplete; - ChannelState(boolean handshakeComplete) { - this.handshakeComplete = handshakeComplete; - } - - /** - * Is this a state in which the handshake has completed? - * @return true if the handshake is complete - */ - public boolean isHandshakeComplete() { - return handshakeComplete; - } - - /** - * Get a string specifying the switch connection, state, and - * message received. To be used as message for SwitchStateException - * or log messages - * @param h The channel handler (to get switch information_ - * @param m The OFMessage that has just been received - * @param details A string giving more details about the exact nature - * of the problem. - * @return display string - */ - // needs to be protected because enum members are actually subclasses - protected String getSwitchStateMessage(OFChannelHandler h, - OFMessage m, - String details) { - return String.format("Switch: [%s], State: [%s], received: [%s]" - + ", details: %s", - h.getSwitchInfoString(), - this.toString(), - m.getType().toString(), - details); - } - - /** - * We have an OFMessage we didn't expect given the current state and - * we want to treat this as an error. - * We currently throw an exception that will terminate the connection - * However, we could be more forgiving - * @param h the channel handler that received the message - * @param m the message - * @throws SwitchStateException we always throw the exception - */ - // needs to be protected because enum members are actually subclasses - protected void illegalMessageReceived(OFChannelHandler h, OFMessage m) - throws SwitchStateException { - String msg = getSwitchStateMessage(h, m, - "Switch should never send this message in the current state"); - throw new SwitchStateException(msg); - - } - - /** - * We have an OFMessage we didn't expect given the current state and - * we want to ignore the message. - * @param h the channel handler the received the message - * @param m the message - */ - protected void unhandledMessageReceived(OFChannelHandler h, - OFMessage m) { - if (log.isDebugEnabled()) { - String msg = getSwitchStateMessage(h, m, - "Ignoring unexpected message"); - log.debug(msg); - } - } - - /** - * Log an OpenFlow error message from a switch. - * @param h The switch that sent the error - * @param error The error message - */ - protected void logError(OFChannelHandler h, OFErrorMsg error) { - log.error("{} from switch {} in state {}", - new Object[] { - error, - h.getSwitchInfoString(), - this.toString()}); - } - - /** - * Log an OpenFlow error message from a switch and disconnect the - * channel. - * - * @param h the IO channel for this switch. - * @param error The error message - */ - protected void logErrorDisconnect(OFChannelHandler h, OFErrorMsg error) { - logError(h, error); - h.channel.disconnect(); - } - - /** - * log an error message for a duplicate dpid and disconnect this channel. - * @param h the IO channel for this switch. - */ - protected void disconnectDuplicate(OFChannelHandler h) { - log.error("Duplicated dpid or incompleted cleanup - " - + "disconnecting channel {}", h.getSwitchInfoString()); - h.duplicateDpidFound = Boolean.TRUE; - h.channel.disconnect(); - } - - - - /** - * Handles all pending port status messages before a switch is declared - * activated in MASTER or EQUAL role. Note that since this handling - * precedes the activation (and therefore notification to IOFSwitchListerners) - * the changes to ports will already be visible once the switch is - * activated. As a result, no notifications are sent out for these - * pending portStatus messages. - * - * @param h the channel handler that received the message - */ - protected void handlePendingPortStatusMessages(OFChannelHandler h) { - try { - handlePendingPortStatusMessages(h, 0); - } catch (SwitchStateException e) { - log.error(e.getMessage()); - } - } - - private void handlePendingPortStatusMessages(OFChannelHandler h, int index) - throws SwitchStateException { - if (h.sw == null) { - String msg = "State machine error: switch is null. Should never " + - "happen"; - throw new SwitchStateException(msg); - } - log.info("Processing {} pending port status messages for {}", - h.pendingPortStatusMsg.size(), h.sw.getStringId()); - - ArrayList<OFPortStatus> temp = new ArrayList<OFPortStatus>(); - for (OFPortStatus ps: h.pendingPortStatusMsg) { - temp.add(ps); - handlePortStatusMessage(h, ps, false); - } - // expensive but ok - we don't expect too many port-status messages - // note that we cannot use clear(), because of the reasons below - h.pendingPortStatusMsg.removeAll(temp); - temp.clear(); - // the iterator above takes a snapshot of the list - so while we were - // dealing with the pending port-status messages, we could have received - // newer ones. Handle them recursively, but break the recursion after - // five steps to avoid an attack. - if (!h.pendingPortStatusMsg.isEmpty() && ++index < 5) { - handlePendingPortStatusMessages(h, index); - } - } - - /** - * Handle a port status message. - * - * Handle a port status message by updating the port maps in the - * IOFSwitch instance and notifying Controller about the change so - * it can dispatch a switch update. - * - * @param h The OFChannelHhandler that received the message - * @param m The PortStatus message we received - * @param doNotify if true switch port changed events will be - * dispatched - * @throws SwitchStateException if the switch is not bound to the channel - * - */ - protected void handlePortStatusMessage(OFChannelHandler h, OFPortStatus m, - boolean doNotify) throws SwitchStateException { - if (h.sw == null) { - String msg = getSwitchStateMessage(h, m, - "State machine error: switch is null. Should never " + - "happen"); - throw new SwitchStateException(msg); - } - - h.sw.handleMessage(m); - } - - - /** - * Process an OF message received on the channel and - * update state accordingly. - * - * The main "event" of the state machine. Process the received message, - * send follow up message if required and update state if required. - * - * Switches on the message type and calls more specific event handlers - * for each individual OF message type. If we receive a message that - * is supposed to be sent from a controller to a switch we throw - * a SwitchStateExeption. - * - * The more specific handlers can also throw SwitchStateExceptions - * - * @param h The OFChannelHandler that received the message - * @param m The message we received. - * @throws SwitchStateException if the switch is not bound to the channel - * @throws IOException if unable to send message back to the switch - */ - void processOFMessage(OFChannelHandler h, OFMessage m) - throws IOException, SwitchStateException { - switch(m.getType()) { - case HELLO: - processOFHello(h, (OFHello) m); - break; - case BARRIER_REPLY: - processOFBarrierReply(h, (OFBarrierReply) m); - break; - case ECHO_REPLY: - processOFEchoReply(h, (OFEchoReply) m); - break; - case ECHO_REQUEST: - processOFEchoRequest(h, (OFEchoRequest) m); - break; - case ERROR: - processOFError(h, (OFErrorMsg) m); - break; - case FEATURES_REPLY: - processOFFeaturesReply(h, (OFFeaturesReply) m); - break; - case FLOW_REMOVED: - processOFFlowRemoved(h, (OFFlowRemoved) m); - break; - case GET_CONFIG_REPLY: - processOFGetConfigReply(h, (OFGetConfigReply) m); - break; - case PACKET_IN: - processOFPacketIn(h, (OFPacketIn) m); - break; - case PORT_STATUS: - processOFPortStatus(h, (OFPortStatus) m); - break; - case QUEUE_GET_CONFIG_REPLY: - processOFQueueGetConfigReply(h, (OFQueueGetConfigReply) m); - break; - case STATS_REPLY: // multipart_reply in 1.3 - processOFStatisticsReply(h, (OFStatsReply) m); - break; - case EXPERIMENTER: - processOFExperimenter(h, (OFExperimenter) m); - break; - case ROLE_REPLY: - processOFRoleReply(h, (OFRoleReply) m); - break; - case GET_ASYNC_REPLY: - processOFGetAsyncReply(h, (OFAsyncGetReply) m); - break; - - // The following messages are sent to switches. The controller - // should never receive them - case SET_CONFIG: - case GET_CONFIG_REQUEST: - case PACKET_OUT: - case PORT_MOD: - case QUEUE_GET_CONFIG_REQUEST: - case BARRIER_REQUEST: - case STATS_REQUEST: // multipart request in 1.3 - case FEATURES_REQUEST: - case FLOW_MOD: - case GROUP_MOD: - case TABLE_MOD: - case GET_ASYNC_REQUEST: - case SET_ASYNC: - case METER_MOD: - default: - illegalMessageReceived(h, m); - break; - } - } - - /*----------------------------------------------------------------- - * Default implementation for message handlers in any state. - * - * Individual states must override these if they want a behavior - * that differs from the default. - * - * In general, these handlers simply ignore the message and do - * nothing. - * - * There are some exceptions though, since some messages really - * are handled the same way in every state (e.g., ECHO_REQUST) or - * that are only valid in a single state (e.g., HELLO, GET_CONFIG_REPLY - -----------------------------------------------------------------*/ - - void processOFHello(OFChannelHandler h, OFHello m) - throws IOException, SwitchStateException { - // we only expect hello in the WAIT_HELLO state - log.warn("Received Hello outside WAIT_HELLO state; switch {} is not complaint.", - h.channel.getRemoteAddress()); - } - - void processOFBarrierReply(OFChannelHandler h, OFBarrierReply m) - throws IOException { - // Silently ignore. - } - - void processOFEchoRequest(OFChannelHandler h, OFEchoRequest m) - throws IOException { - if (h.ofVersion == null) { - log.error("No OF version set for {}. Not sending Echo REPLY", - h.channel.getRemoteAddress()); - return; - } - OFFactory factory = (h.ofVersion == OFVersion.OF_13) ? - h.controller.getOFMessageFactory13() : h.controller.getOFMessageFactory10(); - OFEchoReply reply = factory - .buildEchoReply() - .setXid(m.getXid()) - .setData(m.getData()) - .build(); - h.channel.write(Collections.singletonList(reply)); - } - - void processOFEchoReply(OFChannelHandler h, OFEchoReply m) - throws IOException { - // Do nothing with EchoReplies !! - } - - // no default implementation for OFError - // every state must override it - abstract void processOFError(OFChannelHandler h, OFErrorMsg m) - throws IOException, SwitchStateException; - - - void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m) - throws IOException, SwitchStateException { - unhandledMessageReceived(h, m); - } - - void processOFFlowRemoved(OFChannelHandler h, OFFlowRemoved m) - throws IOException { - unhandledMessageReceived(h, m); - } - - void processOFGetConfigReply(OFChannelHandler h, OFGetConfigReply m) - throws IOException, SwitchStateException { - // we only expect config replies in the WAIT_CONFIG_REPLY state - illegalMessageReceived(h, m); - } - - void processOFPacketIn(OFChannelHandler h, OFPacketIn m) - throws IOException { - unhandledMessageReceived(h, m); - } - - // no default implementation. Every state needs to handle it. - abstract void processOFPortStatus(OFChannelHandler h, OFPortStatus m) - throws IOException, SwitchStateException; - - void processOFQueueGetConfigReply(OFChannelHandler h, - OFQueueGetConfigReply m) - throws IOException { - unhandledMessageReceived(h, m); - } - - void processOFStatisticsReply(OFChannelHandler h, OFStatsReply m) - throws IOException, SwitchStateException { - unhandledMessageReceived(h, m); - } - - void processOFExperimenter(OFChannelHandler h, OFExperimenter m) - throws IOException, SwitchStateException { - // TODO: it might make sense to parse the vendor message here - // into the known vendor messages we support and then call more - // specific event handlers - unhandledMessageReceived(h, m); - } - - void processOFRoleReply(OFChannelHandler h, OFRoleReply m) - throws SwitchStateException, IOException { - unhandledMessageReceived(h, m); - } - - void processOFGetAsyncReply(OFChannelHandler h, - OFAsyncGetReply m) { - unhandledMessageReceived(h, m); - } - - } - - - - //************************* - // Channel handler methods - //************************* - - @Override - public void channelConnected(ChannelHandlerContext ctx, - ChannelStateEvent e) throws Exception { - channel = e.getChannel(); - log.info("New switch connection from {}", - channel.getRemoteAddress()); - /* - hack to wait for the switch to tell us what it's - max version is. This is not spec compliant and should - be removed as soon as switches behave better. - */ - //sendHandshakeHelloMessage(); - setState(ChannelState.WAIT_HELLO); - } - - @Override - public void channelDisconnected(ChannelHandlerContext ctx, - ChannelStateEvent e) throws Exception { - log.info("Switch disconnected callback for sw:{}. Cleaning up ...", - getSwitchInfoString()); - if (thisdpid != 0) { - if (!duplicateDpidFound) { - // if the disconnected switch (on this ChannelHandler) - // was not one with a duplicate-dpid, it is safe to remove all - // state for it at the controller. Notice that if the disconnected - // switch was a duplicate-dpid, calling the method below would clear - // all state for the original switch (with the same dpid), - // which we obviously don't want. - log.info("{}:removal called", getSwitchInfoString()); - if (sw != null) { - sw.removeConnectedSwitch(); - } - } else { - // A duplicate was disconnected on this ChannelHandler, - // this is the same switch reconnecting, but the original state was - // not cleaned up - XXX check liveness of original ChannelHandler - log.info("{}:duplicate found", getSwitchInfoString()); - duplicateDpidFound = Boolean.FALSE; - } - } else { - log.warn("no dpid in channelHandler registered for " - + "disconnected switch {}", getSwitchInfoString()); - } - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) - throws Exception { - if (e.getCause() instanceof ReadTimeoutException) { - // switch timeout - log.error("Disconnecting switch {} due to read timeout", - getSwitchInfoString()); - ctx.getChannel().close(); - } else if (e.getCause() instanceof HandshakeTimeoutException) { - log.error("Disconnecting switch {}: failed to complete handshake", - getSwitchInfoString()); - ctx.getChannel().close(); - } else if (e.getCause() instanceof ClosedChannelException) { - log.debug("Channel for sw {} already closed", getSwitchInfoString()); - } else if (e.getCause() instanceof IOException) { - if (!e.getCause().getMessage().equals(RESET_BY_PEER) && - !e.getCause().getMessage().equals(BROKEN_PIPE)) { - log.error("Disconnecting switch {} due to IO Error: {}", - getSwitchInfoString(), e.getCause().getMessage()); - if (log.isDebugEnabled()) { - // still print stack trace if debug is enabled - log.debug("StackTrace for previous Exception: ", e.getCause()); - } - } - ctx.getChannel().close(); - } else if (e.getCause() instanceof SwitchStateException) { - log.error("Disconnecting switch {} due to switch state error: {}", - getSwitchInfoString(), e.getCause().getMessage()); - if (log.isDebugEnabled()) { - // still print stack trace if debug is enabled - log.debug("StackTrace for previous Exception: ", e.getCause()); - } - ctx.getChannel().close(); - } else if (e.getCause() instanceof OFParseError) { - log.error("Disconnecting switch " - + getSwitchInfoString() + - " due to message parse failure", - e.getCause()); - ctx.getChannel().close(); - } else if (e.getCause() instanceof RejectedExecutionException) { - log.warn("Could not process message: queue full"); - } else { - log.error("Error while processing message from switch " - + getSwitchInfoString() - + "state " + this.state, e.getCause()); - ctx.getChannel().close(); - } - } - - @Override - public String toString() { - return getSwitchInfoString(); - } - - @Override - public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) - throws Exception { - OFFactory factory = (ofVersion == OFVersion.OF_13) ? factory13 : factory10; - OFMessage m = factory.buildEchoRequest().build(); - log.debug("Sending Echo Request on idle channel: {}", - e.getChannel().getPipeline().getLast().toString()); - e.getChannel().write(Collections.singletonList(m)); - // XXX S some problems here -- echo request has no transaction id, and - // echo reply is not correlated to the echo request. - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) - throws Exception { - if (e.getMessage() instanceof List) { - @SuppressWarnings("unchecked") - List<OFMessage> msglist = (List<OFMessage>) e.getMessage(); - - - for (OFMessage ofm : msglist) { - // Do the actual packet processing - state.processOFMessage(this, ofm); - } - } else { - state.processOFMessage(this, (OFMessage) e.getMessage()); - } - } - - - - //************************* - // Channel utility methods - //************************* - - /** - * Is this a state in which the handshake has completed? - * @return true if the handshake is complete - */ - public boolean isHandshakeComplete() { - return this.state.isHandshakeComplete(); - } - - private void dispatchMessage(OFMessage m) { - sw.handleMessage(m); - } - - /** - * Return a string describing this switch based on the already available - * information (DPID and/or remote socket). - * @return display string - */ - private String getSwitchInfoString() { - if (sw != null) { - return sw.toString(); - } - String channelString; - if (channel == null || channel.getRemoteAddress() == null) { - channelString = "?"; - } else { - channelString = channel.getRemoteAddress().toString(); - } - String dpidString; - if (featuresReply == null) { - dpidString = "?"; - } else { - dpidString = featuresReply.getDatapathId().toString(); - } - return String.format("[%s DPID[%s]]", channelString, dpidString); - } - - /** - * Update the channels state. Only called from the state machine. - * TODO: enforce restricted state transitions - * @param state - */ - private void setState(ChannelState state) { - this.state = state; - } - - /** - * Send hello message to the switch using the handshake transactions ids. - * @throws IOException - */ - private void sendHandshakeHelloMessage() throws IOException { - // The OF protocol requires us to start things off by sending the highest - // version of the protocol supported. - - // bitmap represents OF1.0 (ofp_version=0x01) and OF1.3 (ofp_version=0x04) - // see Sec. 7.5.1 of the OF1.3.4 spec - U32 bitmap = U32.ofRaw(0x00000012); - OFHelloElem hem = factory13.buildHelloElemVersionbitmap() - .setBitmaps(Collections.singletonList(bitmap)) - .build(); - OFMessage.Builder mb = factory13.buildHello() - .setXid(this.handshakeTransactionIds--) - .setElements(Collections.singletonList(hem)); - log.info("Sending OF_13 Hello to {}", channel.getRemoteAddress()); - channel.write(Collections.singletonList(mb.build())); - } - - /** - * Send featuresRequest msg to the switch using the handshake transactions ids. - * @throws IOException - */ - private void sendHandshakeFeaturesRequestMessage() throws IOException { - OFFactory factory = (ofVersion == OFVersion.OF_13) ? factory13 : factory10; - OFMessage m = factory.buildFeaturesRequest() - .setXid(this.handshakeTransactionIds--) - .build(); - channel.write(Collections.singletonList(m)); - } - - /** - * Send the configuration requests to tell the switch we want full - * packets. - * @throws IOException - */ - private void sendHandshakeSetConfig() throws IOException { - OFFactory factory = (ofVersion == OFVersion.OF_13) ? factory13 : factory10; - //log.debug("Sending CONFIG_REQUEST to {}", channel.getRemoteAddress()); - List<OFMessage> msglist = new ArrayList<OFMessage>(3); - - // Ensure we receive the full packet via PacketIn - // FIXME: We don't set the reassembly flags. - // Only send config to switches to send full packets, if they have a buffer. - // Saves a packet & OFSetConfig can't be handled by certain switches. - if(this.featuresReply.getNBuffers() > 0) { - OFSetConfig sc = factory - .buildSetConfig() - .setMissSendLen((short) 0xffff) - .setXid(this.handshakeTransactionIds--) - .build(); - msglist.add(sc); - } - - // Barrier - OFBarrierRequest br = factory - .buildBarrierRequest() - .setXid(this.handshakeTransactionIds--) - .build(); - msglist.add(br); - - // Verify (need barrier?) - OFGetConfigRequest gcr = factory - .buildGetConfigRequest() - .setXid(this.handshakeTransactionIds--) - .build(); - msglist.add(gcr); - channel.write(msglist); - } - - /** - * send a description state request. - * @throws IOException - */ - private void sendHandshakeDescriptionStatsRequest() throws IOException { - // Get Description to set switch-specific flags - OFFactory factory = (ofVersion == OFVersion.OF_13) ? factory13 : factory10; - OFDescStatsRequest dreq = factory - .buildDescStatsRequest() - .setXid(handshakeTransactionIds--) - .build(); - channel.write(Collections.singletonList(dreq)); - } - - private void sendHandshakeOFPortDescRequest() throws IOException { - // Get port description for 1.3 switch - OFPortDescStatsRequest preq = factory13 - .buildPortDescStatsRequest() - .setXid(handshakeTransactionIds--) - .build(); - channel.write(Collections.singletonList(preq)); - } - - ChannelState getStateForTesting() { - return state; - } - -} diff --git a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFMessageDecoder.java b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFMessageDecoder.java deleted file mode 100644 index f52d27e5..00000000 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFMessageDecoder.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2014 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 org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.FrameDecoder; -import org.projectfloodlight.openflow.protocol.OFFactories; -import org.projectfloodlight.openflow.protocol.OFMessage; -import org.projectfloodlight.openflow.protocol.OFMessageReader; - -/** - * Decode an openflow message from a Channel, for use in a netty pipeline. - */ -public class OFMessageDecoder extends FrameDecoder { - - @Override - protected Object decode(ChannelHandlerContext ctx, Channel channel, - ChannelBuffer buffer) throws Exception { - if (!channel.isConnected()) { - // In testing, I see decode being called AFTER decode last. - // This check avoids that from reading corrupted frames - return null; - } - - // Note that a single call to decode results in reading a single - // OFMessage from the channel buffer, which is passed on to, and processed - // by, the controller (in OFChannelHandler). - // This is different from earlier behavior (with the original openflowj), - // where we parsed all the messages in the buffer, before passing on - // a list of the parsed messages to the controller. - // The performance *may or may not* not be as good as before. - OFMessageReader<OFMessage> reader = OFFactories.getGenericReader(); - OFMessage message = reader.readFrom(buffer); - - return message; - } - -} diff --git a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFMessageEncoder.java b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFMessageEncoder.java deleted file mode 100644 index 4c1b16fe..00000000 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OFMessageEncoder.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2014 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.util.List; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.oneone.OneToOneEncoder; -import org.projectfloodlight.openflow.protocol.OFMessage; - -/** - * Encode an openflow message for output into a ChannelBuffer, for use in a - * netty pipeline. - */ -public class OFMessageEncoder extends OneToOneEncoder { - - @Override - protected Object encode(ChannelHandlerContext ctx, Channel channel, - Object msg) throws Exception { - if (!(msg instanceof List)) { - return msg; - } - - @SuppressWarnings("unchecked") - List<OFMessage> msglist = (List<OFMessage>) msg; - /* XXX S can't get length of OFMessage in loxigen's openflowj?? - int size = 0; - for (OFMessage ofm : msglist) { - size += ofm.getLengthU(); - }*/ - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - for (OFMessage ofm : msglist) { - if (ofm != null) { - ofm.writeTo(buf); - } - } - return buf; - } - -} 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 deleted file mode 100644 index d0429947..00000000 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenFlowControllerImpl.java +++ /dev/null @@ -1,633 +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.openflow.controller.impl; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; -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.Modified; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.apache.felix.scr.annotations.Service; -import org.onosproject.cfg.ComponentConfigService; -import org.onosproject.net.driver.DefaultDriverProviderService; -import org.onosproject.net.driver.DriverService; -import org.onosproject.openflow.controller.DefaultOpenFlowPacketContext; -import org.onosproject.openflow.controller.Dpid; -import org.onosproject.openflow.controller.OpenFlowController; -import org.onosproject.openflow.controller.OpenFlowEventListener; -import org.onosproject.openflow.controller.OpenFlowPacketContext; -import org.onosproject.openflow.controller.OpenFlowSwitch; -import org.onosproject.openflow.controller.OpenFlowSwitchListener; -import org.onosproject.openflow.controller.PacketListener; -import org.onosproject.openflow.controller.RoleState; -import org.onosproject.openflow.controller.driver.OpenFlowAgent; -import org.osgi.service.component.ComponentContext; -import org.projectfloodlight.openflow.protocol.OFCalientFlowStatsEntry; -import org.projectfloodlight.openflow.protocol.OFCalientFlowStatsReply; -import org.projectfloodlight.openflow.protocol.OFCircuitPortStatus; -import org.projectfloodlight.openflow.protocol.OFExperimenter; -import org.projectfloodlight.openflow.protocol.OFFactories; -import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; -import org.projectfloodlight.openflow.protocol.OFFlowStatsReply; -import org.projectfloodlight.openflow.protocol.OFTableStatsEntry; -import org.projectfloodlight.openflow.protocol.OFTableStatsReply; -import org.projectfloodlight.openflow.protocol.OFGroupDescStatsEntry; -import org.projectfloodlight.openflow.protocol.OFGroupDescStatsReply; -import org.projectfloodlight.openflow.protocol.OFGroupStatsEntry; -import org.projectfloodlight.openflow.protocol.OFGroupStatsReply; -import org.projectfloodlight.openflow.protocol.OFMessage; -import org.projectfloodlight.openflow.protocol.OFPacketIn; -import org.projectfloodlight.openflow.protocol.OFPortDesc; -import org.projectfloodlight.openflow.protocol.OFPortStatsEntry; -import org.projectfloodlight.openflow.protocol.OFPortStatsReply; -import org.projectfloodlight.openflow.protocol.OFPortStatus; -import org.projectfloodlight.openflow.protocol.OFStatsReply; -import org.projectfloodlight.openflow.protocol.OFStatsReplyFlags; -import org.projectfloodlight.openflow.protocol.action.OFActionOutput; -import org.projectfloodlight.openflow.protocol.instruction.OFInstruction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -import static org.onlab.util.Tools.groupedThreads; - -@Component(immediate = true) -@Service -public class OpenFlowControllerImpl implements OpenFlowController { - private static final String DEFAULT_OFPORT = "6633,6653"; - private static final int DEFAULT_WORKER_THREADS = 16; - - private static final Logger log = - LoggerFactory.getLogger(OpenFlowControllerImpl.class); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DriverService driverService; - - // References exists merely for sequencing purpose to assure drivers are loaded - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DefaultDriverProviderService defaultDriverProviderService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ComponentConfigService cfgService; - - @Property(name = "openflowPorts", value = DEFAULT_OFPORT, - label = "Port numbers (comma separated) used by OpenFlow protocol; default is 6633,6653") - private String openflowPorts = DEFAULT_OFPORT; - - @Property(name = "workerThreads", intValue = DEFAULT_WORKER_THREADS, - label = "Number of controller worker threads; default is 16") - private int workerThreads = DEFAULT_WORKER_THREADS; - - private final ExecutorService executorMsgs = - Executors.newFixedThreadPool(32, groupedThreads("onos/of", "event-stats-%d")); - - private final ExecutorService executorBarrier = - Executors.newFixedThreadPool(4, groupedThreads("onos/of", "event-barrier-%d")); - - protected ConcurrentHashMap<Dpid, OpenFlowSwitch> connectedSwitches = - new ConcurrentHashMap<>(); - protected ConcurrentHashMap<Dpid, OpenFlowSwitch> activeMasterSwitches = - new ConcurrentHashMap<>(); - protected ConcurrentHashMap<Dpid, OpenFlowSwitch> activeEqualSwitches = - new ConcurrentHashMap<>(); - - protected OpenFlowSwitchAgent agent = new OpenFlowSwitchAgent(); - protected Set<OpenFlowSwitchListener> ofSwitchListener = new CopyOnWriteArraySet<>(); - - protected Multimap<Integer, PacketListener> ofPacketListener = - ArrayListMultimap.create(); - - protected Set<OpenFlowEventListener> ofEventListener = new CopyOnWriteArraySet<>(); - - protected Multimap<Dpid, OFFlowStatsEntry> fullFlowStats = - ArrayListMultimap.create(); - - protected Multimap<Dpid, OFTableStatsEntry> fullTableStats = - ArrayListMultimap.create(); - - protected Multimap<Dpid, OFGroupStatsEntry> fullGroupStats = - ArrayListMultimap.create(); - - protected Multimap<Dpid, OFGroupDescStatsEntry> fullGroupDescStats = - ArrayListMultimap.create(); - - protected Multimap<Dpid, OFPortStatsEntry> fullPortStats = - ArrayListMultimap.create(); - - private final Controller ctrl = new Controller(); - - @Activate - public void activate(ComponentContext context) { - cfgService.registerProperties(getClass()); - ctrl.setConfigParams(context.getProperties()); - ctrl.start(agent, driverService); - } - - @Deactivate - public void deactivate() { - cfgService.unregisterProperties(getClass(), false); - ctrl.stop(); - } - - @Modified - public void modified(ComponentContext context) { - ctrl.stop(); - ctrl.setConfigParams(context.getProperties()); - ctrl.start(agent, driverService); - } - - @Override - public Iterable<OpenFlowSwitch> getSwitches() { - return connectedSwitches.values(); - } - - @Override - public Iterable<OpenFlowSwitch> getMasterSwitches() { - return activeMasterSwitches.values(); - } - - @Override - public Iterable<OpenFlowSwitch> getEqualSwitches() { - return activeEqualSwitches.values(); - } - - @Override - public OpenFlowSwitch getSwitch(Dpid dpid) { - return connectedSwitches.get(dpid); - } - - @Override - public OpenFlowSwitch getMasterSwitch(Dpid dpid) { - return activeMasterSwitches.get(dpid); - } - - @Override - public OpenFlowSwitch getEqualSwitch(Dpid dpid) { - return activeEqualSwitches.get(dpid); - } - - @Override - public void addListener(OpenFlowSwitchListener listener) { - if (!ofSwitchListener.contains(listener)) { - this.ofSwitchListener.add(listener); - } - } - - @Override - public void removeListener(OpenFlowSwitchListener listener) { - this.ofSwitchListener.remove(listener); - } - - @Override - public void addPacketListener(int priority, PacketListener listener) { - ofPacketListener.put(priority, listener); - } - - @Override - public void removePacketListener(PacketListener listener) { - ofPacketListener.values().remove(listener); - } - - @Override - public void addEventListener(OpenFlowEventListener listener) { - ofEventListener.add(listener); - } - - @Override - public void removeEventListener(OpenFlowEventListener listener) { - ofEventListener.remove(listener); - } - - @Override - public void write(Dpid dpid, OFMessage msg) { - this.getSwitch(dpid).sendMsg(msg); - } - - @Override - public void processPacket(Dpid dpid, OFMessage msg) { - Collection<OFFlowStatsEntry> flowStats; - Collection<OFTableStatsEntry> tableStats; - Collection<OFGroupStatsEntry> groupStats; - Collection<OFGroupDescStatsEntry> groupDescStats; - Collection<OFPortStatsEntry> portStats; - - switch (msg.getType()) { - case PORT_STATUS: - for (OpenFlowSwitchListener l : ofSwitchListener) { - l.portChanged(dpid, (OFPortStatus) msg); - } - break; - case FEATURES_REPLY: - for (OpenFlowSwitchListener l : ofSwitchListener) { - l.switchChanged(dpid); - } - break; - case PACKET_IN: - OpenFlowPacketContext pktCtx = DefaultOpenFlowPacketContext - .packetContextFromPacketIn(this.getSwitch(dpid), - (OFPacketIn) msg); - for (PacketListener p : ofPacketListener.values()) { - p.handlePacket(pktCtx); - } - break; - // TODO: Consider using separate threadpool for sensitive messages. - // ie. Back to back error could cause us to starve. - case FLOW_REMOVED: - case ERROR: - executorMsgs.submit(new OFMessageHandler(dpid, msg)); - break; - case STATS_REPLY: - OFStatsReply reply = (OFStatsReply) msg; - switch (reply.getStatsType()) { - case PORT_DESC: - for (OpenFlowSwitchListener l : ofSwitchListener) { - l.switchChanged(dpid); - } - break; - case FLOW: - flowStats = publishFlowStats(dpid, (OFFlowStatsReply) reply); - if (flowStats != null) { - OFFlowStatsReply.Builder rep = - OFFactories.getFactory(msg.getVersion()).buildFlowStatsReply(); - rep.setEntries(Lists.newLinkedList(flowStats)); - rep.setXid(reply.getXid()); - executorMsgs.submit(new OFMessageHandler(dpid, rep.build())); - } - break; - case TABLE: - tableStats = publishTableStats(dpid, (OFTableStatsReply) reply); - if (tableStats != null) { - OFTableStatsReply.Builder rep = - OFFactories.getFactory(msg.getVersion()).buildTableStatsReply(); - rep.setEntries(Lists.newLinkedList(tableStats)); - executorMsgs.submit(new OFMessageHandler(dpid, rep.build())); - } - break; - case GROUP: - groupStats = publishGroupStats(dpid, (OFGroupStatsReply) reply); - if (groupStats != null) { - OFGroupStatsReply.Builder rep = - OFFactories.getFactory(msg.getVersion()).buildGroupStatsReply(); - rep.setEntries(Lists.newLinkedList(groupStats)); - rep.setXid(reply.getXid()); - executorMsgs.submit(new OFMessageHandler(dpid, rep.build())); - } - break; - case GROUP_DESC: - groupDescStats = publishGroupDescStats(dpid, - (OFGroupDescStatsReply) reply); - if (groupDescStats != null) { - OFGroupDescStatsReply.Builder rep = - OFFactories.getFactory(msg.getVersion()).buildGroupDescStatsReply(); - rep.setEntries(Lists.newLinkedList(groupDescStats)); - rep.setXid(reply.getXid()); - executorMsgs.submit(new OFMessageHandler(dpid, rep.build())); - } - break; - case PORT: - executorMsgs.submit(new OFMessageHandler(dpid, reply)); - break; - case METER: - executorMsgs.submit(new OFMessageHandler(dpid, reply)); - break; - case EXPERIMENTER: - if (reply instanceof OFCalientFlowStatsReply) { - // Convert Calient flow statistics to regular flow stats - // TODO: parse remaining fields such as power levels etc. when we have proper monitoring API - OFFlowStatsReply.Builder fsr = getSwitch(dpid).factory().buildFlowStatsReply(); - List<OFFlowStatsEntry> entries = new LinkedList<>(); - for (OFCalientFlowStatsEntry entry : ((OFCalientFlowStatsReply) msg).getEntries()) { - - // Single instruction, i.e., output to port - OFActionOutput action = OFFactories - .getFactory(msg.getVersion()) - .actions() - .buildOutput() - .setPort(entry.getOutPort()) - .build(); - OFInstruction instruction = OFFactories - .getFactory(msg.getVersion()) - .instructions() - .applyActions(Collections.singletonList(action)); - OFFlowStatsEntry fs = getSwitch(dpid).factory().buildFlowStatsEntry() - .setMatch(entry.getMatch()) - .setTableId(entry.getTableId()) - .setDurationSec(entry.getDurationSec()) - .setDurationNsec(entry.getDurationNsec()) - .setPriority(entry.getPriority()) - .setIdleTimeout(entry.getIdleTimeout()) - .setHardTimeout(entry.getHardTimeout()) - .setFlags(entry.getFlags()) - .setCookie(entry.getCookie()) - .setInstructions(Collections.singletonList(instruction)) - .build(); - entries.add(fs); - } - fsr.setEntries(entries); - - flowStats = publishFlowStats(dpid, fsr.build()); - if (flowStats != null) { - OFFlowStatsReply.Builder rep = - OFFactories.getFactory(msg.getVersion()).buildFlowStatsReply(); - rep.setEntries(Lists.newLinkedList(flowStats)); - executorMsgs.submit(new OFMessageHandler(dpid, rep.build())); - } - } else { - executorMsgs.submit(new OFMessageHandler(dpid, reply)); - } - break; - default: - log.warn("Discarding unknown stats reply type {}", reply.getStatsType()); - break; - } - break; - case BARRIER_REPLY: - executorBarrier.submit(new OFMessageHandler(dpid, msg)); - break; - case EXPERIMENTER: - long experimenter = ((OFExperimenter) msg).getExperimenter(); - if (experimenter == 0x748771) { - // LINC-OE port stats - OFCircuitPortStatus circuitPortStatus = (OFCircuitPortStatus) msg; - OFPortStatus.Builder portStatus = this.getSwitch(dpid).factory().buildPortStatus(); - OFPortDesc.Builder portDesc = this.getSwitch(dpid).factory().buildPortDesc(); - portDesc.setPortNo(circuitPortStatus.getPortNo()) - .setHwAddr(circuitPortStatus.getHwAddr()) - .setName(circuitPortStatus.getName()) - .setConfig(circuitPortStatus.getConfig()) - .setState(circuitPortStatus.getState()); - portStatus.setReason(circuitPortStatus.getReason()).setDesc(portDesc.build()); - for (OpenFlowSwitchListener l : ofSwitchListener) { - l.portChanged(dpid, portStatus.build()); - } - } else { - log.warn("Handling experimenter type {} not yet implemented", - ((OFExperimenter) msg).getExperimenter(), msg); - } - break; - default: - log.warn("Handling message type {} not yet implemented {}", - msg.getType(), msg); - } - } - - private synchronized Collection<OFFlowStatsEntry> publishFlowStats(Dpid dpid, - OFFlowStatsReply reply) { - //TODO: Get rid of synchronized - fullFlowStats.putAll(dpid, reply.getEntries()); - if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { - return fullFlowStats.removeAll(dpid); - } - return null; - } - - private synchronized Collection<OFTableStatsEntry> publishTableStats(Dpid dpid, - OFTableStatsReply reply) { - //TODO: Get rid of synchronized - fullTableStats.putAll(dpid, reply.getEntries()); - if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { - return fullTableStats.removeAll(dpid); - } - return null; - } - - private synchronized Collection<OFGroupStatsEntry> publishGroupStats(Dpid dpid, - OFGroupStatsReply reply) { - //TODO: Get rid of synchronized - fullGroupStats.putAll(dpid, reply.getEntries()); - if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { - return fullGroupStats.removeAll(dpid); - } - return null; - } - - private synchronized Collection<OFGroupDescStatsEntry> publishGroupDescStats(Dpid dpid, - OFGroupDescStatsReply reply) { - //TODO: Get rid of synchronized - fullGroupDescStats.putAll(dpid, reply.getEntries()); - if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { - return fullGroupDescStats.removeAll(dpid); - } - return null; - } - - private synchronized Collection<OFPortStatsEntry> publishPortStats(Dpid dpid, - OFPortStatsReply reply) { - fullPortStats.putAll(dpid, reply.getEntries()); - if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) { - return fullPortStats.removeAll(dpid); - } - return null; - } - - @Override - public void setRole(Dpid dpid, RoleState role) { - final OpenFlowSwitch sw = getSwitch(dpid); - if (sw == null) { - log.debug("Switch not connected. Ignoring setRole({}, {})", dpid, role); - return; - } - sw.setRole(role); - } - - /** - * Implementation of an OpenFlow Agent which is responsible for - * keeping track of connected switches and the state in which - * they are. - */ - public class OpenFlowSwitchAgent implements OpenFlowAgent { - - private final Logger log = LoggerFactory.getLogger(OpenFlowSwitchAgent.class); - private final Lock switchLock = new ReentrantLock(); - - @Override - public boolean addConnectedSwitch(Dpid dpid, OpenFlowSwitch sw) { - - if (connectedSwitches.get(dpid) != null) { - log.error("Trying to add connectedSwitch but found a previous " - + "value for dpid: {}", dpid); - return false; - } else { - log.info("Added switch {}", dpid); - connectedSwitches.put(dpid, sw); - for (OpenFlowSwitchListener l : ofSwitchListener) { - l.switchAdded(dpid); - } - return true; - } - } - - @Override - public boolean validActivation(Dpid dpid) { - if (connectedSwitches.get(dpid) == null) { - log.error("Trying to activate switch but is not in " - + "connected switches: dpid {}. Aborting ..", - dpid); - return false; - } - if (activeMasterSwitches.get(dpid) != null || - 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'}); - return false; - } - return true; - } - - - @Override - public boolean addActivatedMasterSwitch(Dpid dpid, OpenFlowSwitch sw) { - switchLock.lock(); - try { - if (!validActivation(dpid)) { - return false; - } - activeMasterSwitches.put(dpid, sw); - return true; - } finally { - switchLock.unlock(); - } - } - - @Override - public boolean addActivatedEqualSwitch(Dpid dpid, OpenFlowSwitch sw) { - switchLock.lock(); - try { - if (!validActivation(dpid)) { - return false; - } - activeEqualSwitches.put(dpid, sw); - log.info("Added Activated EQUAL Switch {}", dpid); - return true; - } finally { - switchLock.unlock(); - } - } - - @Override - public void transitionToMasterSwitch(Dpid dpid) { - switchLock.lock(); - try { - if (activeMasterSwitches.containsKey(dpid)) { - return; - } - OpenFlowSwitch sw = activeEqualSwitches.remove(dpid); - if (sw == null) { - sw = getSwitch(dpid); - if (sw == null) { - log.error("Transition to master called on sw {}, but switch " - + "was not found in controller-cache", dpid); - return; - } - } - log.info("Transitioned switch {} to MASTER", dpid); - activeMasterSwitches.put(dpid, sw); - } finally { - switchLock.unlock(); - } - } - - - @Override - public void transitionToEqualSwitch(Dpid dpid) { - switchLock.lock(); - try { - if (activeEqualSwitches.containsKey(dpid)) { - return; - } - OpenFlowSwitch sw = activeMasterSwitches.remove(dpid); - if (sw == null) { - sw = getSwitch(dpid); - if (sw == null) { - log.error("Transition to equal called on sw {}, but switch " - + "was not found in controller-cache", dpid); - return; - } - } - log.info("Transitioned switch {} to EQUAL", dpid); - activeEqualSwitches.put(dpid, sw); - } finally { - switchLock.unlock(); - } - - } - - @Override - public void removeConnectedSwitch(Dpid dpid) { - connectedSwitches.remove(dpid); - OpenFlowSwitch sw = activeMasterSwitches.remove(dpid); - if (sw == null) { - log.debug("sw was null for {}", dpid); - sw = activeEqualSwitches.remove(dpid); - } - for (OpenFlowSwitchListener l : ofSwitchListener) { - l.switchRemoved(dpid); - } - } - - @Override - public void processMessage(Dpid dpid, OFMessage m) { - processPacket(dpid, m); - } - - @Override - public void returnRoleReply(Dpid dpid, RoleState requested, RoleState response) { - for (OpenFlowSwitchListener l : ofSwitchListener) { - l.receivedRoleReply(dpid, requested, response); - } - } - } - - private final class OFMessageHandler implements Runnable { - - private final OFMessage msg; - private final Dpid dpid; - - public OFMessageHandler(Dpid dpid, OFMessage msg) { - this.msg = msg; - this.dpid = dpid; - } - - @Override - public void run() { - for (OpenFlowEventListener listener : ofEventListener) { - listener.handleMessage(dpid, msg); - } - } - - } - -} diff --git a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenflowPipelineFactory.java b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenflowPipelineFactory.java deleted file mode 100644 index 1467520d..00000000 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/OpenflowPipelineFactory.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2014 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.util.concurrent.ThreadPoolExecutor; - -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.channel.ChannelPipelineFactory; -import org.jboss.netty.channel.Channels; -import org.jboss.netty.handler.execution.ExecutionHandler; -import org.jboss.netty.handler.timeout.IdleStateHandler; -import org.jboss.netty.handler.timeout.ReadTimeoutHandler; -import org.jboss.netty.util.ExternalResourceReleasable; -import org.jboss.netty.util.HashedWheelTimer; -import org.jboss.netty.util.Timer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.net.ssl.SSLEngine; - -/** - * Creates a ChannelPipeline for a server-side openflow channel. - */ -public class OpenflowPipelineFactory - implements ChannelPipelineFactory, ExternalResourceReleasable { - - private final Logger log = LoggerFactory.getLogger(getClass()); - - private final SSLEngine sslEngine; - protected Controller controller; - protected ThreadPoolExecutor pipelineExecutor; - protected Timer timer; - protected IdleStateHandler idleHandler; - protected ReadTimeoutHandler readTimeoutHandler; - - public OpenflowPipelineFactory(Controller controller, - ThreadPoolExecutor pipelineExecutor, - SSLEngine sslEngine) { - super(); - this.controller = controller; - this.pipelineExecutor = pipelineExecutor; - this.timer = new HashedWheelTimer(); - this.idleHandler = new IdleStateHandler(timer, 20, 25, 0); - this.readTimeoutHandler = new ReadTimeoutHandler(timer, 30); - this.sslEngine = sslEngine; - } - - @Override - public ChannelPipeline getPipeline() throws Exception { - OFChannelHandler handler = new OFChannelHandler(controller); - - ChannelPipeline pipeline = Channels.pipeline(); - if (sslEngine != null) { - log.info("OpenFlow SSL enabled."); - pipeline.addLast("ssl", - new org.jboss.netty.handler.ssl.SslHandler(sslEngine)); - } else { - log.info("OpenFlow SSL disabled"); - } - pipeline.addLast("ofmessagedecoder", new OFMessageDecoder()); - pipeline.addLast("ofmessageencoder", new OFMessageEncoder()); - pipeline.addLast("idle", idleHandler); - pipeline.addLast("timeout", readTimeoutHandler); - // XXX S ONOS: was 15 increased it to fix Issue #296 - pipeline.addLast("handshaketimeout", - new HandshakeTimeoutHandler(handler, timer, 60)); - if (pipelineExecutor != null) { - pipeline.addLast("pipelineExecutor", - new ExecutionHandler(pipelineExecutor)); - } - pipeline.addLast("handler", handler); - return pipeline; - } - - @Override - public void releaseExternalResources() { - timer.stop(); - } -} 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 deleted file mode 100644 index e7e5ffee..00000000 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/RoleManager.java +++ /dev/null @@ -1,405 +0,0 @@ -/* - * Copyright 2014 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 com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import org.onosproject.openflow.controller.RoleState; -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.OFControllerRole; -import org.projectfloodlight.openflow.protocol.OFErrorMsg; -import org.projectfloodlight.openflow.protocol.OFErrorType; -import org.projectfloodlight.openflow.protocol.OFExperimenter; -import org.projectfloodlight.openflow.protocol.OFFactories; -import org.projectfloodlight.openflow.protocol.OFNiciraControllerRole; -import org.projectfloodlight.openflow.protocol.OFNiciraControllerRoleReply; -import org.projectfloodlight.openflow.protocol.OFRoleReply; -import org.projectfloodlight.openflow.protocol.OFRoleRequest; -import org.projectfloodlight.openflow.protocol.OFVersion; -import org.projectfloodlight.openflow.protocol.errormsg.OFBadRequestErrorMsg; -import org.projectfloodlight.openflow.protocol.errormsg.OFRoleRequestFailedErrorMsg; -import org.projectfloodlight.openflow.types.U64; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.concurrent.TimeUnit; - - -/** - * A utility class to handle role requests and replies for this channel. - * After a role request is submitted the role changer keeps track of the - * pending request, collects the reply (if any) and times out the request - * if necessary. - */ -class RoleManager implements RoleHandler { - protected static final long NICIRA_EXPERIMENTER = 0x2320; - - private static Logger log = LoggerFactory.getLogger(RoleManager.class); - - // The time until cached XID is evicted. Arbitrary for now. - private final int pendingXidTimeoutSeconds = 60; - - // The cache for pending expected RoleReplies keyed on expected XID - private Cache<Integer, RoleState> pendingReplies = - CacheBuilder.newBuilder() - .expireAfterWrite(pendingXidTimeoutSeconds, TimeUnit.SECONDS) - .build(); - - // the expectation set by the caller for the returned role - private RoleRecvStatus expectation; - private final OpenFlowSwitchDriver sw; - - - public RoleManager(OpenFlowSwitchDriver sw) { - this.expectation = RoleRecvStatus.MATCHED_CURRENT_ROLE; - this.sw = sw; - } - - /** - * Send NX role request message to the switch requesting the specified - * role. - * - * @param role role to request - */ - private int sendNxRoleRequest(RoleState role) throws IOException { - // Convert the role enum to the appropriate role to send - OFNiciraControllerRole roleToSend = OFNiciraControllerRole.ROLE_OTHER; - switch (role) { - case MASTER: - roleToSend = OFNiciraControllerRole.ROLE_MASTER; - break; - case SLAVE: - case EQUAL: - default: - // ensuring that the only two roles sent to 1.0 switches with - // Nicira role support, are MASTER and SLAVE - roleToSend = OFNiciraControllerRole.ROLE_OTHER; - log.debug("Sending Nx Role.SLAVE to switch {}.", sw); - } - int xid = sw.getNextTransactionId(); - OFExperimenter roleRequest = OFFactories.getFactory(OFVersion.OF_10) - .buildNiciraControllerRoleRequest() - .setXid(xid) - .setRole(roleToSend) - .build(); - sw.sendRoleRequest(roleRequest); - return xid; - } - - private int sendOF13RoleRequest(RoleState role) throws IOException { - // Convert the role enum to the appropriate role to send - OFControllerRole roleToSend = OFControllerRole.ROLE_NOCHANGE; - switch (role) { - case EQUAL: - roleToSend = OFControllerRole.ROLE_EQUAL; - break; - case MASTER: - roleToSend = OFControllerRole.ROLE_MASTER; - break; - case SLAVE: - roleToSend = OFControllerRole.ROLE_SLAVE; - break; - default: - log.warn("Sending default role.noChange to switch {}." - + " Should only be used for queries.", sw); - } - - int xid = sw.getNextTransactionId(); - OFRoleRequest rrm = OFFactories.getFactory(OFVersion.OF_13) - .buildRoleRequest() - .setRole(roleToSend) - .setXid(xid) - //FIXME fix below when we actually use generation ids - .setGenerationId(U64.ZERO) - .build(); - - sw.sendRoleRequest(rrm); - return xid; - } - - @Override - public synchronized boolean sendRoleRequest(RoleState role, RoleRecvStatus exp) - throws IOException { - this.expectation = exp; - - if (sw.factory().getVersion() == OFVersion.OF_10) { - Boolean supportsNxRole = sw.supportNxRole(); - if (!supportsNxRole) { - log.debug("Switch driver indicates no support for Nicira " - + "role request messages. Not sending ..."); - handleUnsentRoleMessage(role, - expectation); - return false; - } - // OF1.0 switch with support for NX_ROLE_REQUEST vendor extn. - // make Role.EQUAL become Role.SLAVE - RoleState roleToSend = (role == RoleState.EQUAL) ? RoleState.SLAVE : role; - pendingReplies.put(sendNxRoleRequest(roleToSend), role); - } else { - // OF1.3 switch, use OFPT_ROLE_REQUEST message - pendingReplies.put(sendOF13RoleRequest(role), role); - } - return true; - } - - private void handleUnsentRoleMessage(RoleState role, - RoleRecvStatus exp) throws IOException { - // typically this is triggered for a switch where role messages - // are not supported - we confirm that the role being set is - // master - if (exp != RoleRecvStatus.MATCHED_SET_ROLE) { - - log.error("Expected MASTER role from registry for switch " - + "which has no support for role-messages." - + "Received {}. It is possible that this switch " - + "is connected to other controllers, in which " - + "case it should support role messages - not " - + "moving forward.", role); - - } - - } - - - @Override - public synchronized RoleRecvStatus deliverRoleReply(RoleReplyInfo rri) - throws SwitchStateException { - int xid = (int) rri.getXid(); - RoleState receivedRole = rri.getRole(); - RoleState expectedRole = pendingReplies.getIfPresent(xid); - - if (expectedRole == null) { - RoleState currentRole = (sw != null) ? sw.getRole() : null; - if (currentRole != null) { - if (currentRole == rri.getRole()) { - // Don't disconnect if the role reply we received is - // for the same role we are already in. - // FIXME: but we do from the caller anyways. - log.debug("Received unexpected RoleReply from " - + "Switch: {}. " - + "Role in reply is same as current role of this " - + "controller for this sw. Ignoring ...", - sw.getStringId()); - return RoleRecvStatus.OTHER_EXPECTATION; - } else { - String msg = String.format("Switch: [%s], " - + "received unexpected RoleReply[%s]. " - + "No roles are pending, and this controller's " - + "current role:[%s] does not match reply. " - + "Disconnecting switch ... ", - sw.getStringId(), - rri, currentRole); - throw new SwitchStateException(msg); - } - } - 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(), }); - return RoleRecvStatus.OTHER_EXPECTATION; - } - - // XXX Should check generation id meaningfully and other cases of expectations - //if (pendingXid != xid) { - // log.info("Received older role reply from " + - // "switch {} ({}). Ignoring. " + - // "Waiting for {}, xid={}", - // new Object[] {sw.getStringId(), rri, - // pendingRole, pendingXid }); - // return RoleRecvStatus.OLD_REPLY; - //} - sw.returnRoleReply(expectedRole, receivedRole); - - if (expectedRole == receivedRole) { - log.debug("Received role reply message from {} that matched " - + "expected role-reply {} with expectations {}", - new Object[] {sw.getStringId(), receivedRole, expectation}); - - // Done with this RoleReply; Invalidate - pendingReplies.invalidate(xid); - if (expectation == RoleRecvStatus.MATCHED_CURRENT_ROLE || - expectation == RoleRecvStatus.MATCHED_SET_ROLE) { - return expectation; - } else { - return RoleRecvStatus.OTHER_EXPECTATION; - } - } - - pendingReplies.invalidate(xid); - // if xids match but role's don't, perhaps its a query (OF1.3) - if (expectation == RoleRecvStatus.REPLY_QUERY) { - return expectation; - } - - return RoleRecvStatus.OTHER_EXPECTATION; - } - - /** - * Called if we receive an error message. If the xid matches the - * pending request we handle it otherwise we ignore it. - * - * Note: since we only keep the last pending request we might get - * error messages for earlier role requests that we won't be able - * to handle - */ - @Override - public synchronized RoleRecvStatus deliverError(OFErrorMsg error) - throws SwitchStateException { - RoleState errorRole = pendingReplies.getIfPresent(error.getXid()); - if (errorRole == null) { - if (error.getErrType() == OFErrorType.ROLE_REQUEST_FAILED) { - log.debug("Received an error msg from sw {} for a role request," - + " but not for pending request in role-changer; " - + " ignoring error {} ...", - sw.getStringId(), error); - } else { - log.debug("Received an error msg from sw {}, but no pending " - + "requests in role-changer; not handling ...", - sw.getStringId()); - } - return RoleRecvStatus.OTHER_EXPECTATION; - } - // it is an error related to a currently pending role request message - if (error.getErrType() == OFErrorType.BAD_REQUEST) { - 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 - }); - return RoleRecvStatus.UNSUPPORTED; - } - - if (error.getErrType() == OFErrorType.ROLE_REQUEST_FAILED) { - OFRoleRequestFailedErrorMsg rrerr = - (OFRoleRequestFailedErrorMsg) error; - switch (rrerr.getCode()) { - case BAD_ROLE: - // switch says that current-role-req has bad role? - // for now we disconnect - // fall-thru - case STALE: - // switch says that current-role-req has stale gen-id? - // for now we disconnect - // fall-thru - case UNSUP: - // switch says that current-role-req has role that - // cannot be supported? for now we disconnect - String msgx = String.format("Switch: [%s], " - + "received Error to for pending role request [%s]. " - + "Error:[%s]. Disconnecting switch ... ", - sw.getStringId(), - errorRole, rrerr); - throw new SwitchStateException(msgx); - default: - break; - } - } - - // This error message was for a role request message but we dont know - // how to handle errors for nicira role request messages - return RoleRecvStatus.OTHER_EXPECTATION; - } - - /** - * Extract the role from an OFVendor message. - * - * Extract the role from an OFVendor message if the message is a - * Nicira role reply. Otherwise return null. - * - * @param experimenterMsg message - * @return The role in the message if the message is a Nicira role - * reply, null otherwise. - * @throws SwitchStateException If the message is a Nicira role reply - * but the numeric role value is unknown. - */ - @Override - public RoleState extractNiciraRoleReply(OFExperimenter experimenterMsg) - throws SwitchStateException { - int vendor = (int) experimenterMsg.getExperimenter(); - if (vendor != 0x2320) { - return null; - } - OFNiciraControllerRoleReply nrr = - (OFNiciraControllerRoleReply) experimenterMsg; - - RoleState role = null; - OFNiciraControllerRole ncr = nrr.getRole(); - switch (ncr) { - case ROLE_MASTER: - role = RoleState.MASTER; - break; - case ROLE_OTHER: - role = RoleState.EQUAL; - break; - case ROLE_SLAVE: - role = RoleState.SLAVE; - break; - default: //handled below - } - - if (role == null) { - String msg = String.format("Switch: [%s], " - + "received NX_ROLE_REPLY with invalid role " - + "value %s", - sw.getStringId(), - nrr.getRole()); - throw new SwitchStateException(msg); - } - return role; - } - - /** - * Extract the role information from an OF1.3 Role Reply Message. - * - * @param rrmsg the role message - * @return RoleReplyInfo object - * @throws SwitchStateException if the role information could not be extracted. - */ - @Override - public RoleReplyInfo extractOFRoleReply(OFRoleReply rrmsg) - throws SwitchStateException { - OFControllerRole cr = rrmsg.getRole(); - RoleState role = null; - switch (cr) { - case ROLE_EQUAL: - role = RoleState.EQUAL; - break; - case ROLE_MASTER: - role = RoleState.MASTER; - break; - case ROLE_SLAVE: - role = RoleState.SLAVE; - break; - case ROLE_NOCHANGE: // switch should send current role - default: - String msg = String.format("Unknown controller role %s " - + "received from switch %s", cr, sw); - throw new SwitchStateException(msg); - } - - return new RoleReplyInfo(role, rrmsg.getGenerationId(), rrmsg.getXid()); - } - -} - diff --git a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/package-info.java b/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/package-info.java deleted file mode 100644 index a5d9f274..00000000 --- a/framework/src/onos/openflow/ctl/src/main/java/org/onosproject/openflow/controller/impl/package-info.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2014 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. - */ - -/** - * Implementation of the OpenFlow controller IO subsystem. - */ -package org.onosproject.openflow.controller.impl; 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 deleted file mode 100644 index 0a71a40d..00000000 --- a/framework/src/onos/openflow/ctl/src/test/java/org/onosproject/openflow/controller/impl/RoleManagerTest.java +++ /dev/null @@ -1,345 +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.openflow.controller.impl; - -import org.jboss.netty.channel.Channel; -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.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; -import static org.onosproject.openflow.controller.driver.RoleRecvStatus.MATCHED_CURRENT_ROLE; -import static org.onosproject.openflow.controller.driver.RoleRecvStatus.OTHER_EXPECTATION; - -public class RoleManagerTest { - - private static final U64 GID = U64.of(10L); - private static final long XID = 1L; - - private OpenFlowSwitchDriver sw; - private RoleManager manager; - - @Before - public void setUp() { - sw = new TestSwitchDriver(); - manager = new RoleManager(sw); - } - - @After - public void tearDown() { - manager = null; - sw = null; - } - - @Test - public void deliverRoleReply() { - RoleRecvStatus status; - - RoleReplyInfo asserted = new RoleReplyInfo(MASTER, GID, XID); - RoleReplyInfo unasserted = new RoleReplyInfo(SLAVE, GID, XID); - - try { - //call without sendRoleReq() for requestPending = false - //first, sw.role == null - status = manager.deliverRoleReply(asserted); - assertEquals("expectation wrong", OTHER_EXPECTATION, status); - - sw.setRole(MASTER); - assertEquals("expectation wrong", OTHER_EXPECTATION, status); - sw.setRole(SLAVE); - - //match to pendingRole = MASTER, requestPending = true - manager.sendRoleRequest(MASTER, MATCHED_CURRENT_ROLE); - status = manager.deliverRoleReply(asserted); - assertEquals("expectation wrong", MATCHED_CURRENT_ROLE, status); - - //requestPending never gets reset -- this might be a bug. - status = manager.deliverRoleReply(unasserted); - assertEquals("expectation wrong", OTHER_EXPECTATION, status); - assertEquals("pending role mismatch", MASTER, ((TestSwitchDriver) sw).failed); - - } catch (IOException | SwitchStateException e) { - assertEquals("unexpected error thrown", - SwitchStateException.class, e.getClass()); - } - } - - private class TestSwitchDriver implements OpenFlowSwitchDriver { - - RoleState failed = null; - RoleState current = null; - - @Override - public void sendMsg(OFMessage msg) { - } - - @Override - public void sendMsg(List<OFMessage> msgs) { - } - - - @Override - public void handleMessage(OFMessage fromSwitch) { - } - - @Override - public void setRole(RoleState role) { - current = role; - } - - @Override - public RoleState getRole() { - return current; - } - - @Override - public List<OFPortDesc> 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<OFPortDescStatsReply> portDescReplies) { - } - - @Override - public void setFeaturesReply(OFFeaturesReply featuresReply) { - } - - @Override - public void setSwitchDescription(OFDescStatsReply desc) { - } - - @Override - public int getNextTransactionId() { - 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; - } - - @Override - 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/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFSwitchImplSpringOpenTTPDellOSR.java b/framework/src/onos/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFSwitchImplSpringOpenTTPDellOSR.java deleted file mode 100644 index 783a37e6..00000000 --- a/framework/src/onos/openflow/drivers/src/main/java/org/onosproject/openflow/drivers/OFSwitchImplSpringOpenTTPDellOSR.java +++ /dev/null @@ -1,65 +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.openflow.drivers; - -import org.onosproject.openflow.controller.Dpid; -import org.projectfloodlight.openflow.protocol.OFDescStatsReply; -import org.projectfloodlight.openflow.types.TableId; - -/** - * OFDescriptionStatistics Vendor (Manufacturer Desc.): Dell Make (Hardware - * Desc.) : OpenFlow 1.3 Reference Userspace Switch Model (Datapath Desc.) : - * None Software : Serial : None. - */ -//TODO: Knock-off this class as we don't need any switch/app specific -//drivers in the south bound layers. -public class OFSwitchImplSpringOpenTTPDellOSR extends OFSwitchImplSpringOpenTTP { - - /* Table IDs to be used for Dell Open Segment Routers*/ - private static final int DELL_TABLE_VLAN = 17; - private static final int DELL_TABLE_TMAC = 18; - private static final int DELL_TABLE_IPV4_UNICAST = 30; - private static final int DELL_TABLE_MPLS = 25; - private static final int DELL_TABLE_ACL = 40; - - public OFSwitchImplSpringOpenTTPDellOSR(Dpid dpid, OFDescStatsReply desc) { - super(dpid, desc); - vlanTableId = DELL_TABLE_VLAN; - tmacTableId = DELL_TABLE_TMAC; - ipv4UnicastTableId = DELL_TABLE_IPV4_UNICAST; - mplsTableId = DELL_TABLE_MPLS; - aclTableId = DELL_TABLE_ACL; - } - - @Override - public TableType getTableType(TableId tid) { - switch (tid.getValue()) { - case DELL_TABLE_IPV4_UNICAST: - return TableType.IP; - case DELL_TABLE_MPLS: - return TableType.MPLS; - case DELL_TABLE_ACL: - return TableType.ACL; - case DELL_TABLE_VLAN: - return TableType.VLAN; - case DELL_TABLE_TMAC: - return TableType.ETHER; - default: - log.error("Table type for Table id {} is not supported in the driver", tid); - return TableType.NONE; - } - } -}
\ No newline at end of file diff --git a/framework/src/onos/openflow/pom.xml b/framework/src/onos/openflow/pom.xml deleted file mode 100644 index 437f7437..00000000 --- a/framework/src/onos/openflow/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Copyright 2014 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>onos-of</artifactId> - <packaging>pom</packaging> - - <description>ONOS OpenFlow Protocol subsystem</description> - - <modules> - <module>api</module> - <module>ctl</module> - </modules> - - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onlab-misc</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onlab-junit</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - </plugin> - </plugins> - </build> - -</project> diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbBridgeName.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbBridgeName.java index 899799fa..759ec499 100644 --- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbBridgeName.java +++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbBridgeName.java @@ -49,7 +49,7 @@ public final class OvsdbBridgeName { @Override public int hashCode() { - return Objects.hash(value); + return value.hashCode(); } @Override 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..cfd844d3 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 @@ -16,6 +16,7 @@ package org.onosproject.ovsdb.controller; import com.google.common.util.concurrent.ListenableFuture; + import org.onlab.packet.IpAddress; import org.onosproject.net.DeviceId; import org.onosproject.net.behaviour.ControllerInfo; @@ -84,6 +85,15 @@ public interface OvsdbClientService extends OvsdbRPC { void createBridge(String bridgeName); /** + * Creates a bridge. + * + * @param bridgeName bridge name + * @param dpid data path id + * @param exPortName external port name + */ + void createBridge(String bridgeName, String dpid, String exPortName); + + /** * Creates a bridge with given name and dpid. * Sets the bridge's controller with given controllers. * @@ -204,7 +214,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 +222,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 +230,7 @@ public interface OvsdbClientService extends OvsdbRPC { ListenableFuture<DatabaseSchema> getOvsdbSchema(String dbName); /** - * Gets the ovsdb table updates. + * Gets the OVSDB table updates. * * @param dbName database name * @param id random uuid @@ -229,7 +239,7 @@ public interface OvsdbClientService extends OvsdbRPC { ListenableFuture<TableUpdates> 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 +249,7 @@ public interface OvsdbClientService extends OvsdbRPC { List<Operation> operations); /** - * Gets the ovsdb database schema from local. + * Gets the OVSDB database schema from local. * * @param dbName database name * @return database schema @@ -247,17 +257,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 +276,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<OvsdbPort> getLocalPorts(Iterable<String> 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/OvsdbDatapathId.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbDatapathId.java index 8ccf45f2..02989afa 100644 --- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbDatapathId.java +++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbDatapathId.java @@ -47,7 +47,7 @@ public final class OvsdbDatapathId { @Override public int hashCode() { - return Objects.hash(value); + return value.hashCode(); } @Override diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbEvent.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbEvent.java index 35fac7bc..f68b3c8a 100644 --- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbEvent.java +++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbEvent.java @@ -48,7 +48,7 @@ public final class OvsdbEvent<S> { } /** - * Returns the type of the event. + * Returns the type of event. * * @return event type */ @@ -57,7 +57,7 @@ public final class OvsdbEvent<S> { } /** - * Returns the subject of the event. + * Returns the subject of event. * * @return subject to which this event pertains */ diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbIfaceId.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbIfaceId.java index 10ba80bc..bf724fa4 100644 --- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbIfaceId.java +++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbIfaceId.java @@ -47,7 +47,7 @@ public class OvsdbIfaceId { @Override public int hashCode() { - return Objects.hash(value); + return value.hashCode(); } @Override 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 f3bba4b8..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,8 +22,8 @@ import java.util.Objects; import org.onlab.packet.IpAddress; /** - * The class representing a OpenStack Compute or Network nodeId. This class is - * immutable. + * The class representing a nodeId of node which using ovsdb connection. + * This class is immutable. */ public final class OvsdbNodeId { private static final String SCHEME = "ovsdb"; @@ -31,7 +31,7 @@ public final class OvsdbNodeId { private final String ipAddress; /** - * Creates a new node identifier from a IpAddress ipAddress, a long port. + * Creates a new node identifier from an IpAddress ipAddress, a long port. * * @param ipAddress node IP address * @param port node port @@ -44,7 +44,7 @@ public final class OvsdbNodeId { @Override public int hashCode() { - return Objects.hash(nodeId); + return nodeId.hashCode(); } @Override diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbPortName.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbPortName.java index d9c7c2da..7d40e99f 100644 --- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbPortName.java +++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbPortName.java @@ -49,7 +49,7 @@ public final class OvsdbPortName { @Override public int hashCode() { - return Objects.hash(value); + return value.hashCode(); } @Override diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbPortNumber.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbPortNumber.java index bd094d04..86fc887a 100644 --- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbPortNumber.java +++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbPortNumber.java @@ -47,7 +47,7 @@ public final class OvsdbPortNumber { @Override public int hashCode() { - return Objects.hash(value); + return Objects.hashCode(value); } @Override diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbPortType.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbPortType.java index bf05fc73..fb7cdb00 100644 --- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbPortType.java +++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbPortType.java @@ -21,14 +21,15 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.util.Objects; /** - * The class representing a port type. This class is immutable. + * The class representing a port type. + * This class is immutable. */ public class OvsdbPortType { private final String value; /** - * Constructor from a String port type. + * Constructor from a String. * * @param value the port type to use */ @@ -38,9 +39,9 @@ public class OvsdbPortType { } /** - * Gets the value of the port type. + * Gets the value of port type. * - * @return the value of the port type + * @return the value of port type */ public String value() { return value; @@ -48,7 +49,7 @@ public class OvsdbPortType { @Override public int hashCode() { - return Objects.hash(value); + return value.hashCode(); } @Override diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbTunnelName.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbTunnelName.java index 80befab3..490d640b 100644 --- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbTunnelName.java +++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/OvsdbTunnelName.java @@ -48,7 +48,7 @@ public final class OvsdbTunnelName { @Override public int hashCode() { - return Objects.hash(value); + return value.hashCode(); } @Override diff --git a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java index 3280ad34..c6038632 100644 --- a/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java +++ b/framework/src/onos/ovsdb/api/src/main/java/org/onosproject/ovsdb/controller/driver/DefaultOvsdbClient.java @@ -24,7 +24,9 @@ import com.google.common.collect.Sets; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; + import io.netty.channel.Channel; + import org.onlab.packet.IpAddress; import org.onosproject.net.DeviceId; import org.onosproject.net.behaviour.ControllerInfo; @@ -489,6 +491,76 @@ public class DefaultOvsdbClient } @Override + public void createBridge(String bridgeName, String dpid, String exPortName) { + log.debug("create bridge {}", bridgeName); + + DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); + if (dbSchema == null) { + log.warn("The schema is null"); + return; + } + + Bridge bridge = (Bridge) TableGenerator.createTable(dbSchema, + OvsdbTable.BRIDGE); + if (bridge == null) { + log.debug("Can not create bridge"); + return; + } + + Set<String> failModes = new HashSet<>(); + failModes.add("secure"); + bridge.setFailMode(failModes); + + Set<String> protocols = new HashSet<>(); + protocols.add(OvsdbConstant.OPENFLOW13); + bridge.setProtocols(protocols); + + String ovsUuid = getOvsUuid(OvsdbConstant.DATABASENAME); + if (ovsUuid == null) { + log.warn("The Open_vSwitch is null"); + return; + } + + String bridgeUuid = getBridgeUuid(bridgeName); + if (bridgeUuid == null) { + log.debug("Create a new bridge"); + + bridge.setName(bridgeName); + if (dpid != null) { + Map<String, String> options = new HashMap<>(); + options.put("datapath-id", dpid); + bridge.setOtherConfig(options); + } + bridgeUuid = insertConfig(OvsdbConstant.BRIDGE, "_uuid", + OvsdbConstant.DATABASENAME, "bridges", + ovsUuid, bridge.getRow()); + + if (bridgeUuid != null) { + Port port = (Port) TableGenerator.createTable(dbSchema, + OvsdbTable.PORT); + if (port != null) { + log.debug("the port is not null"); + port.setName(bridgeName); + + insertConfig(OvsdbConstant.PORT, "_uuid", "Bridge", "ports", bridgeUuid, + port.getRow()); + } + } + + } else { + log.info("Update a bridge"); + updateConfig(OvsdbConstant.BRIDGE, "_uuid", bridgeUuid, bridge.getRow()); + } + // Create external port + if (exPortName != null) { + createPort(bridgeName, exPortName); + } + + setControllerAuto(bridgeUuid); + log.info("Create bridge success"); + } + + @Override public boolean createBridge(String bridgeName, String dpid, List<ControllerInfo> controllers) { DatabaseSchema dbSchema = schema.get(OvsdbConstant.DATABASENAME); diff --git a/framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java b/framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java index 2c418d57..5d80a7bf 100644 --- a/framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java +++ b/framework/src/onos/ovsdb/api/src/test/java/org/onosproject/ovsdb/controller/driver/OvsdbClientServiceAdapter.java @@ -18,6 +18,7 @@ package org.onosproject.ovsdb.controller.driver; import com.fasterxml.jackson.databind.JsonNode; import com.google.common.util.concurrent.ListenableFuture; + import org.onlab.packet.IpAddress; import org.onosproject.net.DeviceId; import org.onosproject.net.behaviour.ControllerInfo; @@ -216,4 +217,9 @@ public class OvsdbClientServiceAdapter implements OvsdbClientService { public ListenableFuture<List<JsonNode>> transact(DatabaseSchema dbSchema, List<Operation> operations) { return null; } + + @Override + public void createBridge(String bridgeName, String dpid, String exPortName) { + + } } diff --git a/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/Controller.java b/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/Controller.java index 2e84a16a..fcbbff8e 100644 --- a/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/Controller.java +++ b/framework/src/onos/ovsdb/ctl/src/main/java/org/onosproject/ovsdb/controller/impl/Controller.java @@ -58,7 +58,7 @@ import org.slf4j.LoggerFactory; /** * The main controller class. Handles all setup and network listeners - - * Distributed ovsdbClient. + * distributed OVSDBClient. */ public class Controller { protected static final Logger log = LoggerFactory @@ -105,7 +105,7 @@ public class Controller { } /** - * Tells controller that we're ready to accept ovsdb node loop. + * Tells controller that we're ready to accept OVSDB node loop. * @throws InterruptedException if thread is interrupted */ public void run() throws InterruptedException { @@ -114,7 +114,7 @@ public class Controller { } /** - * Adds channel pipiline to handle a new connected node. + * Adds channel pipeline to handle a new connected node. */ private class OnosCommunicationChannelInitializer extends ChannelInitializer<SocketChannel> { @@ -128,7 +128,7 @@ public class Controller { } /** - * Handles the new connection of a node. + * Handles the new connection of node. * * @param channel the channel to use. */ @@ -169,9 +169,9 @@ public class Controller { } /** - * Gets an ovsdb client instance. + * Gets an OVSDB client instance. * - * @param nodeId data ovsdb node id + * @param nodeId data OVSDB node id * @param agent OvsdbAgent * @param monitorCallback Callback * @param channel Channel diff --git a/framework/src/onos/ovsdb/rfc/pom.xml b/framework/src/onos/ovsdb/rfc/pom.xml index 2868845a..d4d37587 100644 --- a/framework/src/onos/ovsdb/rfc/pom.xml +++ b/framework/src/onos/ovsdb/rfc/pom.xml @@ -15,35 +15,35 @@ ~ limitations under the License. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-ovsdb</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - <artifactId>onos-ovsdb-rfc</artifactId> - <packaging>bundle</packaging> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onosproject</groupId> + <artifactId>onos-ovsdb</artifactId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + <artifactId>onos-ovsdb-rfc</artifactId> + <packaging>bundle</packaging> - <dependencies> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - </dependency> - </dependencies> + <dependencies> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr.annotations</artifactId> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + </dependency> + </dependencies> - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - </plugin> - </plugins> - </build> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + </plugin> + </plugins> + </build> </project> diff --git a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/message/TableUpdate.java b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/message/TableUpdate.java index 812a034c..0673b79e 100644 --- a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/message/TableUpdate.java +++ b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/message/TableUpdate.java @@ -85,7 +85,7 @@ public final class TableUpdate { @Override public int hashCode() { - return Objects.hash(rows); + return rows.hashCode(); } @Override diff --git a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/message/TableUpdates.java b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/message/TableUpdates.java index 8938beea..e161016b 100644 --- a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/message/TableUpdates.java +++ b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/message/TableUpdates.java @@ -67,7 +67,7 @@ public final class TableUpdates { @Override public int hashCode() { - return Objects.hash(result); + return result.hashCode(); } @Override diff --git a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/OvsdbMap.java b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/OvsdbMap.java index fce3f69f..a62ab0db 100644 --- a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/OvsdbMap.java +++ b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/OvsdbMap.java @@ -61,7 +61,7 @@ public final class OvsdbMap { @Override public int hashCode() { - return Objects.hash(map); + return map.hashCode(); } @Override diff --git a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/OvsdbSet.java b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/OvsdbSet.java index fa5abe83..21f0b72b 100644 --- a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/OvsdbSet.java +++ b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/OvsdbSet.java @@ -63,7 +63,7 @@ public final class OvsdbSet { @Override public int hashCode() { - return Objects.hash(set); + return set.hashCode(); } @Override diff --git a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/UUID.java b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/UUID.java index 463b75de..0177eea3 100644 --- a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/UUID.java +++ b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/notation/UUID.java @@ -62,7 +62,7 @@ public final class UUID { @Override public int hashCode() { - return Objects.hash(value); + return value.hashCode(); } @Override diff --git a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/tableservice/AbstractOvsdbTableService.java b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/tableservice/AbstractOvsdbTableService.java index 6b7c7971..af1a01d6 100644 --- a/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/tableservice/AbstractOvsdbTableService.java +++ b/framework/src/onos/ovsdb/rfc/src/main/java/org/onosproject/ovsdb/rfc/tableservice/AbstractOvsdbTableService.java @@ -210,7 +210,7 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { return null; } ColumnDescription columnDesc = new ColumnDescription("_uuid", "getTableUuidColumn"); - return (Column) getColumnHandler(columnDesc); + return getColumnHandler(columnDesc); } @Override @@ -228,7 +228,7 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { return null; } ColumnDescription columnDesc = new ColumnDescription("_version", "getTableVersionColumn"); - return (Column) getColumnHandler(columnDesc); + return getColumnHandler(columnDesc); } /** @@ -260,7 +260,7 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { @Override public int hashCode() { - return Objects.hash(row); + return row.hashCode(); } @Override @@ -277,7 +277,7 @@ public abstract class AbstractOvsdbTableService implements OvsdbTableService { @Override public String toString() { - TableSchema schema = (TableSchema) getTableSchema(); + TableSchema schema = getTableSchema(); String tableName = schema.name(); return toStringHelper(this).add("tableName", tableName).add("row", row).toString(); } diff --git a/framework/src/onos/pcep/api/pom.xml b/framework/src/onos/pcep/api/pom.xml deleted file mode 100644 index 4588ad6f..00000000 --- a/framework/src/onos/pcep/api/pom.xml +++ /dev/null @@ -1,99 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Copyright 2014 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-controller</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>onos-pcep-controller-api</artifactId> - <packaging>bundle</packaging> - - <description>ONOS Pcep client controller subsystem API</description> - - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-pcep-api</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcepio</artifactId> - </dependency> - <dependency> - <groupId>io.netty</groupId> - <artifactId>netty</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-api</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onlab-misc</artifactId> - </dependency> - - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>2.3</version> - <configuration> - <artifactSet> - <excludes> - <exclude>io.netty:netty</exclude> - <exclude>com.google.guava:guava</exclude> - <exclude>org.slf4j:slfj-api</exclude> - <exclude>ch.qos.logback:logback-core</exclude> - <exclude>ch.qos.logback:logback-classic</exclude> - <exclude>com.google.code.findbugs:annotations</exclude> - </excludes> - </artifactSet> - </configuration> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>shade</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <configuration> - <instructions> - <Export-Package> - org.onosproject.pcep.*,org.onosproject.pcepio.* - </Export-Package> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - -</project> diff --git a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PccId.java b/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PccId.java deleted file mode 100755 index 3ff622bf..00000000 --- a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PccId.java +++ /dev/null @@ -1,120 +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.pcep.controller; - -import static com.google.common.base.Preconditions.checkArgument; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Objects; - -import org.onlab.packet.IpAddress; - -/** - * The class representing a network client pc ip. - * This class is immutable. - */ -public final class PccId { - - private static final String SCHEME = "pcep"; - private static final long UNKNOWN = 0; - private final IpAddress ipAddress; - - /** - * Private constructor. - */ - private PccId(IpAddress ipAddress) { - this.ipAddress = ipAddress; - } - - /** - * Create a PccId from ip address. - * - * @param ipAddress IP address - * @return ipAddress - */ - public static PccId pccId(IpAddress ipAddress) { - return new PccId(ipAddress); - } - - /** - * Returns the ip address. - * - * @return ipAddress - */ - public IpAddress ipAddress() { - return ipAddress; - } - - /** - * Convert the PccId value to a ':' separated hexadecimal string. - * - * @return the PccId value as a ':' separated hexadecimal string. - */ - @Override - public String toString() { - return ipAddress.toString(); - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof PccId)) { - return false; - } - - PccId otherPccid = (PccId) other; - return Objects.equals(ipAddress, otherPccid.ipAddress); - } - - @Override - public int hashCode() { - return Objects.hash(ipAddress); - } - - /** - * Returns PccId created from the given client URI. - * - * @param uri device URI - * @return pccid - */ - public static PccId pccid(URI uri) { - checkArgument(uri.getScheme().equals(SCHEME), "Unsupported URI scheme"); - return new PccId(IpAddress.valueOf(uri.getSchemeSpecificPart())); - } - - /** - * Produces client URI from the given DPID. - * - * @param pccid client pccid - * @return client URI - */ - public static URI uri(PccId pccid) { - return uri(pccid.ipAddress()); - } - - /** - * Produces client URI from the given ip address. - * - * @param ipAddress ip of client - * @return client URI - */ - public static URI uri(IpAddress ipAddress) { - try { - return new URI(SCHEME, ipAddress.toString(), null); - } catch (URISyntaxException e) { - return null; - } - } -} diff --git a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClient.java b/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClient.java deleted file mode 100755 index 95e7789f..00000000 --- a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClient.java +++ /dev/null @@ -1,110 +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.pcep.controller; - -import java.util.List; - -import org.onosproject.pcepio.protocol.PcepFactory; -import org.onosproject.pcepio.protocol.PcepMessage; - -/** - * Represents to provider facing side of a path computation client(pcc). - */ -public interface PcepClient { - - /** - * Writes the message to the driver. - * - * @param msg the message to write - */ - void sendMessage(PcepMessage msg); - - /** - * Writes the PcepMessage list to the driver. - * - * @param msgs the messages to be written - */ - void sendMessage(List<PcepMessage> msgs); - - /** - * Handle a message from the pcc. - * - * @param fromClient the message to handle - */ - void handleMessage(PcepMessage fromClient); - - /** - * Provides the factory for this PCEP version. - * - * @return PCEP version specific factory. - */ - PcepFactory factory(); - - /** - * Gets a string version of the ID for this pcc. - * - * @return string version of the ID - */ - String getStringId(); - - /** - * Gets the ipAddress of the client. - * - * @return the client pccId in IPAddress format - */ - PccId getPccId(); - - /** - * Checks if the pcc is still connected. - * - * @return true if client is connected, false otherwise - */ - boolean isConnected(); - - /** - * Disconnects the pcc by closing the TCP connection. Results in a call - * to the channel handler's channelDisconnected method for cleanup. - */ - void disconnectClient(); - - /** - * Indicates if this pcc is optical. - * - * @return true if optical - */ - boolean isOptical(); - - /** - * Identifies the channel used to communicate with the pcc. - * - * @return string representation of the connection to the client - */ - String channelId(); - - /** - * To set the status of state synchronization. - * - * @param value to set the synchronization status - */ - void setIsSyncComplete(boolean value); - - /** - * Indicates the state synchronization status of this pcc. - * - * @return true/false if the synchronization is completed/not completed - */ - boolean isSyncComplete(); -} diff --git a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClientController.java b/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClientController.java deleted file mode 100644 index 37453eac..00000000 --- a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClientController.java +++ /dev/null @@ -1,93 +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.pcep.controller; - -import java.util.Collection; - -import org.onosproject.pcepio.protocol.PcepMessage; - -/** - * Abstraction of an Pcep client controller. Serves as a one stop - * shop for obtaining Pcep devices and (un)register listeners - * on pcep events - */ -public interface PcepClientController { - - /** - * Returns list of pcc clients connected to this Pcep controller. - * - * @return list of PcepClient elements - */ - Collection<PcepClient> getClients(); - - /** - * Returns the actual pcc client for the given ip address. - * - * @param pccId the id of the pcc client to fetch - * @return the interface to this pcc client - */ - PcepClient getClient(PccId pccId); - - /** - * Register a listener for meta events that occur to pcep - * devices. - * - * @param listener the listener to notify - */ - void addListener(PcepClientListener listener); - - /** - * Unregister a listener. - * - * @param listener the listener to unregister - */ - void removeListener(PcepClientListener listener); - - /** - * Register a listener for OF msg events. - * - * @param listener the listener to notify - */ - void addEventListener(PcepEventListener listener); - - /** - * Unregister a listener. - * - * @param listener the listener to unregister - */ - void removeEventListener(PcepEventListener listener); - - /** - * Send a message to a particular pcc client. - * - * @param pccId the id of the client to send message. - * @param msg the message to send - */ - void writeMessage(PccId pccId, PcepMessage msg); - - /** - * Process a message and notify the appropriate listeners. - * - * @param pccId id of the client the message arrived on - * @param msg the message to process. - */ - void processClientMessage(PccId pccId, PcepMessage msg); - - /** - * Close all connected PCC clients. - */ - void closeConnectedClients(); -} diff --git a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClientListener.java b/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClientListener.java deleted file mode 100755 index e7e0a736..00000000 --- a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepClientListener.java +++ /dev/null @@ -1,36 +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.pcep.controller; - -/** - * Allows for providers interested in PCC client events to be notified. - */ -public interface PcepClientListener { - - /** - * Notify that the PCC was connected. - * - * @param pccId the id of the client that connected - */ - void clientConnected(PccId pccId); - - /** - * Notify that the PCC was disconnected. - * - * @param pccId the id of the client that disconnected. - */ - void clientDisconnected(PccId pccId); -} diff --git a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepEventListener.java b/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepEventListener.java deleted file mode 100644 index f7de215a..00000000 --- a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/PcepEventListener.java +++ /dev/null @@ -1,31 +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.pcep.controller; - -import org.onosproject.pcepio.protocol.PcepMessage; -/** - * Notifies providers about PCEP message events. - */ -public interface PcepEventListener { - - /** - * Handles the message event. - * - * @param pccId id of the pcc - * @param msg the message - */ - void handleMessage(PccId pccId, PcepMessage msg); -} diff --git a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/PcepAgent.java b/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/PcepAgent.java deleted file mode 100755 index 4810417c..00000000 --- a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/PcepAgent.java +++ /dev/null @@ -1,63 +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.pcep.controller.driver; - -import org.onosproject.pcep.controller.PccId; -import org.onosproject.pcep.controller.PcepClient; -import org.onosproject.pcepio.protocol.PcepMessage; - -/** - * Responsible for keeping track of the current set Pcep clients - * connected to the system. - * - */ -public interface PcepAgent { - - /** - * Add a pcc client that has just connected to the system. - * - * @param pccId the id of pcc client to add - * @param pc the actual pce client object. - * @return true if added, false otherwise. - */ - boolean addConnectedClient(PccId pccId, PcepClient pc); - - /** - * Checks if the activation for this pcc client is valid. - * - * @param pccId the id of pcc client to check - * @return true if valid, false otherwise - */ - boolean validActivation(PccId pccId); - - /** - * Clear all state in controller client maps for a pcc client that has - * disconnected from the local controller. Also release control for - * that pccIds client from the global repository. Notify client listeners. - * - * @param pccIds the id of pcc client to remove. - */ - void removeConnectedClient(PccId pccIds); - - /** - * Process a message coming from a pcc client. - * - * @param pccId the id of pcc client the message was received. - * @param m the message to process - */ - void processPcepMessage(PccId pccId, PcepMessage m); - -} diff --git a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/PcepClientDriver.java b/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/PcepClientDriver.java deleted file mode 100755 index f728de54..00000000 --- a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/PcepClientDriver.java +++ /dev/null @@ -1,110 +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.pcep.controller.driver; - -import org.jboss.netty.channel.Channel; -import org.onosproject.pcep.controller.PccId; -import org.onosproject.pcep.controller.PcepClient; -import org.onosproject.pcep.controller.PcepPacketStats; -import org.onosproject.pcepio.protocol.PcepVersion; - - -/** - * Represents the driver side of an Path computation client(pcc). - * - */ -public interface PcepClientDriver extends PcepClient { - - /** - * Sets the Pcep agent to be used. This method - * can only be called once. - * - * @param agent the agent to set. - */ - void setAgent(PcepAgent agent); - - /** - * Announce to the Pcep agent that this pcc client has connected. - * - * @return true if successful, false if duplicate switch. - */ - boolean connectClient(); - - /** - * Remove this pcc client from the Pcep agent. - */ - void removeConnectedClient(); - - /** - * Sets the PCEP version for this pcc. - * - * @param pcepVersion the version to set. - */ - void setPcVersion(PcepVersion pcepVersion); - - /** - * Sets the associated Netty channel for this pcc. - * - * @param channel the Netty channel - */ - void setChannel(Channel channel); - - - /** - * Sets the keep alive time for this pcc. - * - * @param keepAliveTime the keep alive time to set. - */ - void setPcKeepAliveTime(byte keepAliveTime); - - /** - * Sets the dead time for this pcc. - * - * @param deadTime the dead timer value to set. - */ - void setPcDeadTime(byte deadTime); - - /** - * Sets the session id for this pcc. - * - * @param sessionId the session id value to set. - */ - void setPcSessionId(byte sessionId); - - /** - * Sets whether the pcc is connected. - * - * @param connected whether the pcc is connected - */ - void setConnected(boolean connected); - - /** - * Initializes the behavior. - * - * @param pccId id of pcc - * @param pcepVersion Pcep version - * @param pktStats Pcep Packet Stats - */ - void init(PccId pccId, PcepVersion pcepVersion, PcepPacketStats pktStats); - - /** - * Checks whether the handshake is complete. - * - * @return true is finished, false if not. - */ - boolean isHandshakeComplete(); - -} diff --git a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/PcepClientDriverFactory.java b/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/PcepClientDriverFactory.java deleted file mode 100755 index 6ce75bca..00000000 --- a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/PcepClientDriverFactory.java +++ /dev/null @@ -1,38 +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.pcep.controller.driver; - -import org.onlab.packet.IpAddress; -import org.onosproject.pcepio.protocol.PcepVersion; - -/** - * Pcc Client factory which returns concrete pcc client objects for the - * physical pcc client in use. - * - */ -public interface PcepClientDriverFactory { - - - /** - * Constructs the real Pcep Client representation. - * - * @param pccIpAddress the ip address for this pcc client. - * @param pcepVersion the Pcep version in use - * @return the Pcep client representation. - */ - PcepClientDriver getPcepClientImpl(IpAddress pccIpAddress, - PcepVersion pcepVersion); -} diff --git a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/package-info.java b/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/package-info.java deleted file mode 100644 index 9d105ff2..00000000 --- a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/driver/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. - */ - -/** - * PCEP client controller driver API. - */ -package org.onosproject.pcep.controller.driver; diff --git a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/package-info.java b/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/package-info.java deleted file mode 100644 index a0cb2482..00000000 --- a/framework/src/onos/pcep/api/src/main/java/org/onosproject/pcep/controller/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. - */ - -/** - * PCEP client controller API. - */ -package org.onosproject.pcep.controller; diff --git a/framework/src/onos/pcep/ctl/pom.xml b/framework/src/onos/pcep/ctl/pom.xml deleted file mode 100644 index f0ed5c2f..00000000 --- a/framework/src/onos/pcep/ctl/pom.xml +++ /dev/null @@ -1,65 +0,0 @@ -<!-- - ~ Copyright 2014 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-controller</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>onos-pcep-controller-impl</artifactId> - <packaging>bundle</packaging> - - <description>ONOS PCEP client controller subsystem API implementation</description> - - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-controller-api</artifactId> - </dependency> - <dependency> - <groupId>io.netty</groupId> - <artifactId>netty</artifactId> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onlab-misc</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - </plugin> - </plugins> - </build> - -</project> diff --git a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/Controller.java b/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/Controller.java deleted file mode 100644 index 9c27810c..00000000 --- a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/Controller.java +++ /dev/null @@ -1,188 +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.pcep.controller.impl; - -import static org.onlab.util.Tools.groupedThreads; - -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; -import java.net.InetSocketAddress; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Executors; - -import org.jboss.netty.bootstrap.ServerBootstrap; -import org.jboss.netty.channel.ChannelPipelineFactory; -import org.jboss.netty.channel.group.ChannelGroup; -import org.jboss.netty.channel.group.DefaultChannelGroup; -import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory; -import org.onosproject.pcep.controller.PccId; -import org.onosproject.pcep.controller.PcepPacketStats; -import org.onosproject.pcep.controller.driver.PcepAgent; -import org.onosproject.pcep.controller.driver.PcepClientDriver; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepFactory; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * The main controller class. Handles all setup and network listeners - - * Distributed ownership control of pcc through IControllerRegistryService - */ -public class Controller { - - private static final Logger log = LoggerFactory.getLogger(Controller.class); - - private static final PcepFactory FACTORY1 = PcepFactories.getFactory(PcepVersion.PCEP_1); - - private ChannelGroup cg; - - // Configuration options - private int pcepPort = 4189; - private int workerThreads = 10; - - // Start time of the controller - private long systemStartTime; - - private PcepAgent agent; - - private NioServerSocketChannelFactory execFactory; - - // Perf. related configuration - private static final int SEND_BUFFER_SIZE = 4 * 1024 * 1024; - - /** - * Returns factory version for processing pcep messages. - * - * @return instance of factory version - */ - public PcepFactory getPcepMessageFactory1() { - return FACTORY1; - } - - /** - * To get system start time. - * - * @return system start time in milliseconds - */ - public long getSystemStartTime() { - return (this.systemStartTime); - } - - /** - * Tell controller that we're ready to accept pcc connections. - */ - public void run() { - try { - final ServerBootstrap bootstrap = createServerBootStrap(); - - bootstrap.setOption("reuseAddr", true); - bootstrap.setOption("child.keepAlive", true); - bootstrap.setOption("child.tcpNoDelay", true); - bootstrap.setOption("child.sendBufferSize", Controller.SEND_BUFFER_SIZE); - - ChannelPipelineFactory pfact = new PcepPipelineFactory(this); - - bootstrap.setPipelineFactory(pfact); - InetSocketAddress sa = new InetSocketAddress(pcepPort); - cg = new DefaultChannelGroup(); - cg.add(bootstrap.bind(sa)); - log.info("Listening for PCC connection on {}", sa); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - /** - * Creates server boot strap. - * - * @return ServerBootStrap - */ - private ServerBootstrap createServerBootStrap() { - if (workerThreads == 0) { - execFactory = new NioServerSocketChannelFactory( - Executors.newCachedThreadPool(groupedThreads("onos/pcep", "boss-%d")), - Executors.newCachedThreadPool(groupedThreads("onos/pcep", "worker-%d"))); - return new ServerBootstrap(execFactory); - } else { - execFactory = new NioServerSocketChannelFactory( - Executors.newCachedThreadPool(groupedThreads("onos/pcep", "boss-%d")), - Executors.newCachedThreadPool(groupedThreads("onos/pcep", "worker-%d")), workerThreads); - return new ServerBootstrap(execFactory); - } - } - - /** - * Initialize internal data structures. - */ - public void init() { - // These data structures are initialized here because other - // module's startUp() might be called before ours - this.systemStartTime = System.currentTimeMillis(); - } - - public Map<String, Long> getMemory() { - Map<String, Long> m = new HashMap<>(); - Runtime runtime = Runtime.getRuntime(); - m.put("total", runtime.totalMemory()); - m.put("free", runtime.freeMemory()); - return m; - } - - public Long getUptime() { - RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean(); - return rb.getUptime(); - } - - /** - * Creates instance of Pcep client. - * - * @param pccId pcc identifier - * @param sessionID session id - * @param pv pcep version - * @param pktStats pcep packet statistics - * @return instance of PcepClient - */ - protected PcepClientDriver getPcepClientInstance(PccId pccId, int sessionID, PcepVersion pv, - PcepPacketStats pktStats) { - PcepClientDriver pcepClientDriver = new PcepClientImpl(); - pcepClientDriver.init(pccId, pv, pktStats); - pcepClientDriver.setAgent(agent); - return pcepClientDriver; - } - - /** - * Starts the pcep controller. - * - * @param ag Pcep agent - */ - public void start(PcepAgent ag) { - log.info("Started"); - this.agent = ag; - this.init(); - this.run(); - } - - /** - * Stops the pcep controller. - */ - public void stop() { - log.info("Stopped"); - execFactory.shutdown(); - cg.close(); - } -} diff --git a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepChannelHandler.java b/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepChannelHandler.java deleted file mode 100644 index bc8721d7..00000000 --- a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepChannelHandler.java +++ /dev/null @@ -1,652 +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.pcep.controller.impl; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.nio.channels.ClosedChannelException; -import java.util.Collections; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; -import java.util.concurrent.RejectedExecutionException; - -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.ChannelStateEvent; -import org.jboss.netty.channel.ExceptionEvent; -import org.jboss.netty.channel.MessageEvent; -import org.jboss.netty.handler.timeout.IdleState; -import org.jboss.netty.handler.timeout.IdleStateAwareChannelHandler; -import org.jboss.netty.handler.timeout.IdleStateEvent; -import org.jboss.netty.handler.timeout.IdleStateHandler; -import org.jboss.netty.handler.timeout.ReadTimeoutException; -import org.onlab.packet.IpAddress; -import org.onosproject.pcep.controller.PccId; -import org.onosproject.pcep.controller.driver.PcepClientDriver; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepError; -import org.onosproject.pcepio.protocol.PcepErrorInfo; -import org.onosproject.pcepio.protocol.PcepErrorMsg; -import org.onosproject.pcepio.protocol.PcepErrorObject; -import org.onosproject.pcepio.protocol.PcepFactory; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepOpenMsg; -import org.onosproject.pcepio.protocol.PcepOpenObject; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.ErrorObjListWithOpen; -import org.onosproject.pcepio.types.PceccCapabilityTlv; -import org.onosproject.pcepio.types.StatefulPceCapabilityTlv; -import org.onosproject.pcepio.types.PcepErrorDetailInfo; -import org.onosproject.pcepio.types.PcepValueType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Channel handler deals with the pcc client connection and dispatches - * messages from client to the appropriate locations. - */ -class PcepChannelHandler extends IdleStateAwareChannelHandler { - static final byte DEADTIMER_MAXIMUM_VALUE = (byte) 0xFF; - static final byte KEEPALIVE_MULTIPLE_FOR_DEADTIMER = 4; - private static final Logger log = LoggerFactory.getLogger(PcepChannelHandler.class); - private final Controller controller; - private PcepClientDriver pc; - private PccId thispccId; - private Channel channel; - private byte sessionId = 0; - private byte keepAliveTime; - private byte deadTime; - private PcepPacketStatsImpl pcepPacketStats; - static final int MAX_WRONG_COUNT_PACKET = 5; - static final int BYTE_MASK = 0xFF; - - // State needs to be volatile because the HandshakeTimeoutHandler - // needs to check if the handshake is complete - private volatile ChannelState state; - - // When a pcc client with a ip addresss is found (i.e we already have a - // connected client with the same ip), the new client is immediately - // disconnected. At that point netty callsback channelDisconnected() which - // proceeds to cleaup client state - we need to ensure that it does not cleanup - // client state for the older (still connected) client - private volatile Boolean duplicatePccIdFound; - - //Indicates the pcep version used by this pcc client - protected PcepVersion pcepVersion; - protected PcepFactory factory1; - - /** - * Create a new unconnected PcepChannelHandler. - * @param controller parent controller - */ - PcepChannelHandler(Controller controller) { - this.controller = controller; - this.state = ChannelState.INIT; - factory1 = controller.getPcepMessageFactory1(); - duplicatePccIdFound = Boolean.FALSE; - pcepPacketStats = new PcepPacketStatsImpl(); - } - - /** - * To disconnect a PCC. - */ - public void disconnectClient() { - pc.disconnectClient(); - } - - //************************* - // Channel State Machine - //************************* - - /** - * The state machine for handling the client/channel state. All state - * transitions should happen from within the state machine (and not from other - * parts of the code) - */ - enum ChannelState { - /** - * Initial state before channel is connected. - */ - INIT(false) { - - }, - /** - * Once the session is established, wait for open message. - */ - OPENWAIT(false) { - @Override - void processPcepMessage(PcepChannelHandler h, PcepMessage m) throws IOException, PcepParseException { - - log.debug("Message received in OPEN WAIT State"); - - //check for open message - if (m.getType() != PcepType.OPEN) { - // When the message type is not open message increment the wrong packet statistics - h.processUnknownMsg(); - log.debug("message is not OPEN message"); - } else { - - h.pcepPacketStats.addInPacket(); - PcepOpenMsg pOpenmsg = (PcepOpenMsg) m; - // do Capability validation. - if (h.capabilityValidation(pOpenmsg)) { - log.debug("Sending handshake OPEN message"); - h.sessionId = pOpenmsg.getPcepOpenObject().getSessionId(); - h.pcepVersion = pOpenmsg.getPcepOpenObject().getVersion(); - - //setting keepalive and deadTimer - byte yKeepalive = pOpenmsg.getPcepOpenObject().getKeepAliveTime(); - byte yDeadTimer = pOpenmsg.getPcepOpenObject().getDeadTime(); - h.keepAliveTime = yKeepalive; - if (yKeepalive < yDeadTimer) { - h.deadTime = yDeadTimer; - } else { - if (DEADTIMER_MAXIMUM_VALUE > (yKeepalive * KEEPALIVE_MULTIPLE_FOR_DEADTIMER)) { - h.deadTime = (byte) (yKeepalive * KEEPALIVE_MULTIPLE_FOR_DEADTIMER); - } else { - h.deadTime = DEADTIMER_MAXIMUM_VALUE; - } - } - h.sendHandshakeOpenMessage(); - h.pcepPacketStats.addOutPacket(); - h.setState(KEEPWAIT); - } else { - log.debug("Capability validation failed. Sending PCEP-ERROR message to PCC."); - // Send PCEP-ERROR message. - PcepErrorMsg errMsg = h.getErrorMsg(PcepErrorDetailInfo.ERROR_TYPE_2, - PcepErrorDetailInfo.ERROR_VALUE_2); - h.channel.write(Collections.singletonList(errMsg)); - } - } - } - }, - /** - * Once the open messages are exchanged, wait for keep alive message. - */ - KEEPWAIT(false) { - @Override - void processPcepMessage(PcepChannelHandler h, PcepMessage m) throws IOException, PcepParseException { - log.debug("message received in KEEPWAIT state"); - //check for keep alive message - if (m.getType() != PcepType.KEEP_ALIVE) { - // When the message type is not keep alive message increment the wrong packet statistics - h.processUnknownMsg(); - log.debug("message is not KEEPALIVE message"); - } else { - // Set the client connected status - h.pcepPacketStats.addInPacket(); - final SocketAddress address = h.channel.getRemoteAddress(); - if (!(address instanceof InetSocketAddress)) { - throw new IOException("Invalid client connection. Pcc is indentifed based on IP"); - } - log.debug("sending keep alive message in KEEPWAIT state"); - - final InetSocketAddress inetAddress = (InetSocketAddress) address; - h.thispccId = PccId.pccId(IpAddress.valueOf(inetAddress.getAddress())); - h.pc = h.controller.getPcepClientInstance(h.thispccId, h.sessionId, h.pcepVersion, - h.pcepPacketStats); - // set the status of pcc as connected - h.pc.setConnected(true); - h.pc.setChannel(h.channel); - - // set any other specific parameters to the pcc - h.pc.setPcVersion(h.pcepVersion); - h.pc.setPcSessionId(h.sessionId); - h.pc.setPcKeepAliveTime(h.keepAliveTime); - h.pc.setPcDeadTime(h.deadTime); - int keepAliveTimer = h.keepAliveTime & BYTE_MASK; - int deadTimer = h.deadTime & BYTE_MASK; - if (0 == h.keepAliveTime) { - h.deadTime = 0; - } - // handle keep alive and dead time - if (keepAliveTimer != PcepPipelineFactory.DEFAULT_KEEP_ALIVE_TIME - || deadTimer != PcepPipelineFactory.DEFAULT_DEAD_TIME) { - - h.channel.getPipeline().replace("idle", "idle", - new IdleStateHandler(PcepPipelineFactory.TIMER, deadTimer, keepAliveTimer, 0)); - } - log.debug("Dead timer : " + deadTimer); - log.debug("Keep alive time : " + keepAliveTimer); - - //set the state handshake completion. - h.sendKeepAliveMessage(); - h.pcepPacketStats.addOutPacket(); - h.setHandshakeComplete(true); - - if (!h.pc.connectClient()) { - disconnectDuplicate(h); - } else { - h.setState(ESTABLISHED); - } - } - } - }, - /** - * Once the keep alive messages are exchanged, the state is established. - */ - ESTABLISHED(true) { - @Override - void processPcepMessage(PcepChannelHandler h, PcepMessage m) throws IOException, PcepParseException { - - //h.channel.getPipeline().remove("waittimeout"); - log.debug("Message received in established state " + m.getType()); - //dispatch the message - h.dispatchMessage(m); - } - }; - private boolean handshakeComplete; - - ChannelState(boolean handshakeComplete) { - this.handshakeComplete = handshakeComplete; - } - - void processPcepMessage(PcepChannelHandler h, PcepMessage m) throws IOException, PcepParseException { - // do nothing - } - - /** - * Is this a state in which the handshake has completed. - * - * @return true if the handshake is complete - */ - public boolean isHandshakeComplete() { - return this.handshakeComplete; - } - - protected void disconnectDuplicate(PcepChannelHandler h) { - log.error("Duplicated Pcc IP or incompleted cleanup - " + "disconnecting channel {}", - h.getClientInfoString()); - h.duplicatePccIdFound = Boolean.TRUE; - h.channel.disconnect(); - } - - /** - * Sets handshake complete status. - * - * @param handshakeComplete status of handshake - */ - public void setHandshakeComplete(boolean handshakeComplete) { - this.handshakeComplete = handshakeComplete; - } - - } - - @Override - public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { - channel = e.getChannel(); - log.info("PCC connected from {}", channel.getRemoteAddress()); - - // Wait for open message from pcc client - setState(ChannelState.OPENWAIT); - } - - @Override - public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { - log.info("Pcc disconnected callback for pc:{}. Cleaning up ...", getClientInfoString()); - if (thispccId != null) { - if (!duplicatePccIdFound) { - // if the disconnected client (on this ChannelHandler) - // was not one with a duplicate-dpid, it is safe to remove all - // state for it at the controller. Notice that if the disconnected - // client was a duplicate-ip, calling the method below would clear - // all state for the original client (with the same ip), - // which we obviously don't want. - log.debug("{}:removal called", getClientInfoString()); - if (pc != null) { - pc.removeConnectedClient(); - } - } else { - // A duplicate was disconnected on this ChannelHandler, - // this is the same client reconnecting, but the original state was - // not cleaned up - XXX check liveness of original ChannelHandler - log.debug("{}:duplicate found", getClientInfoString()); - duplicatePccIdFound = Boolean.FALSE; - } - } else { - log.warn("no pccip in channelHandler registered for " + "disconnected client {}", getClientInfoString()); - } - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { - PcepErrorMsg errMsg; - log.info("exceptionCaught: " + e.toString()); - - if (e.getCause() instanceof ReadTimeoutException) { - if (ChannelState.OPENWAIT == state) { - // When ReadTimeout timer is expired in OPENWAIT state, it is considered - // OpenWait timer. - errMsg = getErrorMsg(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_2); - log.debug("Sending PCEP-ERROR message to PCC."); - channel.write(Collections.singletonList(errMsg)); - channel.close(); - state = ChannelState.INIT; - return; - } else if (ChannelState.KEEPWAIT == state) { - // When ReadTimeout timer is expired in KEEPWAIT state, is is considered - // KeepWait timer. - errMsg = getErrorMsg(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_7); - log.debug("Sending PCEP-ERROR message to PCC."); - channel.write(Collections.singletonList(errMsg)); - channel.close(); - state = ChannelState.INIT; - return; - } - } else if (e.getCause() instanceof ClosedChannelException) { - log.debug("Channel for pc {} already closed", getClientInfoString()); - } else if (e.getCause() instanceof IOException) { - log.error("Disconnecting client {} due to IO Error: {}", getClientInfoString(), e.getCause().getMessage()); - if (log.isDebugEnabled()) { - // still print stack trace if debug is enabled - log.debug("StackTrace for previous Exception: ", e.getCause()); - } - channel.close(); - } else if (e.getCause() instanceof PcepParseException) { - PcepParseException errMsgParse = (PcepParseException) e.getCause(); - byte errorType = errMsgParse.getErrorType(); - byte errorValue = errMsgParse.getErrorValue(); - - if ((errorType == (byte) 0x0) && (errorValue == (byte) 0x0)) { - processUnknownMsg(); - } else { - errMsg = getErrorMsg(errorType, errorValue); - log.debug("Sending PCEP-ERROR message to PCC."); - channel.write(Collections.singletonList(errMsg)); - } - } else if (e.getCause() instanceof RejectedExecutionException) { - log.warn("Could not process message: queue full"); - } else { - log.error("Error while processing message from client " + getClientInfoString() + "state " + this.state); - channel.close(); - } - } - - @Override - public String toString() { - return getClientInfoString(); - } - - @Override - public void channelIdle(ChannelHandlerContext ctx, IdleStateEvent e) throws Exception { - if (!isHandshakeComplete()) { - return; - } - - if (e.getState() == IdleState.READER_IDLE) { - // When no message is received on channel for read timeout, then close - // the channel - log.info("Disconnecting client {} due to read timeout", getClientInfoString()); - ctx.getChannel().close(); - } else if (e.getState() == IdleState.WRITER_IDLE) { - // Send keep alive message - log.debug("Sending keep alive message due to IdleState timeout " + pc.toString()); - pc.sendMessage(Collections.singletonList(pc.factory().buildKeepaliveMsg().build())); - } - } - - @Override - public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception { - if (e.getMessage() instanceof List) { - @SuppressWarnings("unchecked") - List<PcepMessage> msglist = (List<PcepMessage>) e.getMessage(); - for (PcepMessage pm : msglist) { - // Do the actual packet processing - state.processPcepMessage(this, pm); - } - } else { - state.processPcepMessage(this, (PcepMessage) e.getMessage()); - } - } - - /** - * To set the handshake status. - * - * @param handshakeComplete value is handshake status - */ - public void setHandshakeComplete(boolean handshakeComplete) { - this.state.setHandshakeComplete(handshakeComplete); - } - - /** - * Is this a state in which the handshake has completed. - * - * @return true if the handshake is complete - */ - public boolean isHandshakeComplete() { - return this.state.isHandshakeComplete(); - } - - /** - * To handle the pcep message. - * - * @param m pcep message - */ - private void dispatchMessage(PcepMessage m) { - pc.handleMessage(m); - } - - /** - * Return a string describing this client based on the already available - * information (ip address and/or remote socket). - * - * @return display string - */ - private String getClientInfoString() { - if (pc != null) { - return pc.toString(); - } - String channelString; - if (channel == null || channel.getRemoteAddress() == null) { - channelString = "?"; - } else { - channelString = channel.getRemoteAddress().toString(); - } - String pccIpString; - // TODO : implement functionality to get pcc id string - pccIpString = "?"; - return String.format("[%s PCCIP[%s]]", channelString, pccIpString); - } - - /** - * Update the channels state. Only called from the state machine. - * - * @param state - */ - private void setState(ChannelState state) { - this.state = state; - } - - /** - * Send handshake open message. - * - * @throws IOException,PcepParseException - */ - private void sendHandshakeOpenMessage() throws IOException, PcepParseException { - PcepOpenObject pcepOpenobj = factory1.buildOpenObject() - .setSessionId(sessionId) - .setKeepAliveTime(keepAliveTime) - .setDeadTime(deadTime) - .build(); - PcepMessage msg = factory1.buildOpenMsg() - .setPcepOpenObj(pcepOpenobj) - .build(); - log.debug("Sending OPEN message to {}", channel.getRemoteAddress()); - channel.write(Collections.singletonList(msg)); - } - - /** - * Capability Validation. - * - * @param pOpenmsg pcep open message - * @return success or failure - */ - private boolean capabilityValidation(PcepOpenMsg pOpenmsg) { - LinkedList<PcepValueType> tlvList = pOpenmsg.getPcepOpenObject().getOptionalTlv(); - boolean bFoundPceccCapability = false; - boolean bFoundStatefulPceCapability = false; - boolean bFoundPcInstantiationCapability = false; - - ListIterator<PcepValueType> listIterator = tlvList.listIterator(); - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - switch (tlv.getType()) { - case PceccCapabilityTlv.TYPE: - bFoundPceccCapability = true; - break; - case StatefulPceCapabilityTlv.TYPE: - bFoundStatefulPceCapability = true; - StatefulPceCapabilityTlv stetefulPcCapTlv = (StatefulPceCapabilityTlv) tlv; - if (stetefulPcCapTlv.getIFlag()) { - bFoundPcInstantiationCapability = true; - } - break; - default: - continue; - } - } - - return (bFoundPceccCapability && bFoundStatefulPceCapability && bFoundPcInstantiationCapability); - } - - /** - * Send keep alive message. - * - * @throws IOException when channel is disconnected - * @throws PcepParseException while building keep alive message - */ - private void sendKeepAliveMessage() throws IOException, PcepParseException { - PcepMessage msg = factory1.buildKeepaliveMsg().build(); - log.debug("Sending KEEPALIVE message to {}", channel.getRemoteAddress()); - channel.write(Collections.singletonList(msg)); - } - - /** - * Send error message and close channel with pcc. - */ - private void sendErrMsgAndCloseChannel() { - // TODO send error message - channel.close(); - } - - /** - * Send error message when an invalid message is received. - * - * @throws PcepParseException while building error message - */ - private void sendErrMsgForInvalidMsg() throws PcepParseException { - byte errorType = 0x02; - byte errorValue = 0x00; - PcepErrorMsg errMsg = getErrorMsg(errorType, errorValue); - channel.write(Collections.singletonList(errMsg)); - } - - /** - * Builds pcep error message based on error value and error type. - * - * @param errorType pcep error type - * @param errorValue pcep error value - * @return pcep error message - * @throws PcepParseException while bulding error message - */ - public PcepErrorMsg getErrorMsg(byte errorType, byte errorValue) throws PcepParseException { - LinkedList<PcepErrorObject> llerrObj = new LinkedList<>(); - PcepErrorMsg errMsg; - - PcepErrorObject errObj = factory1.buildPcepErrorObject() - .setErrorValue(errorValue) - .setErrorType(errorType) - .build(); - - llerrObj.add(errObj); - - if (state == ChannelState.OPENWAIT) { - //If Error caught in Openmessage - PcepOpenObject openObj = null; - ErrorObjListWithOpen errorObjListWithOpen = null; - - if (0 != sessionId) { - openObj = factory1.buildOpenObject().setSessionId(sessionId).build(); - errorObjListWithOpen = new ErrorObjListWithOpen(llerrObj, openObj); - } else { - errorObjListWithOpen = new ErrorObjListWithOpen(llerrObj, null); - } - - errMsg = factory1.buildPcepErrorMsg() - .setErrorObjListWithOpen(errorObjListWithOpen) - .build(); - } else { - - //If Error caught in other than Openmessage - LinkedList<PcepError> llPcepErr = new LinkedList<>(); - - PcepError pcepErr = factory1.buildPcepError() - .setErrorObjList(llerrObj) - .build(); - - llPcepErr.add(pcepErr); - - PcepErrorInfo errInfo = factory1.buildPcepErrorInfo() - .setPcepErrorList(llPcepErr) - .build(); - - errMsg = factory1.buildPcepErrorMsg() - .setPcepErrorInfo(errInfo) - .build(); - } - return errMsg; - } - - /** - * Process unknown pcep message received. - * - * @throws PcepParseException while building pcep error message - */ - public void processUnknownMsg() throws PcepParseException { - Date now = null; - if (pcepPacketStats.wrongPacketCount() == 0) { - now = new Date(); - pcepPacketStats.setTime(now.getTime()); - pcepPacketStats.addWrongPacket(); - sendErrMsgForInvalidMsg(); - } - - if (pcepPacketStats.wrongPacketCount() > 1) { - Date lastest = new Date(); - pcepPacketStats.addWrongPacket(); - //converting to seconds - if (((lastest.getTime() - pcepPacketStats.getTime()) / 1000) > 60) { - now = lastest; - pcepPacketStats.setTime(now.getTime()); - pcepPacketStats.resetWrongPacket(); - pcepPacketStats.addWrongPacket(); - } else if (((int) (lastest.getTime() - now.getTime()) / 1000) < 60) { - if (MAX_WRONG_COUNT_PACKET <= pcepPacketStats.wrongPacketCount()) { - //reset once wrong packet count reaches MAX_WRONG_COUNT_PACKET - pcepPacketStats.resetWrongPacket(); - // max wrong packets received send error message and close the session - sendErrMsgAndCloseChannel(); - } - } - } - } -} diff --git a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientControllerImpl.java b/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientControllerImpl.java deleted file mode 100644 index 00c8c694..00000000 --- a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientControllerImpl.java +++ /dev/null @@ -1,222 +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.pcep.controller.impl; - -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -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.Service; -import org.onosproject.pcep.controller.PccId; -import org.onosproject.pcep.controller.PcepClient; -import org.onosproject.pcep.controller.PcepClientController; -import org.onosproject.pcep.controller.PcepClientListener; -import org.onosproject.pcep.controller.PcepEventListener; -import org.onosproject.pcep.controller.driver.PcepAgent; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.collect.Sets; - -/** - * Implementation of PCEP client controller. - */ -@Component(immediate = true) -@Service -public class PcepClientControllerImpl implements PcepClientController { - - private static final Logger log = LoggerFactory.getLogger(PcepClientControllerImpl.class); - - protected ConcurrentHashMap<PccId, PcepClient> connectedClients = - new ConcurrentHashMap<>(); - - protected PcepClientAgent agent = new PcepClientAgent(); - protected Set<PcepClientListener> pcepClientListener = new HashSet<>(); - - protected Set<PcepEventListener> pcepEventListener = Sets.newHashSet(); - - private final Controller ctrl = new Controller(); - - @Activate - public void activate() { - ctrl.start(agent); - log.info("Started"); - } - - @Deactivate - public void deactivate() { - // Close all connected clients - closeConnectedClients(); - ctrl.stop(); - log.info("Stopped"); - } - - @Override - public Collection<PcepClient> getClients() { - return connectedClients.values(); - } - - @Override - public PcepClient getClient(PccId pccId) { - return connectedClients.get(pccId); - } - - @Override - public void addListener(PcepClientListener listener) { - if (!pcepClientListener.contains(listener)) { - this.pcepClientListener.add(listener); - } - } - - @Override - public void removeListener(PcepClientListener listener) { - this.pcepClientListener.remove(listener); - } - - @Override - public void addEventListener(PcepEventListener listener) { - pcepEventListener.add(listener); - } - - @Override - public void removeEventListener(PcepEventListener listener) { - pcepEventListener.remove(listener); - } - - @Override - public void writeMessage(PccId pccId, PcepMessage msg) { - this.getClient(pccId).sendMessage(msg); - } - - @Override - public void processClientMessage(PccId pccId, PcepMessage msg) { - PcepClient pc = getClient(pccId); - - switch (msg.getType()) { - case NONE: - break; - case OPEN: - break; - case KEEP_ALIVE: - break; - case PATH_COMPUTATION_REQUEST: - break; - case PATH_COMPUTATION_REPLY: - break; - case NOTIFICATION: - break; - case ERROR: - break; - case CLOSE: - log.info("Sending Close Message to {" + pccId.toString() + "}"); - pc.sendMessage(Collections.singletonList(pc.factory().buildCloseMsg().build())); - //now disconnect client - pc.disconnectClient(); - break; - case REPORT: - for (PcepEventListener l : pcepEventListener) { - l.handleMessage(pccId, msg); - } - break; - case UPDATE: - for (PcepEventListener l : pcepEventListener) { - l.handleMessage(pccId, msg); - } - break; - case INITIATE: - for (PcepEventListener l : pcepEventListener) { - l.handleMessage(pccId, msg); - } - break; - case LABEL_UPDATE: - break; - case MAX: - break; - case END: - break; - default: - break; - } - } - - @Override - public void closeConnectedClients() { - PcepClient pc; - for (PccId id : connectedClients.keySet()) { - pc = getClient(id); - pc.disconnectClient(); - } - } - - /** - * Implementation of an Pcep Agent which is responsible for - * keeping track of connected clients and the state in which - * they are. - */ - public class PcepClientAgent implements PcepAgent { - - private final Logger log = LoggerFactory.getLogger(PcepClientAgent.class); - - @Override - public boolean addConnectedClient(PccId pccId, PcepClient pc) { - - if (connectedClients.get(pccId) != null) { - log.error("Trying to add connectedClient but found a previous " - + "value for pcc ip: {}", pccId.toString()); - return false; - } else { - log.debug("Added Client {}", pccId.toString()); - connectedClients.put(pccId, pc); - for (PcepClientListener l : pcepClientListener) { - l.clientConnected(pccId); - } - return true; - } - } - - @Override - public boolean validActivation(PccId pccId) { - if (connectedClients.get(pccId) == null) { - log.error("Trying to activate client but is not in " - + "connected client: pccIp {}. Aborting ..", pccId.toString()); - return false; - } - - return true; - } - - @Override - public void removeConnectedClient(PccId pccId) { - - connectedClients.remove(pccId); - for (PcepClientListener l : pcepClientListener) { - log.warn("removal for {}", pccId.toString()); - l.clientDisconnected(pccId); - } - } - - @Override - public void processPcepMessage(PccId pccId, PcepMessage m) { - processClientMessage(pccId, m); - } - } -} diff --git a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientImpl.java b/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientImpl.java deleted file mode 100644 index a10ff5c8..00000000 --- a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepClientImpl.java +++ /dev/null @@ -1,220 +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.pcep.controller.impl; - -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.RejectedExecutionException; - -import org.jboss.netty.channel.Channel; -import org.onlab.packet.IpAddress; -import org.onosproject.pcep.controller.PccId; -import org.onosproject.pcep.controller.PcepPacketStats; -import org.onosproject.pcep.controller.driver.PcepAgent; -import org.onosproject.pcep.controller.driver.PcepClientDriver; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepFactory; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * An abstract representation of an OpenFlow switch. Can be extended by others - * to serve as a base for their vendor specific representation of a switch. - */ -public class PcepClientImpl implements PcepClientDriver { - - protected final Logger log = LoggerFactory.getLogger(PcepClientImpl.class); - - private static final String SHUTDOWN_MSG = "Worker has already been shutdown"; - - private Channel channel; - protected String channelId; - - private boolean connected; - protected boolean startDriverHandshakeCalled = false; - protected boolean isHandShakeComplete = false; - protected boolean isSyncComplete = false; - private PccId pccId; - private PcepAgent agent; - - private PcepVersion pcepVersion; - private byte keepAliveTime; - private byte deadTime; - private byte sessionId; - private PcepPacketStatsImpl pktStats; - - @Override - public void init(PccId pccId, PcepVersion pcepVersion, PcepPacketStats pktStats) { - this.pccId = pccId; - this.pcepVersion = pcepVersion; - this.pktStats = (PcepPacketStatsImpl) pktStats; - } - - @Override - public final void disconnectClient() { - this.channel.close(); - } - - @Override - public final void sendMessage(PcepMessage m) { - log.debug("Sending message to {}", channel.getRemoteAddress()); - try { - channel.write(Collections.singletonList(m)); - this.pktStats.addOutPacket(); - } catch (RejectedExecutionException e) { - log.warn(e.getMessage()); - if (!e.getMessage().contains(SHUTDOWN_MSG)) { - throw e; - } - } - } - - @Override - public final void sendMessage(List<PcepMessage> msgs) { - try { - channel.write(msgs); - this.pktStats.addOutPacket(msgs.size()); - } catch (RejectedExecutionException e) { - log.warn(e.getMessage()); - if (!e.getMessage().contains(SHUTDOWN_MSG)) { - throw e; - } - } - } - - @Override - public final boolean isConnected() { - return this.connected; - } - - @Override - public final void setConnected(boolean connected) { - this.connected = connected; - }; - - @Override - public final void setChannel(Channel channel) { - this.channel = channel; - final SocketAddress address = channel.getRemoteAddress(); - if (address instanceof InetSocketAddress) { - final InetSocketAddress inetAddress = (InetSocketAddress) address; - final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress()); - if (ipAddress.isIp4()) { - channelId = ipAddress.toString() + ':' + inetAddress.getPort(); - } else { - channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort(); - } - } - }; - - @Override - public String channelId() { - return channelId; - } - - @Override - public final PccId getPccId() { - return this.pccId; - } - - @Override - public final String getStringId() { - return this.pccId.toString(); - } - - @Override - public final void setPcVersion(PcepVersion pcepVersion) { - this.pcepVersion = pcepVersion; - } - - @Override - public void setPcKeepAliveTime(byte keepAliveTime) { - this.keepAliveTime = keepAliveTime; - } - - @Override - public void setPcDeadTime(byte deadTime) { - this.deadTime = deadTime; - } - - @Override - public void setPcSessionId(byte sessionId) { - this.sessionId = sessionId; - } - - @Override - public void setIsSyncComplete(boolean value) { - this.isSyncComplete = value; - } - - @Override - public boolean isSyncComplete() { - return isSyncComplete; - } - - @Override - public final void handleMessage(PcepMessage m) { - this.pktStats.addInPacket(); - this.agent.processPcepMessage(pccId, m); - } - - @Override - public final boolean connectClient() { - return this.agent.addConnectedClient(pccId, this); - } - - @Override - public final void removeConnectedClient() { - this.agent.removeConnectedClient(pccId); - } - - @Override - public PcepFactory factory() { - return PcepFactories.getFactory(pcepVersion); - } - - @Override - public boolean isHandshakeComplete() { - return isHandShakeComplete; - } - - @Override - public final void setAgent(PcepAgent ag) { - if (this.agent == null) { - this.agent = ag; - } - } - - @Override - public boolean isOptical() { - return false; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("channel", channelId()) - .add("pccId", getPccId()) - .toString(); - } -} diff --git a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepMessageDecoder.java b/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepMessageDecoder.java deleted file mode 100644 index b1065891..00000000 --- a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepMessageDecoder.java +++ /dev/null @@ -1,68 +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.pcep.controller.impl; - -import java.util.LinkedList; -import java.util.List; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.FrameDecoder; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.util.HexDump; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Decode an pcep message from a Channel, for use in a netty pipeline. - */ -public class PcepMessageDecoder extends FrameDecoder { - - protected static final Logger log = LoggerFactory.getLogger(PcepMessageDecoder.class); - - @Override - protected Object decode(ChannelHandlerContext ctx, Channel channel, - ChannelBuffer buffer) throws Exception { - log.debug("Message received."); - if (!channel.isConnected()) { - log.info("Channel is not connected."); - // In testing, I see decode being called AFTER decode last. - // This check avoids that from reading corrupted frames - return null; - } - - HexDump.pcepHexDump(buffer); - - // Note that a single call to decode results in reading a single - // PcepMessage from the channel buffer, which is passed on to, and processed - // by, the controller (in PcepChannelHandler). - // This is different from earlier behavior (with the original pcepIO), - // where we parsed all the messages in the buffer, before passing on - // a list of the parsed messages to the controller. - // The performance *may or may not* not be as good as before. - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - List<PcepMessage> msgList = new LinkedList<>(); - - while (buffer.readableBytes() > 0) { - PcepMessage message = reader.readFrom(buffer); - msgList.add(message); - } - return msgList; - } -} diff --git a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepMessageEncoder.java b/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepMessageEncoder.java deleted file mode 100644 index ae97221e..00000000 --- a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepMessageEncoder.java +++ /dev/null @@ -1,58 +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.pcep.controller.impl; - -import java.util.List; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.oneone.OneToOneEncoder; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.util.HexDump; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Encode an pcep message for output into a ChannelBuffer, for use in a - * netty pipeline. - */ -public class PcepMessageEncoder extends OneToOneEncoder { - protected static final Logger log = LoggerFactory.getLogger(PcepMessageEncoder.class); - - @Override - protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { - log.debug("Sending message"); - if (!(msg instanceof List)) { - log.debug("Invalid msg."); - return msg; - } - - @SuppressWarnings("unchecked") - List<PcepMessage> msglist = (List<PcepMessage>) msg; - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - for (PcepMessage pm : msglist) { - pm.writeTo(buf); - } - - HexDump.pcepHexDump(buf); - - return buf; - } -} diff --git a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepPacketStatsImpl.java b/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepPacketStatsImpl.java deleted file mode 100644 index f2bc51eb..00000000 --- a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepPacketStatsImpl.java +++ /dev/null @@ -1,105 +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.pcep.controller.impl; - -import org.onosproject.pcep.controller.PcepPacketStats; - -/** - * The implementation for PCEP packet statistics. - */ -public class PcepPacketStatsImpl implements PcepPacketStats { - - private int inPacketCount; - private int outPacketCount; - private int wrongPacketCount; - private long time; - - /** - * Default constructor. - */ - public PcepPacketStatsImpl() { - this.inPacketCount = 0; - this.outPacketCount = 0; - this.wrongPacketCount = 0; - this.time = 0; - } - - @Override - public int outPacketCount() { - return outPacketCount; - } - - @Override - public int inPacketCount() { - return inPacketCount; - } - - @Override - public int wrongPacketCount() { - return wrongPacketCount; - } - - /** - * Increments the received packet counter. - */ - public void addInPacket() { - this.inPacketCount++; - } - - /** - * Increments the sent packet counter. - */ - public void addOutPacket() { - this.outPacketCount++; - } - - /** - * Increments the sent packet counter by specified value. - * - * @param value of no of packets sent - */ - public void addOutPacket(int value) { - this.outPacketCount = this.outPacketCount + value; - } - - /** - * Increments the wrong packet counter. - */ - public void addWrongPacket() { - this.wrongPacketCount++; - } - - /** - * Resets wrong packet count. - */ - public void resetWrongPacket() { - this.wrongPacketCount = 0; - } - - @Override - public long getTime() { - return this.time; - } - - /** - * Sets the time value. - * - * @param time long value of time - */ - public void setTime(long time) { - this.time = time; - } -} diff --git a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepPipelineFactory.java b/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepPipelineFactory.java deleted file mode 100644 index f32b87a8..00000000 --- a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/PcepPipelineFactory.java +++ /dev/null @@ -1,66 +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.pcep.controller.impl; - -import org.jboss.netty.channel.ChannelPipeline; -import org.jboss.netty.channel.ChannelPipelineFactory; -import org.jboss.netty.channel.Channels; -import org.jboss.netty.handler.timeout.IdleStateHandler; -import org.jboss.netty.handler.timeout.ReadTimeoutHandler; -import org.jboss.netty.util.ExternalResourceReleasable; -import org.jboss.netty.util.HashedWheelTimer; -import org.jboss.netty.util.Timer; - -/** - * Creates a ChannelPipeline for a server-side pcep channel. - */ -public class PcepPipelineFactory - implements ChannelPipelineFactory, ExternalResourceReleasable { - - protected Controller controller; - static final Timer TIMER = new HashedWheelTimer(); - protected IdleStateHandler idleHandler; - protected ReadTimeoutHandler readTimeoutHandler; - static final int DEFAULT_KEEP_ALIVE_TIME = 30; - static final int DEFAULT_DEAD_TIME = 120; - static final int DEFAULT_WAIT_TIME = 60; - - public PcepPipelineFactory(Controller controller) { - super(); - this.controller = controller; - this.idleHandler = new IdleStateHandler(TIMER, DEFAULT_DEAD_TIME, DEFAULT_KEEP_ALIVE_TIME, 0); - this.readTimeoutHandler = new ReadTimeoutHandler(TIMER, DEFAULT_WAIT_TIME); - } - - @Override - public ChannelPipeline getPipeline() throws Exception { - PcepChannelHandler handler = new PcepChannelHandler(controller); - - ChannelPipeline pipeline = Channels.pipeline(); - pipeline.addLast("pcepmessagedecoder", new PcepMessageDecoder()); - pipeline.addLast("pcepmessageencoder", new PcepMessageEncoder()); - pipeline.addLast("idle", idleHandler); - pipeline.addLast("waittimeout", readTimeoutHandler); - pipeline.addLast("handler", handler); - return pipeline; - } - - @Override - public void releaseExternalResources() { - TIMER.stop(); - } -} diff --git a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/package-info.java b/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/package-info.java deleted file mode 100644 index d86eefc3..00000000 --- a/framework/src/onos/pcep/ctl/src/main/java/org/onosproject/pcep/controller/impl/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. - */ - -/** - * Implementation of the PCEP client controller subsystem. - */ -package org.onosproject.pcep.controller.impl; diff --git a/framework/src/onos/pcep/pcepio/pom.xml b/framework/src/onos/pcep/pcepio/pom.xml deleted file mode 100755 index d121a83e..00000000 --- a/framework/src/onos/pcep/pcepio/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Copyright 2014 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-controller</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>onos-pcepio</artifactId> - <packaging>bundle</packaging> - - <description>ONOS Pcepio Protocol subsystem</description> - - - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-api</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onlab-osgi</artifactId> - </dependency> - - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-databind</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.core</groupId> - <artifactId>jackson-annotations</artifactId> - </dependency> - - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - </dependency> - <dependency> - <groupId>org.apache.karaf.shell</groupId> - <artifactId>org.apache.karaf.shell.console</artifactId> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - </plugin> - </plugins> - </build> - -</project> diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/exceptions/PcepParseException.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/exceptions/PcepParseException.java deleted file mode 100755 index 85bc33fb..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/exceptions/PcepParseException.java +++ /dev/null @@ -1,92 +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.pcepio.exceptions; - -/** - * Custom Exception for PCEP IO. - */ -public class PcepParseException extends Exception { - - private static final long serialVersionUID = 7960991379951448423L; - private byte errType = 0; - private byte errValue = 0; - - /** - * Default constructor to create a new exception. - */ - public PcepParseException() { - super(); - } - - /** - * Constructor to create exception from message and cause. - * - * @param message the detail of exception in string - * @param cause underlying cause of the error - */ - public PcepParseException(final String message, final Throwable cause) { - super(message, cause); - } - - /** - * Constructor to create exception from message. - * - * @param message the detail of exception in string - */ - public PcepParseException(final String message) { - super(message); - } - - /** - * Constructor to create exception from error type and error value. - * - * @param errType error type of pcep - * @param errValue error value of pcep - */ - public PcepParseException(final byte errType, final byte errValue) { - super(); - this.errType = errType; - this.errValue = errValue; - } - - /** - * Constructor to create exception from cause. - * - * @param cause underlying cause of the error - */ - public PcepParseException(final Throwable cause) { - super(cause); - } - - /** - * Returns error type for this exception. - * - * @return ErrorType - */ - public byte getErrorType() { - return this.errType; - } - - /** - * Returns error value for this exception. - * - * @return ErrorValue - */ - public byte getErrorValue() { - return this.errValue; - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/exceptions/PcepTunnelAttributeException.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/exceptions/PcepTunnelAttributeException.java deleted file mode 100755 index 25bdf5b6..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/exceptions/PcepTunnelAttributeException.java +++ /dev/null @@ -1,60 +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.pcepio.exceptions; - -/** - * Custom exception for Tunnel Attributes. - */ -public class PcepTunnelAttributeException extends Exception { - - private static final long serialVersionUID = 7860981378961458434L; - - /** - * Default constructor to create a new exception. - */ - public PcepTunnelAttributeException() { - super(); - } - - /** - * Constructor to create exception from message and cause. - * - * @param message the detail of exception in string - * @param cause underlying cause of the error - */ - public PcepTunnelAttributeException(final String message, final Throwable cause) { - super(message, cause); - } - - /** - * Constructor to create exception from message. - * - * @param message the detail of exception in string - */ - public PcepTunnelAttributeException(final String message) { - super(message); - } - - /** - * Constructor to create exception from cause. - * - * @param cause underlying cause of the error - */ - public PcepTunnelAttributeException(final Throwable cause) { - super(cause); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/exceptions/package-info.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/exceptions/package-info.java deleted file mode 100644 index 44d09f0d..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/exceptions/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. - */ - -/** - * PCEP custom exceptions. - */ -package org.onosproject.pcepio.exceptions; diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcInitiatedLspRequest.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcInitiatedLspRequest.java deleted file mode 100755 index 6a2fdc88..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcInitiatedLspRequest.java +++ /dev/null @@ -1,185 +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.pcepio.protocol; - -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity Provides PcInitiatedLspRequest for PCEP Initiate message. - * Reference : PCE initiated tunnel setup draft-ietf-pce-pce-initiated-lsp-03. - */ -public interface PcInitiatedLspRequest { - - /** - * Returns object of PcepSrpObject. - * - * @return srpObject PCEP SRP object - */ - PcepSrpObject getSrpObject(); - - /** - * Returns object of PcepLspObject. - * - * @return lspObject PCEP LSP object - */ - PcepLspObject getLspObject(); - - /** - * Returns object of PcepEndPointsObject. - * - * @return endPointsObject PCEP EndPoints object - */ - PcepEndPointsObject getEndPointsObject(); - - /** - * Returns object of PcepEroObject. - * - * @return eroObject PCEP ERO object - */ - PcepEroObject getEroObject(); - - /** - * Returns object of PcepAttribute. - * - * @return pcepAttribute PCEP Attributes - */ - PcepAttribute getPcepAttribute(); - - /** - * Sets PcepSrpObject. - * - * @param srpobj PCEP SRP object - */ - void setSrpObject(PcepSrpObject srpobj); - - /** - * Sets PcepLspObject. - * - * @param lspObject PCEP LSP object - */ - void setLspObject(PcepLspObject lspObject); - - /** - * Sets PcepEndPointsObject. - * - * @param endPointsObject PCEP EndPoints object - */ - void setEndPointsObject(PcepEndPointsObject endPointsObject); - - /** - * Sets PcepEroObject. - * - * @param eroObject PCEP ERO object - */ - void setEroObject(PcepEroObject eroObject); - - /** - * Sets PcepAttribute. - * - * @param pcepAttribute PCEP Attributes - */ - void setPcepAttribute(PcepAttribute pcepAttribute); - - /** - * Builder interface with get and set functions to build PcInitiatedLspRequest. - */ - interface Builder { - - /** - * Builds PcInitiatedLspRequest. - * - * @return PcInitiatedLspRequest - * @throws PcepParseException when mandatory object is not set - */ - PcInitiatedLspRequest build() throws PcepParseException; - - /** - * Returns object of PcepSrpObject. - * - * @return srpObject - */ - PcepSrpObject getSrpObject(); - - /** - * Returns object of PcepLspObject. - * - * @return lspObject - */ - PcepLspObject getLspObject(); - - /** - * Returns object of PcepEndPointsObject. - * - * @return endPointsObject - */ - PcepEndPointsObject getEndPointsObject(); - - /** - * Returns object of PcepEroObject. - * - * @return eroObject - */ - PcepEroObject getEroObject(); - - /** - * Returns object of PcepAttribute. - * - * @return pcepAttribute - */ - PcepAttribute getPcepAttribute(); - - /** - * Sets PcepSrpObject. - * - * @param srpobj PCEP SRP Object - * @return builder by setting PcepSrpObject - */ - Builder setSrpObject(PcepSrpObject srpobj); - - /** - * Sets PcepLspObject. - * - * @param lspObject PCEP LSP Object - * @return builder by setting PcepLspObject - */ - Builder setLspObject(PcepLspObject lspObject); - - /** - * Sets PcepEndPointsObject. - * - * @param endPointsObject EndPoints Object - * @return builder by setting PcepEndPointsObject - */ - Builder setEndPointsObject(PcepEndPointsObject endPointsObject); - - /** - * Sets PcepEroObject. - * - * @param eroObject PCEP ERO Object - * @return builder by setting PcepEroObject - */ - Builder setEroObject(PcepEroObject eroObject); - - /** - * Sets PcepAttribute. - * - * @param pcepAttribute PCEP Attributes - * @return builder by setting PcepAttribute - */ - Builder setPcepAttribute(PcepAttribute pcepAttribute); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepAttribute.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepAttribute.java deleted file mode 100644 index 122b943f..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepAttribute.java +++ /dev/null @@ -1,166 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity which Provides List of PCEP Attributes. - */ -public interface PcepAttribute { - - /** - * writes lspa , bandwidth , Metriclist and Iro objects to the channel. - * - * @param bb of type channel buffer. - * @return object length index. - * @throws PcepParseException while writing objects to channel buffer - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Returns PcepLspaObject. - * - * @return LspaObject - */ - PcepLspaObject getLspaObject(); - - /** - * Returns PcepBandwidthObject. - * - * @return BandwidthObject - */ - PcepBandwidthObject getBandwidthObject(); - - /** - * Returns PcepIroObject. - * - * @return iroObject - */ - PcepIroObject getIroObject(); - - /** - * Sets the PcepBandwidthObject. - * - * @param bandwidthObject bandwidth object - */ - void setBandwidthObject(PcepBandwidthObject bandwidthObject); - - /** - * Sets the PcepLspaObject. - * - * @param lspaObject lspa object - */ - void setLspaObject(PcepLspaObject lspaObject); - - /** - * Sets the PcepIroObject. - * - * @param iroObject iro object - */ - void setIroObject(PcepIroObject iroObject); - - /** - * Returns PcepMetricObject List. - * - * @return list of metric objects - */ - LinkedList<PcepMetricObject> getMetricObjectList(); - - /** - * Sets PcepMetricObject List. - * - * @param llMetricList list of metric objects - */ - void setMetricObjectList(LinkedList<PcepMetricObject> llMetricList); - - /** - * Builder interface with get and set functions to build PcepAttribute. - */ - interface Builder { - - /** - * Builds PcepAttribute. - * - * @return PcepAttribute - */ - PcepAttribute build(); - - /** - * Returns PcepLspaObject. - * - * @return LspaObject - */ - PcepLspaObject getLspaObject(); - - /** - * Returns PcepBandwidthObject. - * - * @return BandwidthObject - */ - PcepBandwidthObject getBandwidthObject(); - - /** - * Returns PcepIroObject. - * - * @return iroObject - */ - PcepIroObject getIroObject(); - - /** - * Sets the PcepBandwidthObject. - * - * @param bandwidthObject bandwidth object - * @return Builder object for PcepAttrubute - */ - Builder setBandwidthObject(PcepBandwidthObject bandwidthObject); - - /** - * Sets the PcepLspaObject. - * - * @param lspaObject lspa object - * @return Builder object for PcepAttrubute - */ - Builder setLspaObject(PcepLspaObject lspaObject); - - /** - * Sets the PcepIroObject. - * - * @param iroObject iro object - * @return Builder object for PcepAttrubute - */ - Builder setIroObject(PcepIroObject iroObject); - - /** - * Returns PcepMetricObject List. - * - * @return list of metric objects - */ - LinkedList<PcepMetricObject> getMetricObjectList(); - - /** - * Sets PcepMetricObject List. - * - * @param llMetricList list of metric objects - * @return Builder object for PcepAttrubute - */ - Builder setMetricObjectList(LinkedList<PcepMetricObject> llMetricList); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepBandwidthObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepBandwidthObject.java deleted file mode 100755 index 58d05821..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepBandwidthObject.java +++ /dev/null @@ -1,109 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; - -/** - * Abstraction of an entity providing PCEP Bandwidth Object. - */ -public interface PcepBandwidthObject { - - /** - * Returns bandwidth value. - * - * @return bandwidth value - */ - int getBandwidth(); - - /** - * Sets bandwidth with specified value. - * - * @param iBandwidth Bandwidth's value - */ - void setBandwidth(int iBandwidth); - - /** - * Writes the BandwidthObject into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException if bandwidth object header fails to write in channel buffer - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build bandwidth object. - */ - interface Builder { - - /** - * Builds BandwidthObject. - * - * @return BandwidthObject - * @throws PcepParseException if build fails while creating PcepBandwidthObject - */ - PcepBandwidthObject build() throws PcepParseException; - - /** - * Returns bandwidth object header. - * - * @return bandwidth object header - */ - PcepObjectHeader getBandwidthObjHeader(); - - /** - * Sets bandwidth object header and returns its builder. - * - * @param obj Bandwidth object header - * @return Builder by setting Bandwidth object header - */ - Builder setBandwidthObjHeader(PcepObjectHeader obj); - - /** - * Returns bandwidth value. - * - * @return bandwidth - */ - int getBandwidth(); - - /** - * Sets bandwidth value and return its builder. - * - * @param iBandwidth bandwidth value - * @return Builder by setting bandwidth - */ - Builder setBandwidth(int iBandwidth); - - /** - * Sets P flag in Bandwidth object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in Bandwidth object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepCloseMsg.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepCloseMsg.java deleted file mode 100644 index 00fad800..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepCloseMsg.java +++ /dev/null @@ -1,143 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; - -/** - * Abstraction of an entity providing PCEP Close Message. - */ -public interface PcepCloseMsg extends PcepObject, PcepMessage { - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns reason field in Close message. - * - * @return reason field - */ - byte getReason(); - - /** - * Sets reason field in Close message with specified value. - * - * @param value of Reason field - */ - void setReason(byte value); - - /** - * Returns LinkedList of Optional Tlv in Close Message. - * - * @return list of optional tlv - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets LinkedList of Optional Tlvs in Close Message. - * - * @param llOptionalTlv LinkedList of type PcepValueType - */ - void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - @Override - void writeTo(ChannelBuffer channelBuffer) throws PcepParseException; - - /** - * Builder interface with get and set functions to build Close message. - */ - interface Builder extends PcepMessage.Builder { - - @Override - PcepCloseMsg build(); - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns Close Object header. - * - * @return Close Object header - */ - PcepObjectHeader getCloseObjHeader(); - - /** - * Sets close object header and returns its builder. - * - * @param obj close object header - * @return Builder by setting Close object header - */ - Builder setCloseObjHeader(PcepObjectHeader obj); - - /** - * Returns reason field in Close message. - * - * @return reason field in Close message - */ - byte getReason(); - - /** - * Sets reason field and return its builder. - * - * @param value of Reason field - * @return builder by setting reason field - */ - Builder setReason(byte value); - - /** - * Returns LinkedList of Optional Tlvs. - * - * @return list of optional tlv - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets LinkedList of Optional Tlvs in Close Message. - * - * @param llOptionalTlv list of optional tlv - * @return Builder by setting Optional Tlvs - */ - Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Sets P flag in Close object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in Close object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepEndPointsObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepEndPointsObject.java deleted file mode 100755 index 92d43874..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepEndPointsObject.java +++ /dev/null @@ -1,139 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; - -/** - * Abstraction of an entity providing PCEP End Points Object. - */ -public interface PcepEndPointsObject { - - /** - * Returns Source IpAddress from End Points Object. - * - * @return Source IpAddress from End Points Object - */ - int getSourceIpAddress(); - - /** - * Sets Source IpAddress in End Points Object. - * - * @param sourceIpAddress Source IP Address - */ - void setSourceIpAddress(int sourceIpAddress); - - /** - * Returns Destination IpAddress from End Points Object. - * - * @return Destination IpAddress from End Points Object - */ - int getDestIpAddress(); - - /** - * Sets Destination IpAddress in End Points Object. - * - * @param destIpAddress Destination IP Address - */ - void setDestIpAddress(int destIpAddress); - - /** - * Writes the EndPointsObject into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException while writing EndPointObject into ChannelBuffer - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build EndPoints object. - */ - interface Builder { - - /** - * Builds End Points Object. - * - * @return End Points Object - * @throws PcepParseException while building EndPointObject - */ - PcepEndPointsObject build() throws PcepParseException; - - /** - * Returns End Points Object header. - * - * @return End Points Object header - */ - PcepObjectHeader getEndPointsObjHeader(); - - /** - * Sets End Points Object header and returns its builder. - * - * @param obj End Points Object header - * @return Builder by setting End Points Object header - */ - Builder setEndPointsObjHeader(PcepObjectHeader obj); - - /** - * Returns Source IpAddress from End Points Object. - * - * @return Source IpAddress from End Points Object - */ - int getSourceIpAddress(); - - /** - * Sets Source IpAddress in End Points Object and returns builder. - * - * @param sourceIpAddress Source IP Address - * @return Builder by setting Source IpAddress in End Points Object - */ - Builder setSourceIpAddress(int sourceIpAddress); - - /** - * Returns Destination IpAddress from End Points Object. - * - * @return Destination IpAddress from End Points Object - */ - int getDestIpAddress(); - - /** - * Sets Destination IpAddress in End Points Object. - * - * @param destIpAddress Destination IP Address - * @return Builder by setting Destination IpAddress in End Points Object - */ - Builder setDestIpAddress(int destIpAddress); - - /** - * Sets P flag in Bandwidth object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in Bandwidth object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepEroObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepEroObject.java deleted file mode 100755 index 3af6b759..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepEroObject.java +++ /dev/null @@ -1,112 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; - -/** - * Abstraction of an entity providing PCEP ERO Object. - */ -public interface PcepEroObject { - - /** - * Return LinkedList of SubObjects of ERO Object. - * - * @return list of subobjects - */ - LinkedList<PcepValueType> getSubObjects(); - - /** - * Sets LinkedList of SubObjects in ERO Object. - * - * @param llSubObjects list of subobjects - */ - void setSubObjects(LinkedList<PcepValueType> llSubObjects); - - /** - * Writes the ERO Object into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException while writing ERO Object into ChannelBuffer - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build ERO object. - */ - interface Builder { - - /** - * Builds ERO Object. - * - * @return ERO Object - */ - PcepEroObject build(); - - /** - * Returns ERO Object Header. - * - * @return ERO Object Header - */ - PcepObjectHeader getEroObjHeader(); - - /** - * Sets ERO Object header and returns its builder. - * - * @param obj ERO Object header - * @return Builder by setting ERO Object header - */ - Builder setEroObjHeader(PcepObjectHeader obj); - - /** - * Returns LinkedList of SubObjects in ERO Objects. - * - * @return list of subobjects - */ - LinkedList<PcepValueType> getSubObjects(); - - /** - * Sets LinkedList of SubObjects and returns its builder. - * - * @param llSubObjects list of SubObjects - * @return Builder by setting list of SubObjects - */ - Builder setSubObjects(LinkedList<PcepValueType> llSubObjects); - - /** - * Sets P flag in ERO object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in ERO object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepError.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepError.java deleted file mode 100755 index b61bfb9f..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepError.java +++ /dev/null @@ -1,136 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity which provides PCEP error for PCEP error message. - */ -public interface PcepError { - - /** - * Returns the PcepRPObject List. - * - * @return list of type PcepRPObject - */ - LinkedList<PcepRPObject> getRPObjList(); - - /** - * Sets the RP Objects lists. - * - * @param llRPObjList list of type PcepRPObject - */ - void setRPObjList(LinkedList<PcepRPObject> llRPObjList); - - /** - * Returns the PcepTEObject List. - * - * @return list of type PcepTEObject - */ - LinkedList<PcepTEObject> getTEObjList(); - - /** - * Sets the TE Objects lists. - * - * @param llTEObjList list of type PcepTEObject - */ - void setTEObjList(LinkedList<PcepTEObject> llTEObjList); - - /** - * Returns the PcepErrorObject. - * - * @return list of type PcepErrorObject - */ - LinkedList<PcepErrorObject> getErrorObjList(); - - /** - * Sets the Error Objects lists. - * - * @param llErrorObjList list of type PcepErrorObject - */ - void setErrorObjList(LinkedList<PcepErrorObject> llErrorObjList); - - /** - * Writes the byte stream of PCEP error to the channel buffer. - * - * @param bb of type channel buffer - * @return object length index - * @throws PcepParseException while writing Error part into ChannelBuffer - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build PcepError. - */ - interface Builder { - - /** - * Builds PcepError Object. - * - * @return PcepError Object - */ - PcepError build(); - - /** - * Returns the PcepRPObject. - * - * @return list of type PcepRPObject - */ - LinkedList<PcepRPObject> getRPObjList(); - - /** - * Sets RP Object lists and returns its builder. - * - * @param llRPObjList list of type PcepRpObject - * @return builder by setting Linked list of RP Object - */ - Builder setRPObjList(LinkedList<PcepRPObject> llRPObjList); - - /** - * Returns the PcepTEObject. - * - * @return llTEObjList of type PcepTEObject - */ - LinkedList<PcepTEObject> getTEObjList(); - - /** - * Sets TE Object lists and returns its builder. - * - * @param llTEObjList list of type PcepTEObject - * @return builder by setting list of type PcepTEObject - */ - Builder setTEObjList(LinkedList<PcepTEObject> llTEObjList); - - /** - * Returns the PcepErrorObject. - * - * @return list of type PcepErrorObject - */ - LinkedList<PcepErrorObject> getErrorObjList(); - - /** - * Sets Error Object lists and returns its builder. - * - * @param llErrorObjList list of type PcepErrorObject - * @return builder by setting list of type PcepErrorObject - */ - Builder setErrorObjList(LinkedList<PcepErrorObject> llErrorObjList); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepErrorInfo.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepErrorInfo.java deleted file mode 100755 index 0c625a03..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepErrorInfo.java +++ /dev/null @@ -1,93 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity which provides PCEP Error Info. - * Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02. - */ -public interface PcepErrorInfo { - - /** - * Returns whether error info list is present or not. - * - * @return true if error info present, false otherwise - */ - boolean isErrorInfoPresent(); - - /** - * Reads from channel buffer for TE and RP objects. - * - * @param bb of channel buffer - * @throws PcepParseException while parsing Error info part. - */ - void read(ChannelBuffer bb) throws PcepParseException; - - /** - * Writes byte stream of PCEP error info to channel buffer. - * - * @param bb of type channel buffer - * @throws PcepParseException while writing Error info part into Channel Buffer. - */ - void write(ChannelBuffer bb) throws PcepParseException; - - /** - * Returns Error Value in PCEP-ERROR Object. - * - * @return list of Error Value in PCEP-ERROR Object - */ - LinkedList<Integer> getErrorValue(); - - /** - * Returns Error Type in PCEP-ERROR Object. - * - * @return list of Error Type in PCEP-ERROR Object - */ - LinkedList<Integer> getErrorType(); - - /** - * Builder interface with get and set functions to build ErrorInfo. - */ - interface Builder { - - /** - * Builds ErrorInfo Object. - * - * @return ErrorInfo Object. - */ - PcepErrorInfo build(); - - /** - * Returns list of PcepError. - * - * @return list of PcepError - */ - LinkedList<PcepError> getPcepErrorList(); - - /** - * Sets PcepError lists and returns its builder. - * - * @param llPcepErrorList list of PcepError - * @return builder by setting list of PcepError. - */ - Builder setPcepErrorList(LinkedList<PcepError> llPcepErrorList); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepErrorMsg.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepErrorMsg.java deleted file mode 100644 index ff06885d..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepErrorMsg.java +++ /dev/null @@ -1,109 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.ErrorObjListWithOpen; - -/** - * Abstraction of an entity providing PCEP Error Message. - */ -public interface PcepErrorMsg extends PcepMessage { - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns Object of ErrorObjListWithOpen. - * - * @return Object of ErrorObjListWithOpen - */ - ErrorObjListWithOpen getErrorObjListWithOpen(); - - /** - * Sets errObjListWithOpen object. - * - * @param errObjListWithOpen error object List with open object - */ - void setErrorObjListWithOpen(ErrorObjListWithOpen errObjListWithOpen); - - /** - * Returns Object of PcepErrorInfo. - * - * @return Object of PcepErrorInfo - */ - PcepErrorInfo getPcepErrorInfo(); - - /** - * Sets errInfo Object. - * - * @param errInfo error information - */ - void setPcepErrorInfo(PcepErrorInfo errInfo); - - @Override - void writeTo(ChannelBuffer channelBuffer) throws PcepParseException; - - /** - * Builder interface with get and set functions to build PCEP Error message. - */ - interface Builder extends PcepMessage.Builder { - - @Override - PcepErrorMsg build(); - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns Object of ErrorObjListWithOpen. - * - * @return Object of ErrorObjListWithOpen - */ - ErrorObjListWithOpen getErrorObjListWithOpen(); - - /** - * Sets errObjListWithOpen object. - * - * @param errObjListWithOpen error object with open object - * @return builder by setting Object of ErrorObjListWithOpen - */ - Builder setErrorObjListWithOpen(ErrorObjListWithOpen errObjListWithOpen); - - /** - * Returns Object of PcepErrorInfo. - * - * @return Object of PcepErrorInfo - */ - PcepErrorInfo getPcepErrorInfo(); - - /** - * Sets errInfo Object. - * - * @param errInfo error information - * @return builder by getting Object of PcepErrorInfo - */ - Builder setPcepErrorInfo(PcepErrorInfo errInfo); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepErrorObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepErrorObject.java deleted file mode 100644 index 16374d5b..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepErrorObject.java +++ /dev/null @@ -1,169 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; - -/** - * Abstraction of an entity providing PCEP Error Object. - */ -public interface PcepErrorObject { - - /** - * Returns Error Type in Error Object. - * - * @return Error Type in Error Object - */ - int getErrorType(); - - /** - * Sets Error Type in Error Object. - * - * @param value Error Type - */ - void setErrorType(byte value); - - /** - * Returns Error Value in Error Object. - * - * @return Error Value - */ - byte getErrorValue(); - - /** - * Sets Error Value in Error Object. - * - * @param value Error Value - */ - void setErrorValue(byte value); - - /** - * Returns Optional Tlvs in Error Object. - * - * @return list of Optional Tlvs in Error Object - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets Optional Tlvs in Error Object. - * - * @param llOptionalTlv list of Optional Tlvs - */ - void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Writes the Error Object into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException while writing Error Object into ChannelBuffer - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build Error object. - */ - interface Builder { - - /** - * Builds Error Object. - * - * @return Error Object. - */ - PcepErrorObject build(); - - /** - * Returns Error Object header. - * - * @return Error Object header - */ - PcepObjectHeader getErrorObjHeader(); - - /** - * Sets Error Object header and returns its Builder. - * - * @param obj Error Object header - * @return Builder by setting Error Object header - */ - Builder setErrorObjHeader(PcepObjectHeader obj); - - /** - * Returns Error Type in Error Object. - * - * @return Error Type in Error Object - */ - int getErrorType(); - - /** - * Sets Error Type and returns its builder. - * - * @param value of Error-Type field - * @return builder by setting Error Type field. - */ - Builder setErrorType(byte value); - - /** - * Returns Error Value in Error Object. - * - * @return Error Value - */ - byte getErrorValue(); - - /** - * Sets Error Value and returns its builder. - * - * @param value of Error-Value field - * @return Builder by setting Error Value field. - */ - Builder setErrorValue(byte value); - - /** - * Returns list of Optional Tlvs of Error Object. - * - * @return list of Optional Tlvs of Error Object - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets Optional Tlvs of Error Object and returns its Builder. - * - * @param llOptionalTlv Optional Tlvs of Error Object - * @return Builder by setting Optional Tlvs. - */ - Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Sets P flag in Error object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in Error object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFactories.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFactories.java deleted file mode 100644 index 85416f98..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFactories.java +++ /dev/null @@ -1,98 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.ver1.PcepFactoryVer1; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Abstraction to provide the version for PCEP. - */ -public final class PcepFactories { - - protected static final Logger log = LoggerFactory.getLogger(PcepFactories.class); - - private static final GenericReader GENERIC_READER = new GenericReader(); - - public static final byte SHIFT_FLAG = 5; - - private PcepFactories() { - } - - /** - * Returns the instance of PCEP Version. - * - * @param version PCEP version - * @return PCEP version - */ - public static PcepFactory getFactory(PcepVersion version) { - switch (version) { - case PCEP_1: - return PcepFactoryVer1.INSTANCE; - default: - throw new IllegalArgumentException("Unknown version: " + version); - } - } - - private static class GenericReader implements PcepMessageReader<PcepMessage> { - - @Override - public PcepMessage readFrom(ChannelBuffer bb) throws PcepParseException { - - if (!bb.readable()) { - throw new PcepParseException("Empty message received"); - } - - /* - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Ver | Flags | | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * Currently Version 1 is supported - * Currently no flags are used, it is all ignored - */ - - byte packetVersion = bb.getByte(bb.readerIndex()); - packetVersion = (byte) (packetVersion >> SHIFT_FLAG); - PcepFactory factory; - - switch (packetVersion) { - - case 1: - factory = org.onosproject.pcepio.protocol.ver1.PcepFactoryVer1.INSTANCE; - break; - default: - throw new PcepParseException("Unknown Packet version: " + packetVersion); - } - return factory.getReader().readFrom(bb); - } - } - - /** - * Returns GENERIC_READER. - * - * @return GENERIC_READER - */ - public static PcepMessageReader<PcepMessage> getGenericReader() { - return GENERIC_READER; - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFactory.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFactory.java deleted file mode 100755 index 1a31e0a3..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFactory.java +++ /dev/null @@ -1,255 +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.pcepio.protocol; - -/** - * Abstraction of an Message factory providing Builder functions to PCEP Messages and Objects. - * - */ -public interface PcepFactory { - - /** - * To get Builder Object for Open Message. - * - * @return Builder Object for Open Message - */ - PcepOpenMsg.Builder buildOpenMsg(); - - /** - * To get Builder Object for Open Object. - * - * @return Builder Object for Open Object - */ - PcepOpenObject.Builder buildOpenObject(); - - /** - * To get Builder Object for Keepalive Message. - * - * @return Builder Object for Keepalive Message - */ - PcepKeepaliveMsg.Builder buildKeepaliveMsg(); - - /** - * To get Builder Object for Close Message. - * - * @return Builder Object for Close Message - */ - PcepCloseMsg.Builder buildCloseMsg(); - - /** - * To get Builder Object for Report Message. - * - * @return Builder Object for Report Message - */ - PcepReportMsg.Builder buildReportMsg(); - - /** - * To get Builder Object for Update Message. - * - * @return Builder Object for Update Message - */ - PcepUpdateMsg.Builder buildUpdateMsg(); - - /** - * To get Builder Object for Initiate Message. - * - * @return Builder Object for Initiate Message - */ - PcepInitiateMsg.Builder buildPcepInitiateMsg(); - - /** - * To get Builder Object for LSP Object. - * - * @return Builder Object for LSP Object - */ - PcepLspObject.Builder buildLspObject(); - - /** - * To get Builder Object for SRP Object. - * - * @return Builder Object for SRP Object - */ - PcepSrpObject.Builder buildSrpObject(); - - /** - * To get Builder Object for EndPoints Object. - * - * @return Builder Object for EndPoints Object - */ - PcepEndPointsObject.Builder buildEndPointsObject(); - - /** - * To get Builder Object for ERO Object. - * - * @return Builder Object for ERO Object - */ - PcepEroObject.Builder buildEroObject(); - - /** - * To get Builder Object for RRO Object. - * - * @return Builder Object for RRO Object - */ - PcepRroObject.Builder buildRroObject(); - - /** - * To get Builder Object for LSPA Object. - * - * @return Builder Object for LSPA Object - */ - PcepLspaObject.Builder buildLspaObject(); - - /** - * To get Builder Object for IRO Object. - * - * @return Builder Object for IRO Object - */ - PcepIroObject.Builder buildIroObject(); - - /** - * To get Builder Object for METRIC Object. - * - * @return Builder Object for METRIC Object - */ - PcepMetricObject.Builder buildMetricObject(); - - /** - * To get Builder Object for Bandwidth Object. - * - * @return Builder Object for Bandwidth Object - */ - PcepBandwidthObject.Builder buildBandwidthObject(); - - /** - * Returns PCEP Message Reader. - * - * @return PCEP Message Reader - */ - PcepMessageReader<PcepMessage> getReader(); - - /** - * Returns PCEP version. - * - * @return PCEP version - */ - PcepVersion getVersion(); - - /** - * Returns PcepStateReport. - * - * @return PcepStateReport - */ - PcepStateReport.Builder buildPcepStateReport(); - - /** - * Returns PcepUpdateRequest. - * - * @return PcepUpdateRequest - */ - PcepUpdateRequest.Builder buildPcepUpdateRequest(); - - /** - * Returns PcInitiatedLspRequest. - * - * @return PcInitiatedLspRequest - */ - PcInitiatedLspRequest.Builder buildPcInitiatedLspRequest(); - - /** - * Returns PcepMsgPath. - * - * @return PcepMsgPath - */ - PcepMsgPath.Builder buildPcepMsgPath(); - - /** - * Return PcepAttribute list. - * - * @return PcepAttribute - */ - PcepAttribute.Builder buildPcepAttribute(); - - /** - * To get Builder Object for LabelUpdate message. - * - * @return Builder Object for LabelUpdate message - */ - PcepLabelUpdateMsg.Builder buildPcepLabelUpdateMsg(); - - /** - * To get Builder Object for PcepLabelUpdate Object. - * - * @return Builder Object for PcepLabelUpdate Object - */ - PcepLabelUpdate.Builder buildPcepLabelUpdateObject(); - - /** - * To get Builder Object for PcepLabel Object. - * - * @return Builder Object for PcepLabel Object - */ - PcepLabelObject.Builder buildLabelObject(); - - /** - * To get Builder Object for Error Message. - * - * @return Builder Object for Error Message - */ - PcepErrorMsg.Builder buildPcepErrorMsg(); - - /** - * To get Builder Object for Error Object. - * - * @return Builder Object for Error Object - */ - PcepErrorObject.Builder buildPcepErrorObject(); - - /** - * To get Builder Object for FecIpv4Adjacency. - * - * @return Builder Object for FecIpv4Adjacency - */ - PcepFecObjectIPv4Adjacency.Builder buildFecIpv4Adjacency(); - - /** - * To get Builder Object for ErrorInfo. - * - * @return Builder Object for ErrorInfo - */ - PcepErrorInfo.Builder buildPcepErrorInfo(); - - /** - * To get Builder Object for PcepError. - * - * @return Builder Object for PcepError - */ - PcepError.Builder buildPcepError(); - - /** - * To get Builder Object for PcepLabelRangeObject. - * - * @return Builder Object for PcepLabelRangeObject - */ - PcepLabelRangeObject.Builder buildPcepLabelRangeObject(); - - /** - * To get Builder Object for PcepLabelRangeResvMsg. - * - * @return Builder Object for PcepLabelRangeResvMsg - */ - PcepLabelRangeResvMsg.Builder buildPcepLabelRangeResvMsg(); -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObject.java deleted file mode 100755 index 2df7cc9c..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObject.java +++ /dev/null @@ -1,49 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing PCEP FEC Object. - */ -public interface PcepFecObject { - - /** - * Returns PCEP Version of FEC Object. - * - * @return PCEP Version of FEC Object - */ - PcepVersion getVersion(); - - /** - * Returns FEC Object type. - * - * @return FEC Object type - */ - int getType(); - - /** - * Writes the FEC into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException while writing FEC Object into Channel Buffer. - */ - int write(ChannelBuffer bb) throws PcepParseException; -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv4.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv4.java deleted file mode 100755 index 5ed4e1e3..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv4.java +++ /dev/null @@ -1,104 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; - -/** - * Abstraction of an entity providing PCEP FEC Object of Type 1 IPv4 Node ID. - */ -public interface PcepFecObjectIPv4 extends PcepFecObject { - - /** - * Returns NodeID of FEC Object. - * - * @return NodeID of FEC Object - */ - int getNodeID(); - - /** - * Sets NodeID with specified value. - * - * @param value node id - */ - void setNodeID(int value); - - @Override - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build FEC object. - */ - interface Builder { - - /** - * Builds FEC Object IPv4. - * - * @return FEC Object IPv4 - * @throws PcepParseException while creating FEC IPv4 Object. - */ - PcepFecObjectIPv4 build() throws PcepParseException; - - /** - * Returns FEC Object IPv4 header. - * - * @return FEC Object IPv4 header - */ - PcepObjectHeader getFecIpv4ObjHeader(); - - /** - * Sets FEC Object IPv4 header and returns its builder. - * - * @param obj FEC Object IPv4 header - * @return Builder by setting FEC Object IPv4 header - */ - Builder setFecIpv4ObjHeader(PcepObjectHeader obj); - - /** - * Returns NodeID of FEC Object. - * - * @return NodeID of FEC Object - */ - int getNodeID(); - - /** - * Sets NodeID and returns its builder. - * - * @param value node id - * @return builder by setting NodeID - */ - Builder setNodeID(int value); - - /** - * Sets P flag in FEC object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in FEC object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv4Adjacency.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv4Adjacency.java deleted file mode 100755 index 55205299..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv4Adjacency.java +++ /dev/null @@ -1,133 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; - -/** - * Abstraction of an entity providing FEC Object of Type 3 IPv4 Adjacency. - */ -public interface PcepFecObjectIPv4Adjacency extends PcepFecObject { - - /** - * Returns Local IPv4Address of FEC Object. - * - * @return Local IPv4Address of FEC Object - */ - int getLocalIPv4Address(); - - /** - * Sets Local IPv4Address with specified value. - * - * @param value Local IPv4Address - */ - void seLocalIPv4Address(int value); - - /** - * Returns Remote IPv4Address of FEC Object. - * - * @return Remote IPv4Address of FEC Object - */ - int getRemoteIPv4Address(); - - /** - * Sets Remote IPv4Address with specified value. - * - * @param value Remote IPv4Address - */ - void seRemoteIPv4Address(int value); - - @Override - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build FEC object. - */ - interface Builder { - - /** - * Builds FEC Object IPv4 Adjacency. - * - * @return FEC Object IPv4 Adjacency - * @throws PcepParseException while building FEC IPv4 Adjacency object. - */ - PcepFecObjectIPv4Adjacency build() throws PcepParseException; - - /** - * Returns FEC Object IPv4 Adjacency header. - * - * @return FEC Object IPv4 Adjacency header - */ - PcepObjectHeader getFecIpv4AdjacencyObjHeader(); - - /** - * Sets FEC Object IPv4 Adjacency header and returns its builder. - * - * @param obj FEC Object IPv4 Adjacency header - * @return Builder by setting FEC Object IPv4 header - */ - Builder setFecIpv4AdjacencyObjHeader(PcepObjectHeader obj); - - /** - * Returns Local IPv4Address of FEC Object. - * - * @return Local IPv4Address of FEC Object - */ - int getLocalIPv4Address(); - - /** - * Sets Local IPv4Address and returns its builder. - * - * @param value Local IPv4Address - * @return Builder by setting Local IPv4Address - */ - Builder seLocalIPv4Address(int value); - - /** - * Sets Remote IPv4Address with specified value. - * - * @return Remote IPv4 Address - */ - int getRemoteIPv4Address(); - - /** - * Sets Remote IPv4Address and returns its builder. - * - * @param value Remote IPv4Address - * @return Builder by setting Remote IPv4Address - */ - Builder seRemoteIPv4Address(int value); - - /** - * Sets P flag in FEC object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in FEC object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv4UnnumberedAdjacency.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv4UnnumberedAdjacency.java deleted file mode 100755 index d240445e..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv4UnnumberedAdjacency.java +++ /dev/null @@ -1,191 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; - -/** - * Abstraction of an entity providing PCEP FEC Object of Type is 5 Unnumbered Adjacency with IPv4 NodeIDs. - */ -public interface PcepFecObjectIPv4UnnumberedAdjacency extends PcepFecObject { - - /** - * Returns Local NodeID of FEC Object. - * - * @return Local NodeID of FEC Object - */ - int getLocalNodeID(); - - /** - * Sets Local NodeID with specified value. - * - * @param value Local NodeID - */ - void setLocalNodeID(int value); - - /** - * Returns Local InterfaceID of FEC Object. - * - * @return Local InterfaceID of FEC Object - */ - int getLocalInterfaceID(); - - /** - * Sets Local InterfaceID with specified value. - * - * @param value Local InterfaceID - */ - void setLocalInterfaceID(int value); - - /** - * Returns Remote NodeID of FEC Object. - * - * @return Remote NodeID of FEC Object - */ - int getRemoteNodeID(); - - /** - * Sets Remote NodeID with specified value. - * - * @param value Remote NodeID - */ - void setRemoteNodeID(int value); - - /** - * Returns Remote InterfaceID of FEC Object. - * - * @return Remote InterfaceID of FEC Object - */ - int getRemoteInterfaceID(); - - /** - * Sets Remote InterfaceID with specified value. - * - * @param value Remote InterfaceID - */ - void setRemoteInterfaceID(int value); - - @Override - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build bandwidth object. - */ - interface Builder { - - /** - * Builds FEC Unnumbered Adjacency with IPv4 Object. - * - * @return FEC Unnumbered Adjacency with IPv4 Object - * @throws PcepParseException when building FEC IPv4 Unnumbered Adjacency object. - */ - PcepFecObjectIPv4UnnumberedAdjacency build() throws PcepParseException; - - /** - * Returns FEC Unnumbered Adjacency with IPv4 header. - * - * @return FEC Unnumbered Adjacency with IPv4 header - */ - PcepObjectHeader getFecIpv4UnnumberedAdjacencyObjHeader(); - - /** - * Sets FEC Unnumbered Adjacency with IPv4 header and returns its builder. - * - * @param obj FEC Unnumbered Adjacency with IPv4 header - * @return Builder by setting FEC Unnumbered Adjacency with IPv4 header - */ - Builder setFecIpv4UnnumberedAdjacencyObjHeader(PcepObjectHeader obj); - - /** - * Returns Local NodeID of FEC Object. - * - * @return Local NodeID of FEC Object - */ - int getLocalNodeID(); - - /** - * Sets Local NodeID and returns its builder. - * - * @param value Local NodeID - * @return Builder by setting Local NodeID - */ - Builder setLocalNodeID(int value); - - /** - * Returns Local InterfaceID of FEC Object. - * - * @return Local InterfaceID of FEC Object - */ - int getLocalInterfaceID(); - - /** - * Sets Local InterfaceID and returns its builder. - * - * @param value Local InterfaceID - * @return Builder by setting Local InterfaceID - */ - Builder setLocalInterfaceID(int value); - - /** - * Returns Remote NodeID of FEC Object. - * - * @return Remote NodeID of FEC Object - */ - int getRemoteNodeID(); - - /** - * Sets Remote NodeID and returns its builder. - * - * @param value Remote NodeID - * @return Builder by setting Remote NodeID - */ - Builder setRemoteNodeID(int value); - - /** - * Returns Remote InterfaceID of FEC Object. - * - * @return Remote InterfaceID of FEC Object - */ - int getRemoteInterfaceID(); - - /** - * Sets Remote InterfaceID and returns its builder. - * - * @param value Remote InterfaceID - * @return Builder by setting Remote InterfaceID - */ - Builder setRemoteInterfaceID(int value); - - /** - * Sets P flag in FEC object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in FEC object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv6.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv6.java deleted file mode 100755 index 1c29b76a..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv6.java +++ /dev/null @@ -1,104 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; - -/** - * Abstraction of an entity providing FEC Object of Type is 2 IPv6 Node ID. - */ -public interface PcepFecObjectIPv6 extends PcepFecObject { - - /** - * Returns NodeID of FEC Object. - * - * @return NodeID of FEC Object - */ - byte[] getNodeID(); - - /** - * Sets NodeID with specified value. - * - * @param value node id - */ - void setNodeID(byte[] value); - - @Override - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build FEC object. - */ - interface Builder { - - /** - * Builds FEC Object IPv6. - * - * @return FEC Object IPv6 - * @throws PcepParseException while building FEC IPv6 Object. - */ - PcepFecObjectIPv6 build() throws PcepParseException; - - /** - * Returns FEC Object IPv6 header. - * - * @return FEC Object IPv6 header - */ - PcepObjectHeader getFecIpv6ObjHeader(); - - /** - * Sets FEC Object IPv6 header and returns its builder. - * - * @param obj FEC Object IPv6 header - * @return Builder by setting FEC Object IPv6 header - */ - Builder setFecIpv6ObjHeader(PcepObjectHeader obj); - - /** - * Returns NodeID of FEC Object. - * - * @return NodeID of FEC Object - */ - byte[] getNodeID(); - - /** - * Sets NodeID and returns its builder. - * - * @param value node id - * @return Builder by setting NodeID - */ - Builder setNodeID(byte[] value); - - /** - * Sets P flag in FEC object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in FEC object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv6Adjacency.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv6Adjacency.java deleted file mode 100755 index ef802780..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepFecObjectIPv6Adjacency.java +++ /dev/null @@ -1,133 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; - -/** - * Abstraction of an entity providing FEC Object of Type is 4 IPv6 Adjacency. - */ -public interface PcepFecObjectIPv6Adjacency extends PcepFecObject { - - /** - * Returns Local IPv6Address of FEC Object. - * - * @return Local IPv6Address of FEC Object - */ - byte[] getLocalIPv6Address(); - - /** - * Sets Local IPv6Address with specified value. - * - * @param value Local IPv6Address - */ - void seLocalIPv6Address(byte[] value); - - /** - * Returns Remote IPv6Address of FEC Object. - * - * @return Remote IPv6Address of FEC Object - */ - byte[] getRemoteIPv6Address(); - - /** - * Sets Remote IPv6Address with specified value. - * - * @param value Remote IPv6Address - */ - void seRemoteIPv6Address(byte[] value); - - @Override - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build FEC object. - */ - interface Builder { - - /** - * Builds FEC Object IPv6 Adjacency. - * - * @return FEC Object IPv6 Adjacency - * @throws PcepParseException while building FEC IPv6 Adjacency object. - */ - PcepFecObjectIPv6Adjacency build() throws PcepParseException; - - /** - * Returns FEC Object IPv6 Adjacency header. - * - * @return FEC Object IPv6 Adjacency header - */ - PcepObjectHeader getFecIpv6AdjacencyObjHeader(); - - /** - * Sets FEC Object IPv6 Adjacency header and returns its builder. - * - * @param obj FEC Object IPv6 Adjacency header - * @return Builder by setting FEC Object IPv6 Adjacency header - */ - Builder setFecIpv6AdjacencyObjHeader(PcepObjectHeader obj); - - /** - * Returns Local IPv6Address of FEC Object. - * - * @return Local IPv6Address of FEC Object - */ - byte[] getLocalIPv6Address(); - - /** - * Sets Local IPv6Address and returns its builder. - * - * @param value Local IPv6Address - * @return Builder by setting Local IPv6Address - */ - Builder setLocalIPv6Address(byte[] value); - - /** - * Returns Remote IPv6Address of FEC Object. - * - * @return Remote IPv6Address of FEC Object - */ - byte[] getRemoteIPv6Address(); - - /** - * Sets Remote IPv6Address and returns its builder. - * - * @param value Remote IPv6Address - * @return Builder by setting Remote IPv6Address - */ - Builder setRemoteIPv6Address(byte[] value); - - /** - * Sets P flag in FEC object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in FEC object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepInitiateMsg.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepInitiateMsg.java deleted file mode 100755 index 2b061430..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepInitiateMsg.java +++ /dev/null @@ -1,81 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing PCEP Initiate Message. - */ -public interface PcepInitiateMsg extends PcepObject, PcepMessage { - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns list of PcInitiatedLspRequestList. - * - * @return list of PcInitiatedLspRequestList - */ - LinkedList<PcInitiatedLspRequest> getPcInitiatedLspRequestList(); - - /** - * Sets list of PcInitiatedLspRequestList. - * - * @param llPcInitiatedLspRequestList list of PcInitiatedLspRequestList - */ - void setPcInitiatedLspRequestList(LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList); - - @Override - void writeTo(ChannelBuffer channelBuffer) throws PcepParseException; - - /** - * Builder interface with get and set functions to build Initiate message. - */ - interface Builder extends PcepMessage.Builder { - - @Override - PcepInitiateMsg build(); - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns list of PcInitiatedLspRequestList. - * - * @return list of PcInitiatedLspRequestList - */ - LinkedList<PcInitiatedLspRequest> getPcInitiatedLspRequestList(); - - /** - * Sets PcInitiatedLspRequestList. - * - * @param llPcInitiatedLspRequestList list of PcInitiatedLspRequestList - * @return builder by setting list of PcInitiatedLspRequestList - */ - Builder setPcInitiatedLspRequestList(LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepInterLayerObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepInterLayerObject.java deleted file mode 100755 index 675e0557..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepInterLayerObject.java +++ /dev/null @@ -1,137 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; - -/** - * Abstraction of an entity providing PCEP INTER Layer Object. - */ -public interface PcepInterLayerObject { - - /** - * Returns N Flag in INTER Layer Object. - * - * @return N Flag in INTER Layer Object - */ - boolean getbNFlag(); - - /** - * Sets N Flag in INTER Layer Object with specified value. - * - * @param value N Flag - */ - void setbNFlag(boolean value); - - /** - * Returns I Flag in INTER Layer Object. - * - * @return I Flag in INTER Layer Object - */ - boolean getbIFlag(); - - /** - * Sets I Flag in INTER Layer Object with specified value. - * - * @param value I Flag - */ - void setbIFlag(boolean value); - - /** - * Writes the INTER Layer Object into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException while writing Inter Layer Object. - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build INTER Layer object. - */ - interface Builder { - - /** - * Builds INTER Layer object. - * - * @return INTER Layer object - */ - PcepInterLayerObject build(); - - /** - * Returns INTER Layer object header. - * - * @return INTER Layer object header - */ - PcepObjectHeader getInterLayerObjHeader(); - - /** - * Sets INTER Layer object header and returns its builder. - * - * @param obj INTER Layer object header - * @return Builder by setting INTER Layer object header - */ - Builder setInterLayerObjHeader(PcepObjectHeader obj); - - /** - * Returns N Flag in INTER Layer Object. - * - * @return N Flag in INTER Layer Object - */ - boolean getbNFlag(); - - /** - * Sets N flag and return its builder. - * - * @param value N flag - * @return Builder by setting N flag - */ - Builder setbNFlag(boolean value); - - /** - * Returns I Flag in INTER Layer Object. - * - * @return I Flag in INTER Layer Object - */ - boolean getbIFlag(); - - /** - * Sets I flag and return its builder. - * - * @param value I flag - * @return Builder by setting N flag - */ - Builder setbIFlag(boolean value); - - /** - * Sets P flag in INTER Layer object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in INTER Layer object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepIroObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepIroObject.java deleted file mode 100755 index a1c1fc59..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepIroObject.java +++ /dev/null @@ -1,110 +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.pcepio.protocol; - -import java.util.LinkedList; -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; - -/** - * Abstraction of an entity providing PCEP IRO Object. - */ -public interface PcepIroObject { - - /** - * Returns list of SubObjects. - * - * @return list of SubObjects - */ - LinkedList<PcepValueType> getSubObjects(); - - /** - * Sets list of SubObjects. - * - * @param llSubObjects list of SubObjects - */ - void setSubObjects(LinkedList<PcepValueType> llSubObjects); - - /** - * Writes the IRO into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException while writing IRO object. - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build IRO object. - */ - interface Builder { - - /** - * Builds IRO Object. - * - * @return IRO Object - */ - PcepIroObject build(); - - /** - * Returns IRO object header. - * - * @return IRO object header - */ - PcepObjectHeader getIroObjHeader(); - - /** - * Sets IRO object header and returns its builder. - * - * @param obj IRO object header - * @return Builder by setting IRO object header - */ - Builder setIroObjHeader(PcepObjectHeader obj); - - /** - * Returns list of SubObjects. - * - * @return list of SubObjects - */ - LinkedList<PcepValueType> getSubObjects(); - - /** - * Sets list of SubObjects in IRO Object and returns its builder. - * - * @param llSubObjects list of SubObjects - * @return Builder by setting list of SubObjects - */ - Builder setSubObjects(LinkedList<PcepValueType> llSubObjects); - - /** - * Sets P flag in IRO object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in IRO object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepKeepaliveMsg.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepKeepaliveMsg.java deleted file mode 100755 index 160f0a2a..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepKeepaliveMsg.java +++ /dev/null @@ -1,49 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; - -/** - * Abstraction of an entity providing PCEP Keepalive Message. - */ -public interface PcepKeepaliveMsg extends PcepObject, PcepMessage { - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - @Override - void writeTo(ChannelBuffer channelBuffer); - - /** - * Builder interface with get and set functions to build Keepalive message. - */ - interface Builder extends PcepMessage.Builder { - - @Override - PcepKeepaliveMsg build(); - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelObject.java deleted file mode 100755 index b64c21e0..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelObject.java +++ /dev/null @@ -1,171 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; - -/** - * Abstraction of an entity providing PCEP Label Object. - */ -public interface PcepLabelObject { - - /** - * Returns O flag in Label Object. - * - * @return Boolean value - */ - boolean getOFlag(); - - /** - * Sets O flag in Label Object with specified value. - * - * @param value O flag - */ - void setOFlag(boolean value); - - /** - * Returns Label from Label Object. - * - * @return Label value - */ - int getLabel(); - - /** - * Sets Label field in Label Object with specified value. - * - * @param value Label - */ - void setLabel(int value); - - /** - * Returns list of Optional Tlvs. - * - * @return list of Optional Tlvs - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets Optional Tlvs in Label Object. - * - * @param llOptionalTlv list of Optional Tlvs - */ - void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Writes the Label Object into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException while writing LABEL object into Channel Buffer. - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build Label object. - */ - interface Builder { - - /** - * Builds Label Object. - * - * @return Label Object - * @throws PcepParseException while building LABEL object. - */ - PcepLabelObject build() throws PcepParseException; - - /** - * Returns Label object header. - * - * @return Label object header - */ - PcepObjectHeader getLabelObjHeader(); - - /** - * Sets Label object header and returns its builder. - * - * @param obj Label object header - * @return Builder by setting Label object header - */ - Builder setLabelObjHeader(PcepObjectHeader obj); - - /** - * Returns O flag in Label Object. - * - * @return Label value - */ - boolean getOFlag(); - - /** - * Sets O flag and return its builder. - * - * @param value O flag - * @return Builder by setting O flag - */ - Builder setOFlag(boolean value); - - /** - * Returns Label from Label Object. - * - * @return Label value - */ - int getLabel(); - - /** - * Sets Label field and return its builder. - * - * @param value Label field - * @return Builder by setting Label field - */ - Builder setLabel(int value); - - /** - * Returns list of Optional Tlvs. - * - * @return list of Optional Tlvs - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets list of Optional Tlvs and return its builder. - * - * @param llOptionalTlv list of Optional Tlvs - * @return Builder by setting list of Optional Tlvs - */ - Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Sets P flag in Label object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in Label object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelRange.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelRange.java deleted file mode 100755 index 72d0a38e..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelRange.java +++ /dev/null @@ -1,65 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing PCEP Label Range. - */ -public interface PcepLabelRange { - - /** - * Returns object of PCEP SRP Object. - * - * @return srpObject - */ - PcepSrpObject getSrpObject(); - - /** - * Sets PCEP SRP Object. - * - * @param srpObject SRP object. - */ - void setSrpObject(PcepSrpObject srpObject); - - /** - * Returns list of PcepLabelRangeObject. - * - * @return Label Range List - */ - LinkedList<PcepLabelRangeObject> getLabelRangeList(); - - /** - * Sets list of PcepLabelRangeObject. - * - * @param llLabelRangeList Label Range List - */ - void setLabelRangeList(LinkedList<PcepLabelRangeObject> llLabelRangeList); - - /** - * Write the byte stream of PcepLabelRange to channel buffer. - * - * @param bb of type channel buffer - * @return object length index - * @throws PcepParseException while writing LABEL RANGE into Channel Buffer. - */ - int write(ChannelBuffer bb) throws PcepParseException; -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelRangeObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelRangeObject.java deleted file mode 100755 index 9155434e..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelRangeObject.java +++ /dev/null @@ -1,182 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; - -/** - * Abstraction of an entity providing PCEP LabelRange Object. - */ -public interface PcepLabelRangeObject { - - /** - * Sets LabelRange Object header. - * - * @param obj LabelRange Object header - */ - void setLabelRangeObjHeader(PcepObjectHeader obj); - - /** - * Sets LabelType in LabelRange Object. - * - * @param labelType label type value - */ - void setLabelType(byte labelType); - - /** - * Sets RangeSize in LabelRange Object. - * - * @param rangeSize range size value - */ - void setRangeSize(int rangeSize); - - /** - * Sets LabelBase in LabelRange Object. - * - * @param labelBase label base value - */ - void setLabelBase(int labelBase); - - /** - * Returns LabelRange object header. - * - * @return LabelRange object header - */ - PcepObjectHeader getLabelRangeObjHeader(); - - /** - * Returns LabelType field in LabelRange object. - * - * @return LabelType field in LabelRange object - */ - byte getLabelType(); - - /** - * Returns RangeSize field in LabelRange object. - * - * @return RangeSize field in LabelRange object - */ - int getRangeSize(); - - /** - * Returns LabelBase field in LabelRange object. - * - * @return LabelBase field in LabelRange object - */ - int getLabelBase(); - - /** - * Writes the LabelRange Object into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException while writing LABEL RANGE object into Channel Buffer. - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build LabelRange object. - */ - interface Builder { - - /** - * Builds LabelRange Object. - * - * @return LabelRange Object - * @throws PcepParseException while building LABEL RANGE object. - */ - PcepLabelRangeObject build() throws PcepParseException; - - /** - * Returns LabelRange object header. - * - * @return LabelRange object header - */ - PcepObjectHeader getLabelRangeObjHeader(); - - /** - * Sets LabelRange object header and returns its builder. - * - * @param obj LabelRange object header - * @return Builder by setting LabelRange object header - */ - Builder setLabelRangeObjHeader(PcepObjectHeader obj); - - /** - * Returns LabelType field in LabelRange object. - * - * @return LabelType field in LabelRange object - */ - byte getLabelType(); - - /** - * Sets LabelType field and returns its builder. - * - * @param labelType LabelType field - * @return Builder by setting LabelType field - */ - Builder setLabelType(byte labelType); - - /** - * Returns RangeSize field in LabelRange object. - * - * @return RangeSize field in LabelRange object - */ - int getRangeSize(); - - /** - * Sets RangeSize field and returns its builder. - * - * @param rangeSize RangeSize field - * @return Builder by setting RangeSize field - */ - Builder setRangeSize(int rangeSize); - - /** - * Returns LabelBase field in LabelRange object. - * - * @return LabelBase field in LabelRange object - */ - int getLabelBase(); - - /** - * Sets LabelBase field and returns its builder. - * - * @param labelBase LabelBase field - * @return Builder by setting LabelBase field - */ - Builder setLabelBase(int labelBase); - - /** - * Sets P flag in TE object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in TE object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelRangeResvMsg.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelRangeResvMsg.java deleted file mode 100755 index 3e2a3a95..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelRangeResvMsg.java +++ /dev/null @@ -1,79 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing PCEP Label Range Reservation Message. - */ -public interface PcepLabelRangeResvMsg extends PcepObject, PcepMessage { - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns LabelRange field in Label Range Reservation message. - * - * @return LabelRange field - */ - PcepLabelRange getLabelRange(); - - /** - * Sets LabelRange field in Label Range Reservation message with specified value. - * - * @param lR label range object - */ - void setLabelRange(PcepLabelRange lR); - - @Override - void writeTo(ChannelBuffer channelBuffer) throws PcepParseException; - - /** - * Builder interface with get and set functions to build Label Range Reservation message. - */ - interface Builder extends PcepMessage.Builder { - - @Override - PcepLabelRangeResvMsg build(); - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns LabelRange field in Label Range Reservation message. - * - * @return LabelRange object - */ - PcepLabelRange getLabelRange(); - - /** - * Sets LabelRange field and returns its Builder. - * - * @param lR label range object - * @return builder by setting LabelRange field - */ - Builder setLabelRange(PcepLabelRange lR); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelUpdate.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelUpdate.java deleted file mode 100644 index 5ef870d4..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelUpdate.java +++ /dev/null @@ -1,108 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepLabelDownload; -import org.onosproject.pcepio.types.PcepLabelMap; - -/*** - * Abstraction to provide PCEP Label Updates. - */ -public interface PcepLabelUpdate { - - /** - * Writes the byte stream of PcepLabelUpdate into channel buffer. - * - * @param bb of type channel buffer - * @throws PcepParseException while writing LABEL UPDATE. - */ - void write(ChannelBuffer bb) throws PcepParseException; - - /** - * Sets the Label Download object. - * - * @param labelDownload PCEP Label Download object - */ - void setLabelDownload(PcepLabelDownload labelDownload); - - /** - * Returns the PcepLabelDownload object. - * - * @return labelDownload PCEP Label Download - */ - PcepLabelDownload getLabelDownload(); - - /** - * Sets the Label map object. - * - * @param labelMap PCEP Label Map object - */ - void setLabelMap(PcepLabelMap labelMap); - - /** - * Returns the PcepLabelMap object. - * - * @return labelMap PCEP Label Map - */ - PcepLabelMap getLabelMap(); - - /** - * Builder interface with get and set functions to build Label Update message. - */ - interface Builder { - - /** - * Builds PcepLableUpdate Object. - * - * @return PcepLableUpdate Object - * @throws PcepParseException while building LABEL-UPDATE. - */ - PcepLabelUpdate build() throws PcepParseException; - - /** - * Sets the Label Download object. - * - * @param labelDownload PCEP Label Download object - * @return Builder by setting labelDownload object - */ - Builder setLabelDownload(PcepLabelDownload labelDownload); - - /** - * Returns the PcepLabelDownload object. - * - * @return labelDownload PCEP Label Download - */ - PcepLabelDownload getLabelDownload(); - - /** - * Sets the Label map object. - * - * @param labelMap PCEP Label Map object - * @return Builder by setting PcepLabelMap object - */ - Builder setLabelMap(PcepLabelMap labelMap); - - /** - * Returns the PcepLabelMap object. - * - * @return labelMap PCEP Label Map - */ - PcepLabelMap getLabelMap(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelUpdateMsg.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelUpdateMsg.java deleted file mode 100755 index 3740df3b..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLabelUpdateMsg.java +++ /dev/null @@ -1,81 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing PCEP Label Update Message. - */ -public interface PcepLabelUpdateMsg extends PcepObject, PcepMessage { - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns list of PcLabelUpdateList. - * - * @return list of PcLabelUpdateList. - */ - LinkedList<PcepLabelUpdate> getPcLabelUpdateList(); - - /** - * Sets list of PcLabelUpdateList. - * - * @param llPcLabelUpdateList list of PcLabelUpdateList - */ - void setPcLabelUpdateList(LinkedList<PcepLabelUpdate> llPcLabelUpdateList); - - @Override - void writeTo(ChannelBuffer channelBuffer) throws PcepParseException; - - /** - * Builder interface with get and set functions to build Label Update message. - */ - interface Builder extends PcepMessage.Builder { - - @Override - PcepLabelUpdateMsg build(); - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns list of PcLabelUpdateList. - * - * @return list of PcLabelUpdateList. - */ - LinkedList<PcepLabelUpdate> getPcLabelUpdateList(); - - /** - * Sets list of PcLabelUpdateList. - * - * @param llPcLabelUpdateList list of PcLabelUpdateList. - * @return Builder by setting list of PcLabelUpdateList. - */ - Builder setPcLabelUpdateList(LinkedList<PcepLabelUpdate> llPcLabelUpdateList); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLspObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLspObject.java deleted file mode 100755 index 5d55250a..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLspObject.java +++ /dev/null @@ -1,286 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; - -/** - * Abstraction of an entity providing PCEP LSP Object. - */ -public interface PcepLspObject { - - /** - * Returns PlspId of LSP Object. - * - * @return PlspId of LSP Object - */ - int getPlspId(); - - /** - * Sets PlspId with specified value. - * - * @param value PlspId - */ - void setPlspId(int value); - - /** - * Returns O flag in LSP Object. - * - * @return O flag in LSP Object - */ - byte getOFlag(); - - /** - * Sets O flag with specified value. - * - * @param value O flag - */ - void setOFlag(byte value); - - /** - * Returns A flag in LSP Object. - * - * @return A flag in LSP Object - */ - boolean getAFlag(); - - /** - * Sets A flag with specified value. - * - * @param value A flag - */ - void setAFlag(boolean value); - - /** - * Returns R flag in LSP Object. - * - * @return R flag in LSP Object - */ - boolean getRFlag(); - - /** - * Sets R flag with specified value. - * - * @param value R flag - */ - void setRFlag(boolean value); - - /** - * Returns S flag in LSP Object. - * - * @return S flag in LSP Object - */ - boolean getSFlag(); - - /** - * Sets S flag with specified value. - * - * @param value S flag - */ - void setSFlag(boolean value); - - /** - * Returns D flag in LSP Object. - * - * @return D flag in LSP Object - */ - boolean getDFlag(); - - /** - * Sets D flag with specified value. - * - * @param value D flag - */ - void setDFlag(boolean value); - - /** - * Returns list of Optional Tlvs in LSP Object. - * - * @return list of Optional Tlvs - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets list of Optional Tlvs in LSP Object. - * - * @param llOptionalTlv list of Optional Tlvs - */ - void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Writes the LSP Object into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException while writing LSP object into Channel Buffer. - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build LSP object. - */ - interface Builder { - - /** - * Builds LSP Object. - * - * @return LSP Object - */ - PcepLspObject build(); - - /** - * Returns LSP object header. - * - * @return LSP object header - */ - PcepObjectHeader getLspObjHeader(); - - /** - * Sets LSP object header and returns its builder. - * - * @param obj LSP object header - * @return Builder by setting LSP object header - */ - Builder setLspObjHeader(PcepObjectHeader obj); - - /** - * Returns PlspId of LSP Object. - * - * @return PlspId of LSP Object - */ - int getPlspId(); - - /** - * Sets PlspId with specific value and return its builder. - * - * @param value PlspId - * @return Builder by setting PlspId - */ - Builder setPlspId(int value); - - /** - * Returns O flag in LSP Object. - * - * @return O flag in LSP Object - */ - byte getOFlag(); - - /** - * Sets O flag with specific value and return its builder. - * - * @param value O flag - * @return Builder by setting O flag - */ - Builder setOFlag(byte value); - - /** - * Returns A flag in LSP Object. - * - * @return A flag in LSP Object - */ - boolean getAFlag(); - - /** - * Sets A flag with specific value and return its builder. - * - * @param value A flag - * @return Builder by setting A flag - */ - Builder setAFlag(boolean value); - - /** - * Returns A flag in LSP Object. - * - * @return A flag in LSP Object - */ - boolean getRFlag(); - - /** - * Sets R flag with specific value and return its builder. - * - * @param value r flag - * @return Builder by setting r flag - */ - Builder setRFlag(boolean value); - - /** - * Returns S flag in LSP Object. - * - * @return S flag in LSP Object - */ - boolean getSFlag(); - - /** - * Sets S flag with specific value and return its builder. - * - * @param value s flag - * @return Builder by setting S flag - */ - Builder setSFlag(boolean value); - - /** - * Returns D flag in LSP Object. - * - * @return D flag in LSP Object - */ - boolean getDFlag(); - - /** - * Sets D flag with specific value and return its builder. - * - * @param value D flag - * @return Builder by setting D flag - */ - Builder setDFlag(boolean value); - - /** - * Returns list of Optional Tlvs in LSP Object. - * - * @return list of Optional Tlvs in LSP Object - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets list of Optional Tlvs and return its builder. - * - * @param llOptionalTlv list of Optional Tlvs - * @return Builder by setting list of Optional Tlvs - */ - Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Sets P flag in LSP object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in LSP object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLspaObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLspaObject.java deleted file mode 100755 index d541e92b..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepLspaObject.java +++ /dev/null @@ -1,286 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; - -/** - * Abstraction of an entity providing PCEP LSPA Object. - */ -public interface PcepLspaObject { - - /** - * Returns L flag in LSPA Object. - * - * @return L flag in LSPA Object - */ - boolean getLFlag(); - - /** - * Sets L flag in LSPA Object. - * - * @param value L flag - */ - void setLFlag(boolean value); - - /** - * Returns Exclude Any field in LSPA Object. - * - * @return Exclude Any field in LSPA Object - */ - int getExcludeAny(); - - /** - * Sets Exclude Any field in LSPA Object. - * - * @param value Exclude Any field - */ - void setExcludeAny(int value); - - /** - * Returns Include Any field in LSPA Object. - * - * @return Include Any field in LSPA Object - */ - int getIncludeAny(); - - /** - * Sets Include Any field in LSPA Object. - * - * @param value Include Any field - */ - void setIncludeAny(int value); - - /** - * Returns Include All field in LSPA Object. - * - * @return Include All field in LSPA Object - */ - int getIncludeAll(); - - /** - * Sets Include All field in LSPA Object. - * - * @param value Include All field - */ - void setIncludeAll(int value); - - /** - * Returns Setup Priority field in LSPA Object. - * - * @return Setup Priority field in LSPA Object - */ - byte getSetupPriority(); - - /** - * Sets Setup Priority field in LSPA Object. - * - * @param value Setup Priority field - */ - void setSetupPriority(byte value); - - /** - * Returns Hold Priority field in LSPA Object. - * - * @return Hold Priority field in LSPA Object - */ - byte getHoldPriority(); - - /** - * Sets Hold Priority field in LSPA Object. - * - * @param value Hold Priority field - */ - void setHoldPriority(byte value); - - /** - * Returns list of Optional Tlvs in LSPA Object. - * - * @return list of Optional Tlvs in LSPA Object - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets Optional Tlvs in LSPA Object. - * - * @param llOptionalTlv Optional Tlvs in LSPA Object - */ - void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Writes the LSPA Object into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException while writing LSPA object into Channel Buffer. - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build bandwidth object. - */ - interface Builder { - - /** - * Builds LSPA Object. - * - * @return LSPA Object - * @throws PcepParseException while building LSPA object. - */ - PcepLspaObject build() throws PcepParseException; - - /** - * Returns LSPA object header. - * - * @return LSPA object header - */ - PcepObjectHeader getLspaObjHeader(); - - /** - * Sets LSPA object header and returns its builder. - * - * @param obj LSPA object header - * @return Builder by setting LSPA object header - */ - Builder setLspaObjHeader(PcepObjectHeader obj); - - /** - * Returns L flag in LSPA Object. - * - * @return L flag in LSPA Object - */ - boolean getLFlag(); - - /** - * Sets L flag in LSPA Object and return its builder. - * - * @param value L flag in LSPA Object - * @return Builder by setting L flag - */ - Builder setLFlag(boolean value); - - /** - * Returns Exclude Any field in LSPA Object. - * - * @return Exclude Any field in LSPA Object - */ - int getExcludeAny(); - - /** - * Sets Exclude Any field in LSPA Object and return its builder. - * - * @param value Exclude Any field in LSPA Object - * @return Builder by setting Exclude Any field - */ - Builder setExcludeAny(int value); - - /** - * Returns Include Any field in LSPA Object. - * - * @return Include Any field in LSPA Object - */ - int getIncludeAny(); - - /** - * Sets Include Any field in LSPA Object and return its builder. - * - * @param value Include Any field in LSPA Object - * @return Builder by setting Include Any field - */ - Builder setIncludeAny(int value); - - /** - * Returns Include All field in LSPA Object. - * - * @return Include All field in LSPA Object - */ - int getIncludeAll(); - - /** - * Sets Include All field in LSPA Object and return its builder. - * - * @param value Include All field in LSPA Object - * @return Builder by setting Include All field - */ - Builder setIncludeAll(int value); - - /** - * Returns Setup Priority field in LSPA Object. - * - * @return Setup Priority field in LSPA Object - */ - byte getSetupPriority(); - - /** - * Sets Setup Priority field in LSPA Object and return its builder. - * - * @param value Setup Priority field in LSPA Object - * @return Builder by setting Setup Priority field - */ - Builder setSetupPriority(byte value); - - /** - * Returns Hold Priority field in LSPA Object. - * - * @return Hold Priority field in LSPA Object - */ - byte getHoldPriority(); - - /** - * Sets Hold Priority field in LSPA Object and return its builder. - * - * @param value Hold Priority field in LSPA Object - * @return Builder by setting Hold Priority field - */ - Builder setHoldPriority(byte value); - - /** - * Returns list of Optional Tlvs in LSPA Object. - * - * @return list of Optional Tlvs in LSPA Object - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets list of Optional Tlvs in LSPA Object. - * - * @param llOptionalTlv list of Optional Tlvs - * @return builder by setting list of Optional Tlvs - */ - Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Sets P flag in LSPA object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in LSPA object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMessage.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMessage.java deleted file mode 100755 index 7de07169..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMessage.java +++ /dev/null @@ -1,67 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing PCEP Messages. - */ -public interface PcepMessage extends PcepObject { - - @Override - PcepVersion getVersion(); - - /** - * Returns Type of PCEP Message. - * - * @return Type of PCEP Message - */ - PcepType getType(); - - @Override - void writeTo(ChannelBuffer channelBuffer) throws PcepParseException; - - /** - * Builder interface with get and set functions to build PCEP Message. - */ - interface Builder { - - /** - * Builds PCEP Message. - * - * @return PCEP Message - * @throws PcepParseException when build fails to create PCEP message - */ - PcepMessage build() throws PcepParseException; - - /** - * Returns Version of PCEP Message. - * - * @return Version of PCEP Message - */ - PcepVersion getVersion(); - - /** - * Returns Type of PCEP Message. - * - * @return Type of PCEP Message - */ - PcepType getType(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMessageReader.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMessageReader.java deleted file mode 100755 index 591a033d..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMessageReader.java +++ /dev/null @@ -1,36 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing PCEP Message Reader. - */ -public interface PcepMessageReader<T> { - - /** - * Reads the Objects in the PCEP Message and Returns PCEP Message. - * - * @param bb Channel Buffer - * @return PCEP Message - * @throws PcepParseException while parsing PCEP message. - * @throws PcepParseException when received message is empty - */ - T readFrom(ChannelBuffer bb) throws PcepParseException; -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMessageWriter.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMessageWriter.java deleted file mode 100755 index e7477b51..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMessageWriter.java +++ /dev/null @@ -1,35 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing PCEP Message Writer. - */ -public interface PcepMessageWriter<T> { - - /** - * Writes the Objects of the PCEP Message into Channel Buffer. - * - * @param bb Channel Buffer - * @param message PCEP Message - * @throws PcepParseException while writing PCEP message. - */ - void write(ChannelBuffer bb, T message) throws PcepParseException; -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMetricObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMetricObject.java deleted file mode 100755 index 380fb42e..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMetricObject.java +++ /dev/null @@ -1,225 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; - -/** - * Abstraction of an entity providing PCEP Metric Object. - */ -public interface PcepMetricObject { - - /** - * Returns Metric value in Metric Object. - * - * @return Metric value - */ - int getMetricVal(); - - /** - * Sets Metric value in Metric Object with specified value. - * - * @param value Metric value - */ - void setMetricVal(int value); - - /** - * Returns Y flag in Metric Object. - * - * @return Y flag in Metric Object - */ - byte getYFlag(); - - /** - * Sets Y flag in Metric Object with specified value. - * - * @param value Y flag - */ - void setYFlag(byte value); - - /** - * Returns C flag in Metric Object. - * - * @return C flag in Metric Object - */ - boolean getCFlag(); - - /** - * Sets C flag in Metric Object with specified value. - * - * @param value C flag - */ - void setCFlag(boolean value); - - /** - * Returns B flag in Metric Object. - * - * @return B flag in Metric Object - */ - boolean getBFlag(); - - /** - * Sets B flag in Metric Object with specified value. - * - * @param value B flag - */ - void setBFlag(boolean value); - - /** - * Returns BType field in Metric Object. - * - * @return BType field in Metric Object - */ - byte getBType(); - - /** - * Sets BType field in Metric Object with specified value. - * - * @param value BType field - */ - void setBType(byte value); - - /** - * Writes the Metric Object into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException while writing METRIC object into Channel Buffer. - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build Metric object. - */ - interface Builder { - - /** - * Builds Metric Object. - * - * @return Metric Object - * @throws PcepParseException when mandatory object is not set - */ - PcepMetricObject build() throws PcepParseException; - - /** - * Returns Metric object header. - * - * @return Metric object header - */ - PcepObjectHeader getMetricObjHeader(); - - /** - * Sets Metric object header and returns its builder. - * - * @param obj Metric object header - * @return Builder by setting Metric object header - */ - Builder setMetricObjHeader(PcepObjectHeader obj); - - /** - * Returns Metric value in Metric Object. - * - * @return Metric value - */ - int getMetricVal(); - - /** - * Sets Metric Value in Metric Object and returns its builder. - * - * @param value Metric Value - * @return Builder by setting Metric Value - */ - Builder setMetricVal(int value); - - /** - * Returns Flags in Metric Object. - * - * @return Flags in Metric Object - */ - byte getYFlag(); - - /** - * Sets Flags in Metric Object and returns its builder. - * - * @param value Flags - * @return Builder by setting Flags - */ - Builder setYFlag(byte value); - - /** - * Returns C flag in Metric Object. - * - * @return C flag in Metric Object - */ - boolean getCFlag(); - - /** - * Sets C flag in Metric Object and returns its builder. - * - * @param value C flag - * @return Builder by setting C flag - */ - Builder setCFlag(boolean value); - - /** - * Returns B flag in Metric Object. - * - * @return B flag in Metric Object - */ - boolean getBFlag(); - - /** - * Sets B flag in Metric Object and returns its builder. - * - * @param value B flag - * @return Builder by setting B flag - */ - Builder setBFlag(boolean value); - - /** - * Returns BType field in Metric Object. - * - * @return BType field in Metric Object - */ - byte getBType(); - - /** - * Sets B Type field in Metric Object and returns its builder. - * - * @param value B Type field - * @return Builder by setting B Type field - */ - Builder setBType(byte value); - - /** - * Sets P flag in Metric object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in Metric object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMsgPath.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMsgPath.java deleted file mode 100644 index 4b1d50a5..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepMsgPath.java +++ /dev/null @@ -1,117 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity Provides PCEP Message PAth for update message. - * Reference :PCE extensions for stateful draft-ietf-pce-stateful-pce-10. - */ -public interface PcepMsgPath { - - /** - * Returns object of PcepEroObject. - * - * @return eroObject - */ - PcepEroObject getEroObject(); - - /** - * Returns object of PcepAttribute. - * - * @return pcepAttribute - */ - PcepAttribute getPcepAttribute(); - - /** - * Sets PcepEroObject. - * - * @param eroObject PCEP ERO Object. - */ - void setEroObject(PcepEroObject eroObject); - - /** - * Sets PcepAttribute. - * - * @param pcepAttribute PCEP-Attribute. - */ - void setPcepAttribute(PcepAttribute pcepAttribute); - - /** - * reads ERO object and attribute list. - * - * @param bb of type channel buffer - * @return PcepMsgPath - * @throws PcepParseException while parsing Message Path from Channel Buffer. - */ - PcepMsgPath read(ChannelBuffer bb) throws PcepParseException; - - /** - * writes ERO object and attribute list to channel. - * - * @param bb of type channel buffer - * @return object length index - * @throws PcepParseException while writing Message Path into Channel Buffer. - */ - - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build PcepMsgPath. - */ - interface Builder { - - /** - * Builds PcepMsgPath. - * - * @return PcepMsgPath - * @throws PcepParseException when mandatory object is not set - */ - PcepMsgPath build() throws PcepParseException; - - /** - * Returns object of PcepEroObject. - * - * @return PcepEroObject - */ - PcepEroObject getEroObject(); - - /** - * Returns object of PcepAttribute. - * - * @return pcepAttribute - */ - PcepAttribute getPcepAttribute(); - - /** - * Sets PcepEroObject. - * - * @param eroObject PcepEroObject - * @return Builder by setting ERO object. - */ - Builder setEroObject(PcepEroObject eroObject); - - /** - * Sets PcepAttribute. - * - * @param pcepAttribute PCEP-Attribute - * @return Builder by setting PCEP-Attribute. - */ - Builder setPcepAttribute(PcepAttribute pcepAttribute); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepNai.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepNai.java deleted file mode 100755 index 6be8c65a..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepNai.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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; - -/** - * Abstraction of an entity provides NAI information in SR ERO Object. - */ -public interface PcepNai { - - /** - * To get the ST type of the NAI information. - * - * @return type of ST info - */ - byte getType(); - - /** - * To write the object information to channelBuffer. - * - * @param cb of type channel buffer - * @return length of written bytes. - */ - int write(ChannelBuffer cb); -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepObject.java deleted file mode 100755 index 26dad566..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepObject.java +++ /dev/null @@ -1,30 +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.pcepio.protocol; - -/** - * Abstraction of an entity providing PCEP Object. - */ -public interface PcepObject extends Writeable { - - /** - * Returns Version of PCEP Object. - * - * @return Version of PCEP Object - */ - PcepVersion getVersion(); -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepOpenMsg.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepOpenMsg.java deleted file mode 100644 index 904156f0..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepOpenMsg.java +++ /dev/null @@ -1,73 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing PCEP Open Message. - */ -public interface PcepOpenMsg extends PcepObject, PcepMessage { - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Sets OpenObject in Open Message with Specified Obj. - * - * @param obj OpenObject - */ - void setPcepOpenObject(PcepOpenObject obj); - - /** - * Returns OpenObject in Open Message. - * - * @return OpenObject in Open Message - */ - PcepOpenObject getPcepOpenObject(); - - @Override - void writeTo(ChannelBuffer channelBuffer) throws PcepParseException; - - /** - * Builder interface with get and set functions to build Open message. - */ - interface Builder extends PcepMessage.Builder { - - @Override - PcepOpenMsg build() throws PcepParseException; - - /** - * Sets Open Object in Open Message and return its builder. - * - * @param obj Open Object - * @return builder by setting Open Object - */ - Builder setPcepOpenObj(PcepOpenObject obj); - - /** - * Returns OpenObject in Open Message. - * - * @return OpenObject in Open Message - */ - PcepOpenObject getPcepOpenObj(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepOpenObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepOpenObject.java deleted file mode 100755 index 13dd2fa8..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepOpenObject.java +++ /dev/null @@ -1,221 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; - -/** - * Abstraction of an entity providing PCEP Open Object. - */ -public interface PcepOpenObject { - - /** - * Returns Open object header. - * - * @return Open object header - */ - PcepObjectHeader getOpenObjHeader(); - - /** - * Sets Open object header in Open Object. - * - * @param obj Open object header - */ - void setOpenObjHeader(PcepObjectHeader obj); - - /** - * Returns version of Open Object. - * - * @return Version of Open Object - */ - PcepVersion getVersion(); - - /** - * Returns KeepAlive Time in Open Object. - * - * @return KeepAlive Time in Open Object - */ - byte getKeepAliveTime(); - - /** - * Sets KeepAlive Time in Open Object with specified value. - * - * @param value KeepAlive Time - */ - void setKeepAliveTime(byte value); - - /** - * Returns Dead Time in Open Object. - * - * @return Dead Time in Open Object - */ - byte getDeadTime(); - - /** - * Sets Dead Time in Open Object with specified value. - * - * @param value Dead Time - */ - void setDeadTime(byte value); - - /** - * Returns SessionId in Open Object. - * - * @return SessionId in Open Object - */ - byte getSessionId(); - - /** - * Sets SessionId in Open Object with specified value. - * - * @param value SessionId - */ - void setSessionId(byte value); - - /** - * Returns list of Optional Tlvs in Open Object. - * - * @return list of Optional Tlvs - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets list of Optional Tlvs in Open Object. - * - * @param llOptionalTlv list of Optional Tlvs - */ - void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Writes the Open into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException while writing Open Object into Channel Buffer. - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build Open object. - */ - interface Builder { - - /** - * Builds Open Object. - * - * @return Open Object - * @throws PcepParseException while building PCEP-Open object - */ - PcepOpenObject build() throws PcepParseException; - - /** - * Returns Open object header. - * - * @return Open object header - */ - PcepObjectHeader getOpenObjHeader(); - - /** - * Sets Open object header and returns its builder. - * - * @param obj Open object header - * @return Builder by setting Open object header - */ - Builder setOpenObjHeader(PcepObjectHeader obj); - - /** - * Returns KeepAlive Time in Open Object. - * - * @return KeepAlive Time in Open Object - */ - byte getKeepAliveTime(); - - /** - * Sets KeepAlive Time and returns its builder. - * - * @param value KeepAlive Time - * @return Builder by setting KeepAlive Time - */ - Builder setKeepAliveTime(byte value); - - /** - * Returns Dead Time in Open Object. - * - * @return Dead Time in Open Object - */ - byte getDeadTime(); - - /** - * Sets Dead Time and returns its builder. - * - * @param value Dead Time - * @return Builder by setting Dead Time - */ - Builder setDeadTime(byte value); - - /** - * Returns SessionId in Open Object. - * - * @return SessionId in Open Object - */ - byte getSessionId(); - - /** - * Sets SessionId and returns its builder. - * - * @param value SessionId - * @return Builder by setting SessionId - */ - Builder setSessionId(byte value); - - /** - * Returns list of Optional Tlvs in Open Object. - * - * @return list of Optional Tlvs in Open Object - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets list of Optional Tlvs and return its Builder. - * - * @param llOptionalTlv list of Optional Tlvs - * @return builder by setting list of Optional Tlvs - */ - Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Sets P flag in Open object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in Open object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepRPObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepRPObject.java deleted file mode 100755 index c6993c3a..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepRPObject.java +++ /dev/null @@ -1,256 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; - -/** - * Abstraction of an entity providing PCEP RP Object. - */ -public interface PcepRPObject { - - /** - * Returns RequestId Number in RP Object. - * - * @return RequestId Number in RP Object - */ - int getRequestIdNum(); - - /** - * Sets RequestId Number with specified value. - * - * @param value RequestId Number - */ - void setRequestIdNum(int value); - - /** - * Returns O flag in RP Object. - * - * @return O flag in RP Object - */ - boolean getOFlag(); - - /** - * Sets O flag with specified value. - * - * @param value O flag - */ - void setOFlag(boolean value); - - /** - * Returns B flag in RP Object. - * - * @return B flag in RP Object - */ - boolean getBFlag(); - - /** - * Sets B flag with specified value. - * - * @param value B flag - */ - void setBFlag(boolean value); - - /** - * Returns R flag in RP Object. - * - * @return R flag in RP Object - */ - boolean getRFlag(); - - /** - * Sets R flag with specified value. - * - * @param value R flag - */ - void setRFlag(boolean value); - - /** - * Returns Priority Flag in RP Object. - * - * @return Priority Flag in RP Object - */ - byte getPriFlag(); - - /** - * Sets Priority Flag with specified value. - * - * @param value Priority Flag - */ - void setPriFlag(byte value); - - /** - * Returns list of Optional Tlvs in RP Object. - * - * @return list of Optional Tlvs in RP Object - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets list of Optional Tlvs in RP Object and returns its builder. - * - * @param llOptionalTlv list of Optional Tlvs - */ - void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Writes the RP Object into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException while writing RP object into Channel Buffer. - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build bandwidth object. - */ - interface Builder { - - /** - * Builds RP Object. - * - * @return RP Object - */ - PcepRPObject build(); - - /** - * Returns RP object header. - * - * @return RP object header - */ - PcepObjectHeader getRPObjHeader(); - - /** - * Sets RP object header and returns its builder. - * - * @param obj RP object header - * @return Builder by setting RP object header - */ - Builder setRPObjHeader(PcepObjectHeader obj); - - /** - * Returns Request Id Number in RP Object. - * - * @return Request Id Number in RP Object - */ - int getRequestIdNum(); - - /** - * Sets Request Id Number and returns its builder. - * - * @param value Request Id Number - * @return Builder by setting Request Id Number - */ - Builder setRequestIdNum(int value); - - /** - * Returns O flag in RP Object. - * - * @return O flag in RP Object - */ - boolean getOFlag(); - - /** - * Sets O flag and returns its builder. - * - * @param value O flag - * @return Builder by setting O flag - */ - Builder setOFlag(boolean value); - - /** - * Returns B flag in RP Object. - * - * @return B flag in RP Object - */ - boolean getBFlag(); - - /** - * Sets B flag and returns its builder. - * - * @param value B flag - * @return Builder by setting B flag - */ - Builder setBFlag(boolean value); - - /** - * Returns R flag in RP Object. - * - * @return R flag in RP Object - */ - boolean getRFlag(); - - /** - * Sets R flag and returns its builder. - * - * @param value R flag - * @return Builder by setting R flag - */ - Builder setRFlag(boolean value); - - /** - * Returns Priority Flag in RP Object. - * - * @return Priority Flag in RP Object - */ - byte getPriFlag(); - - /** - * Sets Priority Flag and returns its builder. - * - * @param value Priority Flag - * @return Builder by setting Priority Flag - */ - Builder setPriFlag(byte value); - - /** - * Returns list of Optional Tlvs in RP Object. - * - * @return list of Optional Tlvs - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets list of Optional Tlvs and returns its builder. - * - * @param llOptionalTlv list of Optional Tlvs - * @return Builder by setting list of Optional Tlvs - */ - Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Sets P flag in RP object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in RP object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepReportMsg.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepReportMsg.java deleted file mode 100755 index f4355206..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepReportMsg.java +++ /dev/null @@ -1,81 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing PCEP Report Message. - */ -public interface PcepReportMsg extends PcepObject, PcepMessage { - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns PcepStateReport list. - * - * @return list of PcepStateReport - */ - LinkedList<PcepStateReport> getStateReportList(); - - /** - * Sets StateReportList. - * - * @param llStateReportList list of PcepStateReport. - */ - void setStateReportList(LinkedList<PcepStateReport> llStateReportList); - - @Override - void writeTo(ChannelBuffer channelBuffer) throws PcepParseException; - - /** - * Builder interface with get and set functions to build Report message. - */ - interface Builder extends PcepMessage.Builder { - - @Override - PcepReportMsg build(); - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns StateReportList. - * - * @return StateReportList. - */ - LinkedList<PcepStateReport> getStateReportList(); - - /** - * Sets list of PcepStateReport and returns builder. - * - * @param llStateReportList list of PcepStateReport. - * @return Builder by setting list of PcepStateReport. - */ - Builder setStateReportList(LinkedList<PcepStateReport> llStateReportList); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepRroObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepRroObject.java deleted file mode 100755 index 928ce1a6..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepRroObject.java +++ /dev/null @@ -1,111 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; - -/** - * Abstraction of an entity providing PCEP RRO Object. - */ -public interface PcepRroObject { - - /** - * Returns list of SubObjects. - * - * @return list of SubObjects - */ - LinkedList<PcepValueType> getSubObjects(); - - /** - * Sets list of SubObjects and return its builder. - * - * @param llSubObjects list of SubObjects - */ - void setSubObjects(LinkedList<PcepValueType> llSubObjects); - - /** - * Writes the RRO Object into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException when object header failed to write in channel buffer - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build RRO object. - */ - interface Builder { - - /** - * Builds RRO Object. - * - * @return RRO Object - */ - PcepRroObject build(); - - /** - * Returns RRO object header. - * - * @return RRO object header - */ - PcepObjectHeader getRroObjHeader(); - - /** - * Sets RRO object header and returns its builder. - * - * @param obj RRO object header - * @return Builder by setting RRO object header - */ - Builder setRroObjHeader(PcepObjectHeader obj); - - /** - * Returns list of SubObjects. - * - * @return list of SubObjects - */ - LinkedList<PcepValueType> getSubObjects(); - - /** - * Sets list of SubObjects in RRO Object and returns its builder. - * - * @param llSubObjects list of SubObjects - * @return Builder by setting list of SubObjects - */ - Builder setSubObjects(LinkedList<PcepValueType> llSubObjects); - - /** - * Sets P flag in RRO object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in RRO object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepSrpObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepSrpObject.java deleted file mode 100755 index e4816efd..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepSrpObject.java +++ /dev/null @@ -1,171 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; - -/** - * Abstraction of an entity providing PCEP SRP Object. - */ -public interface PcepSrpObject { - - /** - * Returns SRP ID of SRP Object. - * - * @return SRP ID of SRP Object - */ - int getSrpID(); - - /** - * Sets SRP ID with specified value. - * - * @param srpID SRP ID of SRP Object - */ - void setSrpID(int srpID); - - /** - * Returns R flag of SRP Object. - * - * @return R flag of SRP Object - */ - boolean getRFlag(); - - /** - * Sets R flag with specified value. - * - * @param bRFlag R Flag of SRP Object - */ - void setRFlag(boolean bRFlag); - - /** - * sets the optional TLvs. - * - * @param llOptionalTlv list of optional tlvs - */ - void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Returns list of optional tlvs. - * - * @return llOptionalTlv list of optional tlvs - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Writes the SRP Object into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException when tlv is null - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build SRP object. - */ - interface Builder { - - /** - * Builds SRP Object. - * - * @return SRP Object - * @throws PcepParseException when mandatory object is not set - */ - PcepSrpObject build() throws PcepParseException; - - /** - * Returns SRP object header. - * - * @return SRP object header - */ - PcepObjectHeader getSrpObjHeader(); - - /** - * Sets SRP object header and returns its builder. - * - * @param obj SRP object header - * @return Builder by setting SRP object header - */ - Builder setSrpObjHeader(PcepObjectHeader obj); - - /** - * Returns SRP ID of SRP Object. - * - * @return SRP ID of SRP Object - */ - int getSrpID(); - - /** - * Sets SRP ID and returns its builder. - * - * @param srpID SRP ID - * @return Builder by setting SRP ID - */ - Builder setSrpID(int srpID); - - /** - * Returns R flag of SRP Object. - * - * @return R flag of SRP Object - */ - boolean getRFlag(); - - /** - * Sets R flag and returns its builder. - * - * @param bRFlag R flag - * @return Builder by setting R flag - */ - Builder setRFlag(boolean bRFlag); - - /** - * Returns list of optional tlvs. - * - * @return llOptionalTlv list of optional tlvs - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * sets the optional TLvs. - * - * @param llOptionalTlv List of optional tlv - * @return builder by setting list of optional tlv. - */ - Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Sets P flag in SRP object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in SRP object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepStateReport.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepStateReport.java deleted file mode 100755 index b8ab9ec8..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepStateReport.java +++ /dev/null @@ -1,207 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity provides State Report for PCEP Report Message. - */ -public interface PcepStateReport { - - /** - * Provides PCEP Message path for report message. - */ - interface PcepMsgPath { - - /** - * Returns PcepEroObject. - * - * @return eroObj - */ - PcepEroObject getEroObject(); - - /** - * Sets PcepEroObject. - * - * @param eroObject Ero Object - */ - void setEroObject(PcepEroObject eroObject); - - /** - * Returns PcepAttribute. - * - * @return attrList - */ - PcepAttribute getPcepAttribute(); - - /** - * Sets PcepAttribute. - * - * @param pcepAttribute Pcep Attribute object - */ - void setPcepAttribute(PcepAttribute pcepAttribute); - - /** - * Returns PcepRroObject. - * - * @return rroObj - */ - PcepRroObject getRroObject(); - - /** - * Sets PcepRroObject. - * - * @param rroObject Rro object - */ - void setRroObject(PcepRroObject rroObject); - - /** - * Returns PcepBandwidthObject. - * - * @return bandwidth object - */ - PcepBandwidthObject getBandwidthObject(); - - /** - * Sets PcepBandwidthObject. - * - * @param bandwidth bandwidth object - */ - void setBandwidthObject(PcepBandwidthObject bandwidth); - - /** - * Reads all the Objects for PCEP Message Path. - * - * @param bb of type channel buffer - * @return PCEP Message path - * @throws PcepParseException when invalid buffer received - */ - PcepMsgPath read(ChannelBuffer bb) throws PcepParseException; - - /** - * Writes all the objects for pcep message path. - * - * @param bb of type channel buffer. - * @return object length index - * @throws PcepParseException when mandatory object is not set - */ - int write(ChannelBuffer bb) throws PcepParseException; - } - - /** - * Returns PcepSrpObject. - * - * @return srpObject - */ - PcepSrpObject getSrpObject(); - - /** - * Returns PcepLspObject. - * - * @return lspObject - */ - PcepLspObject getLspObject(); - - /** - * Returns PcepMsgPath. - * - * @return msgPath - */ - PcepMsgPath getMsgPath(); - - /** - * Sets the SRP Object. - * - * @param srpObj Pcep Srp Object - */ - void setSrpObject(PcepSrpObject srpObj); - - /** - * Sets the LSP Object. - * - * @param lspObject Pcep Lsp Object - */ - void setLspObject(PcepLspObject lspObject); - - /** - * Sets the Path Object. - * - * @param msgPath Pcep MsgPath object - */ - void setMsgPath(PcepMsgPath msgPath); - - /** - * Builder interface with get and set functions to build PcepStateReport. - */ - interface Builder { - - /** - * Builds PcepStateReport. - * - * @return PcepStateReport - * @throws PcepParseException when mandatory object is not set - */ - PcepStateReport build() throws PcepParseException; - - /** - * Returns PcepSrpObject. - * - * @return srpObject - */ - PcepSrpObject getSrpObject(); - - /** - * Returns PcepLspObject. - * - * @return lspObject - */ - PcepLspObject getLspObject(); - - /** - * Returns PcepMsgPath. - * - * @return msgPath - */ - PcepMsgPath getMsgPath(); - - /** - * Sets the SRP Object. - * - * @param srpObj Pcep Srp Object - * @return builder by setting PcepSrpObject - */ - Builder setSrpObject(PcepSrpObject srpObj); - - /** - * Sets the LSP Object. - * - * @param lspObject Pcep Lsp Object - * @return builder by setting PcepLspObject - */ - Builder setLspObject(PcepLspObject lspObject); - - /** - * Sets the Path Object. - * - * @param msgPath Pcep MsgPath object - * @return builder by setting PcepMsgPath - */ - Builder setMsgPath(PcepMsgPath msgPath); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepTEObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepTEObject.java deleted file mode 100755 index 21f6c71c..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepTEObject.java +++ /dev/null @@ -1,241 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; - -/** - * Abstraction of an entity providing PCEP TE Object. - */ -public interface PcepTEObject { - - /** - * Returns TE object header. - * - * @return TE object header - */ - PcepObjectHeader getTEObjHeader(); - - /** - * Sets TE Object header. - * - * @param obj TE Object header - */ - void setTEObjHeader(PcepObjectHeader obj); - - /** - * Returns ProtocolId in TE Object. - * - * @return ProtocolId in TE Object - */ - byte getProtocolId(); - - /** - * Sets ProtocolId in TE Object. - * - * @param yProtId ProtocolId in TE Object - */ - void setProtocolId(byte yProtId); - - /** - * Returns R flag in TE Object. - * - * @return R flag in TE Object - */ - boolean getRFlag(); - - /** - * Sets R flag in TE Object. - * - * @param bRFlag R flag in TE Object - */ - void setRFlag(boolean bRFlag); - - /** - * Returns S flag in TE Object. - * - * @return S flag in TE Object - */ - boolean getSFlag(); - - /** - * Sets S flag in TE Object. - * - * @param bSFlag S flag in TE Object - */ - void setSFlag(boolean bSFlag); - - /** - * Returns TE ID in TE Object. - * - * @return TE ID in TE Object - */ - int getTEId(); - - /** - * Sets TE ID in TE Object. - * - * @param iTEId TE ID in TE Object - */ - void setTEId(int iTEId); - - /** - * Returns list of Optional Tlvs in TE Object. - * - * @return list of Optional Tlvs - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets list of Optional Tlvs in TE Object. - * - * @param llOptionalTlv list of Optional Tlvs - */ - void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Writes the TE Object into channel buffer. - * - * @param bb channel buffer - * @return Returns the writerIndex of this buffer - * @throws PcepParseException when obj header is not written to channel buffer - */ - int write(ChannelBuffer bb) throws PcepParseException; - - /** - * Builder interface with get and set functions to build TE object. - */ - interface Builder { - - /** - * Builds TE Object. - * - * @return TE Object - */ - PcepTEObject build(); - - /** - * Returns TE object header. - * - * @return TE object header - */ - PcepObjectHeader getTEObjHeader(); - - /** - * Sets TE object header and returns its builder. - * - * @param obj TE object header - * @return Builder by setting TE object header - */ - Builder setTEObjHeader(PcepObjectHeader obj); - - /** - * Returns ProtocolId in TE Object. - * - * @return ProtocolId in TE Object - */ - byte getProtocolId(); - - /** - * Sets ProtocolId in TE Object and returns its builder. - * - * @param yProtId ProtocolId in TE Object - * @return Builder by setting ProtocolId - */ - Builder setProtocolId(byte yProtId); - - /** - * Returns R flag in TE Object. - * - * @return R flag in TE Object - */ - boolean getRFlag(); - - /** - * Sets R flag in TE Object and returns its builder. - * - * @param bRFlag R flag in TE Object - * @return Builder by setting R flag - */ - Builder setRFlag(boolean bRFlag); - - /** - * Returns S flag in TE Object. - * - * @return S flag in TE Object - */ - boolean getSFlag(); - - /** - * Sets S flag in TE Object and returns its builder. - * - * @param bSFlag S flag in TE Object - * @return Builder by setting S flag - */ - Builder setSFlag(boolean bSFlag); - - /** - * Returns TE ID in TE Object. - * - * @return TE ID in TE Object - */ - int getTEId(); - - /** - * Sets TE ID in TE Object and returns its builder. - * - * @param iTEId TE ID in TE Object - * @return Builder by setting TE ID - */ - Builder setTEId(int iTEId); - - /** - * Returns list of Optional Tlvs in TE Object. - * - * @return list of Optional Tlvs - */ - LinkedList<PcepValueType> getOptionalTlv(); - - /** - * Sets list of Optional Tlvs in TE Object and returns its builder. - * - * @param llOptionalTlv list of Optional Tlvs - * @return Builder by setting list of Optional Tlvs - */ - Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv); - - /** - * Sets P flag in TE object header and returns its builder. - * - * @param value boolean value to set P flag - * @return Builder by setting P flag - */ - Builder setPFlag(boolean value); - - /** - * Sets I flag in TE object header and returns its builder. - * - * @param value boolean value to set I flag - * @return Builder by setting I flag - */ - Builder setIFlag(boolean value); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepTEReportMsg.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepTEReportMsg.java deleted file mode 100755 index 3bc5034e..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepTEReportMsg.java +++ /dev/null @@ -1,81 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing PCEP TE Report Message. - */ -public interface PcepTEReportMsg extends PcepObject, PcepMessage { - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns list of PCEP TE Objects. - * - * @return list of PCEP TE Objects - */ - LinkedList<PcepTEObject> getTEReportList(); - - /** - * Sets list of Optional Tlvs in TE Report Message. - * - * @param llTEReportList list of optional Tlvs - */ - void setTEReportList(LinkedList<PcepTEObject> llTEReportList); - - @Override - void writeTo(ChannelBuffer channelBuffer) throws PcepParseException; - - /** - * Builder interface with get and set functions to build TE Report message. - */ - interface Builder extends PcepMessage.Builder { - - @Override - PcepTEReportMsg build(); - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns list of Optional Tlv in TE Report Message. - * - * @return list of Optional Tlv - */ - LinkedList<PcepTEObject> getTEReportList(); - - /** - * Sets list of Optional Tlvs and returns its builder. - * - * @param llTEReportList list of Optional Tlvs - * @return Builder object for TE report message - */ - Builder setTEReportList(LinkedList<PcepTEObject> llTEReportList); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepType.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepType.java deleted file mode 100755 index 450fdfac..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepType.java +++ /dev/null @@ -1,49 +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.pcepio.protocol; - -/** - * Enum to Provide the Different types of PCEP messages. - */ -public enum PcepType { - - NONE(0), OPEN(1), KEEP_ALIVE(2), PATH_COMPUTATION_REQUEST(3), PATH_COMPUTATION_REPLY(4), - NOTIFICATION(5), ERROR(6), CLOSE(7), REPORT(10), UPDATE(11), INITIATE(12), LABEL_UPDATE(13), - TE_REPORT(14), LABEL_RANGE_RESERV(15), MAX(16), END(17); - - int iValue; - - /** - * Assign iValue with the value iVal as the types of PCEP message. - * - * @param iVal type of pcep message - */ - PcepType(int iVal) { - - iValue = iVal; - } - - /** - * Returns iValue as type of PCEP message. - * - * @return iValue type of pcep message - */ - public byte getType() { - - return (byte) iValue; - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepUpdateMsg.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepUpdateMsg.java deleted file mode 100755 index dc2ac3a8..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepUpdateMsg.java +++ /dev/null @@ -1,81 +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.pcepio.protocol; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing PCEP Update Message. - */ -public interface PcepUpdateMsg extends PcepObject, PcepMessage { - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns the update request list for PCEP Update Message. - * - * @return list of Update Requests - */ - LinkedList<PcepUpdateRequest> getUpdateRequestList(); - - /** - * Sets the update request list for PCEP update message. - * - * @param llUpdateRequestList is a list of PCEP Update Requests - */ - void setUpdateRequestList(LinkedList<PcepUpdateRequest> llUpdateRequestList); - - @Override - void writeTo(ChannelBuffer channelBuffer) throws PcepParseException; - - /** - * Builder interface with Get and Set Functions to build the PCEP update Message. - */ - interface Builder extends PcepMessage.Builder { - - @Override - PcepUpdateMsg build(); - - @Override - PcepVersion getVersion(); - - @Override - PcepType getType(); - - /** - * Returns the update request list for the PCEP update message. - * - * @return list of Update Requests - */ - LinkedList<PcepUpdateRequest> getUpdateRequestList(); - - /** - * Sets the update request list for the PCEP update message. - * - * @param llUpdateRequestList list of Update requests - * @return builder by setting list llUpdateRequestList of PcepUpdateRequest. - */ - Builder setUpdateRequestList(LinkedList<PcepUpdateRequest> llUpdateRequestList); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepUpdateRequest.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepUpdateRequest.java deleted file mode 100755 index 8d1c89e2..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepUpdateRequest.java +++ /dev/null @@ -1,126 +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.pcepio.protocol; - -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing PCEP Update Request List. - */ -public interface PcepUpdateRequest { - - /** - * Returns object of PCEP SRP Object. - * - * @return srpObject of type PCEP SRP Object - */ - PcepSrpObject getSrpObject(); - - /** - * Returns object of PCEP LSP Object. - * - * @return lspObject of type PCEP LSP Object - */ - PcepLspObject getLspObject(); - - /** - * Returns object of PCEP MSG PATH. - * - * @return msgPath of type PCEP MSG PATH - */ - PcepMsgPath getMsgPath(); - - /** - * Sets the PCEP SRP Object. - * - * @param srpObject object of type PCEP SRP Object - */ - void setSrpObject(PcepSrpObject srpObject); - - /** - * Sets the PCEP LSP Object. - * - * @param lspObject object of type PCEP LSP Object - */ - void setLspObject(PcepLspObject lspObject); - - /** - * sets the PCEP MSG PATH. - * - * @param msgPath object of type PCEP MSG PATH - */ - void setMsgPath(PcepMsgPath msgPath); - - /** - * Builder interface with get and set functions to build PcepUpdateRequest. - */ - interface Builder { - - /** - * Builds PcepUpdateRequest. - * - * @return PcepUpdateRequest - * @throws PcepParseException if mandatory object is not set - */ - PcepUpdateRequest build() throws PcepParseException; - - /** - * Returns PcepSrpObject. - * - * @return srpObject - */ - PcepSrpObject getSrpObject(); - - /** - * Returns PcepLspObject. - * - * @return lspObject - */ - PcepLspObject getLspObject(); - - /** - * Returns PcepMsgPath. - * - * @return msgPath - */ - PcepMsgPath getMsgPath(); - - /** - * Sets the SRP Object. - * - * @param srpObj of type PcepSrpObject - * @return builder by setting PcepSrpObject - */ - Builder setSrpObject(PcepSrpObject srpObj); - - /** - * Sets the LSP Object. - * - * @param lspObject of type PcepLspObject - * @return builder by setting PcepLspObject - */ - Builder setLspObject(PcepLspObject lspObject); - - /** - * Sets the Path Object. - * - * @param msgPath of type PcepMsgPath - * @return builder by setting PcepMsgPath - */ - Builder setMsgPath(PcepMsgPath msgPath); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepVersion.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepVersion.java deleted file mode 100755 index c761ed08..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/PcepVersion.java +++ /dev/null @@ -1,46 +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.pcepio.protocol; - -/** - * Enum to provide PCEP Message Version. - */ -public enum PcepVersion { - - PCEP_1(1); - - public final int packetVersion; - - /** - * Assign PCEP PacketVersion with WireVersion. - * - * @param wireVersion version of pcep - */ - PcepVersion(final int wireVersion) { - - this.packetVersion = wireVersion; - } - - /** - * Returns Wire version of PCEP Message. - * - * @return packetVersion - */ - public int getWireVersion() { - return packetVersion; - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/Writeable.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/Writeable.java deleted file mode 100755 index 37aef58d..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/Writeable.java +++ /dev/null @@ -1,35 +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.pcepio.protocol; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; - -/** - * Abstraction of an entity providing functionality to write byte streams of - * Messages to channel buffer. - */ -public interface Writeable { - - /** - * Writes byte streams of messages to channel buffer. - * - * @param bb parameter of type channel buffer - * @throws PcepParseException when error occurs while writing pcep message to channel buffer - */ - void writeTo(ChannelBuffer bb) throws PcepParseException; -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/package-info.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/package-info.java deleted file mode 100644 index 53ee5934..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/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. - */ - -/** - * Abstraction of an entity providing PCEP messages. - */ -package org.onosproject.pcepio.protocol; diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcInitiatedLspRequestVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcInitiatedLspRequestVer1.java deleted file mode 100644 index d61f7319..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcInitiatedLspRequestVer1.java +++ /dev/null @@ -1,291 +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.pcepio.protocol.ver1; - -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcInitiatedLspRequest; -import org.onosproject.pcepio.protocol.PcepAttribute; -import org.onosproject.pcepio.protocol.PcepEndPointsObject; -import org.onosproject.pcepio.protocol.PcepEroObject; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PcInitiatedLspRequest for PCEP Initiate message. - * Reference : PCE initiated tunnel setup draft-ietf-pce-pce-initiated-lsp-03. - */ -public class PcInitiatedLspRequestVer1 implements PcInitiatedLspRequest { - - /* - * <PCE-initiated-lsp-request> ::= (<PCE-initiated-lsp-instantiation>|<PCE-initiated-lsp-deletion>) - <PCE-initiated-lsp-instantiation> ::= <SRP> - <LSP> - <END-POINTS> - <ERO> - [<attribute-list>] - <PCE-initiated-lsp-deletion> ::= <SRP> - <LSP> - */ - - protected static final Logger log = LoggerFactory.getLogger(PcInitiatedLspRequestVer1.class); - - //PCEP SRP Object - private PcepSrpObject srpObject; - //PCEP LSP Object - private PcepLspObject lspObject; - //PCEP End Point Object - private PcepEndPointsObject endPointsObject; - //PCEP ERO Object - private PcepEroObject eroObject; - //PCEP Attribute list - private PcepAttribute pcepAttribute; - - /** - * Default constructor. - */ - public PcInitiatedLspRequestVer1() { - srpObject = null; - lspObject = null; - endPointsObject = null; - eroObject = null; - pcepAttribute = null; - - } - - /** - * Constructor to initialize all parameters of PC initiated lsp request. - * - * @param srpObject PCEP srp Object - * @param lspObject PCEP lsp object - * @param endPointsObject PCPE endpoints object - * @param eroObject PCEP ero object - * @param pcepAttribute PCEP attribute - */ - public PcInitiatedLspRequestVer1(PcepSrpObject srpObject, PcepLspObject lspObject, - PcepEndPointsObject endPointsObject, PcepEroObject eroObject, PcepAttribute pcepAttribute) { - this.srpObject = srpObject; - this.lspObject = lspObject; - this.endPointsObject = endPointsObject; - this.eroObject = eroObject; - this.pcepAttribute = pcepAttribute; - - } - - @Override - public PcepSrpObject getSrpObject() { - return srpObject; - } - - @Override - public PcepLspObject getLspObject() { - return lspObject; - } - - @Override - public PcepEndPointsObject getEndPointsObject() { - return endPointsObject; - } - - @Override - public PcepEroObject getEroObject() { - return eroObject; - } - - @Override - public PcepAttribute getPcepAttribute() { - return pcepAttribute; - } - - @Override - public void setSrpObject(PcepSrpObject srpobj) { - this.srpObject = srpobj; - - } - - @Override - public void setLspObject(PcepLspObject lspObject) { - this.lspObject = lspObject; - } - - @Override - public void setEndPointsObject(PcepEndPointsObject endPointsObject) { - this.endPointsObject = endPointsObject; - } - - @Override - public void setEroObject(PcepEroObject eroObject) { - this.eroObject = eroObject; - } - - @Override - public void setPcepAttribute(PcepAttribute pcepAttribute) { - this.pcepAttribute = pcepAttribute; - } - - /** - * Builder class for PC initiated lsp reuqest. - */ - public static class Builder implements PcInitiatedLspRequest.Builder { - - private boolean bIsSRPObjectSet = false; - private boolean bIsLSPObjectSet = false; - private boolean bIsEndPointsObjectSet = false; - private boolean bIsEROObjectSet = false; - private boolean bIsPcepAttributeSet = false; - private boolean bIsbRFlagSet = false; - - //PCEP SRP Object - private PcepSrpObject srpObject; - //PCEP LSP Object - private PcepLspObject lspObject; - //PCEP End Point Object - private PcepEndPointsObject endPointsObject; - //PCEP ERO Object - private PcepEroObject eroObject; - //PCEP Attribute list - private PcepAttribute pcepAttribute; - - @Override - public PcInitiatedLspRequest build() throws PcepParseException { - - //PCEP SRP Object - PcepSrpObject srpObject = null; - //PCEP LSP Object - PcepLspObject lspObject = null; - //PCEP End Point Object - PcepEndPointsObject endPointsObject = null; - //PCEP ERO Object - PcepEroObject eroObject = null; - //PCEP Attribute list - PcepAttribute pcepAttribute = null; - boolean bRFlag = false; - - if (!this.bIsSRPObjectSet) { - throw new PcepParseException("Srp object NOT Set while building PcInitiatedLspRequest"); - } else { - srpObject = this.srpObject; - bRFlag = srpObject.getRFlag(); - } - - if (bRFlag) { - this.bIsbRFlagSet = true; - } else { - this.bIsbRFlagSet = false; - } - - if (!this.bIsLSPObjectSet) { - throw new PcepParseException("LSP Object NOT Set while building PcInitiatedLspRequest"); - } else { - lspObject = this.lspObject; - } - if (!this.bIsbRFlagSet) { - - if (!this.bIsEndPointsObjectSet) { - throw new PcepParseException("EndPoints Object NOT Set while building PcInitiatedLspRequest"); - } else { - endPointsObject = this.endPointsObject; - } - if (!this.bIsEROObjectSet) { - throw new PcepParseException("ERO Object NOT Set while building PcInitiatedLspRequest"); - } else { - eroObject = this.eroObject; - } - if (bIsPcepAttributeSet) { - pcepAttribute = this.pcepAttribute; - } - } - return new PcInitiatedLspRequestVer1(srpObject, lspObject, endPointsObject, eroObject, pcepAttribute); - } - - @Override - public PcepSrpObject getSrpObject() { - return this.srpObject; - } - - @Override - public PcepLspObject getLspObject() { - return this.lspObject; - } - - @Override - public PcepEndPointsObject getEndPointsObject() { - return this.endPointsObject; - } - - @Override - public PcepEroObject getEroObject() { - return this.eroObject; - } - - @Override - public PcepAttribute getPcepAttribute() { - return this.pcepAttribute; - } - - @Override - public Builder setSrpObject(PcepSrpObject srpobj) { - this.srpObject = srpobj; - this.bIsSRPObjectSet = true; - return this; - - } - - @Override - public Builder setLspObject(PcepLspObject lspObject) { - this.lspObject = lspObject; - this.bIsLSPObjectSet = true; - return this; - } - - @Override - public Builder setEndPointsObject(PcepEndPointsObject endPointsObject) { - this.endPointsObject = endPointsObject; - this.bIsEndPointsObjectSet = true; - return this; - } - - @Override - public Builder setEroObject(PcepEroObject eroObject) { - this.eroObject = eroObject; - this.bIsEROObjectSet = true; - return this; - } - - @Override - public Builder setPcepAttribute(PcepAttribute pcepAttribute) { - this.pcepAttribute = pcepAttribute; - this.bIsPcepAttributeSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .omitNullValues() - .add("SrpObject", srpObject) - .add("LspObject", lspObject) - .add("EndPointObject", endPointsObject) - .add("EroObject", eroObject) - .add("PcepAttribute", pcepAttribute) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepAttributeVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepAttributeVer1.java deleted file mode 100644 index 65a844c2..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepAttributeVer1.java +++ /dev/null @@ -1,431 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepAttribute; -import org.onosproject.pcepio.protocol.PcepBandwidthObject; -import org.onosproject.pcepio.protocol.PcepIroObject; -import org.onosproject.pcepio.protocol.PcepLspaObject; -import org.onosproject.pcepio.protocol.PcepMetricObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Attribute List. - */ -public class PcepAttributeVer1 implements PcepAttribute { - - /* Reference : RFC5440 - * where: - * <attribute-list> ::=[<LSPA>] - * [<BANDWIDTH>] - * [<metric-list>] - * [<IRO>] - * - * <metric-list> ::=<METRIC>[<metric-list>] - */ - protected static final Logger log = LoggerFactory.getLogger(PcepAttributeVer1.class); - - public static final int OBJECT_HEADER_LENGTH = 4; - - //PCEP LSPA Object - private PcepLspaObject lspaObject; - private boolean isLspaObjectSet; - - //PCEP Bandwidth Object - private PcepBandwidthObject bandwidthObject; - private boolean isBandwidthObjectSet; - - //PCEP Metric list - private LinkedList<PcepMetricObject> llMetricList; - private boolean isMetricListSet; - - //PCEP IRO object - private PcepIroObject iroObject; - private boolean isIroObjectSet; - - /** - * Default constructor to initialize member variables. - */ - public PcepAttributeVer1() { - - lspaObject = null; - bandwidthObject = null; - llMetricList = null; - iroObject = null; - this.isLspaObjectSet = false; - this.isBandwidthObjectSet = false; - this.isMetricListSet = false; - this.isIroObjectSet = false; - } - - /** - * Constructor to initialize all parameters for PCEP attribute. - * - * @param lspaObject PCEP lspa Object. - * @param bandwidthObject PCEP bandwidth object. - * @param llMetricList list of PCEP metric objects. - * @param iroObject PCEP iro object. - */ - public PcepAttributeVer1(PcepLspaObject lspaObject, PcepBandwidthObject bandwidthObject, - LinkedList<PcepMetricObject> llMetricList, PcepIroObject iroObject) { - - this.lspaObject = lspaObject; - this.bandwidthObject = bandwidthObject; - this.llMetricList = llMetricList; - this.iroObject = iroObject; - if (lspaObject == null) { - this.isLspaObjectSet = false; - } else { - this.isLspaObjectSet = true; - } - if (bandwidthObject == null) { - this.isBandwidthObjectSet = false; - } else { - this.isBandwidthObjectSet = true; - } - if (llMetricList == null) { - this.isMetricListSet = false; - } else { - this.isMetricListSet = true; - } - if (iroObject == null) { - this.isIroObjectSet = false; - } else { - this.isIroObjectSet = true; - } - } - - /** - * constructor to initialize bandwidthObject. - * - * @param bandwidthObject bandwidth object - */ - public PcepAttributeVer1(PcepBandwidthObject bandwidthObject) { - this.isLspaObjectSet = false; - - this.bandwidthObject = bandwidthObject; - this.isBandwidthObjectSet = true; - - this.isMetricListSet = false; - - this.isIroObjectSet = false; - } - - /** - * Parse list for MeticObject. - * - * @param cb of type channel buffer - * @return true if parsing metric list is success - * @throws PcepParseException when a non metric object is received - */ - public boolean parseMetricList(ChannelBuffer cb) throws PcepParseException { - - if (llMetricList == null) { - llMetricList = new LinkedList<>(); - } - - PcepMetricObject metriclist; - - //caller should verify for metric object - byte yObjClass = PcepMetricObjectVer1.METRIC_OBJ_CLASS; - byte yObjType = PcepMetricObjectVer1.METRIC_OBJ_TYPE; - - while ((yObjClass == PcepMetricObjectVer1.METRIC_OBJ_CLASS) - && (yObjType == PcepMetricObjectVer1.METRIC_OBJ_TYPE)) { - - metriclist = PcepMetricObjectVer1.read(cb); - llMetricList.add(metriclist); - yObjClass = 0; - yObjType = 0; - - if (cb.readableBytes() > OBJECT_HEADER_LENGTH) { - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - } - } - return true; - } - - /** - * Reads lspa , bandwidth , Metriclist and Iro objects and sets the objects. - * - * @param cb of type channel buffer - * @return instance of Pcep Attribute - * @throws PcepParseException while parsing Pcep Attributes from channel buffer - */ - - public static PcepAttribute read(ChannelBuffer cb) throws PcepParseException { - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - return null; - } - //check whether any pcep attribute is present - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - byte yObjClass = tempObjHeader.getObjClass(); - - if (PcepLspaObjectVer1.LSPA_OBJ_CLASS != yObjClass && PcepBandwidthObjectVer1.BANDWIDTH_OBJ_CLASS != yObjClass - && PcepMetricObjectVer1.METRIC_OBJ_CLASS != yObjClass && PcepIroObjectVer1.IRO_OBJ_CLASS != yObjClass) { - //No PCEP attribute is present - return null; - } - - PcepAttributeVer1 pcepAttribute = new PcepAttributeVer1(); - - //If LSPA present then store it.LSPA is optional - if (yObjClass == PcepLspaObjectVer1.LSPA_OBJ_CLASS) { - pcepAttribute.setLspaObject(PcepLspaObjectVer1.read(cb)); - yObjClass = checkNextObject(cb); - } - - //If BANDWIDTH present then store it.BANDWIDTH is optional - if (yObjClass == PcepBandwidthObjectVer1.BANDWIDTH_OBJ_CLASS) { - pcepAttribute.setBandwidthObject(PcepBandwidthObjectVer1.read(cb)); - yObjClass = checkNextObject(cb); - } - - //If Metric list present then store it.MetricList is optional - if (yObjClass == PcepMetricObjectVer1.METRIC_OBJ_CLASS) { - pcepAttribute.parseMetricList(cb); - yObjClass = checkNextObject(cb); - } - - //If IRO present then store it.IRO is optional - if (yObjClass == PcepIroObjectVer1.IRO_OBJ_CLASS) { - pcepAttribute.setIroObject(PcepIroObjectVer1.read(cb)); - } - - PcepLspaObject lspaObject = pcepAttribute.getLspaObject(); - PcepBandwidthObject bandwidthObject = pcepAttribute.getBandwidthObject(); - LinkedList<PcepMetricObject> metriclist = pcepAttribute.llMetricList; - PcepIroObject iroObject = pcepAttribute.getIroObject(); - - return new PcepAttributeVer1(lspaObject, bandwidthObject, metriclist, iroObject); - } - - /** - * Checks whether there is a more object or not. - * - * @param cb of type channel buffer - * @return instance of object header - */ - private static byte checkNextObject(ChannelBuffer cb) { - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - return 0; - } - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - return tempObjHeader.getObjClass(); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - int iLenStartIndex = cb.writerIndex(); - //PCEP LSPA object is optional - if (this.isLspaObjectSet) { - this.lspaObject.write(cb); - } - - //PCEP BANDWIDTH object is optional - if (this.isBandwidthObjectSet) { - this.bandwidthObject.write(cb); - } - - //PCEP Metric list is optional - if (this.isMetricListSet) { - ListIterator<PcepMetricObject> listIterator = this.llMetricList.listIterator(); - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - } - - //PCEP IRO object is optional - if (this.isIroObjectSet) { - this.iroObject.write(cb); - } - return cb.writerIndex() - iLenStartIndex; - } - - @Override - public PcepLspaObject getLspaObject() { - return lspaObject; - } - - @Override - public PcepBandwidthObject getBandwidthObject() { - return bandwidthObject; - } - - @Override - public LinkedList<PcepMetricObject> getMetricObjectList() { - return llMetricList; - } - - @Override - public PcepIroObject getIroObject() { - return iroObject; - } - - @Override - public void setBandwidthObject(PcepBandwidthObject bandwidthObject) { - this.isBandwidthObjectSet = true; - this.bandwidthObject = bandwidthObject; - } - - @Override - public void setMetricObjectList(LinkedList<PcepMetricObject> llMetricList) { - this.isMetricListSet = true; - this.llMetricList = llMetricList; - - } - - @Override - public void setLspaObject(PcepLspaObject lspaObject) { - this.isLspaObjectSet = true; - this.lspaObject = lspaObject; - } - - @Override - public void setIroObject(PcepIroObject iroObject) { - this.isIroObjectSet = true; - this.iroObject = iroObject; - } - - /** - * Builder class for PCEP attributes. - */ - public static class Builder implements PcepAttribute.Builder { - - //PCEP LSPA Object - private PcepLspaObject lspaObject; - private boolean isLspaObjectSet; - - //PCEP BANDWIDTH Object - private PcepBandwidthObject bandwidthObject; - private boolean isBandwidthObjectSet; - - //PCEP Metric list - private LinkedList<PcepMetricObject> llMetricList; - private boolean isMetricListSet; - - //PCEP IRO object - private PcepIroObject iroObject; - private boolean isIroObjectSet; - - @Override - public PcepAttribute build() { - - //PCEP LSPA Object - PcepLspaObject lspaObject = null; - - //PCEP BANDWIDTH Object - PcepBandwidthObject bandwidthObject = null; - - //PCEP Metric list - LinkedList<PcepMetricObject> llMetricList = null; - - //PCEP IRO object - PcepIroObject iroObject = null; - - if (this.isLspaObjectSet) { - lspaObject = this.lspaObject; - } - if (this.isBandwidthObjectSet) { - bandwidthObject = this.bandwidthObject; - } - if (this.isMetricListSet) { - llMetricList = this.llMetricList; - } - if (this.isIroObjectSet) { - iroObject = this.iroObject; - } - return new PcepAttributeVer1(lspaObject, bandwidthObject, llMetricList, iroObject); - } - - @Override - public PcepLspaObject getLspaObject() { - return this.lspaObject; - } - - @Override - public PcepBandwidthObject getBandwidthObject() { - return this.bandwidthObject; - } - - @Override - public LinkedList<PcepMetricObject> getMetricObjectList() { - return this.llMetricList; - } - - @Override - public PcepIroObject getIroObject() { - return this.iroObject; - } - - @Override - public Builder setBandwidthObject(PcepBandwidthObject bandwidthObject) { - this.isBandwidthObjectSet = true; - this.bandwidthObject = bandwidthObject; - return this; - } - - @Override - public Builder setMetricObjectList(LinkedList<PcepMetricObject> llMetricList) { - this.isMetricListSet = true; - this.llMetricList = llMetricList; - return this; - } - - @Override - public Builder setLspaObject(PcepLspaObject lspaObject) { - this.isLspaObjectSet = true; - this.lspaObject = lspaObject; - return this; - } - - @Override - public Builder setIroObject(PcepIroObject iroObject) { - this.isIroObjectSet = true; - this.iroObject = iroObject; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .omitNullValues() - .add("lspaObject", lspaObject) - .add("bandwidthObject", bandwidthObject) - .add("MetricObjectList", llMetricList) - .add("IroObject", iroObject) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepBandwidthObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepBandwidthObjectVer1.java deleted file mode 100644 index 1c78d5b4..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepBandwidthObjectVer1.java +++ /dev/null @@ -1,233 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepBandwidthObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PcepBandwidthObject. - */ -public class PcepBandwidthObjectVer1 implements PcepBandwidthObject { - - /* - * RFC : 5440 , section : 7.7. - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Bandwidth | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - The BANDWIDTH Object format - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepBandwidthObjectVer1.class); - /* - * Requested bandwidth: BANDWIDTH Object-Type is 1. - Bandwidth of an existing TE LSP for which a re-optimization is - requested. BANDWIDTH Object-Type is 2. - */ - //Right now handling type 1 - public static final byte BANDWIDTH_OBJ_TYPE = 1; - public static final byte BANDWIDTH_OBJ_CLASS = 5; - public static final byte BANDWIDTH_OBJECT_VERSION = 1; - public static final short BANDWIDTH_OBJ_MINIMUM_LENGTH = 8; - - static final PcepObjectHeader DEFAULT_BANDWIDTH_OBJECT_HEADER = new PcepObjectHeader(BANDWIDTH_OBJ_CLASS, - BANDWIDTH_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - BANDWIDTH_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader bandwidthObjHeader; - private int iBandwidth; - - /** - * Constructor to bandwidth object header and bandwidth. - * - * @param bandwidthObjHeader bandwidth object header - * @param iBandwidth bandwidth value - */ - public PcepBandwidthObjectVer1(PcepObjectHeader bandwidthObjHeader, int iBandwidth) { - this.bandwidthObjHeader = bandwidthObjHeader; - this.iBandwidth = iBandwidth; - } - - /** - * Constructor to initialize bandwidth. - * - * @param iBandwidth bandwidth value - */ - public PcepBandwidthObjectVer1(int iBandwidth) { - this.bandwidthObjHeader = DEFAULT_BANDWIDTH_OBJECT_HEADER; - this.iBandwidth = iBandwidth; - } - - /** - * Returns Object Header. - * - * @return bandwidthObjHeader - */ - public PcepObjectHeader getBandwidthObjHeader() { - return this.bandwidthObjHeader; - } - - /** - * Sets Object Header. - * - * @param obj bandwidth object header - */ - public void setBandwidthObjHeader(PcepObjectHeader obj) { - this.bandwidthObjHeader = obj; - } - - @Override - public int getBandwidth() { - return this.iBandwidth; - } - - @Override - public void setBandwidth(int iBandwidth) { - this.iBandwidth = iBandwidth; - } - - /** - * Reads from channel buffer and returns object of PcepBandwidthObject. - * - * @param cb channel buffer to parse - * @return object of PcepBandwidthObject - * @throws PcepParseException while parsing channel buffer - */ - public static PcepBandwidthObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader bandwidthObjHeader; - int iBandwidth; - - bandwidthObjHeader = PcepObjectHeader.read(cb); - iBandwidth = cb.readInt(); - - return new PcepBandwidthObjectVer1(bandwidthObjHeader, iBandwidth); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - int objLenIndex = bandwidthObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("Failed to write bandwidth object header. Index " + objLenIndex); - } - - cb.writeInt(iBandwidth); - short hLength = (short) (cb.writerIndex() - objStartIndex); - cb.setShort(objLenIndex, hLength); - //will be helpful during print(). - bandwidthObjHeader.setObjLen(hLength); - - return cb.writerIndex() - objStartIndex; - } - - /** - * builder class for PCEP bandwidth object. - */ - public static class Builder implements PcepBandwidthObject.Builder { - - private PcepObjectHeader bandwidthObjHeader; - private boolean bIsHeaderSet = false; - - private int iBandwidth; - private boolean bIsBandwidthSet = false; - - private boolean bPFlag; - private boolean bIsPFlagSet = false; - - private boolean bIFlag; - private boolean bIsIFlagSet = false; - - @Override - public PcepBandwidthObject build() throws PcepParseException { - - PcepObjectHeader bandwidthObjHeader = this.bIsHeaderSet ? this.bandwidthObjHeader - : DEFAULT_BANDWIDTH_OBJECT_HEADER; - - if (bIsPFlagSet) { - bandwidthObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - bandwidthObjHeader.setIFlag(bIFlag); - } - - if (!this.bIsBandwidthSet) { - throw new PcepParseException("bandwidth not Set while building Bandwidth Object."); - } - - return new PcepBandwidthObjectVer1(bandwidthObjHeader, iBandwidth); - } - - @Override - public int getBandwidth() { - return this.iBandwidth; - } - - @Override - public PcepObjectHeader getBandwidthObjHeader() { - return this.bandwidthObjHeader; - } - - @Override - public Builder setBandwidthObjHeader(PcepObjectHeader obj) { - this.bandwidthObjHeader = obj; - return this; - } - - @Override - public Builder setBandwidth(int iBandwidth) { - this.iBandwidth = iBandwidth; - this.bIsBandwidthSet = true; - return this; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("BandwidthObjectHeader", bandwidthObjHeader) - .add("Bandwidth", iBandwidth).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepCloseMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepCloseMsgVer1.java deleted file mode 100644 index bcc679d3..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepCloseMsgVer1.java +++ /dev/null @@ -1,351 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepCloseMsg; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Close Message. - */ -class PcepCloseMsgVer1 implements PcepCloseMsg { - - /* - * RFC : 5440 , section : 6.8 - * <Close Message> ::= <Common Header> <CLOSE> - * - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Ver | Flags | Message-Type | Message-Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Reserved | Flags | Reason | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepCloseMsgVer1.class); - - // Pcep version: 1 - public static final byte PACKET_VERSION = 1; - public static final int PACKET_MINIMUM_LENGTH = 12; - public static final PcepType MSG_TYPE = PcepType.CLOSE; - public static final byte CLOSE_OBJ_TYPE = 1; - public static final byte CLOSE_OBJ_CLASS = 15; - public static final byte CLOSE_OBJECT_VERSION = 1; - public static final byte DEFAULT_REASON = 1; // Default reason to close - public static final short CLOSE_OBJ_MINIMUM_LENGTH = 8; - public static final int SHIFT_FLAG = 5; - static final PcepObjectHeader DEFAULT_CLOSE_HEADER = new PcepObjectHeader(CLOSE_OBJ_CLASS, CLOSE_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, CLOSE_OBJ_MINIMUM_LENGTH); - - private final PcepObjectHeader closeObjHeader; - private byte yReason; - private LinkedList<PcepValueType> llOptionalTlv; - - public static final PcepCloseMsgVer1.Reader READER = new Reader(); - - /** - * Reader class for reading close message for channel buffer. - */ - static class Reader implements PcepMessageReader<PcepCloseMsg> { - PcepObjectHeader closeObjHeader; - byte yReason; - // Optional TLV - private LinkedList<PcepValueType> llOptionalTlv; - - @Override - public PcepCloseMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Packet size is less than the minimum length."); - } - // fixed value property version == 1 - byte version = cb.readByte(); - version = (byte) (version >> SHIFT_FLAG); - if (version != PACKET_VERSION) { - throw new PcepParseException("Wrong version. Expected=PcepVersion.PCEP_1(1), got=" + version); - } - // fixed value property type == 7 - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type. Expected=PcepType.CLOSE(7), got=" + type); - } - short length = cb.readShort(); - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " - + length); - } - closeObjHeader = PcepObjectHeader.read(cb); - // Reserved - cb.readShort(); - // Flags - cb.readByte(); - // Reason - yReason = cb.readByte(); - // parse optional TLV - llOptionalTlv = parseOptionalTlv(cb); - return new PcepCloseMsgVer1(closeObjHeader, yReason, llOptionalTlv); - } - } - - /** - * Parse the list of Optional Tlvs. - * - * @param cb channel buffer - * @return list of Optional Tlvs - * @throws PcepParseException when fails to parse optional tlvs - */ - public static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - /* - rfc 5440: - Optional TLVs may be included within the CLOSE object body. The - specification of such TLVs is outside the scope of this document. - */ - return llOptionalTlv; - } - - /** - * constructor to initialize PCEP close Message with all the parameters. - * - * @param closeObjHeader object header for close message - * @param yReason reason for closing the channel - * @param llOptionalTlv list of optional tlvs - */ - PcepCloseMsgVer1(PcepObjectHeader closeObjHeader, byte yReason, LinkedList<PcepValueType> llOptionalTlv) { - - this.closeObjHeader = closeObjHeader; - this.yReason = yReason; - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Builder class for PCEP close message. - */ - static class Builder implements PcepCloseMsg.Builder { - - // PCEP Close message fields - private boolean bIsHeaderSet = false; - private PcepObjectHeader closeObjHeader; - private boolean bIsReasonSet = false; - private byte yReason; - private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.CLOSE; - } - - @Override - public PcepCloseMsg build() { - - PcepObjectHeader closeObjHeader = this.bIsHeaderSet ? this.closeObjHeader : DEFAULT_CLOSE_HEADER; - byte yReason = this.bIsReasonSet ? this.yReason : DEFAULT_REASON; - - if (bIsPFlagSet) { - closeObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - closeObjHeader.setIFlag(bIFlag); - } - return new PcepCloseMsgVer1(closeObjHeader, yReason, this.llOptionalTlv); - } - - @Override - public PcepObjectHeader getCloseObjHeader() { - return this.closeObjHeader; - } - - @Override - public Builder setCloseObjHeader(PcepObjectHeader obj) { - this.closeObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public byte getReason() { - return this.yReason; - } - - @Override - public Builder setReason(byte value) { - this.yReason = value; - this.bIsReasonSet = true; - return this; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer class for writing close message to channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepCloseMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepCloseMsgVer1 message) throws PcepParseException { - int startIndex = cb.writerIndex(); - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << SHIFT_FLAG)); - // message type - cb.writeByte(MSG_TYPE.getType()); - // length is length of variable message, will be updated at the end - // Store the position of message - // length in buffer - int msgLenIndex = cb.writerIndex(); - cb.writeShort((short) 0); - int objStartIndex = cb.writerIndex(); - int objLenIndex = message.closeObjHeader.write(cb); - if (objLenIndex <= 0) { - throw new PcepParseException("Failed to write Close object header."); - } - // first 3 bits set to version - cb.writeShort(0); // Reserved - cb.writeByte(0); // Flags - cb.writeByte(message.yReason); - // Pack optional TLV - packOptionalTlv(cb, message); - int length = cb.writerIndex() - objStartIndex; - cb.setShort(objLenIndex, (short) length); - // will be helpful during print(). - message.closeObjHeader.setObjLen((short) length); - // As per RFC the length of object should be - // multiples of 4 - int pad = length % 4; - if (pad != 0) { - pad = 4 - pad; - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = length + pad; - } - // update message length field - length = cb.writerIndex() - startIndex; - cb.setShort(msgLenIndex, (short) length); - } - - public void packOptionalTlv(ChannelBuffer cb, PcepCloseMsgVer1 message) { - - LinkedList<PcepValueType> llOptionalTlv = message.llOptionalTlv; - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - @Override - public byte getReason() { - return this.yReason; - } - - @Override - public void setReason(byte value) { - this.yReason = value; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("closeObjectHeader", closeObjHeader).add("Reason", yReason) - .add("OptionalTlvlist", llOptionalTlv).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepEndPointsObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepEndPointsObjectVer1.java deleted file mode 100644 index 08dc0c9b..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepEndPointsObjectVer1.java +++ /dev/null @@ -1,256 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepEndPointsObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Endpoints Object. - */ -public class PcepEndPointsObjectVer1 implements PcepEndPointsObject { - - /* - * RFC : 5440 , section : 7.6 - * An End point is defined as follows: - END-POINTS Object-Class is 4. - - END-POINTS Object-Type is 1 for IPv4 and 2 for IPv6. - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Source IPv4 address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Destination IPv4 address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - protected static final Logger log = LoggerFactory.getLogger(PcepEndPointsObjectVer1.class); - - static final byte END_POINTS_OBJ_TYPE = 1; - static final byte END_POINTS_OBJ_CLASS = 4; - static final byte END_POINTS_OBJECT_VERSION = 1; - static final short END_POINTS_OBJ_MINIMUM_LENGTH = 12; - public static byte endPointObjType; - - static final PcepObjectHeader DEFAULT_END_POINTS_OBJECT_HEADER = new PcepObjectHeader(END_POINTS_OBJ_CLASS, - END_POINTS_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - END_POINTS_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader endPointsObjHeader; - public int sourceIpAddress; - public int destIpAddress; - - /** - * Constructor to initialize all variables. - * - * @param endPointsObjHeader end points object header - * @param sourceIpAddress source IP address - * @param destIpAddress destination IP address - */ - public PcepEndPointsObjectVer1(PcepObjectHeader endPointsObjHeader, int sourceIpAddress, int destIpAddress) { - - this.endPointsObjHeader = endPointsObjHeader; - this.sourceIpAddress = sourceIpAddress; - this.destIpAddress = destIpAddress; - } - - /** - * Sets End Points Object Header. - * - * @param obj of PcepObjectHeader - */ - public void setEndPointsObjHeader(PcepObjectHeader obj) { - this.endPointsObjHeader = obj; - } - - @Override - public void setSourceIpAddress(int sourceIpAddress) { - this.sourceIpAddress = sourceIpAddress; - } - - @Override - public void setDestIpAddress(int destIpAddress) { - this.destIpAddress = destIpAddress; - } - - @Override - public int getSourceIpAddress() { - return this.sourceIpAddress; - } - - @Override - public int getDestIpAddress() { - return this.destIpAddress; - } - - /** - * Reads from channel buffer and returns object of PcepEndPointsObject. - * - * @param cb of channel buffer - * @return object of PcepEndPointsObject - * @throws PcepParseException while parsing channel buffer - */ - public static PcepEndPointsObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader endPointsObjHeader; - int sourceIpAddress; - int destIpAddress; - - endPointsObjHeader = PcepObjectHeader.read(cb); - if (endPointsObjHeader.getObjType() == END_POINTS_OBJ_TYPE - && endPointsObjHeader.getObjClass() == END_POINTS_OBJ_CLASS) { - sourceIpAddress = cb.readInt(); - destIpAddress = cb.readInt(); - } else { - throw new PcepParseException("Expected PcepEndPointsObject."); - } - return new PcepEndPointsObjectVer1(endPointsObjHeader, sourceIpAddress, destIpAddress); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - int objStartIndex = cb.writerIndex(); - //write common header - int objLenIndex = endPointsObjHeader.write(cb); - - //write source IPv4 IP - cb.writeInt(sourceIpAddress); - //write destination IPv4 IP - cb.writeInt(destIpAddress); - - int length = cb.writerIndex() - objStartIndex; - //now write EndPoints Object Length - cb.setShort(objLenIndex, (short) length); - //will be helpful during print(). - endPointsObjHeader.setObjLen((short) length); - - return cb.writerIndex(); - - } - - /** - * Builder class for PCEP end points objects. - */ - public static class Builder implements PcepEndPointsObject.Builder { - - private boolean bIsHeaderSet = false; - private boolean bIsSourceIpAddressset = false; - private boolean bIsDestIpAddressset = false; - private PcepObjectHeader endpointsObjHeader; - private int sourceIpAddress; - private int destIpAddress; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepEndPointsObject build() throws PcepParseException { - - PcepObjectHeader endpointsObjHeader = this.bIsHeaderSet ? this.endpointsObjHeader - : DEFAULT_END_POINTS_OBJECT_HEADER; - - if (bIsPFlagSet) { - endpointsObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - endpointsObjHeader.setIFlag(bIFlag); - } - - if (!this.bIsSourceIpAddressset) { - throw new PcepParseException("SourceIpAddress not set while building EndPoints object"); - } - - if (!this.bIsDestIpAddressset) { - throw new PcepParseException("DestIpAddress not set while building EndPoints object"); - } - - return new PcepEndPointsObjectVer1(endpointsObjHeader, this.sourceIpAddress, this.destIpAddress); - } - - @Override - public PcepObjectHeader getEndPointsObjHeader() { - return this.endpointsObjHeader; - } - - @Override - public Builder setEndPointsObjHeader(PcepObjectHeader obj) { - this.endpointsObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getSourceIpAddress() { - return this.sourceIpAddress; - } - - @Override - public Builder setSourceIpAddress(int sourceIpAddress) { - this.sourceIpAddress = sourceIpAddress; - this.bIsSourceIpAddressset = true; - return this; - } - - @Override - public int getDestIpAddress() { - return this.destIpAddress; - } - - @Override - public Builder setDestIpAddress(int destIpAddress) { - this.destIpAddress = destIpAddress; - this.bIsDestIpAddressset = true; - return this; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("sourceIpAddress", sourceIpAddress) - .add("destIpAddress", destIpAddress).toString(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepEroObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepEroObjectVer1.java deleted file mode 100644 index 4d7cb16e..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepEroObjectVer1.java +++ /dev/null @@ -1,407 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepEroObject; -import org.onosproject.pcepio.types.AutonomousSystemTlv; -import org.onosproject.pcepio.types.IPv4SubObject; -import org.onosproject.pcepio.types.IPv6SubObject; -import org.onosproject.pcepio.types.PathKeySubObject; -import org.onosproject.pcepio.types.PcepErrorDetailInfo; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.SrEroSubObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Ero Object. - */ -public class PcepEroObjectVer1 implements PcepEroObject { - /* - * rfc3209 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // (Subobjects) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - If a Path message contains multiple EXPLICIT_ROUTE objects, only the - first object is meaningful. Subsequent EXPLICIT_ROUTE objects MAY be - ignored and SHOULD NOT be propagated. - - In current implementation, only strict hops are supported. So, - empty ERO with no sub-objects is considered illegal. - - Subobjects: - 0 1 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-------------//----------------+ - |L| Type | Length | (Subobject contents) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-------------//----------------+ - - L - - The L bit is an attribute of the subobject. The L bit is set - if the subobject represents a loose hop in the explicit route. - If the bit is not set, the subobject represents a strict hop in - the explicit route. - - Type - - The Type indicates the type of contents of the subobject. - - - Subobject 1: IPv4 address - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L| Type | Length | IPv4 address (4 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 address (continued) | Prefix Length | Resvd | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Subobject 2: IPv6 Prefix - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L| Type | Length | IPv6 address (16 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | Prefix Length | Resvd | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Subobject 3: Autonomous System Number - - The contents of an Autonomous System (AS) number subobject are a 2- - octet AS number. The abstract node represented by this subobject is - the set of nodes belonging to the autonomous system. - - The length of the AS number subobject is 4 octets. - - Subobject 4: PATH_KEY_32_BIT_SUB_OBJ_TYPE: - - Pathkey subobject(RFC 5520): - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L| Type | Length | Path-Key | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | PCE ID (4 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Subobject 5: SR_ERO_SUB_OBJ_TYPE: - - SR-ERO subobject: (draft-ietf-pce-segment-routing-00) - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L| Type | Length | ST | Flags |F|S|C|M| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | SID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // NAI (variable) // - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepEroObjectVer1.class); - - public static final byte ERO_OBJ_TYPE = 1; - public static final byte ERO_OBJ_CLASS = 7; - public static final byte ERO_OBJECT_VERSION = 1; - public static final short ERO_OBJ_MINIMUM_LENGTH = 12; - public static final byte IPV4_TYPE = 1; - public static final byte PATH_KEY_32_BIT_SUB_OBJ_TYPE = 64; - public static final int LABEL_SUB_OBJ_TYPE = 3; - public static final int SR_ERO_SUB_OBJ_TYPE = 96; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int YTYPE_SHIFT_VALUE = 0x7F; - - static final PcepObjectHeader DEFAULT_ERO_OBJECT_HEADER = new PcepObjectHeader(ERO_OBJ_CLASS, ERO_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, ERO_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader eroObjHeader; - private LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - /** - * reset variables. - */ - public PcepEroObjectVer1() { - this.eroObjHeader = null; - this.llSubObjects = null; - } - - /** - * Constructor to initialize parameters of ERO object. - * - * @param eroObjHeader ERO object header - * @param llSubObjects list of sub objects. - */ - public PcepEroObjectVer1(PcepObjectHeader eroObjHeader, LinkedList<PcepValueType> llSubObjects) { - - this.eroObjHeader = eroObjHeader; - this.llSubObjects = llSubObjects; - } - - /** - * Returns ERO object header. - * - * @return eroObjHeader ERO object header - */ - public PcepObjectHeader getEroObjHeader() { - return this.eroObjHeader; - } - - /** - * Sets Object Header. - * - * @param obj ERO object header - */ - public void setEroObjHeader(PcepObjectHeader obj) { - this.eroObjHeader = obj; - } - - @Override - public LinkedList<PcepValueType> getSubObjects() { - return this.llSubObjects; - } - - @Override - public void setSubObjects(LinkedList<PcepValueType> llSubObjects) { - this.llSubObjects = llSubObjects; - } - - /** - * Reads from channel buffer and returns object of PcepEroObject. - * - * @param cb channel buffer. - * @return object of PcepEroObject - * @throws PcepParseException when ERO object is not present in channel buffer - */ - public static PcepEroObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader eroObjHeader; - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - eroObjHeader = PcepObjectHeader.read(cb); - - if (eroObjHeader.getObjClass() != PcepEroObjectVer1.ERO_OBJ_CLASS) { - log.debug("ErrorType:" + PcepErrorDetailInfo.ERROR_TYPE_6 + " ErrorValue:" - + PcepErrorDetailInfo.ERROR_VALUE_9); - throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_6, PcepErrorDetailInfo.ERROR_VALUE_9); - } - - if (eroObjHeader.getObjLen() > OBJECT_HEADER_LENGTH) { - ChannelBuffer tempCb = cb.readBytes(eroObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - llSubObjects = parseSubObjects(tempCb); - } - return new PcepEroObjectVer1(eroObjHeader, llSubObjects); - } - - /** - * Parse list of Sub Objects. - * - * @param cb channel buffer - * @return list of Sub Objects - * @throws PcepParseException when fails to parse sub object list - */ - protected static LinkedList<PcepValueType> parseSubObjects(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - while (0 < cb.readableBytes()) { - - //check the Type of the TLV - byte yType = cb.readByte(); - yType = (byte) (yType & (YTYPE_SHIFT_VALUE)); - byte hLength = cb.readByte(); - - PcepValueType subObj; - - switch (yType) { - - case IPv4SubObject.TYPE: - subObj = IPv4SubObject.read(cb); - break; - case IPv6SubObject.TYPE: - byte[] ipv6Value = new byte[IPv6SubObject.VALUE_LENGTH]; - cb.readBytes(ipv6Value, 0, IPv6SubObject.VALUE_LENGTH); - subObj = new IPv6SubObject(ipv6Value); - break; - case AutonomousSystemTlv.TYPE: - subObj = AutonomousSystemTlv.read(cb); - break; - case PathKeySubObject.TYPE: - subObj = PathKeySubObject.read(cb); - break; - case SrEroSubObject.TYPE: - subObj = SrEroSubObject.read(cb); - break; - default: - throw new PcepParseException("Unexpected sub object. Type: " + (int) yType); - } - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - - llSubObjects.add(subObj); - } - if (0 < cb.readableBytes()) { - throw new PcepParseException("Subobject parsing error. Extra bytes received."); - } - return llSubObjects; - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = eroObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("Failed to write ERO object header. Index " + objLenIndex); - } - - ListIterator<PcepValueType> listIterator = llSubObjects.listIterator(); - - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - cb.setShort(objLenIndex, (short) length); - //will be helpful during print(). - eroObjHeader.setObjLen((short) length); - - //As per RFC the length of object should be multiples of 4 - int pad = length % 4; - - if (pad != 0) { - pad = 4 - pad; - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = length + pad; - } - - objLenIndex = cb.writerIndex(); - return objLenIndex; - } - - /** - * Builder class for PCEP ERO object. - */ - public static class Builder implements PcepEroObject.Builder { - - private boolean bIsHeaderSet = false; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - private PcepObjectHeader eroObjHeader; - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - @Override - public PcepEroObject build() { - - PcepObjectHeader eroObjHeader = this.bIsHeaderSet ? this.eroObjHeader : DEFAULT_ERO_OBJECT_HEADER; - - if (bIsPFlagSet) { - eroObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - eroObjHeader.setIFlag(bIFlag); - } - - return new PcepEroObjectVer1(eroObjHeader, this.llSubObjects); - } - - @Override - public PcepObjectHeader getEroObjHeader() { - return this.eroObjHeader; - } - - @Override - public Builder setEroObjHeader(PcepObjectHeader obj) { - this.eroObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public LinkedList<PcepValueType> getSubObjects() { - return this.llSubObjects; - } - - @Override - public Builder setSubObjects(LinkedList<PcepValueType> llSubObjects) { - this.llSubObjects = llSubObjects; - return this; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("EroObjHeader", eroObjHeader).add("SubObjects", llSubObjects) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorInfoVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorInfoVer1.java deleted file mode 100644 index 594e40c1..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorInfoVer1.java +++ /dev/null @@ -1,204 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepError; -import org.onosproject.pcepio.protocol.PcepErrorInfo; -import org.onosproject.pcepio.protocol.PcepErrorObject; -import org.onosproject.pcepio.protocol.PcepRPObject; -import org.onosproject.pcepio.protocol.PcepTEObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Error Info. - * Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02. - */ -public class PcepErrorInfoVer1 implements PcepErrorInfo { - - protected static final Logger log = LoggerFactory.getLogger(PcepErrorInfoVer1.class); - //Error list is optional - private LinkedList<PcepError> errList; - - /** - * Constructor to add PCEP error object to the list. - * - * @param llRPObjList list of PCEP RP object - * @param llTEObjList list of PCEP TE object - * @param llErrObjList list of PCEP error object - */ - public PcepErrorInfoVer1(LinkedList<PcepRPObject> llRPObjList, LinkedList<PcepTEObject> llTEObjList, - LinkedList<PcepErrorObject> llErrObjList) { - this.errList = new LinkedList<>(); - if ((llErrObjList != null) && (!llErrObjList.isEmpty())) { - this.errList.add(new PcepErrorVer1(llRPObjList, llTEObjList, llErrObjList)); - } - } - - /** - * Constructor to initialize error info. - * - * @param errll linked list or pcep error - */ - public PcepErrorInfoVer1(LinkedList<PcepError> errll) { - this.errList = errll; - } - - @Override - public boolean isErrorInfoPresent() { - return !this.errList.isEmpty(); - } - - @Override - public void read(ChannelBuffer cb) throws PcepParseException { - PcepObjectHeader tempObjHeader; - - while (0 < cb.readableBytes()) { - cb.markReaderIndex(); - tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - byte yObjClass = tempObjHeader.getObjClass(); - if ((yObjClass != PcepRPObjectVer1.RP_OBJ_CLASS) && (yObjClass != PcepTEObjectVer1.TE_OBJ_CLASS) - && (yObjClass != PcepErrorObjectVer1.ERROR_OBJ_CLASS)) { - throw new PcepParseException("Unknown Object is present in PCEP-ERROR. Object Class: " + yObjClass); - } - - this.errList.add(PcepErrorVer1.read(cb)); - } - } - - @Override - public void write(ChannelBuffer cb) throws PcepParseException { - //write <error> - ListIterator<PcepError> listIterator = errList.listIterator(); - while (listIterator.hasNext()) { - PcepError pcepError = listIterator.next(); - - //RP Object list is optional - LinkedList<PcepRPObject> llRPObjList = pcepError.getRPObjList(); - if (llRPObjList != null) { - ListIterator<PcepRPObject> rpListIterator = llRPObjList.listIterator(); - while (rpListIterator.hasNext()) { - rpListIterator.next().write(cb); - } - } - - //TE Object list is optional - LinkedList<PcepTEObject> llTEObjList = pcepError.getTEObjList(); - if (llTEObjList != null) { - ListIterator<PcepTEObject> teListIterator = llTEObjList.listIterator(); - while (teListIterator.hasNext()) { - teListIterator.next().write(cb); - } - } - - // <error-obj-list> is mandatory - boolean bIsErrorObjListFound = false; - - LinkedList<PcepErrorObject> llErrObjList = pcepError.getErrorObjList(); - if (llErrObjList != null) { - ListIterator<PcepErrorObject> errObjListIterator = llErrObjList.listIterator(); - while (errObjListIterator.hasNext()) { - errObjListIterator.next().write(cb); - bIsErrorObjListFound = true; - } - } - - if (!bIsErrorObjListFound) { - throw new PcepParseException("<error-obj-list> is mandatory."); - } - } - } - - @Override - public LinkedList<Integer> getErrorType() { - LinkedList<Integer> errorType = new LinkedList<>(); - ListIterator<PcepError> listIterator = errList.listIterator(); - PcepErrorObject errObj; - int error; - while (listIterator.hasNext()) { - PcepError pcepError = listIterator.next(); - LinkedList<PcepErrorObject> llErrObjList = pcepError.getErrorObjList(); - if (llErrObjList != null) { - ListIterator<PcepErrorObject> errObjListIterator = llErrObjList.listIterator(); - while (errObjListIterator.hasNext()) { - errObj = errObjListIterator.next(); - error = errObj.getErrorType(); - errorType.add(error); - } - } - } - return errorType; - } - - @Override - public LinkedList<Integer> getErrorValue() { - LinkedList<Integer> errorValue = new LinkedList<>(); - ListIterator<PcepError> listIterator = errList.listIterator(); - PcepErrorObject errObj; - int error; - while (listIterator.hasNext()) { - PcepError pcepError = listIterator.next(); - LinkedList<PcepErrorObject> llErrObjList = pcepError.getErrorObjList(); - if (llErrObjList != null) { - ListIterator<PcepErrorObject> errObjListIterator = llErrObjList.listIterator(); - while (errObjListIterator.hasNext()) { - errObj = errObjListIterator.next(); - error = errObj.getErrorValue(); - errorValue.add(error); - } - } - } - return errorValue; - } - - /** - * Builder class for PCEP error info. - */ - public static class Builder implements PcepErrorInfo.Builder { - private LinkedList<PcepError> errll; - - @Override - public PcepErrorInfo build() { - return new PcepErrorInfoVer1(errll); - } - - @Override - public LinkedList<PcepError> getPcepErrorList() { - return this.errll; - } - - @Override - public Builder setPcepErrorList(LinkedList<PcepError> errll) { - this.errll = errll; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ErrorList", errList).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorMsgVer1.java deleted file mode 100644 index 927d83d6..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorMsgVer1.java +++ /dev/null @@ -1,383 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepErrorInfo; -import org.onosproject.pcepio.protocol.PcepErrorMsg; -import org.onosproject.pcepio.protocol.PcepErrorObject; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepOpenObject; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.ErrorObjListWithOpen; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides PCEP Error Message. - */ -public class PcepErrorMsgVer1 implements PcepErrorMsg { - - /* - * PCE Error message format. - - <PCErr Message> ::= <Common Header> - ( <error-obj-list> [<Open>] ) | <error> - [<error-list>] - - <error-obj-list> ::=<PCEP-ERROR>[<error-obj-list>] - - <error> ::=[<request-id-list> | <te-id-list>] - <error-obj-list> - - <request-id-list> ::=<RP>[<request-id-list>] - - <te-id-list> ::=<TE>[<te-id-list>] - - <error-list> ::=<error>[<error-list>] - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepOpenMsgVer1.class); - public static final byte PACKET_VERSION = 1; - public static final int PACKET_MINIMUM_LENGTH = 12; - public static final PcepType MSG_TYPE = PcepType.ERROR; - - //Below either one should be present. - private ErrorObjListWithOpen errObjListWithOpen; //optional ( <error-obj-list> [<Open>] ) - private PcepErrorInfo errInfo; //optional <error> [<error-list>] - - public static final PcepErrorMsgVer1.Reader READER = new Reader(); - - /** - * constructor to initialize variables. - */ - public PcepErrorMsgVer1() { - errObjListWithOpen = null; - errInfo = null; - } - - /** - * Constructor to initialize variables. - * - * @param errObjListWithOpen error-object-list with open object - * @param errInfo error information - */ - public PcepErrorMsgVer1(ErrorObjListWithOpen errObjListWithOpen, PcepErrorInfo errInfo) { - this.errObjListWithOpen = errObjListWithOpen; - this.errInfo = errInfo; - } - - /** - * Reader class for reading PCEP error Message from channel buffer. - */ - public static class Reader implements PcepMessageReader<PcepErrorMsg> { - - ErrorObjListWithOpen errObjListWithOpen; - PcepErrorInfo errInfo; - PcepObjectHeader tempObjHeader; - - @Override - public PcepErrorMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - errObjListWithOpen = null; - errInfo = null; - tempObjHeader = null; - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Packet size is less than the minimum length."); - } - - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != PACKET_VERSION) { - throw new PcepParseException("Wrong version: Expected=PcepVersion.PCEP_1(1), got=" + version); - } - // fixed value property type == 1 - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type: Expected=PcepType.ERROR(6), got=" + type); - } - int length = cb.readShort(); - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException( - "Wrong length: Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " + length); - } - - //parse <PCErr Message> - parsePCErrMsg(cb); - - // If other than RP or TE or PCEP-ERROR present then it is error. - if (0 < cb.readableBytes()) { - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - throw new PcepParseException("Unexpected Object found. Object Class : " + tempObjHeader.getObjClass()); - } - - return new PcepErrorMsgVer1(errObjListWithOpen, errInfo); - } - - /** - * Parsing PCErr Message. - * - * @param cb channel buffer. - * @throws PcepParseException if mandatory fields are missing - * output: this.errObjListWithOpen, this.errInfo - */ - public void parsePCErrMsg(ChannelBuffer cb) throws PcepParseException { - //If PCEP-ERROR list is followed by OPEN Object then store into ErrorObjListWithOpen. - // ( <error-obj-list> [<Open>] - //If PCEP-ERROR list is followed by RP or TE Object then store into errInfo. <error> [<error-list>] - //If only PCEP-ERROR list is present then store into ErrorObjListWithOpen. - PcepObjectHeader tempObjHeader; - LinkedList<PcepErrorObject> llErrObjList; - - if (0 >= cb.readableBytes()) { - throw new PcepParseException("PCEP-ERROR message came with empty objects."); - } - - //parse PCEP-ERROR list - llErrObjList = new LinkedList<>(); - tempObjHeader = parseErrorObjectList(llErrObjList, cb); - - //check whether OPEN-OBJECT is present. - if ((tempObjHeader != null) - && (tempObjHeader.getObjClass() == PcepOpenObjectVer1.OPEN_OBJ_CLASS)) { - - if (llErrObjList.isEmpty()) { - throw new PcepParseException("<error-obj-list> should be present if OPEN-OBJECT exists"); - } - - PcepOpenObject pcepOpenObj = PcepOpenObjectVer1.read(cb); - this.errObjListWithOpen = new ErrorObjListWithOpen(llErrObjList, pcepOpenObj); - - } else if ((tempObjHeader != null) //check whether RP or TE Object is present. - && ((tempObjHeader.getObjClass() == PcepRPObjectVer1.RP_OBJ_CLASS) - || (tempObjHeader.getObjClass() == PcepTEObjectVer1.TE_OBJ_CLASS))) { - - this.errInfo = new PcepErrorInfoVer1(null, null, llErrObjList); - this.errInfo.read(cb); - - } else if (!llErrObjList.isEmpty()) { - //If only PCEP-ERROR list is present then store it in errObjListWithOpen. - this.errObjListWithOpen = new ErrorObjListWithOpen(llErrObjList); - } else { - throw new PcepParseException("Empty PCEP-ERROR message."); - } - } - - /** - * Parse error-obj-list. - * - * @param llErrObjList error object list output - * @param cb channel buffer input - * @throws PcepParseException if mandatory fields are missing - * @return error object header - */ - public PcepObjectHeader parseErrorObjectList(LinkedList<PcepErrorObject> llErrObjList, ChannelBuffer cb) - throws PcepParseException { - PcepObjectHeader tempObjHeader = null; - - while (0 < cb.readableBytes()) { - cb.markReaderIndex(); - tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - if (tempObjHeader.getObjClass() == PcepErrorObjectVer1.ERROR_OBJ_CLASS) { - llErrObjList.add(PcepErrorObjectVer1.read(cb)); - } else { - break; - } - } - return tempObjHeader; - } - } - - /** - * Builder class for PCEP error message. - */ - public static class Builder implements PcepErrorMsg.Builder { - // Pcep error message fields - - private ErrorObjListWithOpen errObjListWithOpen = null; //optional ( <error-obj-list> [<Open>] ) - private PcepErrorInfo errInfo = null; //optional <error> [<error-list>] - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.ERROR; - } - - @Override - public PcepErrorMsg build() { - return new PcepErrorMsgVer1(this.errObjListWithOpen, this.errInfo); - } - - @Override - public ErrorObjListWithOpen getErrorObjListWithOpen() { - return this.errObjListWithOpen; - } - - @Override - public Builder setErrorObjListWithOpen(ErrorObjListWithOpen errObjListWithOpen) { - this.errObjListWithOpen = errObjListWithOpen; - return this; - } - - @Override - public PcepErrorInfo getPcepErrorInfo() { - return this.errInfo; - } - - @Override - public Builder setPcepErrorInfo(PcepErrorInfo errInfo) { - this.errInfo = errInfo; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - public static final Writer WRITER = new Writer(); - - /** - * Writer class for writing PCEP error Message to channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepErrorMsgVer1> { - @Override - public void write(ChannelBuffer cb, PcepErrorMsgVer1 message) throws PcepParseException { - int startIndex = cb.writerIndex(); - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - // message type 0xC - cb.writeByte(MSG_TYPE.getType()); - // length is length of variable message, will be updated at the end - // Store the position of message - // length in buffer - int msgLenIndex = cb.writerIndex(); - cb.writeShort(0); - ErrorObjListWithOpen errObjListWithOpen = message.getErrorObjListWithOpen(); - PcepErrorInfo errInfo = message.getPcepErrorInfo(); - - // write ( <error-obj-list> [<Open>] ) if exists. - // otherwise write <error> [<error-list>] - - if ((errObjListWithOpen != null) - && (errObjListWithOpen.isErrorObjListWithOpenPresent())) { - errObjListWithOpen.write(cb); - } else if ((errInfo != null) && (errInfo.isErrorInfoPresent())) { - errInfo.write(cb); - } else { - throw new PcepParseException("Empty PCEP-ERROR message."); - } - // PcepErrorMessage message length field - int length = cb.writerIndex() - startIndex; - cb.setShort(msgLenIndex, (short) length); - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - @Override - public ErrorObjListWithOpen getErrorObjListWithOpen() { - return this.errObjListWithOpen; - } - - @Override - public void setErrorObjListWithOpen(ErrorObjListWithOpen errObjListWithOpen) { - this.errObjListWithOpen = errObjListWithOpen; - } - - @Override - public PcepErrorInfo getPcepErrorInfo() { - return this.errInfo; - } - - @Override - public void setPcepErrorInfo(PcepErrorInfo errInfo) { - this.errInfo = errInfo; - } - - /** - * Return list of Error types. - * - * @return error types list - */ - public LinkedList<Integer> getErrorType() { - LinkedList<Integer> llErrorType = new LinkedList<>(); - if ((errObjListWithOpen != null) - && (errObjListWithOpen.isErrorObjListWithOpenPresent())) { - llErrorType = errObjListWithOpen.getErrorType(); - } else if ((errInfo != null) && (errInfo.isErrorInfoPresent())) { - llErrorType = errInfo.getErrorType(); - } - - return llErrorType; - } - - /** - * Return list of Error values. - * - * @return error value list - */ - public LinkedList<Integer> getErrorValue() { - LinkedList<Integer> llErrorValue = new LinkedList<>(); - if ((errObjListWithOpen != null) - && (errObjListWithOpen.isErrorObjListWithOpenPresent())) { - llErrorValue = errObjListWithOpen.getErrorValue(); - } else if ((errInfo != null) && (errInfo.isErrorInfoPresent())) { - llErrorValue = errInfo.getErrorValue(); - } - - return llErrorValue; - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - if ((errObjListWithOpen != null) - && (errObjListWithOpen.isErrorObjListWithOpenPresent())) { - toStrHelper.add("ErrorObjectListWithOpen", errObjListWithOpen); - } - if ((errInfo != null) && (errInfo.isErrorInfoPresent())) { - toStrHelper.add("ErrorInfo", errInfo); - } - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorObjectVer1.java deleted file mode 100644 index 48a337f4..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorObjectVer1.java +++ /dev/null @@ -1,341 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepErrorObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Error Object. - */ -public class PcepErrorObjectVer1 implements PcepErrorObject { - - /* - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Reserved | Flags | Error-Type | Error-value | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - protected static final Logger log = LoggerFactory.getLogger(PcepErrorObjectVer1.class); - - public static final byte ERROR_OBJ_TYPE = 1; - public static final byte ERROR_OBJ_CLASS = 13; - public static final byte ERROR_OBJECT_VERSION = 1; - //ERROR_OBJ_MINIMUM_LENGTH = CommonHeaderLen(4)+ErrorObjectHeaderLen(4) - public static final short ERROR_OBJ_MINIMUM_LENGTH = 8; - public static final int OBJECT_HEADER_LENGTH = 4; - - public static final PcepObjectHeader DEFAULT_ERROR_OBJECT_HEADER = new PcepObjectHeader(ERROR_OBJ_CLASS, - ERROR_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - ERROR_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader errorObjHeader; - private byte yErrorType; - private byte yErrorValue; - private LinkedList<PcepValueType> llOptionalTlv; // Optional TLV - - /** - * Constructor to initialize variables. - * - * @param errorObjHeader ERROR Object header - * @param yErrorType Error Type - * @param yErrorValue Error Value - * @param llOptionalTlv list of optional TLV - */ - - public PcepErrorObjectVer1(PcepObjectHeader errorObjHeader, byte yErrorType, byte yErrorValue, - LinkedList<PcepValueType> llOptionalTlv) { - this.errorObjHeader = errorObjHeader; - this.yErrorType = yErrorType; - this.yErrorValue = yErrorValue; - this.llOptionalTlv = llOptionalTlv; - } - - /** - * sets Object Header. - * - * @param obj Error-Object header - */ - public void setLspObjHeader(PcepObjectHeader obj) { - this.errorObjHeader = obj; - } - - @Override - public void setErrorType(byte yErrorType) { - this.yErrorType = yErrorType; - } - - @Override - public void setErrorValue(byte yErrorValue) { - this.yErrorValue = yErrorValue; - } - - /** - * returns object header. - * - * @return errorObjHeader Error-Object header - */ - public PcepObjectHeader getErrorObjHeader() { - return this.errorObjHeader; - } - - @Override - public int getErrorType() { - return this.yErrorType; - } - - @Override - public byte getErrorValue() { - return this.yErrorValue; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Reads from channel buffer and returns object of PcepErrorObject. - * - * @param cb of channel buffer. - * @return object of PCEP-ERROR-OBJECT - */ - public static PcepErrorObject read(ChannelBuffer cb) { - - PcepObjectHeader errorObjHeader; - byte yErrorType; - byte yErrorValue; - LinkedList<PcepValueType> llOptionalTlv; - - errorObjHeader = PcepObjectHeader.read(cb); - - //take only ErrorObject buffer. - ChannelBuffer tempCb = cb.readBytes(errorObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - tempCb.readByte(); //ignore Reserved - tempCb.readByte(); //ignore Flags - yErrorType = tempCb.readByte(); - yErrorValue = tempCb.readByte(); - - llOptionalTlv = parseOptionalTlv(tempCb); - - return new PcepErrorObjectVer1(errorObjHeader, yErrorType, yErrorValue, llOptionalTlv); - } - - /** - * returns Linked list of optional tlvs. - * - * @param cb channel buffer. - * @return Linked list of optional tlvs - */ - protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) { - - LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<>(); - - byte[] yTemp = new byte[cb.readableBytes()]; - cb.readBytes(yTemp); - - return llOutOptionalTlv; - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = errorObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("While writing Error Object Header."); - } - - //write Reserved - cb.writeByte(0); - //write Flags - cb.writeByte(0); - //write ErrorType and ErrorValue - cb.writeByte(this.yErrorType); - cb.writeByte(this.yErrorValue); - - // Add optional TLV - packOptionalTlv(cb); - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - //will be helpful during print(). - errorObjHeader.setObjLen((short) length); - // As per RFC the length of object should be - // multiples of 4 - int pad = length % 4; - if (pad != 0) { - pad = 4 - pad; - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = length + pad; - } - - cb.setShort(objLenIndex, (short) length); - return length; - } - - /** - * Pack the Optional tlvs. - * - * @param cb channel buffer. - * @return writer index. - */ - protected int packOptionalTlv(ChannelBuffer cb) { - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - int startIndex = cb.writerIndex(); - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - if (tlv == null) { - log.debug("TLV is null from OptionalTlv list"); - continue; - } - tlv.write(cb); - } - - return cb.writerIndex() - startIndex; - } - - /** - * Builder class for PCEP error object. - */ - public static class Builder implements PcepErrorObject.Builder { - - private boolean bIsHeaderSet = false; - - private PcepObjectHeader errorObjHeader; - private byte yErrorType; - private byte yErrorValue; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - @Override - public PcepErrorObject build() { - - PcepObjectHeader errorObjHeader = this.bIsHeaderSet ? this.errorObjHeader : DEFAULT_ERROR_OBJECT_HEADER; - - if (bIsPFlagSet) { - errorObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - errorObjHeader.setIFlag(bIFlag); - } - - return new PcepErrorObjectVer1(errorObjHeader, yErrorType, yErrorValue, llOptionalTlv); - } - - @Override - public PcepObjectHeader getErrorObjHeader() { - return this.errorObjHeader; - } - - @Override - public Builder setErrorObjHeader(PcepObjectHeader obj) { - this.errorObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getErrorType() { - return this.yErrorType; - } - - @Override - public Builder setErrorType(byte value) { - this.yErrorType = value; - return this; - } - - @Override - public byte getErrorValue() { - return this.yErrorValue; - } - - @Override - public Builder setErrorValue(byte value) { - this.yErrorValue = value; - return this; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ObjectHeader", errorObjHeader).add("ErrorType", yErrorType) - .add("ErrorValue", yErrorValue).add("OptionalTlv", llOptionalTlv).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorVer1.java deleted file mode 100644 index 0ea51410..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorVer1.java +++ /dev/null @@ -1,399 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepError; -import org.onosproject.pcepio.protocol.PcepErrorObject; -import org.onosproject.pcepio.protocol.PcepRPObject; -import org.onosproject.pcepio.protocol.PcepTEObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PcepError list which contains RP or TE objects. - * Reference:PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02. - */ -public class PcepErrorVer1 implements PcepError { - - /* - <error>::=[<request-id-list> | <te-id-list>] - <error-obj-list> - - <request-id-list>::=<RP>[<request-id-list>] - - <te-id-list>::=<TE>[<te-id-list>] - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepErrorVer1.class); - - private boolean isErroInfoSet; - //PcepErrorObject list - private LinkedList<PcepErrorObject> llErrObjList; - //PcepRPObject list - private LinkedList<PcepRPObject> llRPObjList; - //PcepTEObject list - private LinkedList<PcepTEObject> llTEObjList; - private boolean isTEObjListSet; - - public static final int OBJECT_HEADER_LENGTH = 4; - - /** - * Constructor to initialize variable. - */ - public PcepErrorVer1() { - this.llRPObjList = null; - this.llTEObjList = null; - this.llErrObjList = null; - } - - /** - * Constructor to initialize variable. - * - * @param llRPObjList list of PcepRPObject - * @param llTEObjList list of PcepTEObject - * @param llErrObjListObjList list of PcepErrorObject - */ - public PcepErrorVer1(LinkedList<PcepRPObject> llRPObjList, LinkedList<PcepTEObject> llTEObjList, - LinkedList<PcepErrorObject> llErrObjListObjList) { - this.llRPObjList = llRPObjList; - this.llTEObjList = llTEObjList; - this.llErrObjList = llErrObjListObjList; - } - - /** - * Constructor to initialize PcepError. - * - * @param llErrObjList list of PcepErrorObject - */ - public PcepErrorVer1(LinkedList<PcepErrorObject> llErrObjList) { - this.llRPObjList = null; - this.llTEObjList = null; - this.llErrObjList = llErrObjList; - } - - @Override - public LinkedList<PcepRPObject> getRPObjList() { - return this.llRPObjList; - } - - @Override - public LinkedList<PcepTEObject> getTEObjList() { - return this.llTEObjList; - } - - @Override - public LinkedList<PcepErrorObject> getErrorObjList() { - return this.llErrObjList; - } - - /** - * Parse RP List from the channel buffer. - * - * @param cb of type channel buffer - * @throws PcepParseException if mandatory fields are missing - */ - public void parseRPList(ChannelBuffer cb) throws PcepParseException { - byte yObjClass; - byte yObjType; - - llRPObjList = new LinkedList<>(); - - // caller should verify for RP object - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - log.debug("Unable to find RP Object"); - return; - } - - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - PcepRPObject rpObj; - while ((yObjClass == PcepRPObjectVer1.RP_OBJ_CLASS) && (yObjType == PcepRPObjectVer1.RP_OBJ_TYPE)) { - rpObj = PcepRPObjectVer1.read(cb); - llRPObjList.add(rpObj); - - if (cb.readableBytes() > OBJECT_HEADER_LENGTH) { - cb.markReaderIndex(); - tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - } else { - break; - } - } - } - - /** - * Parse TE List from the channel buffer. - * - * @param cb of type channel buffer - * @throws PcepParseException if mandatory fields are missing - */ - public void parseTEList(ChannelBuffer cb) throws PcepParseException { - byte yObjClass; - byte yObjType; - - llTEObjList = new LinkedList<>(); - - // caller should verify for TE object - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - log.debug("Unable to find TE Object"); - return; - } - - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - PcepTEObject teObj; - while ((yObjClass == PcepTEObjectVer1.TE_OBJ_CLASS) && ((yObjType == PcepTEObjectVer1.TE_OBJ_TYPE_NODE_VALUE) - || (yObjType == PcepTEObjectVer1.TE_OBJ_TYPE_LINK_VALUE))) { - teObj = PcepTEObjectVer1.read(cb); - llTEObjList.add(teObj); - - if (cb.readableBytes() > OBJECT_HEADER_LENGTH) { - cb.markReaderIndex(); - tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - } else { - break; - } - } - } - - /** - * parseErrObjList from the channel buffer. - * - * @param cb of type channel buffer - * @throws PcepParseException if mandatory fields are missing - */ - public void parseErrObjList(ChannelBuffer cb) throws PcepParseException { - byte yObjClass; - byte yObjType; - boolean bIsErrorObjFound = false; - - llErrObjList = new LinkedList<>(); - - // caller should verify for RP object - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - throw new PcepParseException("Unable to find PCEP-ERROR Object"); - } - - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - PcepErrorObject errorObject; - while ((yObjClass == PcepErrorObjectVer1.ERROR_OBJ_CLASS) && (yObjType == PcepErrorObjectVer1.ERROR_OBJ_TYPE)) { - errorObject = PcepErrorObjectVer1.read(cb); - llErrObjList.add(errorObject); - bIsErrorObjFound = true; - - if (cb.readableBytes() > OBJECT_HEADER_LENGTH) { - cb.markReaderIndex(); - tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - yObjClass = tempObjHeader.getObjClass(); - yObjType = tempObjHeader.getObjType(); - } else { - break; - } - } - - if (!bIsErrorObjFound) { - throw new PcepParseException("At least one PCEP-ERROR Object should be present."); - } - } - - /** - * Reads the byte stream of PcepError from channel buffer. - * - * @param cb of type channel buffer - * @return PcepError error part of PCEP-ERROR - * @throws PcepParseException if mandatory fields are missing - */ - public static PcepErrorVer1 read(ChannelBuffer cb) throws PcepParseException { - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - throw new PcepParseException("Unknown Object"); - } - - PcepErrorVer1 pcepError = new PcepErrorVer1(); - // check whether any PCEP Error Info is present - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - byte yObjClass = tempObjHeader.getObjClass(); - - //If RPlist present then store it.RPList and TEList are optional - if (yObjClass == PcepRPObjectVer1.RP_OBJ_CLASS) { - log.debug("RP_LIST"); - pcepError.parseRPList(cb); - yObjClass = checkNextObject(cb); - } else if (yObjClass == PcepTEObjectVer1.TE_OBJ_CLASS) { - log.debug("TE_LIST"); - pcepError.parseTEList(cb); - yObjClass = checkNextObject(cb); - } - - if (yObjClass == PcepErrorObjectVer1.ERROR_OBJ_CLASS) { - log.debug("PCEP-ERROR obj list"); - pcepError.parseErrObjList(cb); - yObjClass = checkNextObject(cb); - } - - return pcepError; - } - - /** - * Checks Next Object. - * - * @param cb of type channel buffer. - * @return object type class. - */ - private static byte checkNextObject(ChannelBuffer cb) { - if (cb.readableBytes() < OBJECT_HEADER_LENGTH) { - return 0; - } - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - return tempObjHeader.getObjClass(); - } - - /** - * Writes the byte stream of PCEP error to the channel buffer. - * - * @param cb of type channel buffer - * @return object length index - * @throws PcepParseException if mandatory fields are missing - */ - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - int iLenStartIndex = cb.writerIndex(); - - // RPlist is optional - if (this.isErroInfoSet) { - ListIterator<PcepRPObject> rpObjlistIterator = this.llRPObjList.listIterator(); - while (rpObjlistIterator.hasNext()) { - rpObjlistIterator.next().write(cb); - } - } - - // TElist is optional - if (this.isTEObjListSet) { - ListIterator<PcepTEObject> teObjlistIterator = this.llTEObjList.listIterator(); - while (teObjlistIterator.hasNext()) { - teObjlistIterator.next().write(cb); - } - } - //ErrList is mandatory - ListIterator<PcepErrorObject> errlistIterator = this.llErrObjList.listIterator(); - while (errlistIterator.hasNext()) { - errlistIterator.next().write(cb); - } - - return cb.writerIndex() - iLenStartIndex; - } - - /** - * Builder for error part of PCEP-ERROR. - */ - public static class Builder implements PcepError.Builder { - - private LinkedList<PcepRPObject> llRPObjList; - private LinkedList<PcepTEObject> llTEObjList; - private LinkedList<PcepErrorObject> llErrObjList; - - @Override - public PcepError build() { - return new PcepErrorVer1(llRPObjList, llTEObjList, llErrObjList); - } - - @Override - public LinkedList<PcepRPObject> getRPObjList() { - return this.llRPObjList; - } - - @Override - public Builder setRPObjList(LinkedList<PcepRPObject> llRPObjList) { - this.llRPObjList = llRPObjList; - return this; - } - - @Override - public LinkedList<PcepTEObject> getTEObjList() { - return this.llTEObjList; - } - - @Override - public Builder setTEObjList(LinkedList<PcepTEObject> llTEObjList) { - this.llTEObjList = llTEObjList; - return this; - } - - @Override - public LinkedList<PcepErrorObject> getErrorObjList() { - return this.llErrObjList; - } - - @Override - public Builder setErrorObjList(LinkedList<PcepErrorObject> llErrObjList) { - this.llErrObjList = llErrObjList; - return this; - } - - } - - @Override - public void setRPObjList(LinkedList<PcepRPObject> llRPObjList) { - this.llRPObjList = llRPObjList; - } - - @Override - public void setTEObjList(LinkedList<PcepTEObject> llTEObjList) { - this.llTEObjList = llTEObjList; - } - - @Override - public void setErrorObjList(LinkedList<PcepErrorObject> llErrObjList) { - this.llErrObjList = llErrObjList; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .omitNullValues() - .add("RpObjectList", llRPObjList) - .add("TeObjectList", llTEObjList) - .add("ErrorObjectList", llErrObjList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFactoryVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFactoryVer1.java deleted file mode 100644 index 6b5d450a..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFactoryVer1.java +++ /dev/null @@ -1,226 +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.pcepio.protocol.ver1; - -import org.onosproject.pcepio.protocol.PcInitiatedLspRequest; -import org.onosproject.pcepio.protocol.PcepAttribute; -import org.onosproject.pcepio.protocol.PcepBandwidthObject; -import org.onosproject.pcepio.protocol.PcepCloseMsg; -import org.onosproject.pcepio.protocol.PcepEndPointsObject; -import org.onosproject.pcepio.protocol.PcepEroObject; -import org.onosproject.pcepio.protocol.PcepErrorInfo; -import org.onosproject.pcepio.protocol.PcepError; -import org.onosproject.pcepio.protocol.PcepErrorMsg; -import org.onosproject.pcepio.protocol.PcepErrorObject; -import org.onosproject.pcepio.protocol.PcepFactory; -import org.onosproject.pcepio.protocol.PcepFecObjectIPv4Adjacency; -import org.onosproject.pcepio.protocol.PcepInitiateMsg; -import org.onosproject.pcepio.protocol.PcepIroObject; -import org.onosproject.pcepio.protocol.PcepKeepaliveMsg; -import org.onosproject.pcepio.protocol.PcepLabelObject; -import org.onosproject.pcepio.protocol.PcepLabelRangeObject; -import org.onosproject.pcepio.protocol.PcepLabelRangeResvMsg; -import org.onosproject.pcepio.protocol.PcepLabelUpdate; -import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepLspaObject; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMetricObject; -import org.onosproject.pcepio.protocol.PcepMsgPath; -import org.onosproject.pcepio.protocol.PcepOpenMsg; -import org.onosproject.pcepio.protocol.PcepOpenObject; -import org.onosproject.pcepio.protocol.PcepReportMsg; -import org.onosproject.pcepio.protocol.PcepRroObject; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.onosproject.pcepio.protocol.PcepStateReport; -import org.onosproject.pcepio.protocol.PcepUpdateMsg; -import org.onosproject.pcepio.protocol.PcepUpdateRequest; -import org.onosproject.pcepio.protocol.PcepVersion; - -/** - * Provides PCEP Factory and returns builder classes for all objects and messages. - */ -public class PcepFactoryVer1 implements PcepFactory { - - public static final PcepFactoryVer1 INSTANCE = new PcepFactoryVer1(); - - @Override - public PcepOpenMsg.Builder buildOpenMsg() { - return new PcepOpenMsgVer1.Builder(); - } - - @Override - public PcepOpenObject.Builder buildOpenObject() { - return new PcepOpenObjectVer1.Builder(); - } - - @Override - public PcepKeepaliveMsg.Builder buildKeepaliveMsg() { - return new PcepKeepaliveMsgVer1.Builder(); - } - - @Override - public PcepCloseMsg.Builder buildCloseMsg() { - return new PcepCloseMsgVer1.Builder(); - } - - @Override - public PcepUpdateMsg.Builder buildUpdateMsg() { - return new PcepUpdateMsgVer1.Builder(); - } - - @Override - public PcepReportMsg.Builder buildReportMsg() { - return new PcepReportMsgVer1.Builder(); - } - - @Override - public PcepInitiateMsg.Builder buildPcepInitiateMsg() { - return new PcepInitiateMsgVer1.Builder(); - } - - @Override - public PcepLspObject.Builder buildLspObject() { - return new PcepLspObjectVer1.Builder(); - } - - @Override - public PcepMessageReader<PcepMessage> getReader() { - return PcepMessageVer1.READER; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepSrpObject.Builder buildSrpObject() { - return new PcepSrpObjectVer1.Builder(); - } - - @Override - public PcepEndPointsObject.Builder buildEndPointsObject() { - return new PcepEndPointsObjectVer1.Builder(); - } - - @Override - public PcepEroObject.Builder buildEroObject() { - return new PcepEroObjectVer1.Builder(); - } - - @Override - public PcepRroObject.Builder buildRroObject() { - return new PcepRroObjectVer1.Builder(); - } - - @Override - public PcepLspaObject.Builder buildLspaObject() { - return new PcepLspaObjectVer1.Builder(); - } - - @Override - public PcepIroObject.Builder buildIroObject() { - return new PcepIroObjectVer1.Builder(); - } - - @Override - public PcepMetricObject.Builder buildMetricObject() { - return new PcepMetricObjectVer1.Builder(); - } - - @Override - public PcepBandwidthObject.Builder buildBandwidthObject() { - return new PcepBandwidthObjectVer1.Builder(); - } - - @Override - public PcepMsgPath.Builder buildPcepMsgPath() { - return new PcepMsgPathVer1.Builder(); - } - - @Override - public PcepStateReport.Builder buildPcepStateReport() { - return new PcepStateReportVer1.Builder(); - } - - @Override - public PcepUpdateRequest.Builder buildPcepUpdateRequest() { - return new PcepUpdateRequestVer1.Builder(); - } - - @Override - public PcInitiatedLspRequest.Builder buildPcInitiatedLspRequest() { - return new PcInitiatedLspRequestVer1.Builder(); - } - - @Override - public PcepAttribute.Builder buildPcepAttribute() { - return new PcepAttributeVer1.Builder(); - } - - @Override - public PcepLabelUpdateMsg.Builder buildPcepLabelUpdateMsg() { - return new PcepLabelUpdateMsgVer1.Builder(); - } - - @Override - public PcepLabelUpdate.Builder buildPcepLabelUpdateObject() { - return new PcepLabelUpdateVer1.Builder(); - } - - @Override - public PcepLabelObject.Builder buildLabelObject() { - return new PcepLabelObjectVer1.Builder(); - } - - @Override - public PcepErrorMsg.Builder buildPcepErrorMsg() { - return new PcepErrorMsgVer1.Builder(); - } - - @Override - public PcepErrorObject.Builder buildPcepErrorObject() { - return new PcepErrorObjectVer1.Builder(); - } - - @Override - public PcepFecObjectIPv4Adjacency.Builder buildFecIpv4Adjacency() { - return new PcepFecObjectIPv4AdjacencyVer1.Builder(); - } - - @Override - public PcepErrorInfo.Builder buildPcepErrorInfo() { - return new PcepErrorInfoVer1.Builder(); - } - - @Override - public PcepError.Builder buildPcepError() { - return new PcepErrorVer1.Builder(); - } - - @Override - public PcepLabelRangeObject.Builder buildPcepLabelRangeObject() { - return new PcepLabelRangeObjectVer1.Builder(); - } - - @Override - public PcepLabelRangeResvMsg.Builder buildPcepLabelRangeResvMsg() { - return new PcepLabelRangeResvMsgVer1.Builder(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4AdjacencyVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4AdjacencyVer1.java deleted file mode 100644 index 51c672d3..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4AdjacencyVer1.java +++ /dev/null @@ -1,253 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFecObjectIPv4Adjacency; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP fec Object IPv4 Adjacency object. - */ -public class PcepFecObjectIPv4AdjacencyVer1 implements PcepFecObjectIPv4Adjacency { - - /* - * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5 - * - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Local IPv4 address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Remote IPv4 address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - FEC Object-Type is 3 IPv4 Adjacency - */ - protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv4AdjacencyVer1.class); - - public static final byte FEC_OBJ_TYPE = 3; - public static final byte FEC_OBJ_CLASS = 36; //to be defined - public static final byte FEC_OBJECT_VERSION = 1; - public static final short FEC_OBJ_MINIMUM_LENGTH = 12; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - - static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader fecObjHeader; - private int localIPv4Address; - private int remoteIPv4Address; - - /** - * Constructor to initialize parameters for PCEP fec object . - * - * @param fecObjHeader FEC Object header - * @param localIPv4Address Local IPv4 Address - * @param remoteIPv4Address Remote IPv4 Address - */ - public PcepFecObjectIPv4AdjacencyVer1(PcepObjectHeader fecObjHeader, int localIPv4Address, int remoteIPv4Address) { - this.fecObjHeader = fecObjHeader; - this.localIPv4Address = localIPv4Address; - this.remoteIPv4Address = remoteIPv4Address; - } - - /** - * Sets Object header. - * - * @param obj Pcep fec Object Header - */ - public void setFecIpv4ObjHeader(PcepObjectHeader obj) { - this.fecObjHeader = obj; - } - - @Override - public int getLocalIPv4Address() { - return this.localIPv4Address; - } - - @Override - public void seLocalIPv4Address(int value) { - this.localIPv4Address = value; - } - - @Override - public int getRemoteIPv4Address() { - return this.remoteIPv4Address; - } - - @Override - public void seRemoteIPv4Address(int value) { - this.remoteIPv4Address = value; - } - - /** - * Reads from channel buffer and Returns object of PcepFecObjectIPv4Adjacency. - * - * @param cb of channel buffer. - * @return object of PcepFecObjectIPv4Adjacency - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepFecObjectIPv4Adjacency read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader fecObjHeader; - int localIPv4Address; - int remoteIPv4Address; - - fecObjHeader = PcepObjectHeader.read(cb); - - //take only FEC IPv4 Adjacency Object buffer. - ChannelBuffer tempCb = cb.readBytes(fecObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH); - localIPv4Address = tempCb.readInt(); - remoteIPv4Address = tempCb.readInt(); - - return new PcepFecObjectIPv4AdjacencyVer1(fecObjHeader, localIPv4Address, remoteIPv4Address); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - int objStartIndex = cb.writerIndex(); - - //Write common header - int objLenIndex = fecObjHeader.write(cb); - cb.writeInt(localIPv4Address); - cb.writeInt(remoteIPv4Address); - - //Now write FEC IPv4 Adjacency Object Length - cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex)); - return cb.writerIndex(); - } - - /** - * Builder class for PCEP fec object IPv4 Adjacency. - */ - public static class Builder implements PcepFecObjectIPv4Adjacency.Builder { - private boolean bIsHeaderSet = false; - private boolean bIsLocalIPv4Addressset = false; - private boolean bIsRemoteIPv4Addressset = false; - - private PcepObjectHeader fecObjHeader; - int localIPv4Address; - int remoteIPv4Address; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepFecObjectIPv4Adjacency build() throws PcepParseException { - PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER; - - if (!this.bIsLocalIPv4Addressset) { - throw new PcepParseException( - "Local IPv4 Address not set while building PcepFecObjectIPv4Adjacency object."); - } - - if (!this.bIsRemoteIPv4Addressset) { - throw new PcepParseException( - " Remote IPv4 Address not set while building PcepFecObjectIPv4Adjacency object."); - } - - if (bIsPFlagSet) { - fecObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - fecObjHeader.setIFlag(bIFlag); - } - return new PcepFecObjectIPv4AdjacencyVer1(fecObjHeader, this.localIPv4Address, this.remoteIPv4Address); - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - @Override - public PcepObjectHeader getFecIpv4AdjacencyObjHeader() { - return this.fecObjHeader; - } - - @Override - public Builder setFecIpv4AdjacencyObjHeader(PcepObjectHeader obj) { - this.fecObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getLocalIPv4Address() { - return this.localIPv4Address; - } - - @Override - public Builder seLocalIPv4Address(int value) { - this.localIPv4Address = value; - this.bIsLocalIPv4Addressset = true; - return this; - } - - @Override - public int getRemoteIPv4Address() { - return this.remoteIPv4Address; - } - - @Override - public Builder seRemoteIPv4Address(int value) { - this.remoteIPv4Address = value; - this.bIsRemoteIPv4Addressset = true; - return this; - } - - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public int getType() { - return FEC_OBJ_TYPE; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("fecObjHeader", fecObjHeader) - .add("localIPv4Address", localIPv4Address) - .add("remoteIPv4Address", remoteIPv4Address).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4UnnumberedAdjacencyVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4UnnumberedAdjacencyVer1.java deleted file mode 100644 index f2f54cda..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4UnnumberedAdjacencyVer1.java +++ /dev/null @@ -1,334 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFecObjectIPv4UnnumberedAdjacency; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides Pcep Fec Object IPv4 Unnumbered Adjacency object. - */ -public class PcepFecObjectIPv4UnnumberedAdjacencyVer1 implements PcepFecObjectIPv4UnnumberedAdjacency { - - /* - * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5 - * - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Local Node-ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Local Interface ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Remote Node-ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Remote Interface ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - FEC Object-Type is 5, Unnumbered Adjacency with IPv4 NodeIDs - */ - protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv4UnnumberedAdjacencyVer1.class); - - public static final byte FEC_OBJ_TYPE = 5; - public static final byte FEC_OBJ_CLASS = 63; //to be defined - public static final byte FEC_OBJECT_VERSION = 1; - public static final short FEC_OBJ_MINIMUM_LENGTH = 20; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - - static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader fecObjHeader; - private int localNodeID; - private int localInterfaceID; - private int remoteNodeID; - private int remoteInterfaceID; - - /** - * Constructor to initialize parameter for PCEP fec object. - * - * @param fecObjHeader fec object header - * @param localNodeID local node ID - * @param localInterfaceID local interface ID - * @param remoteNodeID remote node ID - * @param remoteInterfaceID remote interface ID - */ - public PcepFecObjectIPv4UnnumberedAdjacencyVer1(PcepObjectHeader fecObjHeader, int localNodeID, - int localInterfaceID, int remoteNodeID, int remoteInterfaceID) { - this.fecObjHeader = fecObjHeader; - this.localNodeID = localNodeID; - this.localInterfaceID = localInterfaceID; - this.remoteNodeID = remoteNodeID; - this.remoteInterfaceID = remoteInterfaceID; - } - - /** - * Sets Object Header. - * - * @param obj object header - */ - public void setFecIpv4UnnumberedAdjacencyObjHeader(PcepObjectHeader obj) { - this.fecObjHeader = obj; - } - - @Override - public void setLocalNodeID(int localNodeID) { - this.localNodeID = localNodeID; - } - - /** - * Returns Object Header. - * - * @return fecObjHeader fec object header - */ - public PcepObjectHeader getFecIpv4UnnumberedAdjacencyObjHeader() { - return this.fecObjHeader; - } - - @Override - public int getLocalNodeID() { - return this.localNodeID; - } - - @Override - public int getLocalInterfaceID() { - return this.localInterfaceID; - } - - @Override - public void setLocalInterfaceID(int localInterfaceID) { - this.localInterfaceID = localInterfaceID; - } - - @Override - public int getRemoteNodeID() { - return this.remoteNodeID; - } - - @Override - public void setRemoteNodeID(int remoteNodeID) { - this.remoteNodeID = remoteNodeID; - } - - @Override - public int getRemoteInterfaceID() { - return this.remoteInterfaceID; - } - - @Override - public void setRemoteInterfaceID(int remoteInterfaceID) { - this.remoteInterfaceID = remoteInterfaceID; - } - - /** - * Reads from channel buffer and returns object of PcepFecObjectIPv4UnnumberedAdjacency. - * - * @param cb of channel buffer - * @return object of PcepFecObjectIPv4UnnumberedAdjacency - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepFecObjectIPv4UnnumberedAdjacency read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader fecObjHeader; - int localNodeID; - int localInterfaceID; - int remoteNodeID; - int remoteInterfaceID; - - fecObjHeader = PcepObjectHeader.read(cb); - - //take only FEC IPv4 Unnumbered Adjacency Object buffer. - ChannelBuffer tempCb = cb.readBytes(fecObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH); - localNodeID = tempCb.readInt(); - localInterfaceID = tempCb.readInt(); - remoteNodeID = tempCb.readInt(); - remoteInterfaceID = tempCb.readInt(); - - return new PcepFecObjectIPv4UnnumberedAdjacencyVer1(fecObjHeader, localNodeID, localInterfaceID, remoteNodeID, - remoteInterfaceID); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - int objStartIndex = cb.writerIndex(); - - //Write common header - int objLenIndex = fecObjHeader.write(cb); - cb.writeInt(localNodeID); - cb.writeInt(localInterfaceID); - cb.writeInt(remoteNodeID); - cb.writeInt(remoteInterfaceID); - - //Now write FEC IPv4 Unnumbered Adjacency Object Length - cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex)); - - return cb.writerIndex(); - } - - /** - * Builder class for PCEP Fec object IPv4 unnumbered Adjacency. - */ - public static class Builder implements PcepFecObjectIPv4UnnumberedAdjacency.Builder { - private boolean bIsHeaderSet = false; - private boolean bIsLocalNodeIDset = false; - private boolean bIsLocalInterfaceIDset = false; - private boolean bIsRemoteNodeIDset = false; - private boolean bIsRemoteInterfaceIDset = false; - - private PcepObjectHeader fecObjHeader; - private int localNodeID; - private int localInterfaceID; - private int remoteNodeID; - private int remoteInterfaceID; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepFecObjectIPv4UnnumberedAdjacency build() throws PcepParseException { - PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER; - - if (!this.bIsLocalNodeIDset) { - throw new PcepParseException( - " Local Node ID not set while building PcepFecObjectIPv4UnnumberedAdjacency object."); - } - if (!this.bIsLocalInterfaceIDset) { - throw new PcepParseException( - " Local Interface ID not set while building PcepFecObjectIPv4UnnumberedAdjacency object."); - } - if (!this.bIsRemoteNodeIDset) { - throw new PcepParseException( - " Remote Node ID not set while building PcepFecObjectIPv4UnnumberedAdjacency object."); - } - if (!this.bIsRemoteInterfaceIDset) { - throw new PcepParseException( - " Remote Interface ID not set while building PcepFecObjectIPv4UnnumberedAdjacency object."); - } - if (bIsPFlagSet) { - fecObjHeader.setPFlag(bPFlag); - } - if (bIsIFlagSet) { - fecObjHeader.setIFlag(bIFlag); - } - return new PcepFecObjectIPv4UnnumberedAdjacencyVer1(fecObjHeader, this.localNodeID, this.localInterfaceID, - this.remoteNodeID, this.remoteInterfaceID); - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - @Override - public PcepObjectHeader getFecIpv4UnnumberedAdjacencyObjHeader() { - return this.fecObjHeader; - } - - @Override - public Builder setFecIpv4UnnumberedAdjacencyObjHeader(PcepObjectHeader obj) { - this.fecObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getLocalNodeID() { - return this.localNodeID; - } - - @Override - public Builder setLocalNodeID(int value) { - this.localNodeID = value; - this.bIsLocalNodeIDset = true; - return this; - } - - @Override - public int getLocalInterfaceID() { - return this.localInterfaceID; - } - - @Override - public Builder setLocalInterfaceID(int value) { - this.localInterfaceID = value; - this.bIsLocalInterfaceIDset = true; - return this; - } - - @Override - public int getRemoteNodeID() { - return this.remoteNodeID; - } - - @Override - public Builder setRemoteNodeID(int value) { - this.remoteNodeID = value; - this.bIsRemoteNodeIDset = true; - return this; - } - - @Override - public int getRemoteInterfaceID() { - return this.remoteInterfaceID; - } - - @Override - public Builder setRemoteInterfaceID(int value) { - this.remoteInterfaceID = value; - this.bIsRemoteInterfaceIDset = true; - return this; - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public int getType() { - return FEC_OBJ_TYPE; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("LocalNodeID: ", localNodeID) - .add("LocalInterfaceID: ", localInterfaceID).add("RemoteNodeID: ", remoteNodeID) - .add("RemoteInterfaceID: ", remoteInterfaceID).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4Ver1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4Ver1.java deleted file mode 100644 index 354547a1..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv4Ver1.java +++ /dev/null @@ -1,217 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFecObjectIPv4; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides Pcep Fec Object IPv4 object. - */ -public class PcepFecObjectIPv4Ver1 implements PcepFecObjectIPv4 { - - /* - * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5 - * - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 Node ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - FEC Object-Type is 1 IPv4 Node ID - */ - protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv4Ver1.class); - - public static final byte FEC_OBJ_TYPE = 1; - public static final byte FEC_OBJ_CLASS = 63; //to be defined - public static final byte FEC_OBJECT_VERSION = 1; - public static final short FEC_OBJ_MINIMUM_LENGTH = 8; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - - static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader fecObjHeader; - private int nodeID; - - /** - * Constructor to initialize parameters for PCEP fec object. - * - * @param fecObjHeader fec object header - * @param nodeID node id - */ - public PcepFecObjectIPv4Ver1(PcepObjectHeader fecObjHeader, int nodeID) { - this.fecObjHeader = fecObjHeader; - this.nodeID = nodeID; - } - - /** - * Sets the Object Header. - * - * @param obj object header - */ - public void setFecIpv4ObjHeader(PcepObjectHeader obj) { - this.fecObjHeader = obj; - } - - @Override - public void setNodeID(int nodeID) { - this.nodeID = nodeID; - } - - /** - * Returns Object Header. - * - * @return fecObjHeader fec object header - */ - public PcepObjectHeader getFecIpv4ObjHeader() { - return this.fecObjHeader; - } - - @Override - public int getNodeID() { - return this.nodeID; - } - - /** - * Reads from channel buffer and returns object of PcepFecObjectIPv4. - * - * @param cb of channel buffer - * @return object of PcepFecObjectIPv4 - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepFecObjectIPv4 read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader fecObjHeader; - int nodeID; - fecObjHeader = PcepObjectHeader.read(cb); - nodeID = cb.readInt(); - return new PcepFecObjectIPv4Ver1(fecObjHeader, nodeID); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - int objStartIndex = cb.writerIndex(); - - //write common header - int objLenIndex = fecObjHeader.write(cb); - cb.writeInt(nodeID); - - //now write FEC IPv4 Object Length - cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex)); - return cb.writerIndex(); - } - - /** - * Builder class for PCEP fec pobject IPv4. - */ - public static class Builder implements PcepFecObjectIPv4.Builder { - private boolean bIsHeaderSet = false; - private boolean bIsNodeIdset = false; - - private PcepObjectHeader fecObjHeader; - private int nodeID; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepFecObjectIPv4 build() throws PcepParseException { - PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER; - - if (!this.bIsNodeIdset) { - throw new PcepParseException("NodeID not set while building PcepFecObjectIPv4 object."); - } - if (bIsPFlagSet) { - fecObjHeader.setPFlag(bPFlag); - } - if (bIsIFlagSet) { - fecObjHeader.setIFlag(bIFlag); - } - return new PcepFecObjectIPv4Ver1(fecObjHeader, this.nodeID); - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - @Override - public PcepObjectHeader getFecIpv4ObjHeader() { - return this.fecObjHeader; - } - - @Override - public Builder setFecIpv4ObjHeader(PcepObjectHeader obj) { - this.fecObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getNodeID() { - return this.nodeID; - } - - @Override - public Builder setNodeID(int value) { - this.nodeID = value; - this.bIsNodeIdset = true; - return this; - } - - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public int getType() { - return FEC_OBJ_TYPE; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("fecObjHeader", fecObjHeader) - .add("nodeID: ", nodeID) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6AdjacencyVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6AdjacencyVer1.java deleted file mode 100644 index f8ea7869..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6AdjacencyVer1.java +++ /dev/null @@ -1,249 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFecObjectIPv6Adjacency; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides Pcep Fec Object IPv6 Adjacency object. - */ -public class PcepFecObjectIPv6AdjacencyVer1 implements PcepFecObjectIPv6Adjacency { - - /* - * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5 - * - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Local IPv6 address (16 bytes) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Remote IPv6 address (16 bytes) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - FEC Object-Type is 4 IPv6 Adjacency - */ - protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv6AdjacencyVer1.class); - - public static final byte FEC_OBJ_TYPE = 4; - public static final byte FEC_OBJ_CLASS = 63; //to be defined - public static final byte FEC_OBJECT_VERSION = 1; - public static final short FEC_OBJ_MINIMUM_LENGTH = 36; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - public static final int IPV6_ADDRESS_LENGTH = 16; - - static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader fecObjHeader; - private byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH]; - private byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH]; - - /** - * Constructor to initialize parameters for PCEP fec object. - * - * @param fecObjHeader fec object header - * @param localIPv6Address local IPv6 address - * @param remoteIPv6Address remote IPv6 address - */ - public PcepFecObjectIPv6AdjacencyVer1(PcepObjectHeader fecObjHeader, byte[] localIPv6Address, - byte[] remoteIPv6Address) { - this.fecObjHeader = fecObjHeader; - this.localIPv6Address = localIPv6Address; - this.remoteIPv6Address = remoteIPv6Address; - } - - /** - * Sets Object Header. - * - * @param obj object header - */ - public void setFecIpv4ObjHeader(PcepObjectHeader obj) { - this.fecObjHeader = obj; - } - - @Override - public byte[] getLocalIPv6Address() { - return this.localIPv6Address; - } - - @Override - public void seLocalIPv6Address(byte[] value) { - this.localIPv6Address = value; - } - - @Override - public byte[] getRemoteIPv6Address() { - return this.remoteIPv6Address; - } - - @Override - public void seRemoteIPv6Address(byte[] value) { - this.remoteIPv6Address = value; - } - - /** - * Reads channel buffer and Returns object of PcepFecObjectIPv6Adjacency. - * - * @param cb of channel buffer - * @return object of PcepFecObjectIPv6Adjacency - * @throws PcepParseException when fails tp read from channel buffer - */ - public static PcepFecObjectIPv6Adjacency read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader fecObjHeader; - byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH]; - byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH]; - fecObjHeader = PcepObjectHeader.read(cb); - cb.readBytes(localIPv6Address, 0, IPV6_ADDRESS_LENGTH); - cb.readBytes(remoteIPv6Address, 0, IPV6_ADDRESS_LENGTH); - return new PcepFecObjectIPv6AdjacencyVer1(fecObjHeader, localIPv6Address, remoteIPv6Address); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - int objStartIndex = cb.writerIndex(); - - //write common header - int objLenIndex = fecObjHeader.write(cb); - cb.writeBytes(localIPv6Address); - cb.writeBytes(remoteIPv6Address); - //now write FEC IPv6 Adjacency Object Length - cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex)); - return cb.writerIndex(); - } - - /** - * Builder class for PCEP fec object IPv6 Adjacency. - */ - public static class Builder implements PcepFecObjectIPv6Adjacency.Builder { - private boolean bIsHeaderSet = false; - private boolean bIsLocalIPv6Addressset = false; - private boolean bIsRemoteIPv6Addressset = false; - - private PcepObjectHeader fecObjHeader; - byte[] localIPv6Address = new byte[IPV6_ADDRESS_LENGTH]; - byte[] remoteIPv6Address = new byte[IPV6_ADDRESS_LENGTH]; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepFecObjectIPv6Adjacency build() throws PcepParseException { - PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER; - - if (!this.bIsLocalIPv6Addressset) { - throw new PcepParseException( - "Local IPv6 Address not set while building PcepFecObjectIPv6Adjacency object."); - } - if (!this.bIsRemoteIPv6Addressset) { - throw new PcepParseException( - "Remote IPv6 Address not set while building PcepFecObjectIPv6Adjacency object."); - } - if (bIsPFlagSet) { - fecObjHeader.setPFlag(bPFlag); - } - if (bIsIFlagSet) { - fecObjHeader.setIFlag(bIFlag); - } - return new PcepFecObjectIPv6AdjacencyVer1(fecObjHeader, this.localIPv6Address, this.remoteIPv6Address); - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - @Override - public PcepObjectHeader getFecIpv6AdjacencyObjHeader() { - return this.fecObjHeader; - } - - @Override - public Builder setFecIpv6AdjacencyObjHeader(PcepObjectHeader obj) { - this.fecObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public byte[] getLocalIPv6Address() { - return this.localIPv6Address; - } - - @Override - public Builder setLocalIPv6Address(byte[] value) { - this.localIPv6Address = value; - this.bIsLocalIPv6Addressset = true; - return this; - } - - @Override - public byte[] getRemoteIPv6Address() { - return this.remoteIPv6Address; - } - - @Override - public Builder setRemoteIPv6Address(byte[] value) { - this.remoteIPv6Address = value; - this.bIsRemoteIPv6Addressset = true; - return this; - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public int getType() { - return FEC_OBJ_TYPE; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("localIPv6Address", localIPv6Address) - .add("remoteIPv6Address: ", remoteIPv6Address) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6Ver1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6Ver1.java deleted file mode 100644 index 240a96f7..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepFecObjectIPv6Ver1.java +++ /dev/null @@ -1,220 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFecObjectIPv6; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides Pcep Fec Object IPv6 object. - */ -public class PcepFecObjectIPv6Ver1 implements PcepFecObjectIPv6 { - - /* - * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.5 - * - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // IPv6 Node ID (16 bytes) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - FEC Object-Type is 2 IPv6 Node ID - */ - protected static final Logger log = LoggerFactory.getLogger(PcepFecObjectIPv6Ver1.class); - - public static final byte FEC_OBJ_TYPE = 2; - public static final byte FEC_OBJ_CLASS = 63; //to be defined - public static final byte FEC_OBJECT_VERSION = 1; - public static final short FEC_OBJ_MINIMUM_LENGTH = 20; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - public static final int IPV6_ADDRESS_LENGTH = 16; - - static final PcepObjectHeader DEFAULT_FEC_OBJECT_HEADER = new PcepObjectHeader(FEC_OBJ_CLASS, FEC_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, FEC_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader fecObjHeader; - private byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH]; - - /** - * Constructor to initialize parameters for PCEP fec object. - * - * @param fecObjHeader Fec object header - * @param nodeID node ID - */ - public PcepFecObjectIPv6Ver1(PcepObjectHeader fecObjHeader, byte[] nodeID) { - this.fecObjHeader = fecObjHeader; - this.nodeID = nodeID; - } - - /** - * Sets the Object header. - * - * @param obj object header - */ - public void setFecIpv6ObjHeader(PcepObjectHeader obj) { - this.fecObjHeader = obj; - } - - @Override - public void setNodeID(byte[] nodeID) { - this.nodeID = nodeID; - } - - /** - * Returns object header. - * - * @return fec Object Header - */ - public PcepObjectHeader getFecIpv6ObjHeader() { - return this.fecObjHeader; - } - - @Override - public byte[] getNodeID() { - return this.nodeID; - } - - /** - * reads the channel buffer and returns object of PcepFecObjectIPv6. - * - * @param cb of channel buffer. - * @return object of PcepFecObjectIPv6 - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepFecObjectIPv6 read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader fecObjHeader; - byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH]; - fecObjHeader = PcepObjectHeader.read(cb); - cb.readBytes(nodeID, 0, IPV6_ADDRESS_LENGTH); - return new PcepFecObjectIPv6Ver1(fecObjHeader, nodeID); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - int objStartIndex = cb.writerIndex(); - - //write common header - int objLenIndex = fecObjHeader.write(cb); - cb.writeBytes(nodeID); - - //now write FEC IPv4 Object Length - cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex)); - return cb.writerIndex(); - } - - /** - * Builder class for PCEP fec object IPv6. - */ - public static class Builder implements PcepFecObjectIPv6.Builder { - private boolean bIsHeaderSet = false; - private boolean bIsNodeIdset = false; - - private PcepObjectHeader fecObjHeader; - private byte[] nodeID = new byte[IPV6_ADDRESS_LENGTH]; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepFecObjectIPv6 build() throws PcepParseException { - PcepObjectHeader fecObjHeader = this.bIsHeaderSet ? this.fecObjHeader : DEFAULT_FEC_OBJECT_HEADER; - - if (!this.bIsNodeIdset) { - throw new PcepParseException(" NodeID not set while building PcepFecObjectIPv6 object."); - } - if (bIsPFlagSet) { - fecObjHeader.setPFlag(bPFlag); - } - if (bIsIFlagSet) { - fecObjHeader.setIFlag(bIFlag); - } - return new PcepFecObjectIPv6Ver1(fecObjHeader, this.nodeID); - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - @Override - public PcepObjectHeader getFecIpv6ObjHeader() { - return this.fecObjHeader; - } - - @Override - public Builder setFecIpv6ObjHeader(PcepObjectHeader obj) { - this.fecObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public byte[] getNodeID() { - return this.nodeID; - } - - @Override - public Builder setNodeID(byte[] value) { - this.nodeID = value; - this.bIsNodeIdset = true; - return this; - } - - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public int getType() { - return FEC_OBJ_TYPE; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("fecObjHeader", fecObjHeader) - .add("NodeID: ", nodeID) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInitiateMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInitiateMsgVer1.java deleted file mode 100644 index 60d14b07..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInitiateMsgVer1.java +++ /dev/null @@ -1,332 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcInitiatedLspRequest; -import org.onosproject.pcepio.protocol.PcepAttribute; -import org.onosproject.pcepio.protocol.PcepEndPointsObject; -import org.onosproject.pcepio.protocol.PcepEroObject; -import org.onosproject.pcepio.protocol.PcepInitiateMsg; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP initiate message. - */ -class PcepInitiateMsgVer1 implements PcepInitiateMsg { - - protected static final Logger log = LoggerFactory.getLogger(PcepInitiateMsgVer1.class); - - // Ref : PCE initiated tunnel setup draft-ietf-pce-pce-initiated-lsp-03, section 5.1 - /* <PCInitiate Message> ::= <Common Header> - * <PCE-initiated-lsp-list> - * Where: - * <PCE-initiated-lsp-list> ::= <PCE-initiated-lsp-request>[<PCE-initiated-lsp-list>] - * <PCE-initiated-lsp-request> ::= (<PCE-initiated-lsp-instantiation>|<PCE-initiated-lsp-deletion>) - * <PCE-initiated-lsp-instantiation> ::= <SRP> - * <LSP> - * <END-POINTS> - * <ERO> - * [<attribute-list>] - * <PCE-initiated-lsp-deletion> ::= <SRP> - * <LSP> - */ - - static final byte PACKET_VERSION = 1; - /* considering LspDelete Request PcInitiate msg will contain - * common header - * srp object - * lsp object - * so min length for this can be - * PACKET_MINIMUM_LENGTH = CommonHeaderLen(4)+SrpObjectMinLen(12)+LspObjectMinLen(8) - */ - public static final short PACKET_MINIMUM_LENGTH = 24; - public static final short MINIMUM_COMMON_HEADER_LENGTH = 4; - public static final PcepType MSG_TYPE = PcepType.INITIATE; - private LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList; - public static final PcepInitiateMsgVer1.Reader READER = new Reader(); - - /** - * Reader class for reading of Pcep initiate message from channel buffer. - */ - static class Reader implements PcepMessageReader<PcepInitiateMsg> { - - LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList; - - @Override - public PcepInitiateMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - return null; - } - - llPcInitiatedLspRequestList = new LinkedList<>(); - - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != PACKET_VERSION) { - throw new PcepParseException("Wrong version. Expected=PcepVersion.PCEP_1(1), received=" + version); - } - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type. Expected=PcepType.INITIATE(12), recived=" + type); - } - short length = cb.readShort(); - - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Wrong length. Initiate message length expected to be >= " - + PACKET_MINIMUM_LENGTH + ", but received=" + length); - } - - log.debug("reading PcInitiate message of length " + length); - - // parse Start initiate/deletion list - if (!parsePcInitiatedLspRequestList(cb)) { - throw new PcepParseException("Parsing PCE-initiated-lsp-Request-list failed"); - } - - return new PcepInitiateMsgVer1(llPcInitiatedLspRequestList); - } - - /** - * To parse PcInitiatedLspRequestList from PcInitiate Message. - * - * @param cb of type channel buffer - * @return true if parsing PcInitiatedLspRequestList is success, false otherwise - * @throws PcepParseException while parsing from channel buffer - */ - public boolean parsePcInitiatedLspRequestList(ChannelBuffer cb) throws PcepParseException { - - boolean isDelLspRequest = false; - - if (cb == null) { - throw new PcepParseException("Channel buffer is empty"); - } - - while (0 < cb.readableBytes()) { - PcInitiatedLspRequest pceInitLspReq = new PcInitiatedLspRequestVer1(); - - //store SRP object - PcepSrpObject srpObj; - srpObj = PcepSrpObjectVer1.read(cb); - pceInitLspReq.setSrpObject(srpObj); - isDelLspRequest = srpObj.getRFlag(); - - //store LSP object - PcepLspObject lspObj; - lspObj = PcepLspObjectVer1.read(cb); - pceInitLspReq.setLspObject(lspObj); - - /* if R bit will be set then pcInitiate msg will contain only LSp and SRP objects - * so if R bit is not set then we should read for Ero and EndPoint objects also. - */ - if (!isDelLspRequest) { - - //store EndPoint object - PcepEndPointsObject endPointObj; - endPointObj = PcepEndPointsObjectVer1.read(cb); - pceInitLspReq.setEndPointsObject(endPointObj); - - //store ERO object - PcepEroObject eroObj; - eroObj = PcepEroObjectVer1.read(cb); - pceInitLspReq.setEroObject(eroObj); - - if (cb.readableBytes() > MINIMUM_COMMON_HEADER_LENGTH) { - pceInitLspReq.setPcepAttribute(PcepAttributeVer1.read(cb)); - } - } - llPcInitiatedLspRequestList.add(pceInitLspReq); - } - return true; - } - } - - /** - * Constructor to initialize PcInitiatedLspRequest. - * - * @param llPcInitiatedLspRequestList list of PcInitiatedLspRequest - */ - PcepInitiateMsgVer1(LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList) { - - if (llPcInitiatedLspRequestList == null) { - throw new NullPointerException("PcInitiatedLspRequestList cannot be null."); - } - this.llPcInitiatedLspRequestList = llPcInitiatedLspRequestList; - } - - /** - * Builder class for PCEP initiate message. - */ - static class Builder implements PcepInitiateMsg.Builder { - - // Pcep initiate message fields - LinkedList<PcInitiatedLspRequest> llPcInitiatedLspRequestList; - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.INITIATE; - } - - @Override - public PcepInitiateMsg build() { - return new PcepInitiateMsgVer1(this.llPcInitiatedLspRequestList); - } - - @Override - public LinkedList<PcInitiatedLspRequest> getPcInitiatedLspRequestList() { - return this.llPcInitiatedLspRequestList; - } - - @Override - public Builder setPcInitiatedLspRequestList(LinkedList<PcInitiatedLspRequest> ll) { - this.llPcInitiatedLspRequestList = ll; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer class for writing pcep initiate message to channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepInitiateMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepInitiateMsgVer1 message) throws PcepParseException { - - boolean isDelLspRequest = false; - int startIndex = cb.writerIndex(); - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - // message type 0xC - cb.writeByte(MSG_TYPE.getType()); - // length is length of variable message, will be updated at the end - // Store the position of message - // length in buffer - int msgLenIndex = cb.writerIndex(); - cb.writeShort(0); - - ListIterator<PcInitiatedLspRequest> listIterator = message.llPcInitiatedLspRequestList.listIterator(); - - while (listIterator.hasNext()) { - - PcInitiatedLspRequest listReq = listIterator.next(); - - //Srp Object is mandatory - PcepSrpObject srpObj = listReq.getSrpObject(); - if (srpObj != null) { - isDelLspRequest = srpObj.getRFlag(); - srpObj.write(cb); - } else { - throw new PcepParseException("SRP Object is mandatory for PcInitiate message."); - } - - //LSP Object is mandatory - PcepLspObject lspObj = listReq.getLspObject(); - if (lspObj != null) { - lspObj.write(cb); - } else { - throw new PcepParseException("LSP Object is mandatory for PcInitiate message."); - } - - /* if R bit will be set then pcInitiate msg will contain only LSp and SRP objects - * so if R bit is not set then we should read for Ero and EndPoint objects also. - */ - - if (!isDelLspRequest) { - - //EndPoints object is mandatory - PcepEndPointsObject endPointObj = listReq.getEndPointsObject(); - if (endPointObj != null) { - endPointObj.write(cb); - } else { - throw new PcepParseException("End points Object is mandatory for PcInitiate message."); - } - - //Ero object is mandatory - PcepEroObject eroObj = listReq.getEroObject(); - if (eroObj != null) { - eroObj.write(cb); - } else { - throw new PcepParseException("ERO Object is mandatory for PcInitiate message."); - } - - //PcepAttribute is optional - PcepAttribute pcepAttribute = listReq.getPcepAttribute(); - if (pcepAttribute != null) { - pcepAttribute.write(cb); - } - } - } - - // PCInitiate message length field - int length = cb.writerIndex() - startIndex; - cb.setShort(msgLenIndex, (short) length); - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - @Override - public LinkedList<PcInitiatedLspRequest> getPcInitiatedLspRequestList() { - return this.llPcInitiatedLspRequestList; - } - - @Override - public void setPcInitiatedLspRequestList(LinkedList<PcInitiatedLspRequest> ll) { - this.llPcInitiatedLspRequestList = ll; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("PcInitiaitedLspRequestList", llPcInitiatedLspRequestList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInterLayerObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInterLayerObjectVer1.java deleted file mode 100644 index 5130d9e9..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInterLayerObjectVer1.java +++ /dev/null @@ -1,263 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepInterLayerObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP inter layer object. - */ -public class PcepInterLayerObjectVer1 implements PcepInterLayerObject { - - /* - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Reserved |N|I| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - protected static final Logger log = LoggerFactory.getLogger(PcepInterLayerObjectVer1.class); - - public static final byte INTER_LAYER_OBJ_TYPE = 1; - public static final byte INTER_LAYER_OBJ_CLASS = 18; - public static final byte INTER_LAYER_OBJECT_VERSION = 1; - public static final short INTER_LAYER_OBJ_MINIMUM_LENGTH = 8; - public static final boolean DEFAULT_IFLAG = false; - public static final boolean DEFAULT_NFLAG = false; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int NFLAG_SHIFT_VALUE = 0x02; - public static final int IFLAG_SHIFT_VALUE = 0x01; - - static final PcepObjectHeader DEFAULT_INTER_LAYER_OBJECT_HEADER = new PcepObjectHeader(INTER_LAYER_OBJ_CLASS, - INTER_LAYER_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - INTER_LAYER_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader interLayerObjHeader; - private boolean bNFlag; - private boolean bIFlag; - - /** - * Constructor to initialize all parameters for Pcep Inter Layer Object. - * - * @param interLayerObjHeader inter layer object header - * @param bNFlag N flag - * @param bIFlag I flag - */ - public PcepInterLayerObjectVer1(PcepObjectHeader interLayerObjHeader, boolean bNFlag, boolean bIFlag) { - - this.interLayerObjHeader = interLayerObjHeader; - this.bNFlag = bNFlag; - this.bIFlag = bIFlag; - } - - /** - * Sets Object Header. - * - * @param obj object header - */ - public void setInterLayerObjHeader(PcepObjectHeader obj) { - this.interLayerObjHeader = obj; - } - - @Override - public void setbNFlag(boolean bNFlag) { - this.bNFlag = bNFlag; - } - - @Override - public void setbIFlag(boolean bIFlag) { - this.bIFlag = bIFlag; - } - - /** - * Returns object header. - * - * @return inter Layer Object Header - */ - public PcepObjectHeader getInterLayerObjHeader() { - return this.interLayerObjHeader; - } - - @Override - public boolean getbNFlag() { - return this.bNFlag; - } - - @Override - public boolean getbIFlag() { - return this.bIFlag; - } - - /** - * Reads channel buffer and returns object of PcepInterLayerObject. - * - * @param cb of type channel buffer - * @return object of PcepInterLayerObject - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepInterLayerObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader interLayerObjHeader; - boolean bNFlag; - boolean bIFlag; - - interLayerObjHeader = PcepObjectHeader.read(cb); - - //take only InterLayerObject buffer. - ChannelBuffer tempCb = cb.readBytes(interLayerObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - - int iTemp = tempCb.readInt(); - bIFlag = ((iTemp & (byte) IFLAG_SHIFT_VALUE) == IFLAG_SHIFT_VALUE); - bNFlag = ((iTemp & (byte) NFLAG_SHIFT_VALUE) == NFLAG_SHIFT_VALUE); - - return new PcepInterLayerObjectVer1(interLayerObjHeader, bNFlag, bIFlag); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = interLayerObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException(" ObjectLength Index is " + objLenIndex); - } - - int iTemp = 0; - - if (bIFlag) { - iTemp = iTemp | (byte) IFLAG_SHIFT_VALUE; - } - if (bNFlag) { - iTemp = iTemp | (byte) NFLAG_SHIFT_VALUE; - } - - cb.writeInt(iTemp); - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - //will be helpful during print(). - interLayerObjHeader.setObjLen((short) length); - cb.setShort(objLenIndex, (short) length); - - objLenIndex = cb.writerIndex(); - return objLenIndex; - } - - /** - * Builder class for PCEP inter layer object. - */ - public static class Builder implements PcepInterLayerObject.Builder { - - private boolean bIsHeaderSet = false; - private boolean bIsNFlagset = false; - private boolean bIsIFlagset = false; - - private PcepObjectHeader interLayerObjHeader; - private boolean bNFlag; - private boolean bIFlag; - - private boolean bIsPFlagSet = false; - private boolean bPFalg; - - private boolean bIsIFlagSet = false; - private boolean iFlag; - - @Override - public PcepInterLayerObject build() { - PcepObjectHeader interLayerObjHeader = this.bIsHeaderSet ? this.interLayerObjHeader - : DEFAULT_INTER_LAYER_OBJECT_HEADER; - - boolean bNFlag = this.bIsNFlagset ? this.bNFlag : DEFAULT_NFLAG; - boolean bIFlag = this.bIsIFlagset ? this.bIFlag : DEFAULT_IFLAG; - - if (bIsPFlagSet) { - interLayerObjHeader.setPFlag(bPFalg); - } - - if (bIsIFlagSet) { - interLayerObjHeader.setIFlag(iFlag); - } - return new PcepInterLayerObjectVer1(interLayerObjHeader, bNFlag, bIFlag); - } - - @Override - public PcepObjectHeader getInterLayerObjHeader() { - return this.interLayerObjHeader; - } - - @Override - public Builder setInterLayerObjHeader(PcepObjectHeader obj) { - this.interLayerObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public boolean getbNFlag() { - return this.bNFlag; - } - - @Override - public Builder setbNFlag(boolean value) { - this.bNFlag = value; - this.bIsNFlagset = true; - return this; - } - - @Override - public boolean getbIFlag() { - return this.bIFlag; - } - - @Override - public Builder setbIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagset = true; - return this; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFalg = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.iFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("IFlag", bIFlag) - .add("NFlag", bNFlag).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepIroObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepIroObjectVer1.java deleted file mode 100644 index 2e01bdaa..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepIroObjectVer1.java +++ /dev/null @@ -1,299 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepIroObject; -import org.onosproject.pcepio.types.IPv4SubObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP iro object. - */ -public class PcepIroObjectVer1 implements PcepIroObject { - - /* - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // (Sub-objects) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - The IRO Object format - - Each IPV4 suboject - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L| Type | Length | IPv4 address (4 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 address (continued) | Prefix Length | Resvd | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - protected static final Logger log = LoggerFactory.getLogger(PcepIroObjectVer1.class); - - public static final byte IRO_OBJ_TYPE = 1; - public static final byte IRO_OBJ_CLASS = 10; - public static final byte IRO_OBJECT_VERSION = 1; - public static final short IRO_OBJ_MINIMUM_LENGTH = 12; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int YTYPE_SHIFT_VALUE = 0x7F; - - public static final PcepObjectHeader DEFAULT_IRO_OBJECT_HEADER = new PcepObjectHeader(IRO_OBJ_CLASS, IRO_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, IRO_OBJ_MINIMUM_LENGTH); - - private short iroObjType = 0; - private byte yLength; - private byte yPrefixLength; - private byte yResvd; - private PcepObjectHeader iroObjHeader; - private LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - /** - * Default constructor. - */ - public PcepIroObjectVer1() { - this.iroObjHeader = null; - this.iroObjType = 0; - this.yLength = 0; - } - - /** - * Constructor to initialize member variables. - * - * @param iroObjHeader IRO object header - * @param llSubObjects list of sub-objects - */ - public PcepIroObjectVer1(PcepObjectHeader iroObjHeader, LinkedList<PcepValueType> llSubObjects) { - this.iroObjHeader = iroObjHeader; - this.llSubObjects = llSubObjects; - } - - /** - * Returns object header. - * - * @return iroObjHeader IRO object header - */ - public PcepObjectHeader getIroObjHeader() { - return this.iroObjHeader; - } - - /** - * Sets IRO Object Header. - * - * @param obj IRO object header - */ - public void setIroObjHeader(PcepObjectHeader obj) { - this.iroObjHeader = obj; - } - - @Override - public LinkedList<PcepValueType> getSubObjects() { - return this.llSubObjects; - } - - @Override - public void setSubObjects(LinkedList<PcepValueType> llSubObjects) { - this.llSubObjects = llSubObjects; - } - - /** - * Reads from channel buffer and return object of PcepIroObject. - * - * @param cb of type channel buffer - * @return object of PcepIroObject - * @throws PcepParseException while parsing from channel buffer - */ - public static PcepIroObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader iroObjHeader; - LinkedList<PcepValueType> llSubObjects; - - iroObjHeader = PcepObjectHeader.read(cb); - - //take only IroObject buffer. - ChannelBuffer tempCb = cb.readBytes(iroObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - llSubObjects = parseSubObjects(tempCb); - return new PcepIroObjectVer1(iroObjHeader, llSubObjects); - } - - /** - * Returns linked list of sub objects. - * - * @param cb of type channel buffer - * @return linked list of sub objects - * @throws PcepParseException while parsing subobjects from channel buffer - */ - protected static LinkedList<PcepValueType> parseSubObjects(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - while (0 < cb.readableBytes()) { - - //check the Type of the Subobjects. - byte yType = cb.readByte(); - yType = (byte) (yType & (YTYPE_SHIFT_VALUE)); - byte hLength = cb.readByte(); - - PcepValueType subObj; - switch (yType) { - - case IPv4SubObject.TYPE: - subObj = IPv4SubObject.read(cb); - break; - - default: - throw new PcepParseException("Invalid sub object. Type: " + (int) yType); - } - - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - llSubObjects.add(subObj); - } - return llSubObjects; - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = iroObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException(" ObjectLength is " + objLenIndex); - } - - ListIterator<PcepValueType> listIterator = llSubObjects.listIterator(); - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - //will be helpful during print(). - iroObjHeader.setObjLen((short) length); - // As per RFC the length of object should be - // multiples of 4 - int pad = length % 4; - if (pad != 0) { - pad = 4 - pad; - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = length + pad; - } - cb.setShort(objLenIndex, (short) length); - objLenIndex = cb.writerIndex(); - return objLenIndex; - } - - /** - * Builder class for PCEP iro object. - */ - public static class Builder implements PcepIroObject.Builder { - - private boolean bIsHeaderSet = false; - - private PcepObjectHeader iroObjHeader; - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepIroObject build() { - - PcepObjectHeader iroObjHeader = this.bIsHeaderSet ? this.iroObjHeader : DEFAULT_IRO_OBJECT_HEADER; - - if (bIsPFlagSet) { - iroObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - iroObjHeader.setIFlag(bIFlag); - } - - return new PcepIroObjectVer1(iroObjHeader, this.llSubObjects); - } - - @Override - public PcepObjectHeader getIroObjHeader() { - return this.iroObjHeader; - } - - @Override - public Builder setIroObjHeader(PcepObjectHeader obj) { - this.iroObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public LinkedList<PcepValueType> getSubObjects() { - return this.llSubObjects; - } - - @Override - public Builder setSubObjects(LinkedList<PcepValueType> llSubObjects) { - this.llSubObjects = llSubObjects; - return this; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("IroObjectHeader", iroObjHeader) - .add("SubObjects", llSubObjects).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepKeepaliveMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepKeepaliveMsgVer1.java deleted file mode 100644 index 8b6e9382..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepKeepaliveMsgVer1.java +++ /dev/null @@ -1,154 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepKeepaliveMsg; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP keep alive message. - */ -class PcepKeepaliveMsgVer1 implements PcepKeepaliveMsg { - - /* - <Keepalive Message>::= <Common Header> - - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Ver | Flags | Message-Type | Message-Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepKeepaliveMsgVer1.class); - // Pcep version: 1 - public static final byte PACKET_VERSION = 1; - public static final int PACKET_MINIMUM_LENGTH = 4; - public static final PcepType MSG_TYPE = PcepType.KEEP_ALIVE; - - public static final PcepKeepaliveMsgVer1.Reader READER = new Reader(); - - /** - * Reader class for reading PCEP keepalive message from channel buffer. - */ - static class Reader implements PcepMessageReader<PcepKeepaliveMsg> { - - @Override - public PcepKeepaliveMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Packet size is less than the minimum required length."); - } - // fixed value property version == 1 - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != PACKET_VERSION) { - throw new PcepParseException("Wrong version: Expected=PcepVersion.KEEP_ALIVE_1(2), got=" + version); - } - // fixed value property type == 2 - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type: Expected=PcepType.KEEP_ALIVE_1(2), got=" + type); - } - short length = cb.readShort(); - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Wrong length: Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " - + length); - } - return new PcepKeepaliveMsgVer1(); - } - } - - /** - * Default constructor. - */ - PcepKeepaliveMsgVer1() { - } - - /** - * Builder class for PCEP keepalive message. - */ - static class Builder implements PcepKeepaliveMsg.Builder { - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.KEEP_ALIVE; - } - - @Override - public PcepKeepaliveMsg build() { - return new PcepKeepaliveMsgVer1(); - } - } - - @Override - public void writeTo(ChannelBuffer cb) { - WRITER.write(cb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer class for writing the PCEP keepalive message to channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepKeepaliveMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepKeepaliveMsgVer1 message) { - int startIndex = cb.writerIndex(); - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - // message type - cb.writeByte(MSG_TYPE.getType()); - // length is length of variable message, will be updated at the end - // Store the position of message - // length in buffer - int msgLenIndex = cb.writerIndex(); - cb.writeShort((short) 0); - // update message length field - int length = cb.writerIndex() - startIndex; - cb.setShort(msgLenIndex, (short) length); - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelObjectVer1.java deleted file mode 100644 index a4ac87c3..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelObjectVer1.java +++ /dev/null @@ -1,370 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepLabelObject; -import org.onosproject.pcepio.types.NexthopIPv4addressTlv; -import org.onosproject.pcepio.types.NexthopIPv6addressTlv; -import org.onosproject.pcepio.types.NexthopUnnumberedIPv4IDTlv; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP label object. - */ -public class PcepLabelObjectVer1 implements PcepLabelObject { - - /* - * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01 , section : 7.4. - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Reserved | Flags |O| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Label | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLV // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - The LABEL Object format - */ - protected static final Logger log = LoggerFactory.getLogger(PcepLspObjectVer1.class); - - public static final byte LABEL_OBJ_TYPE = 1; - public static final byte LABEL_OBJ_CLASS = 35; //TBD : to be defined - public static final byte LABEL_OBJECT_VERSION = 1; - public static final byte OBJECT_HEADER_LENGTH = 4; - public static final boolean DEFAULT_OFLAG = false; - - // LSP_OBJ_MINIMUM_LENGTH = CommonHeaderLen(4)+ LspObjectHeaderLen(8) - public static final short LABEL_OBJ_MINIMUM_LENGTH = 12; - - public static final int OFLAG_SET = 1; - public static final int OFLAG_RESET = 0; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - - static final PcepObjectHeader DEFAULT_LABEL_OBJECT_HEADER = new PcepObjectHeader(LABEL_OBJ_CLASS, LABEL_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, LABEL_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader labelObjHeader; - private boolean bOFlag; - private int label; - // Optional TLV - private LinkedList<PcepValueType> llOptionalTlv; - - /** - * Constructor to initialize parameters for PCEP label object. - * - * @param labelObjHeader label object header - * @param bOFlag O flag - * @param label label - * @param llOptionalTlv list of optional tlvs - */ - public PcepLabelObjectVer1(PcepObjectHeader labelObjHeader, boolean bOFlag, int label, - LinkedList<PcepValueType> llOptionalTlv) { - this.labelObjHeader = labelObjHeader; - this.bOFlag = bOFlag; - this.label = label; - this.llOptionalTlv = llOptionalTlv; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - } - - @Override - public boolean getOFlag() { - return this.bOFlag; - } - - @Override - public void setOFlag(boolean value) { - this.bOFlag = value; - } - - @Override - public int getLabel() { - return this.label; - } - - @Override - public void setLabel(int value) { - this.label = value; - } - - /** - * Reads form channel buffer and returns objects of PcepLabelObject. - * - * @param cb of type channel buffer - * @return objects of PcepLabelObject - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepLabelObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader labelObjHeader; - - boolean bOFlag; - int label; - - // Optional TLV - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - labelObjHeader = PcepObjectHeader.read(cb); - - //take only LspObject buffer. - ChannelBuffer tempCb = cb.readBytes(labelObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - - int iTemp = tempCb.readInt(); - bOFlag = (iTemp & (byte) 0x01) == 1; - label = tempCb.readInt(); - - // parse optional TLV - llOptionalTlv = parseOptionalTlv(tempCb); - return new PcepLabelObjectVer1(labelObjHeader, bOFlag, label, llOptionalTlv); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - int objLenIndex = labelObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException(" ObjectLength Index is " + objLenIndex); - } - - byte oFlag; - - oFlag = (byte) ((bOFlag) ? OFLAG_SET : OFLAG_RESET); - cb.writeInt(oFlag); - cb.writeInt(label); - - // Add optional TLV - packOptionalTlv(cb); - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - - //will be helpful during print(). - labelObjHeader.setObjLen((short) length); - cb.setShort(objLenIndex, (short) length); - return cb.writerIndex(); - } - - /** - * Returns list of optional tlvs. - * - * @param cb of type channel buffer - * @return list of optional tlvs. - * @throws PcepParseException when fails to parse list of optional tlvs - */ - protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<>(); - - while (MINIMUM_COMMON_HEADER_LENGTH <= cb.readableBytes()) { - - PcepValueType tlv; - short hType = cb.readShort(); - short hLength = cb.readShort(); - int iValue = 0; - - switch (hType) { - - case NexthopIPv4addressTlv.TYPE: - iValue = cb.readInt(); - tlv = new NexthopIPv4addressTlv(iValue); - break; - case NexthopIPv6addressTlv.TYPE: - byte[] ipv6Value = new byte[NexthopIPv6addressTlv.VALUE_LENGTH]; - cb.readBytes(ipv6Value, 0, NexthopIPv6addressTlv.VALUE_LENGTH); - tlv = new NexthopIPv6addressTlv(ipv6Value); - break; - case NexthopUnnumberedIPv4IDTlv.TYPE: - tlv = NexthopUnnumberedIPv4IDTlv.read(cb); - break; - default: - throw new PcepParseException("Unsupported TLV type :" + hType); - } - - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - - llOutOptionalTlv.add(tlv); - } - - if (0 < cb.readableBytes()) { - - throw new PcepParseException("Optional Tlv parsing error. Extra bytes received."); - } - return llOutOptionalTlv; - } - - /** - * Returns the writer index. - * - * @param cb of channel buffer. - * @return writer index - */ - protected int packOptionalTlv(ChannelBuffer cb) { - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - if (tlv == null) { - log.debug("tlv is null from OptionalTlv list"); - continue; - } - tlv.write(cb); - } - return cb.writerIndex(); - } - - /** - * Builder class for PCEP label object. - */ - public static class Builder implements PcepLabelObject.Builder { - - private boolean bIsHeaderSet = false; - private boolean bIsOFlagSet = false; - private boolean bIsLabelSet = false; - - private PcepObjectHeader labelObjHeader; - private boolean bOFlag; - private int label; - - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepLabelObject build() throws PcepParseException { - PcepObjectHeader labelObjHeader = this.bIsHeaderSet ? this.labelObjHeader : DEFAULT_LABEL_OBJECT_HEADER; - boolean bOFlag = this.bIsOFlagSet ? this.bOFlag : DEFAULT_OFLAG; - - if (!this.bIsLabelSet) { - throw new PcepParseException(" Label NOT Set while building PcepLabelObject."); - } - if (bIsPFlagSet) { - labelObjHeader.setPFlag(bPFlag); - } - if (bIsIFlagSet) { - labelObjHeader.setIFlag(bIFlag); - } - return new PcepLabelObjectVer1(labelObjHeader, bOFlag, this.label, this.llOptionalTlv); - } - - @Override - public PcepObjectHeader getLabelObjHeader() { - return this.labelObjHeader; - } - - @Override - public Builder setLabelObjHeader(PcepObjectHeader obj) { - this.labelObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public boolean getOFlag() { - return this.bOFlag; - } - - @Override - public Builder setOFlag(boolean value) { - this.bOFlag = value; - this.bIsOFlagSet = true; - return this; - } - - @Override - public int getLabel() { - return this.label; - } - - @Override - public Builder setLabel(int value) { - this.label = value; - this.bIsLabelSet = true; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - return this; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("OFlag", bOFlag) - .add("label", label) - .add("OptionalTlvList", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeObjectVer1.java deleted file mode 100644 index 9e4be911..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeObjectVer1.java +++ /dev/null @@ -1,377 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepLabelRangeObject; -import org.onosproject.pcepio.types.PathSetupTypeTlv; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP label range object. - */ -public class PcepLabelRangeObjectVer1 implements PcepLabelRangeObject { - - /* - * ref : draft-zhao-pce-pcep-extension-for-pce-controller-01, section : 7.2 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | label type | range size | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | label base | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - LABEL-RANGE Object - */ - protected static final Logger log = LoggerFactory.getLogger(PcepLabelRangeObjectVer1.class); - - public static final byte LABEL_RANGE_OBJ_TYPE = 1; - public static final byte LABEL_RANGE_OBJ_CLASS = 60; //to be defined - public static final byte LABEL_RANGE_OBJECT_VERSION = 1; - public static final short LABEL_RANGE_OBJ_MINIMUM_LENGTH = 12; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - //P flag and I flag must be set to 0 - static final PcepObjectHeader DEFAULT_LABELRANGE_OBJECT_HEADER = new PcepObjectHeader(LABEL_RANGE_OBJ_CLASS, - LABEL_RANGE_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - LABEL_RANGE_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader labelRangeObjHeader; - private byte labelType; - private int rangeSize; - private int labelBase; - //Optional TLV - private LinkedList<PcepValueType> llOptionalTlv; - - /** - * Constructor to initialize parameters for PCEP label range object. - * - * @param labelRangeObjHeader label range object header - * @param labelType label type - * @param rangeSize range size - * @param labelBase label base - * @param llOptionalTlv list of optional tlvs - */ - public PcepLabelRangeObjectVer1(PcepObjectHeader labelRangeObjHeader, byte labelType, int rangeSize, int labelBase, - LinkedList<PcepValueType> llOptionalTlv) { - this.labelRangeObjHeader = labelRangeObjHeader; - this.labelType = labelType; - this.rangeSize = rangeSize; - this.llOptionalTlv = llOptionalTlv; - this.labelBase = labelBase; - } - - @Override - public void setLabelRangeObjHeader(PcepObjectHeader obj) { - this.labelRangeObjHeader = obj; - } - - @Override - public void setLabelType(byte labelType) { - this.labelType = labelType; - } - - @Override - public void setRangeSize(int rangeSize) { - this.rangeSize = rangeSize; - } - - @Override - public void setLabelBase(int labelBase) { - this.labelBase = labelBase; - } - - @Override - public PcepObjectHeader getLabelRangeObjHeader() { - return this.labelRangeObjHeader; - } - - @Override - public byte getLabelType() { - return this.labelType; - } - - @Override - public int getRangeSize() { - return this.rangeSize; - } - - @Override - public int getLabelBase() { - return this.labelBase; - } - - /** - * Reads from the channel buffer and returns object of PcepLabelRangeObject. - * - * @param cb of type channel buffer - * @return object of PcepLabelRangeObject - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepLabelRangeObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader labelRangeObjHeader; - byte labelType; - int rangeSize; - int labelBase; - - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - labelRangeObjHeader = PcepObjectHeader.read(cb); - - //take only LabelRangeObject buffer. - ChannelBuffer tempCb = cb.readBytes(labelRangeObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH); - int temp = 0; - temp = tempCb.readInt(); - rangeSize = temp & 0x00FFFFFF; - labelType = (byte) (temp >> 24); - labelBase = tempCb.readInt(); - llOptionalTlv = parseOptionalTlv(tempCb); - return new PcepLabelRangeObjectVer1(labelRangeObjHeader, labelType, rangeSize, labelBase, llOptionalTlv); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - int objStartIndex = cb.writerIndex(); - - //write common header - int objLenIndex = labelRangeObjHeader.write(cb); - int temp = 0; - temp = labelType; - temp = temp << 24; - temp = temp | rangeSize; - cb.writeInt(temp); - - // Add optional TLV - if (!packOptionalTlv(cb)) { - throw new PcepParseException("Error while writing Optional tlv."); - } - - //now write LabelRange Object Length - cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex)); - return cb.writerIndex() - objStartIndex; - } - - /** - * Returns list of optional tlvs. - * - * @param cb of type channle buffer - * @return list of optional tlvs - * @throws PcepParseException whne fails to parse list of optional tlvs - */ - public static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<>(); - - while (MINIMUM_COMMON_HEADER_LENGTH <= cb.readableBytes()) { - - PcepValueType tlv; - int iValue; - short hType = cb.readShort(); - short hLength = cb.readShort(); - - switch (hType) { - - case PathSetupTypeTlv.TYPE: - iValue = cb.readInt(); - tlv = new PathSetupTypeTlv(iValue); - break; - - default: - throw new PcepParseException("Unsupported TLV in LabelRange Object."); - } - - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - llOutOptionalTlv.add(tlv); - } - return llOutOptionalTlv; - } - - /** - * Pack optional tlvs. - * - * @param cb of channel buffer - * @return true - */ - protected boolean packOptionalTlv(ChannelBuffer cb) { - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - if (tlv == null) { - log.debug("tlv is null from OptionalTlv list"); - continue; - } - tlv.write(cb); - - // need to take care of padding - int pad = tlv.getLength() % 4; - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - cb.writeByte((byte) 0); - } - } - } - return true; - } - - /** - * Builder class for PCEP label range object. - */ - public static class Builder implements PcepLabelRangeObject.Builder { - private boolean bIsHeaderSet = false; - private boolean bIsLabelType = false; - private boolean bIsRangeSize = false; - private boolean bIsLabelBase = false; - - byte labelType; - int rangeSize; - int labelBase; - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - private PcepObjectHeader labelRangeObjHeader; - - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - @Override - public PcepLabelRangeObject build() throws PcepParseException { - PcepObjectHeader labelRangeObjHeader = this.bIsHeaderSet ? this.labelRangeObjHeader - : DEFAULT_LABELRANGE_OBJECT_HEADER; - - if (!this.bIsLabelType) { - throw new PcepParseException("LabelType NOT Set while building label range object."); - } - - if (!this.bIsRangeSize) { - throw new PcepParseException("RangeSize NOT Set while building label range object."); - } - - if (!this.bIsLabelBase) { - throw new PcepParseException("LabelBase NOT Set while building label range object."); - } - - if (bIsPFlagSet) { - labelRangeObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - labelRangeObjHeader.setIFlag(bIFlag); - } - return new PcepLabelRangeObjectVer1(labelRangeObjHeader, this.labelType, this.rangeSize, this.labelBase, - this.llOptionalTlv); - } - - @Override - public PcepObjectHeader getLabelRangeObjHeader() { - return this.labelRangeObjHeader; - } - - @Override - public Builder setLabelRangeObjHeader(PcepObjectHeader obj) { - this.labelRangeObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public byte getLabelType() { - return this.labelType; - } - - @Override - public Builder setLabelType(byte labelType) { - this.labelType = labelType; - this.bIsLabelType = true; - return this; - } - - @Override - public int getRangeSize() { - return this.rangeSize; - } - - @Override - public Builder setRangeSize(int rangeSize) { - this.rangeSize = rangeSize; - this.bIsRangeSize = true; - return this; - } - - @Override - public int getLabelBase() { - return this.labelBase; - } - - @Override - public Builder setLabelBase(int labelBase) { - this.labelBase = labelBase; - this.bIsLabelBase = true; - return this; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("LabelType", labelType) - .add("rangeSize", rangeSize) - .add("labelBase", labelBase) - .add("optionalTlvList", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeResvMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeResvMsgVer1.java deleted file mode 100644 index 6f3648af..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeResvMsgVer1.java +++ /dev/null @@ -1,198 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepLabelRange; -import org.onosproject.pcepio.protocol.PcepLabelRangeResvMsg; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP label range reserve message. - */ -class PcepLabelRangeResvMsgVer1 implements PcepLabelRangeResvMsg { - - // Pcep version: 1 - - /* - The format of a PCLRResv message is as follows: - - PCLRResv Message>::= <Common Header> - <label-range> - Where: - - <label-range> ::= <SRP> - <labelrange-list> - - Where - <labelrange-list>::=<LABEL-RANGE>[<labelrange-list>] - */ - protected static final Logger log = LoggerFactory.getLogger(PcepLabelRangeResvMsgVer1.class); - - public static final byte PACKET_VERSION = 1; - // LabelRangeResvMsgMinLength = COMMON-HEADER(4)+SrpObjMinLentgh(12)+LABEL-RANGE-MIN-LENGTH(12) - public static final int PACKET_MINIMUM_LENGTH = 28; - public static final PcepType MSG_TYPE = PcepType.LABEL_RANGE_RESERV; - //<label-range> - PcepLabelRange labelRange; - - public static final PcepLabelRangeResvMsgVer1.Reader READER = new Reader(); - - /** - * Reader reads LabelRangeResv Message from the channel. - */ - static class Reader implements PcepMessageReader<PcepLabelRangeResvMsg> { - - @Override - public PcepLabelRangeResvMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Channel buffer has less readable bytes than Packet minimum length."); - } - // fixed value property version == 1 - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != PACKET_VERSION) { - throw new PcepParseException("Wrong version. Expected=PcepVersion.PCEP_1(1), got=" + version); - } - // fixed value property type == 15 - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type. Expected=PcepType.LABEL_RANGE_RESERV(15), got=" + type); - } - short length = cb.readShort(); - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Wrong length.Expected to be >= " + PACKET_MINIMUM_LENGTH + ", is: " - + length); - } - // parse <label-range> - PcepLabelRange labelRange = PcepLabelRangeVer1.read(cb); - return new PcepLabelRangeResvMsgVer1(labelRange); - } - } - - /** - * Constructor to initialize PCEP label range. - * - * @param labelRange PCEP label range - */ - PcepLabelRangeResvMsgVer1(PcepLabelRange labelRange) { - this.labelRange = labelRange; - } - - /** - * Builder class for PCEP label range reserve message. - */ - static class Builder implements PcepLabelRangeResvMsg.Builder { - - PcepLabelRange labelRange = new PcepLabelRangeVer1(); - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.LABEL_RANGE_RESERV; - } - - @Override - public PcepLabelRangeResvMsg build() { - return new PcepLabelRangeResvMsgVer1(this.labelRange); - } - - @Override - public PcepLabelRange getLabelRange() { - return this.labelRange; - } - - @Override - public Builder setLabelRange(PcepLabelRange labelRange) { - this.labelRange = labelRange; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer writes LabelRangeResv Message to the channel. - */ - static class Writer implements PcepMessageWriter<PcepLabelRangeResvMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepLabelRangeResvMsgVer1 message) throws PcepParseException { - - int startIndex = cb.writerIndex(); - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - // message type - cb.writeByte(MSG_TYPE.getType()); - // Length will be set after calculating length, but currently set it as 0. - int msgLenIndex = cb.writerIndex(); - - cb.writeShort((short) 0); - //write Label Range - message.labelRange.write(cb); - - // update message length field - int length = cb.writerIndex() - startIndex; - cb.setShort(msgLenIndex, (short) length); - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - @Override - public PcepLabelRange getLabelRange() { - return this.labelRange; - } - - @Override - public void setLabelRange(PcepLabelRange lr) { - this.labelRange = lr; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("labelRange", labelRange) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeVer1.java deleted file mode 100644 index 411c9604..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelRangeVer1.java +++ /dev/null @@ -1,168 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepLabelRange; -import org.onosproject.pcepio.protocol.PcepLabelRangeObject; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Label Range. - */ -public class PcepLabelRangeVer1 implements PcepLabelRange { - - protected static final Logger log = LoggerFactory.getLogger(PcepLabelRangeVer1.class); - - /* - <label-range> ::= <SRP> - <labelrange-list> - Where - <labelrange-list>::=<LABEL-RANGE>[<labelrange-list>] - */ - - // PCEP SRP Object - private PcepSrpObject srpObject; - //<labelrange-list> of type PcepLabelRangeObject. - private LinkedList<PcepLabelRangeObject> llLabelRangeList; - - /** - * Default Constructor. - */ - public PcepLabelRangeVer1() { - srpObject = null; - llLabelRangeList = null; - } - - /** - * Constructor to initialize objects. - * - * @param srpObj PCEP Srp object. - * @param llLabelRangeList list of PcepLabelRangeObject. - */ - PcepLabelRangeVer1(PcepSrpObject srpObj, LinkedList<PcepLabelRangeObject> llLabelRangeList) { - this.srpObject = srpObj; - this.llLabelRangeList = llLabelRangeList; - } - - @Override - public PcepSrpObject getSrpObject() { - return srpObject; - } - - @Override - public void setSrpObject(PcepSrpObject srpObject) { - this.srpObject = srpObject; - - } - - @Override - public LinkedList<PcepLabelRangeObject> getLabelRangeList() { - return llLabelRangeList; - } - - @Override - public void setLabelRangeList(LinkedList<PcepLabelRangeObject> ll) { - this.llLabelRangeList = ll; - } - - /** - * Reads channel buffer and returns object of PcepLabelRange. - * - * @param cb of type channel buffer. - * @return object of PcepLabelRange - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepLabelRange read(ChannelBuffer cb) throws PcepParseException { - - //parse and store SRP mandatory object - PcepSrpObject srpObj = null; - srpObj = PcepSrpObjectVer1.read(cb); - if (srpObj == null) { - throw new PcepParseException("Exception while parsing srp object"); - } - - LinkedList<PcepLabelRangeObject> llLabelRangeList = new LinkedList<>(); - boolean bFoundLabelRangeObj = false; - while (0 < cb.readableBytes()) { - //parse and store <labelrange-list> - PcepLabelRangeObject lrObj; - lrObj = PcepLabelRangeObjectVer1.read(cb); - if (lrObj == null) { - throw new PcepParseException("Exception while parsing label range object"); - } else { - llLabelRangeList.add(lrObj); - bFoundLabelRangeObj = true; - } - } - - if (!bFoundLabelRangeObj) { - throw new PcepParseException("At least one LABEL-RANGE MUST be present."); - } - return new PcepLabelRangeVer1(srpObj, llLabelRangeList); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - //write Object header - int objStartIndex = cb.writerIndex(); - - //write <SRP> - int objLenIndex = srpObject.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("bjectLength is " + objLenIndex); - } - - //write <labelrange-list> - ListIterator<PcepLabelRangeObject> listIterator = llLabelRangeList.listIterator(); - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - // As per RFC the length of object should be - // multiples of 4 - int pad = length % 4; - if (pad != 0) { - pad = 4 - pad; - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = length + pad; - } - cb.setShort(objLenIndex, (short) length); - return length; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("srpObject", srpObject) - .add("LabelRangeList", llLabelRangeList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateMsgVer1.java deleted file mode 100644 index 89347f42..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateMsgVer1.java +++ /dev/null @@ -1,239 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepLabelUpdate; -import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP lable update message. - */ -class PcepLabelUpdateMsgVer1 implements PcepLabelUpdateMsg { - - // Pcep version: 1 - - /* - The format of the PCLabelUpd message: - - <PCLabelUpd Message> ::= <Common Header> - <pce-label-update-list> - Where: - - <pce-label-update-list> ::= <pce-label-update> - [<pce-label-update-list>] - <pce-label-update> ::= (<pce-label-download>|<pce-label-map>) - - Where: - <pce-label-download> ::= <SRP> - <LSP> - <label-list> - - <pce-label-map> ::= <SRP> - <LABEL> - <FEC> - - <label-list > ::= <LABEL> - [<label-list>] - - */ - protected static final Logger log = LoggerFactory.getLogger(PcepLabelUpdateMsgVer1.class); - - public static final byte PACKET_VERSION = 1; - - //LabelUpdateMsgMinLength = COMMON-HEADER(4)+SrpObjMinLentgh(12)+LabelObjectMinLength(12)+FECType1Object(8) - public static final int PACKET_MINIMUM_LENGTH = 36; - public static final PcepType MSG_TYPE = PcepType.LABEL_UPDATE; - //pce-label-update-list - private LinkedList<PcepLabelUpdate> llPcLabelUpdateList; - - static final PcepLabelUpdateMsgVer1.Reader READER = new Reader(); - - /** - * Reader reads LabelUpdate Message from the channel. - */ - static class Reader implements PcepMessageReader<PcepLabelUpdateMsg> { - - @Override - public PcepLabelUpdateMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Readable bytes are less than Packet minimum length."); - } - - // fixed value property version == 1 - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != PACKET_VERSION) { - throw new PcepParseException("Wrong version.Expected=PcepVersion.PCEP_1(1), got=" + version); - } - // fixed value property type == 13 - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type. Expected=PcepType.LABEL_UPDATE(13), got=" + type); - } - short length = cb.readShort(); - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", is: " - + length); - } - // parse <pce-label-download> / <pce-label-map> - LinkedList<PcepLabelUpdate> llPcLabelUpdateList = parsePcLabelUpdateList(cb); - return new PcepLabelUpdateMsgVer1(llPcLabelUpdateList); - } - - /** - * Returns list of PCEP Label Update object. - * - * @param cb of type channel buffer - * @return llPcLabelUpdateList list of PCEP label update object - * @throws PcepParseException when fails to parse list of PCEP label update object - */ - public LinkedList<PcepLabelUpdate> parsePcLabelUpdateList(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepLabelUpdate> llPcLabelUpdateList; - llPcLabelUpdateList = new LinkedList<>(); - - while (0 < cb.readableBytes()) { - llPcLabelUpdateList.add(PcepLabelUpdateVer1.read(cb)); - } - return llPcLabelUpdateList; - } - } - - /** - * Constructor to initialize PCEP Label Update List. - * - * @param llPcLabelUpdateList list of PCEP Label Update object - */ - PcepLabelUpdateMsgVer1(LinkedList<PcepLabelUpdate> llPcLabelUpdateList) { - this.llPcLabelUpdateList = llPcLabelUpdateList; - } - - /** - * Builder class for PCEP label update message. - */ - static class Builder implements PcepLabelUpdateMsg.Builder { - - LinkedList<PcepLabelUpdate> llPcLabelUpdateList; - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.LABEL_UPDATE; - } - - @Override - public PcepLabelUpdateMsg build() { - return new PcepLabelUpdateMsgVer1(this.llPcLabelUpdateList); - } - - @Override - public LinkedList<PcepLabelUpdate> getPcLabelUpdateList() { - return this.llPcLabelUpdateList; - } - - @Override - public Builder setPcLabelUpdateList(LinkedList<PcepLabelUpdate> ll) { - this.llPcLabelUpdateList = ll; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer writes LabelUpdate Message to the channel. - */ - static class Writer implements PcepMessageWriter<PcepLabelUpdateMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepLabelUpdateMsgVer1 message) throws PcepParseException { - - int startIndex = cb.writerIndex(); - - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - - // message type - cb.writeByte(MSG_TYPE.getType()); - - // Length will be set after calculating length, but currently set it as 0. - int msgLenIndex = cb.writerIndex(); - - cb.writeShort((short) 0); - ListIterator<PcepLabelUpdate> listIterator = message.llPcLabelUpdateList.listIterator(); - - while (listIterator.hasNext()) { - PcepLabelUpdate labelUpdate = listIterator.next(); - labelUpdate.write(cb); - } - - // update message length field - int length = cb.writerIndex() - startIndex; - cb.setShort(msgLenIndex, (short) length); - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - @Override - public LinkedList<PcepLabelUpdate> getPcLabelUpdateList() { - return this.llPcLabelUpdateList; - } - - @Override - public void setPcLabelUpdateList(LinkedList<PcepLabelUpdate> ll) { - this.llPcLabelUpdateList = ll; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("PcLabelUpdateList", llPcLabelUpdateList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateVer1.java deleted file mode 100644 index a2293d35..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateVer1.java +++ /dev/null @@ -1,356 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFecObject; -import org.onosproject.pcepio.protocol.PcepLabelObject; -import org.onosproject.pcepio.protocol.PcepLabelUpdate; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.onosproject.pcepio.types.PcepLabelDownload; -import org.onosproject.pcepio.types.PcepLabelMap; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP LABEL update . - * Reference :draft-zhao-pce-pcep-extension-for-pce-controller-01. - */ -public class PcepLabelUpdateVer1 implements PcepLabelUpdate { - - /* - * <pce-label-update> ::= (<pce-label-download>|<pce-label-map>) - - Where: - <pce-label-download> ::= <SRP> - <LSP> - <label-list> - - <pce-label-map> ::= <SRP> - <LABEL> - <FEC> - - <label-list > ::= <LABEL> - [<label-list>] - */ - protected static final Logger log = LoggerFactory.getLogger(PcepLabelUpdateVer1.class); - - //Either PceLabelDownload or PceLabelMap is mandatory. - //label Download - private PcepLabelDownload labelDownload; - private boolean isLabelDownloadSet; - //label Map - private PcepLabelMap labelMap; - private boolean isLabelMapSet; - - /** - * Constructor to reset parameters. - */ - public PcepLabelUpdateVer1() { - this.labelDownload = null; - this.isLabelDownloadSet = false; - this.labelMap = null; - this.isLabelMapSet = false; - } - - /** - * Constructor to initialize PCEP label download. - * - * @param labelDownload PCEP label download - */ - public PcepLabelUpdateVer1(PcepLabelDownload labelDownload) { - this.labelDownload = labelDownload; - this.isLabelDownloadSet = true; - this.labelMap = null; - this.isLabelMapSet = false; - } - - /** - * Constructor to initialize PCEP label map. - * - * @param labelMap PCEP label map - */ - public PcepLabelUpdateVer1(PcepLabelMap labelMap) { - this.labelDownload = null; - this.isLabelDownloadSet = false; - this.labelMap = labelMap; - this.isLabelMapSet = true; - } - - /** - * builder class for PCEP label update. - */ - static class Builder implements PcepLabelUpdate.Builder { - - private PcepLabelDownload labelDownload; - private boolean isLabelDownloadSet; - private PcepLabelMap labelMap; - private boolean isLabelMapSet; - - @Override - public PcepLabelUpdate build() throws PcepParseException { - - if (isLabelDownloadSet) { - return new PcepLabelUpdateVer1(labelDownload); - } - if (isLabelMapSet) { - return new PcepLabelUpdateVer1(labelMap); - } - if (!isLabelDownloadSet && !isLabelMapSet) { - throw new PcepParseException( - "Label Download or Label Map is not set while building PcepLabelUpdate Message"); - } - return new PcepLabelUpdateVer1(); - } - - @Override - public Builder setLabelDownload(PcepLabelDownload labelDownload) { - this.labelDownload = labelDownload; - this.isLabelDownloadSet = true; - return this; - } - - @Override - public PcepLabelDownload getLabelDownload() { - return labelDownload; - } - - @Override - public Builder setLabelMap(PcepLabelMap labelMap) { - this.labelMap = labelMap; - this.isLabelMapSet = true; - return this; - } - - @Override - public PcepLabelMap getLabelMap() { - return labelMap; - } - } - - /** - * Reads PcepLabels from the byte stream received from channel buffer. - * - * @param cb of type channel buffer. - * @return PcepLabelUpdate object. - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepLabelUpdate read(ChannelBuffer cb) throws PcepParseException { - - PcepLabelUpdateVer1 pceLabelUpdate = new PcepLabelUpdateVer1(); - - PcepSrpObject srpObject; - PcepObjectHeader tempObjHeader; - - //read SRP mandatory Object - srpObject = PcepSrpObjectVer1.read(cb); - - //checking next object - cb.markReaderIndex(); - - tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - - if (tempObjHeader.getObjClass() == PcepLspObjectVer1.LSP_OBJ_CLASS) { - - //now it is belong to <pce-label-download> - PcepLabelDownload labelDownload = new PcepLabelDownload(); - - //set SRP - labelDownload.setSrpObject(srpObject); - - //read and set LSP - labelDownload.setLspObject(PcepLspObjectVer1.read(cb)); - - //<label-list> - LinkedList<PcepLabelObject> llLabelList = new LinkedList<>(); - PcepLabelObject labelObject; - - while (0 < cb.readableBytes()) { - - cb.markReaderIndex(); - tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - - if (tempObjHeader.getObjClass() != PcepLabelObjectVer1.LABEL_OBJ_CLASS) { - break; - } - labelObject = PcepLabelObjectVer1.read(cb); - llLabelList.add(labelObject); - } - labelDownload.setLabelList(llLabelList); - pceLabelUpdate.setLabelDownload(labelDownload); - } else if (tempObjHeader.getObjClass() == PcepLabelObjectVer1.LABEL_OBJ_CLASS) { - //belong to <pce-label-map> - PcepLabelMap labelMap = new PcepLabelMap(); - - //set SRP Object - labelMap.setSrpObject(srpObject); - - //read and set Label Object - labelMap.setLabelObject(PcepLabelObjectVer1.read(cb)); - - cb.markReaderIndex(); - tempObjHeader = PcepObjectHeader.read(cb); - cb.resetReaderIndex(); - - PcepFecObject fecObject = null; - switch (tempObjHeader.getObjType()) { - case PcepFecObjectIPv4Ver1.FEC_OBJ_TYPE: - fecObject = PcepFecObjectIPv4Ver1.read(cb); - break; - case PcepFecObjectIPv6Ver1.FEC_OBJ_TYPE: - fecObject = PcepFecObjectIPv6Ver1.read(cb); - break; - case PcepFecObjectIPv4AdjacencyVer1.FEC_OBJ_TYPE: - fecObject = PcepFecObjectIPv4AdjacencyVer1.read(cb); - break; - case PcepFecObjectIPv6AdjacencyVer1.FEC_OBJ_TYPE: - fecObject = PcepFecObjectIPv6AdjacencyVer1.read(cb); - break; - case PcepFecObjectIPv4UnnumberedAdjacencyVer1.FEC_OBJ_TYPE: - fecObject = PcepFecObjectIPv4UnnumberedAdjacencyVer1.read(cb); - break; - default: - throw new PcepParseException("Unkown FEC object type " + tempObjHeader.getObjType()); - } - labelMap.setFECObject(fecObject); - pceLabelUpdate.setLabelMap(labelMap); - } else { - throw new PcepParseException( - "Either <pce-label-download> or <pce-label-map> should be present. Received Class: " - + tempObjHeader.getObjClass()); - } - return pceLabelUpdate; - } - - @Override - public void write(ChannelBuffer cb) throws PcepParseException { - - if ((labelDownload != null) && (labelMap != null)) { - throw new PcepParseException("Label Download and Label Map both can't be present."); - } - - if ((labelDownload == null) && (labelMap == null)) { - throw new PcepParseException("Either Label Download or Label Map should be present."); - } - - if (labelDownload != null) { - - PcepLspObject lspObject; - PcepSrpObject srpObject; - PcepLabelObject labelObject; - LinkedList<PcepLabelObject> llLabelList; - - srpObject = labelDownload.getSrpObject(); - if (srpObject == null) { - throw new PcepParseException("SRP Object is mandatory object for Label Download."); - } else { - srpObject.write(cb); - } - - lspObject = labelDownload.getLspObject(); - if (lspObject == null) { - throw new PcepParseException("LSP Object is mandatory object for Label Download."); - } else { - lspObject.write(cb); - } - - llLabelList = labelDownload.getLabelList(); - if (llLabelList == null) { - throw new PcepParseException("Label list is mandatory object for Label Download."); - } else { - ListIterator<PcepLabelObject> listIterator = llLabelList.listIterator(); - while (listIterator.hasNext()) { - labelObject = listIterator.next(); - labelObject.write(cb); - } - } - } - - if (labelMap != null) { - - PcepSrpObject srpObject; - PcepLabelObject labelObject; - PcepFecObject fecObject; - - srpObject = labelMap.getSrpObject(); - if (srpObject == null) { - throw new PcepParseException("SRP Object is mandatory object for Label map."); - } else { - srpObject.write(cb); - } - labelObject = labelMap.getLabelObject(); - if (labelObject == null) { - throw new PcepParseException("label Object is mandatory object for Label map."); - } else { - labelObject.write(cb); - } - fecObject = labelMap.getFECObject(); - if (fecObject == null) { - throw new PcepParseException("fec Object is mandatory object for Label map."); - } else { - fecObject.write(cb); - } - } - } - - @Override - public void setLabelDownload(PcepLabelDownload labelDownload) { - if (this.isLabelMapSet) { - return; - } - this.labelDownload = labelDownload; - this.isLabelDownloadSet = true; - } - - @Override - public PcepLabelDownload getLabelDownload() { - return this.labelDownload; - } - - @Override - public void setLabelMap(PcepLabelMap labelMap) { - if (this.isLabelDownloadSet) { - return; - } - this.labelMap = labelMap; - this.isLabelMapSet = true; - } - - @Override - public PcepLabelMap getLabelMap() { - return this.labelMap; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .omitNullValues() - .add("LabelDownload", labelDownload) - .add("LabelMap", labelMap) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspObjectVer1.java deleted file mode 100644 index 2b319c12..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspObjectVer1.java +++ /dev/null @@ -1,575 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.types.PcepErrorDetailInfo; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; -import org.onosproject.pcepio.types.StatefulLspDbVerTlv; -import org.onosproject.pcepio.types.StatefulLspErrorCodeTlv; -import org.onosproject.pcepio.types.StatefulRsvpErrorSpecTlv; -import org.onosproject.pcepio.types.SymbolicPathNameTlv; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP lsp object. - */ -public class PcepLspObjectVer1 implements PcepLspObject { - - /* - message format. - Reference : draft-ietf-pce-stateful-pce-11, section 7.3. - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | PLSP-ID | Flag | O|A|R|S|D| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - The LSP Object format - */ - protected static final Logger log = LoggerFactory.getLogger(PcepLspObjectVer1.class); - - public static final byte LSP_OBJ_TYPE = 1; - public static final byte LSP_OBJ_CLASS = 32; - public static final byte LSP_OBJECT_VERSION = 1; - - // LSP_OBJ_MINIMUM_LENGTH = CommonHeaderLen(4)+ LspObjectHeaderLen(4)+TlvAssumedMinLength(8) - public static final short LSP_OBJ_MINIMUM_LENGTH = 16; - - public static final int DEFAULT_PLSPID = 0; - public static final byte DEFAULT_OFLAG = 1; - public static final boolean DEFAULT_AFLAG = false; - public static final boolean DEFAULT_RFLAG = false; - public static final boolean DEFAULT_SFLAG = false; - public static final boolean DEFAULT_DFLAG = false; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int PLSPID_SHIFT_VALUE = 12; - public static final int OFLAG_SHIFT_VALUE = 4; - public static final int AFLAG_SHIFT_VALUE = 3; - public static final int RFLAG_SHIFT_VALUE = 2; - public static final int SFLAG_SHIFT_VALUE = 1; - public static final int PLSPID_TEMP_SHIFT_VALUE = 0xFFFFF000; - public static final int OFLAG_TEMP_SHIFT_VALUE = 0x70; - public static final int AFLAG_TEMP_SHIFT_VALUE = 0x08; - public static final int RFLAG_TEMP_SHIFT_VALUE = 0x04; - public static final int SFLAG_TEMP_SHIFT_VALUE = 0x02; - public static final int DFLAG_TEMP_SHIFT_VALUE = 0x01; - public static final int BIT_SET = 1; - public static final int BIT_RESET = 0; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - - static final PcepObjectHeader DEFAULT_LSP_OBJECT_HEADER = new PcepObjectHeader(LSP_OBJ_CLASS, LSP_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, LSP_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader lspObjHeader; - private int iPlspId; - // 3-bits - private byte yOFlag; - private boolean bAFlag; - private boolean bRFlag; - private boolean bSFlag; - private boolean bDFlag; - - // Optional TLV - private LinkedList<PcepValueType> llOptionalTlv; - - /** - * Constructor to initialize all the member variables. - * - * @param lspObjHeader lsp object header - * @param iPlspId plsp id - * @param yOFlag O flag - * @param bAFlag A flag - * @param bRFlag R flag - * @param bSFlag S flag - * @param bDFlag D flag - * @param llOptionalTlv list of optional tlv - */ - public PcepLspObjectVer1(PcepObjectHeader lspObjHeader, int iPlspId, byte yOFlag, boolean bAFlag, boolean bRFlag, - boolean bSFlag, boolean bDFlag, LinkedList<PcepValueType> llOptionalTlv) { - - this.lspObjHeader = lspObjHeader; - this.iPlspId = iPlspId; - this.yOFlag = yOFlag; - this.bAFlag = bAFlag; - this.bRFlag = bRFlag; - this.bSFlag = bSFlag; - this.bDFlag = bDFlag; - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Sets lsp Object Header. - * - * @param obj lsp object header - */ - public void setLspObjHeader(PcepObjectHeader obj) { - this.lspObjHeader = obj; - } - - @Override - public void setPlspId(int iPlspId) { - this.iPlspId = iPlspId; - } - - @Override - public void setOFlag(byte yOFlag) { - this.yOFlag = yOFlag; - } - - @Override - public void setAFlag(boolean bAFlag) { - this.bAFlag = bAFlag; - } - - @Override - public void setRFlag(boolean bRFlag) { - this.bRFlag = bRFlag; - } - - @Override - public void setSFlag(boolean bSFlag) { - this.bSFlag = bSFlag; - } - - @Override - public void setDFlag(boolean bDFlag) { - this.bDFlag = bDFlag; - } - - /** - * Returns lsp object header. - * - * @return lspObjHeader - */ - public PcepObjectHeader getLspObjHeader() { - return this.lspObjHeader; - } - - @Override - public int getPlspId() { - return this.iPlspId; - } - - @Override - public byte getOFlag() { - return this.yOFlag; - } - - @Override - public boolean getAFlag() { - return this.bAFlag; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public boolean getSFlag() { - return this.bSFlag; - } - - @Override - public boolean getDFlag() { - return this.bDFlag; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Parse channel buffer and returns object of PcepLspObject. - * - * @param cb of type channel buffer - * @return object of PcepLspObject - * @throws PcepParseException when lsp object is not present in channel buffer - */ - public static PcepLspObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader lspObjHeader; - int iPlspId; - // 3-bits - byte yOFlag; - boolean bAFlag; - boolean bRFlag; - boolean bSFlag; - boolean bDFlag; - - // Optional TLV - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - lspObjHeader = PcepObjectHeader.read(cb); - - if (lspObjHeader.getObjClass() != PcepLspObjectVer1.LSP_OBJ_CLASS) { - throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_6, PcepErrorDetailInfo.ERROR_VALUE_8); - } - //take only LspObject buffer. - ChannelBuffer tempCb = cb.readBytes(lspObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - - Integer iTemp = tempCb.readInt(); - iPlspId = (iTemp & PLSPID_TEMP_SHIFT_VALUE) >> PLSPID_SHIFT_VALUE; - Integer iX = (iTemp & OFLAG_TEMP_SHIFT_VALUE) >> OFLAG_SHIFT_VALUE; - yOFlag = iX.byteValue(); - iX = (iTemp & AFLAG_TEMP_SHIFT_VALUE) >> AFLAG_SHIFT_VALUE; - bAFlag = iX > 0; - iX = (iTemp & RFLAG_TEMP_SHIFT_VALUE) >> RFLAG_SHIFT_VALUE; - bRFlag = iX > 0; - iX = (iTemp & SFLAG_TEMP_SHIFT_VALUE) >> SFLAG_SHIFT_VALUE; - bSFlag = iX > 0; - iX = iTemp & DFLAG_TEMP_SHIFT_VALUE; - bDFlag = iX > 0; - - // parse optional TLV - llOptionalTlv = parseOptionalTlv(tempCb); - - return new PcepLspObjectVer1(lspObjHeader, iPlspId, yOFlag, bAFlag, bRFlag, bSFlag, bDFlag, llOptionalTlv); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = lspObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("Failed to write lsp object header. Index " + objLenIndex); - } - - int iTemp = iPlspId << PLSPID_SHIFT_VALUE; - iTemp = iTemp | (yOFlag << OFLAG_SHIFT_VALUE); - byte bFlag; - iTemp = bAFlag ? (iTemp | AFLAG_TEMP_SHIFT_VALUE) : iTemp; - - bFlag = (bRFlag) ? (byte) BIT_SET : BIT_RESET; - iTemp = iTemp | (bFlag << RFLAG_SHIFT_VALUE); - bFlag = (bSFlag) ? (byte) BIT_SET : BIT_RESET; - iTemp = iTemp | (bFlag << SFLAG_SHIFT_VALUE); - bFlag = (bDFlag) ? (byte) BIT_SET : BIT_RESET; - iTemp = iTemp | bFlag; - cb.writeInt(iTemp); - - // Add optional TLV - packOptionalTlv(cb); - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - //will be helpful during print(). - lspObjHeader.setObjLen((short) length); - // As per RFC the length of object should be - // multiples of 4 - - cb.setShort(objLenIndex, (short) length); - - return length; - } - - /** - * Returns Linked list of optional tlvs. - * - * @param cb of channel buffer. - * @return list of optional tlvs - * @throws PcepParseException when unsupported tlv is received - */ - protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOutOptionalTlv; - - llOutOptionalTlv = new LinkedList<>(); - - while (MINIMUM_COMMON_HEADER_LENGTH <= cb.readableBytes()) { - - PcepValueType tlv; - short hType = cb.readShort(); - short hLength = cb.readShort(); - int iValue = 0; - - switch (hType) { - - case StatefulIPv4LspIdentidiersTlv.TYPE: - tlv = StatefulIPv4LspIdentidiersTlv.read(cb); - break; - case StatefulLspErrorCodeTlv.TYPE: - iValue = cb.readInt(); - tlv = new StatefulLspErrorCodeTlv(iValue); - break; - case StatefulRsvpErrorSpecTlv.TYPE: - tlv = StatefulRsvpErrorSpecTlv.read(cb); - break; - case SymbolicPathNameTlv.TYPE: - tlv = SymbolicPathNameTlv.read(cb, hLength); - break; - case StatefulLspDbVerTlv.TYPE: - tlv = StatefulLspDbVerTlv.read(cb); - break; - default: - throw new PcepParseException("Received unsupported TLV type :" + hType); - } - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - - llOutOptionalTlv.add(tlv); - } - - if (0 < cb.readableBytes()) { - - throw new PcepParseException("Optional Tlv parsing error. Extra bytes received."); - } - return llOutOptionalTlv; - } - - /** - * returns writer index. - * - * @param cb of type channel buffer - * @return length of bytes written to channel buffer - */ - protected int packOptionalTlv(ChannelBuffer cb) { - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - int startIndex = cb.writerIndex(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - if (tlv == null) { - log.debug("tlv is null from OptionalTlv list"); - continue; - } - - tlv.write(cb); - - // need to take care of padding - int pad = tlv.getLength() % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - cb.writeByte((byte) 0); - } - } - } - - return cb.writerIndex() - startIndex; - } - - /** - * Builder class for PCEP lsp Object. - */ - public static class Builder implements PcepLspObject.Builder { - - private boolean bIsHeaderSet = false; - private boolean bIsPlspIdSet = false; - private boolean bIsOFlagSet = false; - private boolean bIsRFlagSet = false; - private boolean bIsAFlagSet = false; - private boolean bIsDFlagSet = false; - private boolean bIsSFlagSet = false; - - private PcepObjectHeader lspObjHeader; - private byte yOFlag; - private boolean bAFlag; - private boolean bDFlag; - private boolean bSFlag; - private boolean bRFlag; - LinkedList<PcepValueType> llOptionalTlv = null; - - private int plspId; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepLspObject build() { - PcepObjectHeader lspObjHeader = this.bIsHeaderSet ? this.lspObjHeader : DEFAULT_LSP_OBJECT_HEADER; - - int plspId = this.bIsPlspIdSet ? this.plspId : DEFAULT_PLSPID; - byte yOFlag = this.bIsOFlagSet ? this.yOFlag : DEFAULT_OFLAG; - boolean bAFlag = this.bIsAFlagSet ? this.bAFlag : DEFAULT_AFLAG; - boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : DEFAULT_RFLAG; - boolean bSFlag = this.bIsSFlagSet ? this.bSFlag : DEFAULT_SFLAG; - boolean bDFlag = this.bIsDFlagSet ? this.bDFlag : DEFAULT_DFLAG; - - if (bIsPFlagSet) { - lspObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - lspObjHeader.setIFlag(bIFlag); - } - - return new PcepLspObjectVer1(lspObjHeader, plspId, yOFlag, bAFlag, bRFlag, bSFlag, bDFlag, llOptionalTlv); - } - - @Override - public PcepObjectHeader getLspObjHeader() { - return this.lspObjHeader; - } - - @Override - public Builder setLspObjHeader(PcepObjectHeader obj) { - this.lspObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getPlspId() { - return this.plspId; - } - - @Override - public Builder setPlspId(int value) { - this.plspId = value; - this.bIsPlspIdSet = true; - return this; - } - - @Override - public byte getOFlag() { - return this.yOFlag; - } - - @Override - public Builder setOFlag(byte value) { - this.yOFlag = value; - this.bIsOFlagSet = true; - return this; - } - - @Override - public boolean getAFlag() { - return this.bAFlag; - } - - @Override - public Builder setAFlag(boolean value) { - this.bAFlag = value; - this.bIsAFlagSet = true; - return this; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public Builder setRFlag(boolean value) { - this.bRFlag = value; - this.bIsRFlagSet = true; - return this; - } - - @Override - public boolean getSFlag() { - return this.bSFlag; - } - - @Override - public Builder setSFlag(boolean value) { - this.bSFlag = value; - this.bIsSFlagSet = true; - return this; - } - - @Override - public boolean getDFlag() { - return this.bDFlag; - } - - @Override - public Builder setDFlag(boolean value) { - this.bDFlag = value; - this.bIsDFlagSet = true; - return this; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("PlspIDValue", iPlspId) - .add("OFlag", yOFlag) - .add("AFlag", bAFlag) - .add("RFlag", bRFlag) - .add("SFlag", bSFlag) - .add("DFlag", bDFlag) - .add("OptionalTlvList", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspaObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspaObjectVer1.java deleted file mode 100644 index f4000509..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLspaObjectVer1.java +++ /dev/null @@ -1,529 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepLspaObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP label Object . - */ -public class PcepLspaObjectVer1 implements PcepLspaObject { - - /* LSPA Object Body Format - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Exclude-any | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Include-any | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Include-all | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Setup Prio | Holding Prio | Flags |L| Reserved | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - | Optional TLVs | - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepLspaObjectVer1.class); - - public static final byte LSPA_OBJ_TYPE = 1; - public static final byte LSPA_OBJ_CLASS = 9; - public static final byte LSPA_OBJECT_VERSION = 1; - public static final short LSPA_OBJ_MINIMUM_LENGTH = 20; - public static final int OBJECT_HEADER_LENGTH = 4; - - static final PcepObjectHeader DEFAULT_LSPA_OBJECT_HEADER = new PcepObjectHeader(LSPA_OBJ_CLASS, LSPA_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, LSPA_OBJ_MINIMUM_LENGTH); - - public static final int SETUP_PRIORITY_SHIFT_VALUE = 24; - public static final int HOLD_PRIORITY_SHIFT_VALUE = 16; - public static final int BFLAG_SHIFT_VALUE = 8; - public static final int LFLAG_SET = 1; - public static final int LFLAG_RESET = 0; - private PcepObjectHeader lspaObjHeader; - private int iExcludeAny; - private int iIncludeAny; - private int iIncludeAll; - private byte cSetupPriority; - private byte cHoldPriority; - private boolean bLFlag; - private LinkedList<PcepValueType> llOptionalTlv; //Optional TLV - - /** - * Constructor to initialize member variables. - * - * @param lspaObjHeader lspa object header - * @param bLFlag b l flag - * @param iExcludeAny excludeAny value - * @param iIncludeAny includeAny value - * @param iIncludeAll includeAll value - * @param cSetupPriority setup priority value - * @param cHoldPriority hold priority value - * @param llOptionalTlv list of optional tlv - */ - public PcepLspaObjectVer1(PcepObjectHeader lspaObjHeader, boolean bLFlag, int iExcludeAny, int iIncludeAny, - int iIncludeAll, byte cSetupPriority, byte cHoldPriority, LinkedList<PcepValueType> llOptionalTlv) { - - this.lspaObjHeader = lspaObjHeader; - this.bLFlag = bLFlag; - this.iExcludeAny = iExcludeAny; - this.iIncludeAny = iIncludeAny; - this.iIncludeAll = iIncludeAll; - this.cSetupPriority = cSetupPriority; - this.cHoldPriority = cHoldPriority; - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Sets Object Header. - * - * @param obj lspa object header - */ - public void setLspaObjHeader(PcepObjectHeader obj) { - this.lspaObjHeader = obj; - } - - @Override - public void setExcludeAny(int iExcludeAny) { - this.iExcludeAny = iExcludeAny; - } - - @Override - public void setIncludeAny(int iIncludeAny) { - this.iIncludeAny = iIncludeAny; - } - - @Override - public void setSetupPriority(byte cSetupPriority) { - this.cSetupPriority = cSetupPriority; - } - - @Override - public void setHoldPriority(byte cHoldPriority) { - this.cHoldPriority = cHoldPriority; - } - - @Override - public void setLFlag(boolean bLFlag) { - this.bLFlag = bLFlag; - } - - /** - * Returns lspa Object Header. - * - * @return lspa Object Header - */ - public PcepObjectHeader getLspaObjHeader() { - return this.lspaObjHeader; - } - - @Override - public int getExcludeAny() { - return this.iExcludeAny; - } - - @Override - public int getIncludeAny() { - return this.iIncludeAny; - } - - @Override - public int getIncludeAll() { - return this.iIncludeAll; - } - - @Override - public byte getSetupPriority() { - return this.cSetupPriority; - } - - @Override - public byte getHoldPriority() { - return this.cHoldPriority; - } - - @Override - public boolean getLFlag() { - return this.bLFlag; - } - - @Override - public void setIncludeAll(int value) { - this.iIncludeAll = value; - - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - - } - - /** - * Reads channel buffer and returns object of PcepLspaObject. - * - * @param cb of type channel buffer. - * @return object of PcepLspaObject - * @throws PcepParseException while parsing lspa object from channel buffer - */ - public static PcepLspaObject read(ChannelBuffer cb) throws PcepParseException { - - log.debug("LspaObject::read"); - PcepObjectHeader lspaObjHeader; - int iExcludeAny; - int iIncludeAny; - int iIncludeAll; - byte cSetupPriority; - byte cHoldPriority; - boolean bLFlag; - byte flags; - - // Optional TLV - LinkedList<PcepValueType> llOptionalTlv; - - lspaObjHeader = PcepObjectHeader.read(cb); - - //take only Lspa Object buffer. - ChannelBuffer tempCb = cb.readBytes(lspaObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - iExcludeAny = tempCb.readInt(); - iIncludeAny = tempCb.readInt(); - iIncludeAll = tempCb.readInt(); - cSetupPriority = tempCb.readByte(); - cHoldPriority = tempCb.readByte(); - flags = tempCb.readByte(); - tempCb.readByte(); - - bLFlag = (flags & (byte) LFLAG_SET) == LFLAG_SET; - - llOptionalTlv = parseOptionalTlv(tempCb); - - return new PcepLspaObjectVer1(lspaObjHeader, bLFlag, iExcludeAny, iIncludeAny, iIncludeAll, cSetupPriority, - cHoldPriority, llOptionalTlv); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = lspaObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("Failed to write lspa object header. Index " + objLenIndex); - } - - cb.writeInt(iExcludeAny); - cb.writeInt(iIncludeAny); - cb.writeInt(iIncludeAll); - - int iTemp = cSetupPriority << SETUP_PRIORITY_SHIFT_VALUE; - iTemp = iTemp | (cHoldPriority << HOLD_PRIORITY_SHIFT_VALUE); - byte bFlag; - bFlag = (bLFlag) ? (byte) LFLAG_SET : LFLAG_RESET; - iTemp = iTemp | (bFlag << BFLAG_SHIFT_VALUE); - cb.writeInt(iTemp); - - // Add optional TLV - if (!packOptionalTlv(cb)) { - throw new PcepParseException("Faild to write lspa objects tlv to channel buffer"); - } - - short length = (short) (cb.writerIndex() - objStartIndex); - - lspaObjHeader.setObjLen(length); //will be helpful during print(). - - //As per RFC the length of object should be multiples of 4 - short pad = (short) (length % 4); - - if (pad != 0) { - pad = (short) (4 - pad); - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = (short) (length + pad); - } - cb.setShort(objLenIndex, length); - return cb.writerIndex(); - } - - /** - * Parse list of optional tlvs. - * - * @param cb channel buffer - * @return list of optional tlvs. - * @throws PcepParseException when fails to parse optional tlv list. - */ - public static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<>(); - - return llOutOptionalTlv; - } - - /** - * Writes optional tlvs to channel buffer. - * - * @param cb channel buffer - * @return true - */ - protected boolean packOptionalTlv(ChannelBuffer cb) { - int hTlvType; - int hTlvLength; - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - if (tlv == null) { - log.debug("Warning: tlv is null from OptionalTlv list"); - continue; - } - hTlvType = tlv.getType(); - hTlvLength = tlv.getLength(); - if (0 == hTlvLength) { - log.debug("Warning: invalid length in tlv of OptionalTlv list"); - continue; - } - - cb.writeShort(hTlvType); - cb.writeShort(hTlvLength); - - switch (hTlvType) { - //TODO: optional TLV for LSPA to be added - - default: - log.debug("Warning: PcepLspaObject: unknown tlv"); - } - - // As per RFC the length of object should - // be multiples of 4 - int pad = hTlvLength % 4; - - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - } - return true; - } - - /** - * Builder class for PCEP lspa object. - */ - public static class Builder implements PcepLspaObject.Builder { - private boolean bIsHeaderSet = false; - - private PcepObjectHeader lspaObjHeader; - - private boolean bLFlag; - private int iExcludeAny; - private boolean bIsExcludeAnySet = false; - private int iIncludeAny; - private boolean bIsIncludeAnySet = false; - private int iIncludeAll; - private boolean bIsIncludeAllSet = false; - private byte cSetupPriority; - private boolean bIsSetupPrioritySet = false; - private byte cHoldPriority; - private boolean bIsHoldPrioritySet = false; - private LinkedList<PcepValueType> llOptionalTlv; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepLspaObject build() throws PcepParseException { - - PcepObjectHeader lspaObjHeader = this.bIsHeaderSet ? this.lspaObjHeader : DEFAULT_LSPA_OBJECT_HEADER; - - if (!this.bIsExcludeAnySet) { - throw new PcepParseException("ExcludeAny NOT Set while building PcepLspaObject."); - } - if (!this.bIsIncludeAnySet) { - throw new PcepParseException("IncludeAny NOT Set while building PcepLspaObject."); - } - if (!this.bIsIncludeAllSet) { - throw new PcepParseException("IncludeAll NOT Set while building PcepLspaObject."); - } - if (!this.bIsSetupPrioritySet) { - throw new PcepParseException("Setup Priority NOT Set while building PcepLspaObject."); - } - if (!this.bIsHoldPrioritySet) { - throw new PcepParseException("Hold Priority NOT Set while building PcepLspaObject."); - } - - if (bIsPFlagSet) { - lspaObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - lspaObjHeader.setIFlag(bIFlag); - } - - return new PcepLspaObjectVer1(lspaObjHeader, bLFlag, iExcludeAny, iIncludeAny, iIncludeAll, cSetupPriority, - cHoldPriority, llOptionalTlv); - } - - @Override - public PcepObjectHeader getLspaObjHeader() { - return this.lspaObjHeader; - } - - @Override - public Builder setLspaObjHeader(PcepObjectHeader obj) { - this.lspaObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public boolean getLFlag() { - return this.bLFlag; - } - - @Override - public Builder setLFlag(boolean value) { - this.bLFlag = value; - return this; - } - - @Override - public int getExcludeAny() { - return this.iExcludeAny; - } - - @Override - public Builder setExcludeAny(int value) { - this.iExcludeAny = value; - this.bIsExcludeAnySet = true; - return this; - } - - @Override - public int getIncludeAny() { - return this.iIncludeAny; - } - - @Override - public Builder setIncludeAny(int value) { - this.iIncludeAny = value; - this.bIsIncludeAnySet = true; - return this; - } - - @Override - public int getIncludeAll() { - return this.iIncludeAll; - } - - @Override - public Builder setIncludeAll(int value) { - this.iIncludeAll = value; - this.bIsIncludeAllSet = true; - return this; - } - - @Override - public byte getSetupPriority() { - return this.cSetupPriority; - } - - @Override - public Builder setSetupPriority(byte value) { - this.cSetupPriority = value; - this.bIsSetupPrioritySet = true; - return this; - } - - @Override - public byte getHoldPriority() { - return this.cHoldPriority; - } - - @Override - public Builder setHoldPriority(byte value) { - this.cHoldPriority = value; - this.bIsHoldPrioritySet = true; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - - return this; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("LFlag", bLFlag) - .add("SetupPriority", cSetupPriority) - .add("HoldPriority", cHoldPriority) - .add("IncludeAll", iIncludeAll) - .add("IncludeAny", iIncludeAny) - .add("ExcludeAny", iExcludeAny) - .add("OptionalTlvList", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMessageVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMessageVer1.java deleted file mode 100644 index 2169a673..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMessageVer1.java +++ /dev/null @@ -1,132 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.types.PcepErrorDetailInfo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Provides PCEP messages. - */ -public abstract class PcepMessageVer1 { - - protected static final Logger log = LoggerFactory.getLogger(PcepFactories.class); - - // version: 1.0 - static final byte WIRE_VERSION = 1; - static final int MINIMUM_LENGTH = 4; - static final int PACKET_VERSION = 1; - static final byte OPEN_MSG_TYPE = 0x1; - static final byte KEEPALIVE_MSG_TYPE = 0x2; - static final byte REPORT_MSG_TYPE = 0xa; - static final byte TE_REPORT_MSG_TYPE = 0xe; - static final byte UPDATE_MSG_TYPE = 0xb; - static final byte INITIATE_MSG_TYPE = 0xc; - static final byte CLOSE_MSG_TYPE = 0x7; - static final byte ERROR_MSG_TYPE = 0x6; - static final byte LABEL_UPDATE_MSG_TYPE = 0xD; - static final byte LABEL_RANGE_RESV_MSG_TYPE = 0xF; - public static final int SHIFT_FLAG = 5; - static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - - public static final PcepMessageVer1.Reader READER = new Reader(); - - /** - * Reader class for reading PCEP messages from channel buffer. - */ - static class Reader implements PcepMessageReader<PcepMessage> { - @Override - public PcepMessage readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < MINIMUM_LENGTH) { - throw new PcepParseException("Packet should have minimum length: " + MINIMUM_LENGTH); - } - - try { - int start = cb.readerIndex(); - // fixed value property version == 1 - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != (byte) PACKET_VERSION) { - throw new PcepParseException("Wrong version. Expected=PcepVersion.Message_1(1), got=" + version); - } - - byte type = cb.readByte(); - short length = cb.readShort(); - cb.readerIndex(start); - - switch (type) { - - case OPEN_MSG_TYPE: - log.debug("OPEN MESSAGE is received"); - // message type value 1 means it is open message - return PcepOpenMsgVer1.READER.readFrom(cb.readBytes(length)); - case KEEPALIVE_MSG_TYPE: - log.debug("KEEPALIVE MESSAGE is received"); - // message type value 2 means it is Keepalive message - return PcepKeepaliveMsgVer1.READER.readFrom(cb.readBytes(length)); - case ERROR_MSG_TYPE: - log.debug("ERROR MESSAGE is received"); - // message type value 6 means it is error message - return PcepErrorMsgVer1.READER.readFrom(cb.readBytes(length)); - case REPORT_MSG_TYPE: - log.debug("REPORT MESSAGE is received"); - // message type value 10 means it is Report message - // return - return PcepReportMsgVer1.READER.readFrom(cb.readBytes(length)); - case UPDATE_MSG_TYPE: - log.debug("UPDATE MESSAGE is received"); - //message type value 11 means it is Update message - return PcepUpdateMsgVer1.READER.readFrom(cb.readBytes(length)); - case INITIATE_MSG_TYPE: - log.debug("INITIATE MESSAGE is received"); - //message type value 12 means it is PcInitiate message - return PcepInitiateMsgVer1.READER.readFrom(cb.readBytes(length)); - case CLOSE_MSG_TYPE: - log.debug("CLOSE MESSAGE is received"); - // message type value 7 means it is Close message - return PcepCloseMsgVer1.READER.readFrom(cb.readBytes(length)); - case TE_REPORT_MSG_TYPE: - log.debug("TE REPORT MESSAGE is received"); - // message type value 14 means it is TE REPORT message - // return - return PcepTEReportMsgVer1.READER.readFrom(cb.readBytes(length)); - case LABEL_UPDATE_MSG_TYPE: - log.debug("LABEL UPDATE MESSAGE is received"); - // message type value 13 means it is LABEL UPDATE message - // return - return PcepLabelUpdateMsgVer1.READER.readFrom(cb.readBytes(length)); - case LABEL_RANGE_RESV_MSG_TYPE: - log.debug("LABEL RANGE RESERVE MESSAGE is received"); - // message type value 15 means it is LABEL RANGE RESERVE message - // return - return PcepLabelRangeResvMsgVer1.READER.readFrom(cb.readBytes(length)); - default: - throw new PcepParseException("ERROR: UNKNOWN MESSAGE is received. Msg Type: " + type); - } - } catch (IndexOutOfBoundsException e) { - throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1); - } - } - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMetricObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMetricObjectVer1.java deleted file mode 100644 index 31c27870..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMetricObjectVer1.java +++ /dev/null @@ -1,376 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepMetricObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP metric object. - */ -public class PcepMetricObjectVer1 implements PcepMetricObject { - - /* - METRIC Object Body Format. - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Reserved | Flags |C|B| T | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | metric-value | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepMetricObjectVer1.class); - - public static final byte METRIC_OBJ_TYPE = 1; - public static final byte METRIC_OBJ_CLASS = 6; - public static final byte METRIC_OBJECT_VERSION = 1; - public static final short METRIC_OBJ_MINIMUM_LENGTH = 12; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int IFLAG_SHIFT_VALUE = 9; - public static final int BTYPE_SHIFT_VALUE = 8; - public static final int CFLAG_SET = 1; - public static final int CFLAG_RESET = 0; - public static final int BFLAG_SET = 1; - public static final int BFLAG_RESET = 0; - public static final byte CFLAG_CHECK = 0x02; - - static final PcepObjectHeader DEFAULT_METRIC_OBJECT_HEADER = new PcepObjectHeader(METRIC_OBJ_CLASS, - METRIC_OBJ_TYPE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - METRIC_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader metricObjHeader; - private int iMetricVal; - private byte yFlag; // 6-flags - private boolean bCFlag; - private boolean bBFlag; - private byte bType; - - /** - * Default constructor. - */ - public PcepMetricObjectVer1() { - this.metricObjHeader = null; - this.iMetricVal = 0; - this.yFlag = 0; - this.bCFlag = false; - this.bBFlag = false; - this.bType = 0; - - } - - /** - * Constructor to initialize all member variables. - * - * @param metricObjHeader metric object header - * @param iMetricVal metric value - * @param yFlag Y flag - * @param bCFlag C flag - * @param bBFlag B flag - * @param bType Type value - */ - public PcepMetricObjectVer1(PcepObjectHeader metricObjHeader, int iMetricVal, byte yFlag, boolean bCFlag, - boolean bBFlag, byte bType) { - - this.metricObjHeader = metricObjHeader; - this.iMetricVal = iMetricVal; - this.yFlag = yFlag; - this.bCFlag = bCFlag; - this.bBFlag = bBFlag; - this.bType = bType; - - } - - @Override - public void setMetricVal(int value) { - this.iMetricVal = value; - - } - - @Override - public int getMetricVal() { - return this.iMetricVal; - } - - @Override - public byte getYFlag() { - return this.yFlag; - } - - @Override - public void setYFlag(byte value) { - this.yFlag = value; - } - - @Override - public boolean getCFlag() { - return this.bCFlag; - } - - @Override - public void setCFlag(boolean value) { - this.bCFlag = value; - } - - @Override - public boolean getBFlag() { - return this.bBFlag; - } - - @Override - public void setBFlag(boolean value) { - this.bBFlag = value; - } - - @Override - public byte getBType() { - return this.bType; - } - - @Override - public void setBType(byte value) { - this.bType = value; - } - - /** - * Sets metric Object Header. - * - * @param obj metric object header - */ - public void setMetricObjHeader(PcepObjectHeader obj) { - this.metricObjHeader = obj; - } - - /** - * Returns metric Object Header. - * - * @return metricObjHeader - */ - public PcepObjectHeader getMetricObjHeader() { - return this.metricObjHeader; - } - - /** - * Reads from channel buffer and returns object of PcepMetricObject. - * - * @param cb of channel buffer. - * @return object of PcepMetricObject - * @throws PcepParseException when metric object is not present in channel buffer - */ - public static PcepMetricObject read(ChannelBuffer cb) throws PcepParseException { - - log.debug("MetricObject::read"); - PcepObjectHeader metricObjHeader; - int iMetricVal; - byte yFlag; // 6-flags - boolean bCFlag; - boolean bBFlag; - byte bType; - - metricObjHeader = PcepObjectHeader.read(cb); - - if (metricObjHeader.getObjClass() != METRIC_OBJ_CLASS) { - throw new PcepParseException("This object is not a Metric Object. Object Class: " - + metricObjHeader.getObjClass()); - } - - //take only metric buffer. - ChannelBuffer tempCb = cb.readBytes(metricObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - - tempCb.readShort(); - yFlag = tempCb.readByte(); - bType = tempCb.readByte(); - bCFlag = (yFlag & CFLAG_CHECK) == CFLAG_CHECK; - bBFlag = (yFlag & BFLAG_SET) == BFLAG_SET; - iMetricVal = tempCb.readInt(); - - return new PcepMetricObjectVer1(metricObjHeader, iMetricVal, yFlag, bCFlag, bBFlag, bType); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = metricObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("Error: ObjectLength is " + objLenIndex); - } - - int iFlag = (bCFlag) ? CFLAG_SET : CFLAG_RESET; - int iTemp = iFlag << IFLAG_SHIFT_VALUE; - iFlag = (bBFlag) ? BFLAG_SET : BFLAG_RESET; - iTemp = iTemp | (iFlag << BTYPE_SHIFT_VALUE); - iTemp = iTemp | bType; - cb.writeInt(iTemp); - cb.writeInt(iMetricVal); - - short hLength = (short) (cb.writerIndex() - objStartIndex); - cb.setShort(objLenIndex, hLength); - //will be helpful during print(). - metricObjHeader.setObjLen(hLength); - return hLength; - } - - /** - * Builder class for PCEP metric object. - */ - public static class Builder implements PcepMetricObject.Builder { - - private boolean bIsHeaderSet = false; - private PcepObjectHeader metricObjHeader; - private int iMetricVal; - private boolean bIsMetricValSet = false; - private byte yFlag; // 6-flags - private boolean bCFlag; - private boolean bBFlag; - private byte bType; - private boolean bIsbTypeSet = false; - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepMetricObject build() throws PcepParseException { - - PcepObjectHeader metricObjHeader = this.bIsHeaderSet ? this.metricObjHeader : DEFAULT_METRIC_OBJECT_HEADER; - - if (!this.bIsMetricValSet) { - throw new PcepParseException(" Metric Value NOT Set while building PcepMetricObject."); - } - if (!this.bIsbTypeSet) { - throw new PcepParseException(" Type NOT Set while building PcepMetricObject."); - } - - if (bIsPFlagSet) { - metricObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - metricObjHeader.setIFlag(bIFlag); - } - - return new PcepMetricObjectVer1(metricObjHeader, iMetricVal, yFlag, bCFlag, bBFlag, bType); - } - - @Override - public PcepObjectHeader getMetricObjHeader() { - return this.metricObjHeader; - } - - @Override - public Builder setMetricObjHeader(PcepObjectHeader obj) { - this.metricObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getMetricVal() { - return this.iMetricVal; - } - - @Override - public Builder setMetricVal(int value) { - this.iMetricVal = value; - this.bIsMetricValSet = true; - return this; - } - - @Override - public byte getYFlag() { - return this.yFlag; - } - - @Override - public Builder setYFlag(byte value) { - this.yFlag = value; - return this; - } - - @Override - public boolean getCFlag() { - return this.bCFlag; - } - - @Override - public Builder setCFlag(boolean value) { - this.bCFlag = value; - return this; - } - - @Override - public boolean getBFlag() { - return this.bBFlag; - } - - @Override - public Builder setBFlag(boolean value) { - this.bBFlag = value; - return this; - } - - @Override - public byte getBType() { - return this.bType; - } - - @Override - public Builder setBType(byte value) { - this.bType = value; - this.bIsbTypeSet = true; - return this; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("MetricValue", iMetricVal) - .add("BFlag", bBFlag) - .add("CFlag", bCFlag) - .add("BType", bType) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMsgPathVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMsgPathVer1.java deleted file mode 100644 index 49c738fc..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepMsgPathVer1.java +++ /dev/null @@ -1,187 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepAttribute; -import org.onosproject.pcepio.protocol.PcepEroObject; -import org.onosproject.pcepio.protocol.PcepMsgPath; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Message PAth for update message. - * Reference :PCE extensions for stateful draft-ietf-pce-stateful-pce-10. - */ -public class PcepMsgPathVer1 implements PcepMsgPath { - - /* - * <path> ::= <ERO><attribute-list> - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepMsgPathVer1.class); - //PcepEroObject - private PcepEroObject eroObj; - private boolean isEroObjectSet; - // PcepAttribute - private PcepAttribute attrList; - private boolean isAttributeListSet; - - /** - * constructor to initialize objects. - */ - public PcepMsgPathVer1() { - eroObj = null; - attrList = null; - isEroObjectSet = false; - isAttributeListSet = false; - } - - @Override - public PcepEroObject getEroObject() { - return eroObj; - } - - @Override - public PcepAttribute getPcepAttribute() { - return attrList; - } - - @Override - public void setEroObject(PcepEroObject eroObj) { - this.eroObj = eroObj; - } - - @Override - public void setPcepAttribute(PcepAttribute attrList) { - this.attrList = attrList; - } - - /** - * constructor to initialize member variables. - * - * @param eroObj pcep ero object - * @param attrList pcep attribute - */ - public PcepMsgPathVer1(PcepEroObject eroObj, PcepAttribute attrList) { - this.eroObj = eroObj; - isEroObjectSet = true; - this.attrList = attrList; - if (attrList == null) { - isAttributeListSet = false; - } else { - isAttributeListSet = true; - } - } - - @Override - public PcepMsgPath read(ChannelBuffer cb) throws PcepParseException { - PcepEroObject eroObj; - PcepAttribute attrList; - - eroObj = PcepEroObjectVer1.read(cb); - attrList = PcepAttributeVer1.read(cb); - - return new PcepMsgPathVer1(eroObj, attrList); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - int iLenStartIndex = cb.writerIndex(); - - //write Object header - if (this.isEroObjectSet) { - this.eroObj.write(cb); - } - if (this.isAttributeListSet) { - attrList.write(cb); - } - - return cb.writerIndex() - iLenStartIndex; - } - - /** - * Builder class for PCEP Message path. - */ - public static class Builder implements PcepMsgPath.Builder { - - private boolean bIsEROObjectSet = false; - private boolean bIsPcepAttributeSet = false; - - //PCEP ERO Object - private PcepEroObject eroObject; - //PCEP Attribute list - private PcepAttribute pcepAttribute; - - @Override - public PcepMsgPath build() throws PcepParseException { - - //PCEP ERO Object - PcepEroObject eroObject = null; - //PCEP Attribute list - PcepAttribute pcepAttribute = null; - - if (!this.bIsEROObjectSet) { - throw new PcepParseException("ERO Object NOT Set while building PcepMsgPath."); - } else { - eroObject = this.eroObject; - } - if (!this.bIsPcepAttributeSet) { - throw new PcepParseException("Pcep Attributes NOT Set while building PcepMsgPath."); - } else { - pcepAttribute = this.pcepAttribute; - } - - return new PcepMsgPathVer1(eroObject, pcepAttribute); - } - - @Override - public PcepEroObject getEroObject() { - return this.eroObject; - } - - @Override - public PcepAttribute getPcepAttribute() { - return this.pcepAttribute; - } - - @Override - public Builder setEroObject(PcepEroObject eroObject) { - this.eroObject = eroObject; - this.bIsEROObjectSet = true; - return this; - } - - @Override - public Builder setPcepAttribute(PcepAttribute pcepAttribute) { - this.pcepAttribute = pcepAttribute; - this.bIsPcepAttributeSet = true; - return this; - } - - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("EroObject", eroObj) - .add("AttributeList", attrList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepOpenMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepOpenMsgVer1.java deleted file mode 100644 index 902226e9..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepOpenMsgVer1.java +++ /dev/null @@ -1,204 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepOpenMsg; -import org.onosproject.pcepio.protocol.PcepOpenObject; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.PcepErrorDetailInfo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP open message. - */ -public class PcepOpenMsgVer1 implements PcepOpenMsg { - - /* - * <Open Message>::= <Common Header> <OPEN> - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Ver | Flags | Message-Type | Message-Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Ver | Flags | Keepalive | DeadTimer | SID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepOpenMsgVer1.class); - - public static final byte PACKET_VERSION = 1; - public static final int PACKET_MINIMUM_LENGTH = 12; - public static final PcepType MSG_TYPE = PcepType.OPEN; - private PcepOpenObject pcepOpenObj; - - public static final PcepOpenMsgVer1.Reader READER = new Reader(); - - /** - * Constructor to initialize PcepOpenObject. - * - * @param pcepOpenObj PCEP-OPEN-OBJECT - */ - public PcepOpenMsgVer1(PcepOpenObject pcepOpenObj) { - this.pcepOpenObj = pcepOpenObj; - } - - @Override - public PcepOpenObject getPcepOpenObject() { - return this.pcepOpenObj; - } - - @Override - public void setPcepOpenObject(PcepOpenObject pcepOpenObj) { - this.pcepOpenObj = pcepOpenObj; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - /** - * Reader class for reading PCEP open message from channel buffer. - */ - public static class Reader implements PcepMessageReader<PcepOpenMsg> { - - @Override - public PcepOpenMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Packet size is less than the minimum length."); - } - - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != PACKET_VERSION) { - log.error("[readFrom] Invalid version: " + version); - throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1); - } - // fixed value property type == 1 - byte type = cb.readByte(); - - if (type != MSG_TYPE.getType()) { - log.error("[readFrom] Unexpected type: " + type); - throw new PcepParseException(PcepErrorDetailInfo.ERROR_TYPE_1, PcepErrorDetailInfo.ERROR_VALUE_1); - } - int length = cb.readShort(); - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException( - "Wrong length: Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " + length); - } - return new PcepOpenMsgVer1(PcepOpenObjectVer1.read(cb)); - } - } - - /** - * Builder class for PCEP open message. - */ - static class Builder implements PcepOpenMsg.Builder { - - private PcepOpenObject pcepOpenObj; - - @Override - public PcepOpenMsg build() throws PcepParseException { - if (!(pcepOpenObj instanceof PcepOpenObjectVer1)) { - throw new NullPointerException("PcepOpenObject is null."); - } - return new PcepOpenMsgVer1(pcepOpenObj); - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.OPEN; - } - - @Override - public PcepOpenObject getPcepOpenObj() { - return this.pcepOpenObj; - } - - @Override - public Builder setPcepOpenObj(PcepOpenObject obj) { - this.pcepOpenObj = obj; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - public static final Writer WRITER = new Writer(); - - /** - * Writer class for writing PCEP opne message to channel buffer. - */ - public static class Writer implements PcepMessageWriter<PcepOpenMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepOpenMsgVer1 message) throws PcepParseException { - int startIndex = cb.writerIndex(); - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - // message type - cb.writeByte(MSG_TYPE.getType()); - // length is length of variable message, will be updated at the end - // Store the position of message - // length in buffer - - int msgLenIndex = cb.writerIndex(); - cb.writeShort(0); - - message.getPcepOpenObject().write(cb); - - // update message length field - int iLength = cb.writerIndex() - startIndex; - cb.setShort(msgLenIndex, (short) iLength); - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("OpenObject", pcepOpenObj) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepOpenObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepOpenObjectVer1.java deleted file mode 100644 index d5e58694..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepOpenObjectVer1.java +++ /dev/null @@ -1,491 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepOpenObject; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.GmplsCapabilityTlv; -import org.onosproject.pcepio.types.PceccCapabilityTlv; -import org.onosproject.pcepio.types.PcepLabelDbVerTlv; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.StatefulLspDbVerTlv; -import org.onosproject.pcepio.types.StatefulPceCapabilityTlv; -import org.onosproject.pcepio.types.TedCapabilityTlv; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP open object. - */ -public class PcepOpenObjectVer1 implements PcepOpenObject { - - /* - message format. - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Ver | Flags | Keepalive | DeadTimer | SID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - The OPEN Object format - */ - protected static final Logger log = LoggerFactory.getLogger(PcepOpenObjectVer1.class); - - public static final PcepType MSG_TYPE = PcepType.OPEN; - public static final byte OPEN_OBJECT_VERSION = 1; - public static final byte OPEN_OBJ_TYPE = 1; - public static final byte OPEN_OBJ_CLASS = 1; - public static final byte DEFAULT_KEEPALIVE_TIME = 30; - public static final byte DEFAULT_DEAD_TIME = 120; - public static final short OPEN_OBJ_MINIMUM_LENGTH = 8; - public static final int DEFAULT_GMPLS_CAPABILITY_TLV_IVALUE = 0X0; - public static final int DEFAULT_STATEFUL_PCE_CAPABILITY_TLV_IVALUE = 0xf; - public static final int DEFAULT_PCECC_CAPABILITY_TLV_IVALUE = 0x7; - public static final int DEFAULT_PCEP_LABEL_DB_VER_TLV_IVALUE = 0X0; - - public static final PcepObjectHeader DEFAULT_OPEN_HEADER = new PcepObjectHeader(OPEN_OBJ_CLASS, OPEN_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, OPEN_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader openObjHeader; - private byte keepAliveTime; - private byte deadTime; - private byte sessionId; - private LinkedList<PcepValueType> llOptionalTlv; - - /** - * Default constructor. - */ - public PcepOpenObjectVer1() { - this.openObjHeader = null; - this.keepAliveTime = 0; - this.deadTime = 0; - this.sessionId = 0; - this.llOptionalTlv = null; - } - - /** - * Constructor to initialize all member variables. - * - * @param openObjHeader Open Object Header - * @param keepAliveTime Keepalive timer value - * @param deadTime Dead timer value - * @param sessionID session id - * @param llOptionalTlv Optional TLV - */ - public PcepOpenObjectVer1(PcepObjectHeader openObjHeader, byte keepAliveTime, byte deadTime, byte sessionID, - LinkedList<PcepValueType> llOptionalTlv) { - this.openObjHeader = openObjHeader; - this.keepAliveTime = keepAliveTime; - this.deadTime = deadTime; - this.sessionId = sessionID; - this.llOptionalTlv = llOptionalTlv; - } - - @Override - public PcepObjectHeader getOpenObjHeader() { - return this.openObjHeader; - } - - @Override - public void setOpenObjHeader(PcepObjectHeader obj) { - this.openObjHeader = obj; - } - - @Override - public byte getKeepAliveTime() { - return this.keepAliveTime; - } - - @Override - public void setKeepAliveTime(byte value) { - this.keepAliveTime = value; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public byte getDeadTime() { - return this.deadTime; - } - - @Override - public void setDeadTime(byte value) { - this.deadTime = value; - } - - @Override - public byte getSessionId() { - return this.sessionId; - } - - @Override - public void setSessionId(byte value) { - this.sessionId = value; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Reads from channel buffer and returns object of PcepOpenObject. - * - * @param cb of type channel buffer - * @return object of PcepOpenObject - * @throws PcepParseException if mandatory fields are missing - */ - public static PcepOpenObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader openObjHeader; - byte version; - byte keepAliveTime; - byte deadTime; - byte sessionID; - LinkedList<PcepValueType> llOptionalTlv; - - openObjHeader = PcepObjectHeader.read(cb); - version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != OPEN_OBJECT_VERSION) { - throw new PcepParseException("Wrong version: Expected=PcepVersion.PCEP_1(1), got=" + version); - } - /* Keepalive */ - keepAliveTime = cb.readByte(); - - /* DeadTimer */ - deadTime = cb.readByte(); - - /* SID */ - sessionID = cb.readByte(); - - // Optional TLV - llOptionalTlv = parseOptionalTlv(cb); - - return new PcepOpenObjectVer1(openObjHeader, keepAliveTime, deadTime, sessionID, llOptionalTlv); - } - - /** - * Returns linkedlist of optional tlvs. - * - * @param cb of type channel buffer - * @return llOptionalTlv Optional TLV - * @throws PcepParseException if mandatory fields are missing - */ - protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOptionalTlv; - - llOptionalTlv = new LinkedList<>(); - - while (4 <= cb.readableBytes()) { - PcepValueType tlv; - short hType = cb.readShort(); - short hLength = cb.readShort(); - - switch (hType) { - case GmplsCapabilityTlv.TYPE: - log.debug("GmplsCapabilityTlv"); - if (GmplsCapabilityTlv.LENGTH != hLength) { - throw new PcepParseException("Invalid length received for Gmpls_Capability_Tlv."); - } - int iValue = cb.readInt(); - tlv = new GmplsCapabilityTlv(iValue); - break; - case StatefulPceCapabilityTlv.TYPE: - log.debug("StatefulPceCapabilityTlv"); - if (StatefulPceCapabilityTlv.LENGTH != hLength) { - throw new PcepParseException("Invalid length received for StatefulPceCapabilityTlv."); - } - tlv = StatefulPceCapabilityTlv.read(cb); - break; - case PceccCapabilityTlv.TYPE: - log.debug("PceccCapabilityTlv"); - if (PceccCapabilityTlv.LENGTH != hLength) { - throw new PcepParseException("Invalid length for PceccCapabilityTlv."); - } - iValue = cb.readInt(); - tlv = new PceccCapabilityTlv(iValue); - break; - case StatefulLspDbVerTlv.TYPE: - log.debug("StatefulLspDbVerTlv"); - if (StatefulLspDbVerTlv.LENGTH != hLength) { - throw new PcepParseException("Invalid length received for StatefulLspDbVerTlv."); - } - long lValue = cb.readLong(); - tlv = new StatefulLspDbVerTlv(lValue); - break; - case TedCapabilityTlv.TYPE: - log.debug("TedCapabilityTlv"); - if (TedCapabilityTlv.LENGTH != hLength) { - throw new PcepParseException("Invalid length received for TedCapabilityTlv."); - } - iValue = cb.readInt(); - tlv = new TedCapabilityTlv(iValue); - break; - case PcepLabelDbVerTlv.TYPE: - log.debug("PcepLabelDbVerTlv"); - if (PcepLabelDbVerTlv.LENGTH != hLength) { - throw new PcepParseException("Invalid length received for PcepLabelDbVerTlv."); - } - lValue = cb.readLong(); - tlv = new PcepLabelDbVerTlv(lValue); - break; - default: - log.debug("Unsupported TLV: " + hType); - cb.skipBytes(hLength); - continue; - } - - llOptionalTlv.add(tlv); - } - - if (0 < cb.readableBytes()) { - throw new PcepParseException("Optional Tlv parsing error. Extra bytes received."); - } - - return llOptionalTlv; - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - int objStartIndex = cb.writerIndex(); - - //write common header - int objLenIndex = openObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("Unable to write Open object header."); - } - - cb.writeByte((byte) (OPEN_OBJECT_VERSION << PcepMessageVer1.SHIFT_FLAG)); - cb.writeByte(this.keepAliveTime); - cb.writeByte(this.deadTime); - cb.writeByte(this.sessionId); - - //Pack optional TLV - packOptionalTlv(cb); - - //now write OPEN Object Length - int length = cb.writerIndex() - objStartIndex; - cb.setShort(objLenIndex, (short) length); - //will be helpful during print(). - this.openObjHeader.setObjLen((short) length); - - return length; - } - - /** - * Returns writer index. - * - * @param cb of type channel buffer. - * @return writer index - */ - protected int packOptionalTlv(ChannelBuffer cb) { - int startIndex = cb.writerIndex(); - - LinkedList<PcepValueType> llOptionalTlv = this.llOptionalTlv; - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - if (tlv == null) { - log.debug("TLV is null from OptionalTlv list"); - continue; - } - - tlv.write(cb); - - // need to take care of padding - int pad = tlv.getLength() % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - cb.writeByte((byte) 0); - } - } - } - return cb.writerIndex() - startIndex; - } - - /** - * Builder class for PCPE open object. - */ - public static class Builder implements PcepOpenObject.Builder { - // Pcep open message fields - private boolean bIsHeaderSet = false; - private PcepObjectHeader openObjHeader; - private boolean bIsKeepAliveTimeSet = false; - private byte keepAliveTime; - private boolean bIsDeadTimeSet = false; - private byte deadTime; - private boolean bIsSessionIDSet = false; - private byte sessionID; - private boolean bIsOptionalTlvSet = false; - private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepOpenObject build() throws PcepParseException { - PcepObjectHeader openObjHeader = this.bIsHeaderSet ? this.openObjHeader : DEFAULT_OPEN_HEADER; - byte keepAliveTime = this.bIsKeepAliveTimeSet ? this.keepAliveTime : DEFAULT_KEEPALIVE_TIME; - byte deadTime = this.bIsDeadTimeSet ? this.deadTime : DEFAULT_DEAD_TIME; - - if (!this.bIsSessionIDSet) { - throw new PcepParseException("SessionID is not set (mandatory)"); - } - if (!this.bIsOptionalTlvSet) { - //Add tlv to list - //Add GmplsCapabilityTlv - PcepValueType tlv; - int iValue = DEFAULT_GMPLS_CAPABILITY_TLV_IVALUE; - tlv = new GmplsCapabilityTlv(iValue); - this.llOptionalTlv.add(tlv); - - //Add StatefulPceCapabilityTlv - iValue = DEFAULT_STATEFUL_PCE_CAPABILITY_TLV_IVALUE; - tlv = new StatefulPceCapabilityTlv(iValue); - this.llOptionalTlv.add(tlv); - - } - - if (bIsPFlagSet) { - openObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - openObjHeader.setIFlag(bIFlag); - } - - return new PcepOpenObjectVer1(openObjHeader, keepAliveTime, deadTime, this.sessionID, this.llOptionalTlv); - } - - @Override - public PcepObjectHeader getOpenObjHeader() { - return this.openObjHeader; - } - - @Override - public Builder setOpenObjHeader(PcepObjectHeader obj) { - this.openObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public byte getKeepAliveTime() { - return this.keepAliveTime; - } - - @Override - public Builder setKeepAliveTime(byte value) { - this.keepAliveTime = value; - this.bIsKeepAliveTimeSet = true; - return this; - } - - @Override - public byte getDeadTime() { - return this.deadTime; - } - - @Override - public Builder setDeadTime(byte value) { - this.deadTime = value; - this.bIsDeadTimeSet = true; - return this; - } - - @Override - public byte getSessionId() { - return this.sessionID; - } - - @Override - public Builder setSessionId(byte value) { - this.sessionID = value; - this.bIsSessionIDSet = true; - return this; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - this.bIsOptionalTlvSet = true; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ObjectHeader", openObjHeader) - .add("Keepalive", keepAliveTime) - .add("DeadTimer", deadTime) - .add("SessionId", sessionId) - .add("OptionalTlv", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepRPObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepRPObjectVer1.java deleted file mode 100644 index 7234a467..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepRPObjectVer1.java +++ /dev/null @@ -1,445 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepRPObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP RP object. - */ -public class PcepRPObjectVer1 implements PcepRPObject { - - /* - * RP Object. - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Flags |O|B|R| Pri | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Request-ID-number | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepRPObjectVer1.class); - - public static final byte RP_OBJ_TYPE = 1; - public static final byte RP_OBJ_CLASS = 2; - public static final byte RP_OBJECT_VERSION = 1; - public static final short RP_OBJ_MINIMUM_LENGTH = 12; - - public static final int DEFAULT_REQUEST_ID_NUM = 0; - //Signalled , all default values to be checked. - public static final boolean DEFAULT_OFLAG = false; - public static final boolean DEFAULT_BFLAG = false; - public static final boolean DEFAULT_RFLAG = false; - public static final byte DEFAULT_PRIFLAG = 0; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int OFLAG_SHIFT_VALUE = 5; - public static final int BFLAG_SHIFT_VALUE = 4; - public static final int RFLAG_SHIFT_VALUE = 3; - public static final int OFLAG_TEMP_SHIFT_VALUE = 0x20; - public static final int BFLAG_TEMP_SHIFT_VALUE = 0x10; - public static final int RFLAG_TEMP_SHIFT_VALUE = 0x08; - public static final int PRIFLAG_TEMP_SHIFT_VALUE = 0x07; - public static final int BIT_SET = 1; - public static final int BIT_RESET = 0; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - - public static final PcepObjectHeader DEFAULT_RP_OBJECT_HEADER = new PcepObjectHeader(RP_OBJ_CLASS, RP_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, RP_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader rpObjHeader; - private int iRequestIdNum; - private boolean bOFlag; - private boolean bBFlag; - private boolean bRFlag; - private byte yPriFlag; // 3bytes - private LinkedList<PcepValueType> llOptionalTlv; - - /** - * Constructor to initialize variables. - * - * @param rpObjHeader RP-OBJECT header - * @param iRequestIdNum Request-ID-number - * @param bOFlag O-flag - * @param bBFlag B-flag - * @param bRFlag R-flag - * @param yPriFlag Pri-flag - * @param llOptionalTlv linked list of Optional TLV - */ - public PcepRPObjectVer1(PcepObjectHeader rpObjHeader, int iRequestIdNum, boolean bOFlag, boolean bBFlag, - boolean bRFlag, byte yPriFlag, LinkedList<PcepValueType> llOptionalTlv) { - this.rpObjHeader = rpObjHeader; - this.iRequestIdNum = iRequestIdNum; - this.bOFlag = bOFlag; - this.bBFlag = bBFlag; - this.bRFlag = bRFlag; - this.yPriFlag = yPriFlag; - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Sets RP Object header. - * - * @param obj RP Object header - */ - public void setRPObjHeader(PcepObjectHeader obj) { - this.rpObjHeader = obj; - } - - @Override - public void setRequestIdNum(int iRequestIdNum) { - this.iRequestIdNum = iRequestIdNum; - } - - @Override - public void setOFlag(boolean bOFlag) { - this.bOFlag = bOFlag; - } - - @Override - public void setBFlag(boolean bBFlag) { - this.bBFlag = bBFlag; - } - - @Override - public void setRFlag(boolean bRFlag) { - this.bRFlag = bRFlag; - } - - @Override - public void setPriFlag(byte yPriFlag) { - this.yPriFlag = yPriFlag; - } - - /** - * Returns RP Object header. - * - * @return rpObjHeader - */ - public PcepObjectHeader getRPObjHeader() { - return this.rpObjHeader; - } - - @Override - public int getRequestIdNum() { - return this.iRequestIdNum; - } - - @Override - public boolean getOFlag() { - return this.bOFlag; - } - - @Override - public boolean getBFlag() { - return this.bBFlag; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public byte getPriFlag() { - return this.yPriFlag; - } - - /** - * Reads the channel buffer and returns the object of PcepRPObject. - * - * @param cb of type channel buffer - * @return the object of PcepRPObject - * @throws PcepParseException if mandatory fields are missing - */ - public static PcepRPObject read(ChannelBuffer cb) throws PcepParseException { - log.debug("read"); - PcepObjectHeader rpObjHeader; - int iRequestIdNum; - boolean bOFlag; - boolean bBFlag; - boolean bRFlag; - byte yPriFlag; // 3bytes - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - rpObjHeader = PcepObjectHeader.read(cb); - - //take only LspObject buffer. - ChannelBuffer tempCb = cb.readBytes(rpObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - - int iTemp = tempCb.readInt(); - yPriFlag = (byte) (iTemp & PRIFLAG_TEMP_SHIFT_VALUE); - bOFlag = (iTemp & OFLAG_TEMP_SHIFT_VALUE) == OFLAG_TEMP_SHIFT_VALUE; - bBFlag = (iTemp & BFLAG_TEMP_SHIFT_VALUE) == BFLAG_TEMP_SHIFT_VALUE; - bRFlag = (iTemp & RFLAG_TEMP_SHIFT_VALUE) == RFLAG_TEMP_SHIFT_VALUE; - - iRequestIdNum = tempCb.readInt(); - - // parse optional TLV - llOptionalTlv = parseOptionalTlv(tempCb); - - return new PcepRPObjectVer1(rpObjHeader, iRequestIdNum, bOFlag, bBFlag, bRFlag, yPriFlag, llOptionalTlv); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = rpObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("ObjectLength Index is " + objLenIndex); - } - int iTemp; - iTemp = (yPriFlag); - - iTemp = (bOFlag) ? (iTemp | OFLAG_SHIFT_VALUE) : iTemp; - iTemp = (bBFlag) ? (iTemp | BFLAG_SHIFT_VALUE) : iTemp; - iTemp = (bRFlag) ? (iTemp | RFLAG_SHIFT_VALUE) : iTemp; - - cb.writeInt(iTemp); - cb.writeInt(iRequestIdNum); - - // Add optional TLV - packOptionalTlv(cb); - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - - //will be helpful during print(). - rpObjHeader.setObjLen((short) length); - - cb.setShort(objLenIndex, (short) length); - return cb.writerIndex(); - } - - /** - * Returns list of optional tlvs. - * - * @param cb of type channel buffer. - * @return llOutOptionalTlv linked list of Optional TLV - * @throws PcepParseException if mandatory fields are missing - */ - protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<>(); - //Currently no optional TLvs, will be added based on requirements. - return llOutOptionalTlv; - } - - /** - * Returns optional tlvs. - * - * @param cb of type channel buffer - * @return llOptionalTlv linked list of Optional TLV - */ - protected int packOptionalTlv(ChannelBuffer cb) { - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - - return cb.writerIndex(); - } - - /** - * Builder class for PCEP rp object. - */ - public static class Builder implements PcepRPObject.Builder { - - private boolean bIsHeaderSet = false; - private boolean bIsRequestIdNumSet = false; - private boolean bIsOFlagSet = false; - private boolean bIsRFlagset = false; - private boolean bIsBFlagSet = false; - private boolean bIsPriFlagSet = false; - - private PcepObjectHeader rpObjHeader; - private int requestIdNum; - private boolean bOFlag; - private boolean bBFlag; - private boolean bRFlag; - private byte yPriFlag; - private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepRPObject build() { - PcepObjectHeader lspObjHeader = this.bIsHeaderSet ? this.rpObjHeader : DEFAULT_RP_OBJECT_HEADER; - - int requestIdNum = this.bIsRequestIdNumSet ? this.requestIdNum : DEFAULT_REQUEST_ID_NUM; - boolean bOFlag = this.bIsOFlagSet ? this.bOFlag : DEFAULT_OFLAG; - boolean bBFlag = this.bIsBFlagSet ? this.bBFlag : DEFAULT_BFLAG; - boolean bRFlag = this.bIsRFlagset ? this.bRFlag : DEFAULT_RFLAG; - byte yPriFlag = this.bIsPriFlagSet ? this.yPriFlag : DEFAULT_PRIFLAG; - - if (bIsPFlagSet) { - lspObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - lspObjHeader.setIFlag(bIFlag); - } - - return new PcepRPObjectVer1(lspObjHeader, requestIdNum, bOFlag, bBFlag, bRFlag, yPriFlag, llOptionalTlv); - } - - @Override - public PcepObjectHeader getRPObjHeader() { - return this.rpObjHeader; - } - - @Override - public Builder setRPObjHeader(PcepObjectHeader obj) { - this.rpObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getRequestIdNum() { - return this.requestIdNum; - } - - @Override - public Builder setRequestIdNum(int value) { - this.requestIdNum = value; - this.bIsRequestIdNumSet = true; - return this; - } - - @Override - public Builder setOFlag(boolean value) { - this.bOFlag = value; - this.bIsOFlagSet = true; - return this; - } - - @Override - public boolean getBFlag() { - return this.bBFlag; - } - - @Override - public Builder setBFlag(boolean value) { - this.bBFlag = value; - this.bIsBFlagSet = true; - return this; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public Builder setRFlag(boolean value) { - this.bRFlag = value; - this.bIsRFlagset = true; - return this; - } - - @Override - public byte getPriFlag() { - return this.yPriFlag; - } - - @Override - public Builder setPriFlag(byte value) { - this.yPriFlag = value; - this.bIsPriFlagSet = true; - return this; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - @Override - public boolean getOFlag() { - return this.bOFlag; - } - - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ObjectHeader", rpObjHeader) - .add("OFlag", (bOFlag) ? 1 : 0) - .add("BFlag", (bBFlag) ? 1 : 0) - .add("RFlag", (bRFlag) ? 1 : 0) - .add("PriFlag", yPriFlag) - .add("RequestIdNumber", iRequestIdNum) - .add("OptionalTlv", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepReportMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepReportMsgVer1.java deleted file mode 100644 index 26e48dbd..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepReportMsgVer1.java +++ /dev/null @@ -1,309 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepReportMsg; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.onosproject.pcepio.protocol.PcepStateReport; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP report message. - */ -class PcepReportMsgVer1 implements PcepReportMsg { - - // Pcep version: 1 - - /* - * The format of the PCRpt message is as follows: - * <PCRpt Message> ::= <Common Header> - * <state-report-list> - *Where: - * <state-report-list> ::= <state-report>[<state-report-list>] - * <state-report> ::= [<SRP>] - * <LSP> - * <path> - * Where: - * <path> ::= <ERO><attribute-list>[<RRO>] - * Where: - * <attribute-list> is defined in [RFC5440] and extended by PCEP extensions. - * where: - * <attribute-list> ::=[<LSPA>] - * [<BANDWIDTH>] - * [<metric-list>] - * [<IRO>] - * <metric-list> ::=<METRIC>[<metric-list>] - */ - protected static final Logger log = LoggerFactory.getLogger(PcepReportMsgVer1.class); - - public static final byte PACKET_VERSION = 1; - //PACKET_MINIMUM_LENGTH = CommonHeaderLen(4)+LspObjMinLen(8)+EroObjMinLen(12) - public static final int PACKET_MINIMUM_LENGTH = 24; - public static final PcepType MSG_TYPE = PcepType.REPORT; - public static final byte REPORT_OBJ_TYPE = 1; - //Optional TLV - private LinkedList<PcepStateReport> llStateReportList; - - public static final PcepReportMsgVer1.Reader READER = new Reader(); - - /** - * Reader class for reading PCEP report message from channel buffer. - */ - static class Reader implements PcepMessageReader<PcepReportMsg> { - - LinkedList<PcepStateReport> llStateReportList; - - @Override - public PcepReportMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Received packet size " + cb.readableBytes() - + " is less than the expected size: " + PACKET_MINIMUM_LENGTH); - } - llStateReportList = new LinkedList<>(); - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - - if (version != PACKET_VERSION) { - throw new PcepParseException(" Invalid version: " + version); - } - - byte type = cb.readByte(); - - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Unexpected type: " + type); - } - - short length = cb.readShort(); - - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " - + length); - } - // parse state report list - parseStateReportList(cb); - return new PcepReportMsgVer1(llStateReportList); - } - - // Parse State Report list - public void parseStateReportList(ChannelBuffer cb) throws PcepParseException { - - /* - <state-report-list> - Where: - <state-report-list> ::= <state-report>[<state-report-list>] - <state-report> ::= [<SRP>] - <LSP> - <path> - Where: - <path> ::= <ERO><attribute-list>[<RRO>] - Where: - <attribute-list> is defined in [RFC5440] and extended by PCEP extensions. - - */ - - while (0 < cb.readableBytes()) { - - PcepStateReport pcestateReq = new PcepStateReportVer1(); - - /* - * SRP is optional - * Check whether SRP Object is available, if yes store it. - * First read common object header and check the Object Class whether it is SRP or LSP - * If it is LSP then store only LSP. So, SRP is optional. then read path and store. - * If it is SRP then store SRP and then read LSP, path and store them. - */ - - //mark the reader index to reset - cb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(cb); - - byte yObjectClass = tempObjHeader.getObjClass(); - byte yObjectType = tempObjHeader.getObjType(); - - //reset reader index - cb.resetReaderIndex(); - //If SRP present then store it. - if ((PcepSrpObjectVer1.SRP_OBJ_CLASS == yObjectClass) - && (PcepSrpObjectVer1.SRP_OBJ_TYPE == yObjectType)) { - PcepSrpObject srpObj; - srpObj = PcepSrpObjectVer1.read(cb); - pcestateReq.setSrpObject(srpObj); - } - - //store LSP object - PcepLspObject lspObj; - lspObj = PcepLspObjectVer1.read(cb); - pcestateReq.setLspObject(lspObj); - - //store path - PcepStateReport.PcepMsgPath msgPath = new PcepStateReportVer1().new PcepMsgPath().read(cb); - pcestateReq.setMsgPath(msgPath); - - llStateReportList.add(pcestateReq); - } - } - } - - /** - * Constructor to initialize State Report List. - * - * @param llStateReportList list of type Pcep state report - */ - PcepReportMsgVer1(LinkedList<PcepStateReport> llStateReportList) { - this.llStateReportList = llStateReportList; - } - - /** - * Builder class for PCEP Report message. - */ - static class Builder implements PcepReportMsg.Builder { - // Pcep report message fields - LinkedList<PcepStateReport> llStateReportList; - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.REPORT; - } - - @Override - public PcepReportMsg build() { - return new PcepReportMsgVer1(this.llStateReportList); - } - - @Override - public LinkedList<PcepStateReport> getStateReportList() { - return this.llStateReportList; - } - - @Override - public Builder setStateReportList(LinkedList<PcepStateReport> ll) { - this.llStateReportList = ll; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer class for writing PCEP report message to channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepReportMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepReportMsgVer1 message) throws PcepParseException { - - int startIndex = cb.writerIndex(); - - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - - // message type - cb.writeByte(MSG_TYPE.getType()); - - // length is length of variable message, will be updated at the end - // Store the position of message - // length in buffer - int msgLenIndex = cb.writerIndex(); - - cb.writeShort((short) 0); - ListIterator<PcepStateReport> listIterator = message.llStateReportList.listIterator(); - - while (listIterator.hasNext()) { - - PcepStateReport stateRpt = listIterator.next(); - PcepSrpObject srpObj = stateRpt.getSrpObject(); - - //SRP object is optional - if (srpObj != null) { - srpObj.write(cb); - } - - //LSP object is mandatory - PcepLspObject lspObj = stateRpt.getLspObject(); - if (lspObj == null) { - throw new PcepParseException("LSP Object is mandatory object for PcRpt message."); - } else { - lspObj.write(cb); - } - - //path is mandatory - PcepStateReport.PcepMsgPath msgPath = stateRpt.getMsgPath(); - if (msgPath == null) { - throw new PcepParseException("Message path is mandatory object for PcRpt message."); - } else { - msgPath.write(cb); - } - } - - // update message length field - int length = cb.writerIndex() - startIndex; - cb.setShort(msgLenIndex, (short) length); - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - @Override - public LinkedList<PcepStateReport> getStateReportList() { - return this.llStateReportList; - } - - @Override - public void setStateReportList(LinkedList<PcepStateReport> ll) { - this.llStateReportList = ll; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("StateReportList", llStateReportList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepRroObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepRroObjectVer1.java deleted file mode 100644 index 4df42e05..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepRroObjectVer1.java +++ /dev/null @@ -1,345 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepRroObject; -import org.onosproject.pcepio.types.IPv4SubObject; -import org.onosproject.pcepio.types.IPv6SubObject; -import org.onosproject.pcepio.types.LabelSubObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP RRO object. - */ -public class PcepRroObjectVer1 implements PcepRroObject { - - /* - * rfc3209 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // (Subobjects) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Each subobject has its own Length - field. The length contains the total length of the subobject in - bytes, including the Type and Length fields. The length MUST always - be a multiple of 4, and at least 4. - - An empty RRO with no subobjects is considered illegal. - Three kinds of subobjects are currently defined. - - Subobject 1: IPv4 address - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type | Length | IPv4 address (4 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 address (continued) | Prefix Length | Flags | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Subobject 2: IPv6 address - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type | Length | IPv6 address (16 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | Prefix Length | Flags | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Subobject 3, Label - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type | Length | Flags | C-Type | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Contents of Label Object | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - protected static final Logger log = LoggerFactory.getLogger(PcepRroObjectVer1.class); - - public static final byte RRO_OBJ_TYPE = 1; - public static final byte RRO_OBJ_CLASS = 8; - public static final byte RRO_OBJECT_VERSION = 1; - public static final short RRO_OBJ_MINIMUM_LENGTH = 12; - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int YTYPE_SHIFT_VALUE = 0x7F; - - static final PcepObjectHeader DEFAULT_RRO_OBJECT_HEADER = new PcepObjectHeader(RRO_OBJ_CLASS, RRO_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, RRO_OBJ_MINIMUM_LENGTH); - - private short rroObjType = 0; - private byte length; - private byte prefixLength; - private byte resvd; - PcepObjectHeader rroObjHeader; - private LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - /** - * Reset variables. - */ - public PcepRroObjectVer1() { - this.rroObjHeader = null; - this.rroObjType = 0; - this.length = 0; - } - - /** - * constructor to initialize parameters for RRO object. - * - * @param rroObjHeader RRO object header - * @param llSubObjects list of sub objects - */ - public PcepRroObjectVer1(PcepObjectHeader rroObjHeader, LinkedList<PcepValueType> llSubObjects) { - this.rroObjHeader = rroObjHeader; - this.llSubObjects = llSubObjects; - } - - /** - * Returns PCEP RRO Object Header. - * - * @return rroObjHeader RRO Object header - */ - public PcepObjectHeader getRroObjHeader() { - return this.rroObjHeader; - } - - /** - * Sets PCEP RRO Object Header. - * - * @param obj Object header - */ - public void setRroObjHeader(PcepObjectHeader obj) { - this.rroObjHeader = obj; - } - - @Override - public LinkedList<PcepValueType> getSubObjects() { - return this.llSubObjects; - } - - @Override - public void setSubObjects(LinkedList<PcepValueType> llSubObjects) { - this.llSubObjects = llSubObjects; - } - - /** - * Reads the channel buffer and returns object of PcepRroObject. - * - * @param cb of type channel buffer - * @return object of PcepRroObject - * @throws PcepParseException when fails to read from channel buffer - */ - public static PcepRroObject read(ChannelBuffer cb) throws PcepParseException { - - PcepObjectHeader rroObjHeader; - LinkedList<PcepValueType> llSubObjects; - rroObjHeader = PcepObjectHeader.read(cb); - - //take only RroObject buffer. - ChannelBuffer tempCb = cb.readBytes(rroObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - llSubObjects = parseSubObjects(tempCb); - - return new PcepRroObjectVer1(rroObjHeader, llSubObjects); - } - - /** - * Returns list of sub objects. - * - * @param cb of type channel buffer - * @return list of sub objects - * @throws PcepParseException when fails to parse list of sub objects - */ - protected static LinkedList<PcepValueType> parseSubObjects(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - while (0 < cb.readableBytes()) { - - //check the Type of the Sub objects - byte yType = cb.readByte(); - yType = (byte) (yType & (YTYPE_SHIFT_VALUE)); - byte hLength = cb.readByte(); - - PcepValueType subObj; - - switch (yType) { - - case IPv4SubObject.TYPE: - subObj = IPv4SubObject.read(cb); - break; - case IPv6SubObject.TYPE: - byte[] ipv6Value = new byte[IPv6SubObject.VALUE_LENGTH]; - cb.readBytes(ipv6Value, 0, IPv6SubObject.VALUE_LENGTH); - subObj = new IPv6SubObject(ipv6Value); - break; - case LabelSubObject.TYPE: - subObj = LabelSubObject.read(cb); - break; - default: - throw new PcepParseException(" Unexpected sub object. Type: " + (int) yType); - } - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - llSubObjects.add(subObj); - } - - return llSubObjects; - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - //write Object header - int objStartIndex = cb.writerIndex(); - - int objLenIndex = rroObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException(" object Length Index" + objLenIndex); - } - - ListIterator<PcepValueType> listIterator = llSubObjects.listIterator(); - - while (listIterator.hasNext()) { - listIterator.next().write(cb); - } - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - cb.setShort(objLenIndex, (short) length); - //will be helpful during print(). - rroObjHeader.setObjLen((short) length); - - //As per RFC the length of object should be multiples of 4 - int pad = length % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; i++) { - cb.writeByte((byte) 0); - } - length = length + pad; - } - objLenIndex = cb.writerIndex(); - return objLenIndex; - } - - /** - * Builder class for PCEP RRO object. - */ - public static class Builder implements PcepRroObject.Builder { - private boolean bIsHeaderSet = false; - - private PcepObjectHeader rroObjHeader; - LinkedList<PcepValueType> llSubObjects = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepRroObject build() { - - PcepObjectHeader rroObjHeader = this.bIsHeaderSet ? this.rroObjHeader : DEFAULT_RRO_OBJECT_HEADER; - - if (bIsPFlagSet) { - rroObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - rroObjHeader.setIFlag(bIFlag); - } - return new PcepRroObjectVer1(rroObjHeader, this.llSubObjects); - } - - @Override - public PcepObjectHeader getRroObjHeader() { - return this.rroObjHeader; - } - - @Override - public Builder setRroObjHeader(PcepObjectHeader obj) { - this.rroObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public LinkedList<PcepValueType> getSubObjects() { - return this.llSubObjects; - } - - @Override - public Builder setSubObjects(LinkedList<PcepValueType> llSubObjects) { - this.llSubObjects = llSubObjects; - return this; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("SubObjects", llSubObjects) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepSrpObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepSrpObjectVer1.java deleted file mode 100644 index 9c75b3a6..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepSrpObjectVer1.java +++ /dev/null @@ -1,392 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.SymbolicPathNameTlv; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP SRP obejct. - */ -public class PcepSrpObjectVer1 implements PcepSrpObject { - - /* - * ref : draft-ietf-pce-stateful-pce-10, section : 7.2 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Flags |R| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | SRP-ID-number | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Optional TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - protected static final Logger log = LoggerFactory.getLogger(PcepSrpObjectVer1.class); - - public static final byte SRP_OBJ_TYPE = 1; - public static final byte SRP_OBJ_CLASS = 33; - public static final byte SRP_OBJECT_VERSION = 1; - public static final short SRP_OBJ_MINIMUM_LENGTH = 12; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - public static final boolean DEFAULT_RFLAG = false; - - static final PcepObjectHeader DEFAULT_SRP_OBJECT_HEADER = new PcepObjectHeader(SRP_OBJ_CLASS, SRP_OBJ_TYPE, - PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, SRP_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader srpObjHeader; - private static int flags; - private boolean bRFlag; - private int srpId; - - //Optional TLV - private LinkedList<PcepValueType> llOptionalTlv; - public static final byte BBIT_SET = 1; - public static final byte BBIT_RESET = 0; - - /** - * Constructor to initialize member variables. - * - * @param srpObjHeader srp object header - * @param bRFlag R flag - * @param srpID srp Id - * @param llOptionalTlv list of optional tlv - */ - public PcepSrpObjectVer1(PcepObjectHeader srpObjHeader, boolean bRFlag, int srpID, - LinkedList<PcepValueType> llOptionalTlv) { - - this.srpObjHeader = srpObjHeader; - this.bRFlag = bRFlag; - this.srpId = srpID; - this.llOptionalTlv = llOptionalTlv; - } - - /** - * sets the SRP object header. - * - * @param obj srp object header - */ - public void setSrpObjHeader(PcepObjectHeader obj) { - this.srpObjHeader = obj; - } - - @Override - public void setSrpID(int srpID) { - this.srpId = srpID; - } - - @Override - public void setRFlag(boolean bRFlag) { - this.bRFlag = bRFlag; - } - - /** - * Returns SRP object header. - * - * @return srpObjHeader - */ - public PcepObjectHeader getSrpObjHeader() { - return this.srpObjHeader; - } - - @Override - public int getSrpID() { - return this.srpId; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - /** - * Reads from channel buffer and returns instance of PCEP SRP object. - * - * @param cb of channel buffer. - * @return PCEP SRP object - * @throws PcepParseException when srp object is not received in channel buffer - */ - public static PcepSrpObject read(ChannelBuffer cb) throws PcepParseException { - - log.debug("SrpObject::read"); - PcepObjectHeader srpObjHeader; - boolean bRFlag; - - int srpID; - int flags; - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - srpObjHeader = PcepObjectHeader.read(cb); - - if (srpObjHeader.getObjClass() != SRP_OBJ_CLASS) { - throw new PcepParseException("SRP object expected. But received " + srpObjHeader.getObjClass()); - } - - //take only SrpObject buffer. - ChannelBuffer tempCb = cb.readBytes(srpObjHeader.getObjLen() - MINIMUM_COMMON_HEADER_LENGTH); - flags = tempCb.readInt(); - bRFlag = 0 < flags; - srpID = tempCb.readInt(); - - llOptionalTlv = parseOptionalTlv(tempCb); - - return new PcepSrpObjectVer1(srpObjHeader, bRFlag, srpID, llOptionalTlv); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - int objStartIndex = cb.writerIndex(); - - //write common header - int objLenIndex = srpObjHeader.write(cb); - - //write Flags - byte bFlag; - - bFlag = (bRFlag) ? BBIT_SET : BBIT_RESET; - - cb.writeInt(bFlag); - - //write SrpId - cb.writeInt(srpId); - - // Add optional TLV - if (!packOptionalTlv(cb)) { - throw new PcepParseException("Failed to write srp tlv to channel buffer."); - } - - //now write SRP Object Length - cb.setShort(objLenIndex, (short) (cb.writerIndex() - objStartIndex)); - - return cb.writerIndex(); - } - - /** - * Parse Optional TLvs from the channel buffer. - * - * @param cb of type channel buffer - * @return list of optional tlvs - * @throws PcepParseException when unsupported tlv is received in srp object - */ - public static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOutOptionalTlv = new LinkedList<>(); - - while (MINIMUM_COMMON_HEADER_LENGTH <= cb.readableBytes()) { - - PcepValueType tlv; - short hType = cb.readShort(); - short hLength = cb.readShort(); - - switch (hType) { - - case SymbolicPathNameTlv.TYPE: - tlv = SymbolicPathNameTlv.read(cb, hLength); - cb.skipBytes(hLength); - break; - - default: - throw new PcepParseException("Unsupported TLV received in SRP Object."); - } - - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - llOutOptionalTlv.add(tlv); - } - - return llOutOptionalTlv; - } - - /** - * Writes optional tlvs to channel buffer. - * - * @param cb of type channel buffer - * @return true if writing optional tlv to channel buffer is success. - */ - protected boolean packOptionalTlv(ChannelBuffer cb) { - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - if (tlv == null) { - log.debug("tlv is null from OptionalTlv list"); - continue; - } - tlv.write(cb); - - // need to take care of padding - int pad = tlv.getLength() % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - cb.writeByte((byte) 0); - } - } - } - - return true; - } - - /** - * Builder class for PCEP srp Object. - */ - public static class Builder implements PcepSrpObject.Builder { - private boolean bIsHeaderSet = false; - private boolean bIsSrpIdset = false; - private boolean bIsRFlagSet = false; - - private PcepObjectHeader srpObjHeader; - private int srpId; - private boolean bRFlag; - LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepSrpObject build() throws PcepParseException { - PcepObjectHeader srpObjHeader = this.bIsHeaderSet ? this.srpObjHeader : DEFAULT_SRP_OBJECT_HEADER; - - boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : DEFAULT_RFLAG; - - if (!this.bIsSrpIdset) { - throw new PcepParseException("SrpID not set while building SRP Object."); - } - - if (bIsPFlagSet) { - srpObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - srpObjHeader.setIFlag(bIFlag); - } - - return new PcepSrpObjectVer1(srpObjHeader, bRFlag, this.srpId, this.llOptionalTlv); - } - - @Override - public PcepObjectHeader getSrpObjHeader() { - return this.srpObjHeader; - } - - @Override - public Builder setSrpObjHeader(PcepObjectHeader obj) { - this.srpObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public int getSrpID() { - return this.srpId; - } - - @Override - public Builder setSrpID(int srpID) { - this.srpId = srpID; - this.bIsSrpIdset = true; - return this; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public Builder setRFlag(boolean bRFlag) { - this.bRFlag = bRFlag; - this.bIsRFlagSet = true; - return this; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("RFlag", bRFlag) - .add("SRPID", srpId) - .add("OptionalTlvList", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepStateReportVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepStateReportVer1.java deleted file mode 100644 index ce589bc0..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepStateReportVer1.java +++ /dev/null @@ -1,421 +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.pcepio.protocol.ver1; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepAttribute; -import org.onosproject.pcepio.protocol.PcepBandwidthObject; -import org.onosproject.pcepio.protocol.PcepEroObject; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepRroObject; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.onosproject.pcepio.protocol.PcepStateReport; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provide the State Report for the Pcep Report Message. - * Reference :PCE extensions for stateful draft-ietf-pce-stateful-pce-10. - */ -public class PcepStateReportVer1 implements PcepStateReport { - /* - * <state-report> ::= [<SRP>] - <LSP> - <path> - Where: - <path> ::= <ERO><attribute-list>[<RRO>] - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepStateReport.class); - - public static final int OBJECT_HEADER_LENGTH = 4; - - /** - * Provides PCEP Message path for report message. - */ - public class PcepMsgPath implements PcepStateReport.PcepMsgPath { - - /* - * <path> ::= <ERO><attribute-list>[<RRO>] - */ - - //PcepEroObject - private PcepEroObject eroObj; - private boolean isEroObjectSet; - //PcepAttribute List - private PcepAttribute attrList; - private boolean isAttributeListSet; - //PcepRroObject - private PcepRroObject rroObj; - private boolean isRroObjectSet; - private PcepBandwidthObject bandwidth; - private boolean isBandwidthObjectSet; - - /** - * Constructor to reset the parameters. - */ - public PcepMsgPath() { - eroObj = null; - attrList = null; - rroObj = null; - this.isEroObjectSet = false; - this.isAttributeListSet = false; - this.isRroObjectSet = false; - this.isBandwidthObjectSet = false; - } - - /** - * Constructor to initialize the parameters from PCEP Message path. - * - * @param eroObj PCEP ERO Object - * @param attrList PCEP Attribute - * @param rroObj PCEP Rro Object - * @param bandwidth PCEP bandwidth object - */ - public PcepMsgPath(PcepEroObject eroObj, PcepAttribute attrList, PcepRroObject rroObj, - PcepBandwidthObject bandwidth) { - - this.eroObj = eroObj; - this.attrList = attrList; - this.rroObj = rroObj; - this.bandwidth = bandwidth; - if (rroObj == null) { - this.isRroObjectSet = false; - } else { - this.isRroObjectSet = true; - } - if (eroObj == null) { - this.isEroObjectSet = false; - } else { - this.isEroObjectSet = true; - } - if (attrList == null) { - this.isAttributeListSet = false; - } else { - this.isAttributeListSet = true; - } - if (bandwidth == null) { - this.isBandwidthObjectSet = false; - } else { - this.isBandwidthObjectSet = true; - } - } - - /** - * Returns PcepEroObject. - * - * @return eroObj PCEP ERO Object - */ - @Override - public PcepEroObject getEroObject() { - return this.eroObj; - } - - /** - * Returns PCEP Attribute. - * - * @return attrList Attribute list - */ - @Override - public PcepAttribute getPcepAttribute() { - return this.attrList; - } - - /** - * Returns PcepRroObject. - * - * @return rroObj PCEP RRO Object - */ - @Override - public PcepRroObject getRroObject() { - return this.rroObj; - } - - @Override - public PcepBandwidthObject getBandwidthObject() { - return this.bandwidth; - } - - @Override - public void setEroObject(PcepEroObject eroObj) { - this.eroObj = eroObj; - } - - @Override - public void setPcepAttribute(PcepAttribute attrList) { - this.attrList = attrList; - } - - @Override - public void setRroObject(PcepRroObject rroObj) { - this.rroObj = rroObj; - } - - @Override - public void setBandwidthObject(PcepBandwidthObject bandwidth) { - this.bandwidth = bandwidth; - } - - /** - * Reads all the Objects for PCEP Message Path. - * - * @param bb of type channel buffer - * @return PCEP Message path - * @throws PcepParseException when fails to read pcep message path - */ - @Override - public PcepMsgPath read(ChannelBuffer bb) throws PcepParseException { - - PcepEroObject eroObj; - PcepAttribute attrList; - PcepRroObject rroObj = null; - PcepBandwidthObject bandwidth = null; - - eroObj = PcepEroObjectVer1.read(bb); - attrList = PcepAttributeVer1.read(bb); - - boolean bBreakWhile = false; - while (0 < bb.readableBytes()) { - - if (bb.readableBytes() < OBJECT_HEADER_LENGTH) { - break; - } - bb.markReaderIndex(); - PcepObjectHeader tempObjHeader = PcepObjectHeader.read(bb); - bb.resetReaderIndex(); - byte yObjClass = tempObjHeader.getObjClass(); - - switch (yObjClass) { - case PcepRroObjectVer1.RRO_OBJ_CLASS: - rroObj = PcepRroObjectVer1.read(bb); - break; - case PcepInterLayerObjectVer1.INTER_LAYER_OBJ_CLASS: - bb.skipBytes(tempObjHeader.getObjLen()); - break; - case PcepBandwidthObjectVer1.BANDWIDTH_OBJ_CLASS: - bandwidth = PcepBandwidthObjectVer1.read(bb); - break; - default: - //Otherthan above objects handle those objects in caller. - bBreakWhile = true; - break; - } - if (bBreakWhile) { - break; - } - } - return new PcepMsgPath(eroObj, attrList, rroObj, bandwidth); - } - - /** - * Writes all the objects for PCEP message path. - * - * @param bb of type channel buffer. - * @return object length index - * @throws PcepParseException when fails to write to channel buffer - */ - @Override - public int write(ChannelBuffer bb) throws PcepParseException { - int iLenStartIndex = bb.writerIndex(); - - //write Object header - if (this.isEroObjectSet) { - this.eroObj.write(bb); - } else { - throw new PcepParseException("Ero object is not set in path"); - } - - if (this.isAttributeListSet) { - this.attrList.write(bb); - } - - // RRO is optional check and read - if (this.isRroObjectSet) { - this.rroObj.write(bb); - // bandwidth should come along with RRO. - if (this.isBandwidthObjectSet) { - this.bandwidth.write(bb); - } - } - return bb.writerIndex() - iLenStartIndex; - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - if (attrList != null) { - toStrHelper.add("AttributeList", attrList); - } - if (rroObj instanceof PcepRroObjectVer1) { - toStrHelper.add("RroObject", rroObj); - } - if (bandwidth instanceof PcepBandwidthObjectVer1) { - toStrHelper.add("bandwidthObject", bandwidth); - } - return toStrHelper.toString(); - } - } - - //SRP Object - private PcepSrpObject srpObject; - //LSP Object - private PcepLspObject lspObject; - //PcepMsgPath - private PcepStateReport.PcepMsgPath msgPath; - - /** - * Constructor to reset objects. - */ - public PcepStateReportVer1() { - this.srpObject = null; - this.lspObject = null; - this.msgPath = null; - } - - public PcepStateReportVer1(PcepSrpObject srpObject, PcepLspObject lspObject, PcepStateReport.PcepMsgPath msgPath) { - this.srpObject = srpObject; - this.lspObject = lspObject; - this.msgPath = msgPath; - } - - @Override - public PcepSrpObject getSrpObject() { - return srpObject; - } - - @Override - public PcepLspObject getLspObject() { - return lspObject; - } - - @Override - public PcepStateReport.PcepMsgPath getMsgPath() { - return msgPath; - } - - @Override - public void setSrpObject(PcepSrpObject srpObj) { - this.srpObject = srpObj; - } - - @Override - public void setLspObject(PcepLspObject lspObject) { - this.lspObject = lspObject; - } - - @Override - public void setMsgPath(PcepStateReport.PcepMsgPath msgPath) { - this.msgPath = msgPath; - } - - /** - * Builder class for PCEP state report. - */ - public static class Builder implements PcepStateReport.Builder { - - private boolean bIsSRPObjectSet = false; - private boolean bIsLSPObjectSet = false; - private boolean bIsPcepMsgPathSet = false; - - //PCEP SRP Object - private PcepSrpObject srpObject; - //PCEP LSP Object - private PcepLspObject lspObject; - //PCEP Attribute list - private PcepStateReport.PcepMsgPath msgPath; - - @Override - public PcepStateReport build() throws PcepParseException { - - //PCEP SRP Object - PcepSrpObject srpObject = null; - //PCEP LSP Object - PcepLspObject lspObject = null; - //PCEP Attribute list - PcepStateReport.PcepMsgPath msgPath = null; - - if (this.bIsSRPObjectSet) { - srpObject = this.srpObject; - } - - if (!this.bIsLSPObjectSet) { - throw new PcepParseException(" LSP Object NOT Set while building PcepStateReport."); - } else { - lspObject = this.lspObject; - } - if (!this.bIsPcepMsgPathSet) { - throw new PcepParseException(" Message Path NOT Set while building PcepStateReport."); - } else { - msgPath = this.msgPath; - } - - return new PcepStateReportVer1(srpObject, lspObject, msgPath); - } - - @Override - public PcepSrpObject getSrpObject() { - return this.srpObject; - } - - @Override - public PcepLspObject getLspObject() { - return this.lspObject; - } - - @Override - public PcepStateReport.PcepMsgPath getMsgPath() { - return this.msgPath; - } - - @Override - public Builder setSrpObject(PcepSrpObject srpobj) { - this.srpObject = srpobj; - this.bIsSRPObjectSet = true; - return this; - } - - @Override - public Builder setLspObject(PcepLspObject lspObject) { - this.lspObject = lspObject; - this.bIsLSPObjectSet = true; - return this; - } - - @Override - public Builder setMsgPath(PcepStateReport.PcepMsgPath msgPath) { - this.msgPath = msgPath; - this.bIsPcepMsgPathSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .omitNullValues() - .add("SrpObject", srpObject) - .add("LspObject", lspObject) - .add("MsgPath", msgPath) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepTEObjectVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepTEObjectVer1.java deleted file mode 100644 index b1c69406..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepTEObjectVer1.java +++ /dev/null @@ -1,506 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepTEObject; -import org.onosproject.pcepio.types.LocalTENodeDescriptorsTlv; -import org.onosproject.pcepio.types.PcepObjectHeader; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.RemoteTENodeDescriptorsTlv; -import org.onosproject.pcepio.types.RoutingUniverseTlv; -import org.onosproject.pcepio.types.TELinkAttributesTlv; -import org.onosproject.pcepio.types.TELinkDescriptorsTlv; -import org.onosproject.pcepio.types.TENodeAttributesTlv; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP TE Object. - */ -public class PcepTEObjectVer1 implements PcepTEObject { - /* - * - reference: PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02. - TE Object-Class is [TBD6]. - - Two Object-Type values are defined for the TE object: - - o TE Node: TE Object-Type is 1. - - o TE Link: TE Object-Type is 2. - - The format of the TE object body is as follows: - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Protocol-ID | Flag |R|S| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | TE-ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // TLVs // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepTEObjectVer1.class); - - public static final byte TE_OBJ_TYPE_NODE_VALUE = 1; - public static final byte TE_OBJ_TYPE_LINK_VALUE = 2; - - public static final byte TE_OBJ_CLASS = 101; //TBD6 in RFC. - public static final byte TE_OBJECT_VERSION = 1; - - // TE_OBJ_MINIMUM_LENGTH = TEObjectHeaderLen(4)+ TEObjectLen(8) - public static final short TE_OBJ_MINIMUM_LENGTH = 12; - - // Signaled ,all default values to be checked. - public static final byte DEFAULT_PROTOCOL_ID = 1; //IS-IS Level 1 - public static final boolean DEFAULT_R_FLAG = false; - public static final boolean DEFAULT_S_FLAG = false; - public static final int DEFAULT_TE_ID = 0; - - public static final int OBJECT_HEADER_LENGTH = 4; - public static final int RIGHT_SHIFT_ONE = 1; - public static final int RIGHT_FIRST_FLAG = 0x1; - public static final int FLAG_SET_R_FLAG = 0x2; - public static final int FLAG_SET_S_FLAG = 0x1; - public static final int MINIMUM_COMMON_HEADER_LENGTH = 4; - public static final int MINIMUM_TLV_HEADER_LENGTH = 4; - - public static final PcepObjectHeader DEFAULT_TE_OBJECT_HEADER = new PcepObjectHeader(TE_OBJ_CLASS, - TE_OBJ_TYPE_NODE_VALUE, PcepObjectHeader.REQ_OBJ_OPTIONAL_PROCESS, PcepObjectHeader.RSP_OBJ_PROCESSED, - TE_OBJ_MINIMUM_LENGTH); - - private PcepObjectHeader teObjHeader; - private byte yProtocolId; - // 2-flags - private boolean bRFlag; - private boolean bSFlag; - private int iTEId; - // Optional TLV - private LinkedList<PcepValueType> llOptionalTlv; - - /** - * Constructor to initialize variables. - * - * @param teObjHeader TE Object header - * @param yProtocolId Protocol-ID - * @param bRFlag R-flag - * @param bSFlag S-flag - * @param iTEId TE-ID - * @param llOptionalTlv linked list of Optional TLV - */ - public PcepTEObjectVer1(PcepObjectHeader teObjHeader, byte yProtocolId, boolean bRFlag, boolean bSFlag, int iTEId, - LinkedList<PcepValueType> llOptionalTlv) { - - this.teObjHeader = teObjHeader; - this.yProtocolId = yProtocolId; - this.bRFlag = bRFlag; - this.bSFlag = bSFlag; - this.iTEId = iTEId; - this.llOptionalTlv = llOptionalTlv; - } - - @Override - public PcepObjectHeader getTEObjHeader() { - return this.teObjHeader; - } - - @Override - public void setTEObjHeader(PcepObjectHeader obj) { - this.teObjHeader = obj; - } - - @Override - public byte getProtocolId() { - return this.yProtocolId; - } - - @Override - public void setProtocolId(byte yProtId) { - this.yProtocolId = yProtId; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public void setRFlag(boolean bRFlag) { - this.bRFlag = bRFlag; - } - - @Override - public boolean getSFlag() { - return this.bSFlag; - } - - @Override - public void setSFlag(boolean bSFlag) { - this.bSFlag = bSFlag; - } - - @Override - public int getTEId() { - return this.iTEId; - } - - @Override - public void setTEId(int iTEId) { - this.iTEId = iTEId; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public void setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - } - - /** - * Reads from the channel buffer and returns Object of PcepTEObject. - * - * @param cb of type channel buffer - * @return Object of PcepTEObject - * @throws PcepParseException if mandatory fields are missing - */ - public static PcepTEObject read(ChannelBuffer cb) throws PcepParseException { - log.debug("read"); - - PcepObjectHeader teObjHeader; - byte yProtocolId; - // 2-flags - boolean bRFlag; - boolean bSFlag; - int iTEId; - LinkedList<PcepValueType> llOptionalTlv; - - teObjHeader = PcepObjectHeader.read(cb); - - //take only TEObject buffer. - ChannelBuffer tempCb = cb.readBytes(teObjHeader.getObjLen() - OBJECT_HEADER_LENGTH); - - yProtocolId = tempCb.readByte(); - //ignore first two bytes of Flags - tempCb.readShort(); - - Integer iTemp = (int) tempCb.readByte(); //read 3rd byte Flag - bSFlag = (iTemp & FLAG_SET_S_FLAG) == FLAG_SET_S_FLAG; - bRFlag = (iTemp & FLAG_SET_R_FLAG) == FLAG_SET_R_FLAG; - - iTEId = tempCb.readInt(); - - // parse optional TLV - llOptionalTlv = parseOptionalTlv(tempCb); - - return new PcepTEObjectVer1(teObjHeader, yProtocolId, bRFlag, bSFlag, iTEId, llOptionalTlv); - } - - @Override - public int write(ChannelBuffer cb) throws PcepParseException { - - //write Object header - int objStartIndex = cb.writerIndex(); - int objLenIndex = teObjHeader.write(cb); - - if (objLenIndex <= 0) { - throw new PcepParseException("ObjectLength Index is " + objLenIndex); - } - - //write Protocol ID - cb.writeByte(this.yProtocolId); - - //write Flag - cb.writeShort(0); - - byte bTemp = 0; - if (bSFlag) { - bTemp = FLAG_SET_S_FLAG; - } - - if (bRFlag) { - bTemp = (byte) (bTemp | FLAG_SET_R_FLAG); - } - cb.writeByte(bTemp); - - //write TEId - cb.writeInt(iTEId); - - // Add optional TLV - packOptionalTlv(cb); - - //Update object length now - int length = cb.writerIndex() - objStartIndex; - - //will be helpful during print(). - teObjHeader.setObjLen((short) length); - - cb.setShort(objLenIndex, (short) length); - - return cb.writerIndex(); - } - - /** - * Returns Linked list of PCEP Value Type. - * - * @param cb of channel buffer - * @return Linked list of PCEP Value Type - * @throws PcepParseException if mandatory fields are missing - */ - protected static LinkedList<PcepValueType> parseOptionalTlv(ChannelBuffer cb) throws PcepParseException { - - LinkedList<PcepValueType> llOutOptionalTlv; - - llOutOptionalTlv = new LinkedList<>(); - - while (MINIMUM_TLV_HEADER_LENGTH <= cb.readableBytes()) { - - PcepValueType tlv; - short hType = cb.readShort(); - short hLength = cb.readShort(); - long lValue = 0; - - switch (hType) { - - case RoutingUniverseTlv.TYPE: - lValue = cb.readLong(); - tlv = new RoutingUniverseTlv(lValue); - break; - case LocalTENodeDescriptorsTlv.TYPE: - tlv = LocalTENodeDescriptorsTlv.read(cb, hLength); - break; - case RemoteTENodeDescriptorsTlv.TYPE: - tlv = RemoteTENodeDescriptorsTlv.read(cb, hLength); - break; - case TELinkDescriptorsTlv.TYPE: - tlv = TELinkDescriptorsTlv.read(cb, hLength); - break; - case TENodeAttributesTlv.TYPE: - tlv = TENodeAttributesTlv.read(cb, hLength); - break; - case TELinkAttributesTlv.TYPE: - tlv = TELinkAttributesTlv.read(cb, hLength); - break; - default: - throw new PcepParseException("Unsupported TLV type :" + hType); - } - - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= cb.readableBytes()) { - cb.skipBytes(pad); - } - } - - llOutOptionalTlv.add(tlv); - } - - if (0 < cb.readableBytes()) { - - throw new PcepParseException("Optional Tlv parsing error. Extra bytes received."); - } - return llOutOptionalTlv; - } - - /** - * Returns the writer index. - * - * @param cb of type channel buffer - * @return the writer index. - */ - protected int packOptionalTlv(ChannelBuffer cb) { - - ListIterator<PcepValueType> listIterator = llOptionalTlv.listIterator(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - if (tlv == null) { - log.debug("TLV is null from OptionalTlv list"); - continue; - } - tlv.write(cb); - - // need to take care of padding - int pad = tlv.getLength() % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - cb.writeByte((byte) 0); - } - } - } - return cb.writerIndex(); - } - - /** - * Builder class for PCEP te object. - */ - public static class Builder implements PcepTEObject.Builder { - private boolean bIsHeaderSet = false; - private boolean bIsProtocolIdSet = false; - private boolean bIsRFlagSet = false; - private boolean bIsSFlagSet = false; - private boolean bIsTEIdSet = false; - - private PcepObjectHeader teObjHeader; - private byte yProtocolId; - private boolean bRFlag; - private boolean bSFlag; - private int iTEId; - private LinkedList<PcepValueType> llOptionalTlv = new LinkedList<>(); - - private boolean bIsPFlagSet = false; - private boolean bPFlag; - - private boolean bIsIFlagSet = false; - private boolean bIFlag; - - @Override - public PcepTEObject build() { - PcepObjectHeader teObjHeader = this.bIsHeaderSet ? this.teObjHeader : DEFAULT_TE_OBJECT_HEADER; - - byte yProtocolId = this.bIsProtocolIdSet ? this.yProtocolId : DEFAULT_PROTOCOL_ID; - boolean bRFlag = this.bIsRFlagSet ? this.bRFlag : DEFAULT_R_FLAG; - boolean bSFlag = this.bIsSFlagSet ? this.bSFlag : DEFAULT_S_FLAG; - int iTEId = this.bIsTEIdSet ? this.iTEId : DEFAULT_TE_ID; - - if (bIsPFlagSet) { - teObjHeader.setPFlag(bPFlag); - } - - if (bIsIFlagSet) { - teObjHeader.setIFlag(bIFlag); - } - - return new PcepTEObjectVer1(teObjHeader, yProtocolId, bRFlag, bSFlag, iTEId, llOptionalTlv); - - } - - @Override - public PcepObjectHeader getTEObjHeader() { - return this.teObjHeader; - } - - @Override - public Builder setTEObjHeader(PcepObjectHeader obj) { - this.teObjHeader = obj; - this.bIsHeaderSet = true; - return this; - } - - @Override - public byte getProtocolId() { - return this.yProtocolId; - } - - @Override - public Builder setProtocolId(byte yProtId) { - this.yProtocolId = yProtId; - this.bIsProtocolIdSet = true; - return this; - } - - @Override - public boolean getRFlag() { - return this.bRFlag; - } - - @Override - public Builder setRFlag(boolean bRFlag) { - this.bRFlag = bRFlag; - this.bIsRFlagSet = true; - return this; - } - - @Override - public boolean getSFlag() { - return this.bSFlag; - } - - @Override - public Builder setSFlag(boolean bSFlag) { - this.bSFlag = bSFlag; - this.bIsSFlagSet = true; - return this; - } - - @Override - public int getTEId() { - return this.iTEId; - } - - @Override - public Builder setTEId(int iTEId) { - this.iTEId = iTEId; - this.bIsTEIdSet = true; - return this; - } - - @Override - public LinkedList<PcepValueType> getOptionalTlv() { - return this.llOptionalTlv; - } - - @Override - public Builder setOptionalTlv(LinkedList<PcepValueType> llOptionalTlv) { - this.llOptionalTlv = llOptionalTlv; - return this; - } - - @Override - public Builder setPFlag(boolean value) { - this.bPFlag = value; - this.bIsPFlagSet = true; - return this; - } - - @Override - public Builder setIFlag(boolean value) { - this.bIFlag = value; - this.bIsIFlagSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ObjectHeader", teObjHeader) - .add("ProtocolId", yProtocolId) - .add("RFlag", (bRFlag) ? 1 : 0) - .add("SFlag", (bSFlag) ? 1 : 0) - .add("TeId", iTEId) - .add("OptionalTlv", llOptionalTlv) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepTEReportMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepTEReportMsgVer1.java deleted file mode 100644 index 92833080..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepTEReportMsgVer1.java +++ /dev/null @@ -1,225 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepTEObject; -import org.onosproject.pcepio.protocol.PcepTEReportMsg; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP TE Report Message. - */ -class PcepTEReportMsgVer1 implements PcepTEReportMsg { - - /* - * Ref : draft-dhodylee-pce-pcep-te-data-extn-02, section 8.1 - - <TERpt Message> ::= <Common Header> - <te-report-list> - Where: - <te-report-list> ::= <TE>[<te-report-list>] - */ - - private static final Logger log = LoggerFactory.getLogger(PcepTEReportMsgVer1.class); - //PACKET_MINIMUM_LENGTH = CommonHeaderLen(4)+TEObjMinLen(12) - public static final int PACKET_MINIMUM_LENGTH = 16; - public static final PcepType MSG_TYPE = PcepType.TE_REPORT; - // <te-report-list> - private LinkedList<PcepTEObject> teReportList; - - public static final PcepTEReportMsgVer1.Reader READER = new Reader(); - - /** - * Reader class for reading PCPE te report message form channel buffer. - */ - static class Reader implements PcepMessageReader<PcepTEReportMsg> { - - LinkedList<PcepTEObject> teReportList; - - @Override - public PcepTEReportMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - return null; - } - - teReportList = new LinkedList<>(); - - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != PcepMessageVer1.PACKET_VERSION) { - throw new PcepParseException("Wrong version. Expected=PcepVersion.PCEP_1(1), got=" + version); - } - - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type. Expected=PcepType.TE_REPORT(14), got=" + type); - } - - short length = cb.readShort(); - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException( - "Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", is: " + length); - } - - // Parse state report list - parseTEReportList(cb); - - return new PcepTEReportMsgVer1(teReportList); - } - - /** - * Parse te-report-list. - * - * @param cb input Channel Buffer - * @throws PcepParseException when fails to parse TE Report list. - */ - public void parseTEReportList(ChannelBuffer cb) throws PcepParseException { - // <te-report-list> ::= <TE>[<te-report-list>] - - while (0 < cb.readableBytes()) { - //store TE objectS - if (!teReportList.add(PcepTEObjectVer1.read(cb))) { - throw new PcepParseException("Failed to add TE object to TE report list"); - } - } - } - } - - /** - * Constructor to initialize TE Report List. - * - * @param teReportList list of PCEP TE Object - */ - PcepTEReportMsgVer1(LinkedList<PcepTEObject> teReportList) { - this.teReportList = teReportList; - } - - /** - * Builder class for PCEP te report message. - */ - static class Builder implements PcepTEReportMsg.Builder { - // PCEP TE Report message fields - LinkedList<PcepTEObject> teReportList; - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.TE_REPORT; - } - - @Override - public PcepTEReportMsg build() { - return new PcepTEReportMsgVer1(this.teReportList); - } - - @Override - public LinkedList<PcepTEObject> getTEReportList() { - return this.teReportList; - } - - @Override - public Builder setTEReportList(LinkedList<PcepTEObject> ll) { - this.teReportList = ll; - return this; - } - } - - @Override - public void writeTo(ChannelBuffer bb) throws PcepParseException { - WRITER.write(bb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer class for writing PCEP te report message to channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepTEReportMsgVer1> { - - @Override - public void write(ChannelBuffer bb, PcepTEReportMsgVer1 message) throws PcepParseException { - - int startIndex = bb.writerIndex(); - - // first 3 bits set to version - bb.writeByte((byte) (PcepMessageVer1.PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - - // message type - bb.writeByte(MSG_TYPE.getType()); - - // Length of the message will be updated at the end - // First write with 0s - int msgLenIndex = bb.writerIndex(); - bb.writeShort((short) 0); - - ListIterator<PcepTEObject> listIterator = message.teReportList.listIterator(); - - while (listIterator.hasNext()) { - PcepTEObject teObj = listIterator.next(); - teObj.write(bb); - } - - // update message length field - int length = bb.writerIndex() - startIndex; - bb.setShort(msgLenIndex, (short) length); - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - @Override - public LinkedList<PcepTEObject> getTEReportList() { - return this.teReportList; - } - - @Override - public void setTEReportList(LinkedList<PcepTEObject> ll) { - this.teReportList = ll; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("TeReportList", teReportList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepUpdateMsgVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepUpdateMsgVer1.java deleted file mode 100644 index 53c66872..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepUpdateMsgVer1.java +++ /dev/null @@ -1,300 +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.pcepio.protocol.ver1; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepMessageWriter; -import org.onosproject.pcepio.protocol.PcepMsgPath; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.onosproject.pcepio.protocol.PcepType; -import org.onosproject.pcepio.protocol.PcepUpdateMsg; -import org.onosproject.pcepio.protocol.PcepUpdateRequest; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP update message. - */ - -class PcepUpdateMsgVer1 implements PcepUpdateMsg { - - // Pcep version: 1 - - /* The format of the PCUpd message is as follows: - * <PCUpd Message> ::= <Common Header> - * <update-request-list> - * Where: - * <update-request-list> ::= <update-request>[<update-request-list>] - * <update-request> ::= <SRP> - * <LSP> - * <path> - * Where: - * <path> ::= <ERO><attribute-list> - * Where: - * <attribute-list> is defined in [RFC5440] and extended by PCEP extensions. - * where: - * <attribute-list> ::=[<LSPA>] - * [<BANDWIDTH>] - * [<metric-list>] - * [<IRO>] - * <metric-list> ::=<METRIC>[<metric-list>] - * - * 0 1 2 3 - * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | Ver | Flags | Message-Type | Message-Length | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * | | - * // UPDATE REQUEST LIST // - * | | - * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - * - * Reference:Internet-Draft-PCEP Extensions-for-Stateful-PCE-10 - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepUpdateMsgVer1.class); - - public static final byte PACKET_VERSION = 1; - // UpdateMsgMinLength = SrpObjMinLentgh(12)+LspObjMinLength(8)+EroObjMinLength(12)+ CommonHeaderLength(4) - public static final short PACKET_MINIMUM_LENGTH = 36; - public static final PcepType MSG_TYPE = PcepType.UPDATE; - //Update Request List - private LinkedList<PcepUpdateRequest> llUpdateRequestList; - - public static final PcepUpdateMsgVer1.Reader READER = new Reader(); - - /** - * Reader reads UpdateMessage from the channel. - */ - static class Reader implements PcepMessageReader<PcepUpdateMsg> { - - LinkedList<PcepUpdateRequest> llUpdateRequestList; - - @Override - public PcepUpdateMsg readFrom(ChannelBuffer cb) throws PcepParseException { - - if (cb.readableBytes() < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Readable bytes is less than update message minimum length"); - } - - llUpdateRequestList = new LinkedList<>(); - - // fixed value property version == 1 - byte version = cb.readByte(); - version = (byte) (version >> PcepMessageVer1.SHIFT_FLAG); - if (version != PACKET_VERSION) { - throw new PcepParseException("Wrong version. Expected=PcepVersion.PCEP_1(1), got=" + version); - } - // fixed value property type == 11 - byte type = cb.readByte(); - if (type != MSG_TYPE.getType()) { - throw new PcepParseException("Wrong type. Expected=PcepType.UPDATE(11), got=" + type); - } - short length = cb.readShort(); - if (length < PACKET_MINIMUM_LENGTH) { - throw new PcepParseException("Wrong length. Expected to be >= " + PACKET_MINIMUM_LENGTH + ", was: " - + length); - } - - log.debug("reading update message of length " + length); - - // parse Update Request list - if (!parseUpdateRequestList(cb)) { - throw new PcepParseException("parsing Update Request List Failed."); - } - - return new PcepUpdateMsgVer1(llUpdateRequestList); - } - - /** - * Parse update request list. - * - * @param cb of type channel buffer - * @return true after parsing Update Request List - * @throws PcepParseException while parsing update request list from channel buffer - */ - public boolean parseUpdateRequestList(ChannelBuffer cb) throws PcepParseException { - - /* <update-request-list> - * Where: - * <update-request-list> ::= <update-request>[<update-request-list>] - * <update-request> ::= <SRP> - * <LSP> - * <path> - * Where: - * <path> ::= <ERO><attribute-list> - * Where: - * <attribute-list> is defined in [RFC5440] and extended by PCEP extensions. - */ - - while (0 < cb.readableBytes()) { - - PcepUpdateRequest pceUpdateReq = new PcepUpdateRequestVer1(); - - //Read SRP Object and Store it. - PcepSrpObject srpObj; - srpObj = PcepSrpObjectVer1.read(cb); - pceUpdateReq.setSrpObject(srpObj); - - //Read LSP object and Store it. - PcepLspObject lspObj; - lspObj = PcepLspObjectVer1.read(cb); - pceUpdateReq.setLspObject(lspObj); - - // Read Msg Path and store it. - PcepMsgPath msgPath = new PcepMsgPathVer1().read(cb); - pceUpdateReq.setMsgPath(msgPath); - - llUpdateRequestList.add(pceUpdateReq); - } - return true; - } - } - - /** - * Constructor to initialize llUpdateRequestList. - * - * @param llUpdateRequestList list of PcepUpdateRequest. - */ - PcepUpdateMsgVer1(LinkedList<PcepUpdateRequest> llUpdateRequestList) { - this.llUpdateRequestList = llUpdateRequestList; - } - - /** - * Builder class for PCPE update message. - */ - static class Builder implements PcepUpdateMsg.Builder { - - // PCEP report message fields - LinkedList<PcepUpdateRequest> llUpdateRequestList; - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return PcepType.UPDATE; - } - - @Override - public PcepUpdateMsg build() { - return new PcepUpdateMsgVer1(this.llUpdateRequestList); - } - - @Override - public LinkedList<PcepUpdateRequest> getUpdateRequestList() { - return this.llUpdateRequestList; - } - - @Override - public Builder setUpdateRequestList(LinkedList<PcepUpdateRequest> llUpdateRequestList) { - this.llUpdateRequestList = llUpdateRequestList; - return this; - } - - } - - @Override - public void writeTo(ChannelBuffer cb) throws PcepParseException { - WRITER.write(cb, this); - } - - static final Writer WRITER = new Writer(); - - /** - * Writer writes UpdateMessage to the channel buffer. - */ - static class Writer implements PcepMessageWriter<PcepUpdateMsgVer1> { - - @Override - public void write(ChannelBuffer cb, PcepUpdateMsgVer1 message) throws PcepParseException { - - int startIndex = cb.writerIndex(); - // first 3 bits set to version - cb.writeByte((byte) (PACKET_VERSION << PcepMessageVer1.SHIFT_FLAG)); - // message type - cb.writeByte(MSG_TYPE.getType()); - /* length is length of variable message, will be updated at the end - * Store the position of message - * length in buffer - */ - int msgLenIndex = cb.writerIndex(); - - cb.writeShort((short) 0); - ListIterator<PcepUpdateRequest> listIterator = message.llUpdateRequestList.listIterator(); - - while (listIterator.hasNext()) { - - PcepUpdateRequest updateReq = listIterator.next(); - - //SRP object is mandatory - PcepSrpObject srpObj = updateReq.getSrpObject(); - srpObj.write(cb); - - //LSP object is mandatory - PcepLspObject lspObj = updateReq.getLspObject(); - lspObj.write(cb); - - //PATH object is mandatory - PcepMsgPath msgPath = updateReq.getMsgPath(); - msgPath.write(cb); - } - - // update message length field - int length = cb.writerIndex() - startIndex; - cb.setShort(msgLenIndex, (short) length); - } - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public PcepType getType() { - return MSG_TYPE; - } - - @Override - public LinkedList<PcepUpdateRequest> getUpdateRequestList() { - return this.llUpdateRequestList; - } - - @Override - public void setUpdateRequestList(LinkedList<PcepUpdateRequest> llUpdateRequestList) { - this.llUpdateRequestList = llUpdateRequestList; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("UpdateRequestList", llUpdateRequestList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepUpdateRequestVer1.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepUpdateRequestVer1.java deleted file mode 100644 index 0bcc2907..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepUpdateRequestVer1.java +++ /dev/null @@ -1,199 +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.pcepio.protocol.ver1; - -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepMsgPath; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.onosproject.pcepio.protocol.PcepUpdateRequest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Update Request List. - */ -public class PcepUpdateRequestVer1 implements PcepUpdateRequest { - - /* <update-request-list> - * Where: - * <update-request-list> ::= <update-request>[<update-request-list>] - * <update-request> ::= <SRP> - * <LSP> - * <path> - * Where: - * <path> ::= <ERO><attribute-list> - * Where: - * <attribute-list> is defined in [RFC5440] and extended by PCEP extensions. - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepUpdateRequestVer1.class); - - //PCEP SRP Object - private PcepSrpObject srpObject; - //PCEP LSP Object - private PcepLspObject lspObject; - //PCEP Message path - private PcepMsgPath msgPath; - - /** - * Default constructor. - */ - public PcepUpdateRequestVer1() { - srpObject = null; - lspObject = null; - msgPath = null; - } - - /** - * Constructor to initialize all member variables. - * - * @param srpObject srp object - * @param lspObject lsp object - * @param msgPath message path object - */ - public PcepUpdateRequestVer1(PcepSrpObject srpObject, PcepLspObject lspObject, PcepMsgPath msgPath) { - this.srpObject = srpObject; - this.lspObject = lspObject; - this.msgPath = msgPath; - } - - @Override - public PcepSrpObject getSrpObject() { - return srpObject; - } - - @Override - public PcepLspObject getLspObject() { - return lspObject; - } - - @Override - public PcepMsgPath getMsgPath() { - return msgPath; - } - - @Override - public void setSrpObject(PcepSrpObject srpObject) { - this.srpObject = srpObject; - - } - - @Override - public void setLspObject(PcepLspObject lspObject) { - this.lspObject = lspObject; - } - - @Override - public void setMsgPath(PcepMsgPath msgPath) { - this.msgPath = msgPath; - } - - /** - * Builder class for PCEP update request. - */ - public static class Builder implements PcepUpdateRequest.Builder { - - private boolean bIsSRPObjectSet = false; - private boolean bIsLSPObjectSet = false; - private boolean bIsPcepMsgPathSet = false; - - //PCEP SRP Object - private PcepSrpObject srpObject; - //PCEP LSP Object - private PcepLspObject lspObject; - //PCEP Attribute list - private PcepMsgPath msgPath; - - @Override - public PcepUpdateRequest build() throws PcepParseException { - - //PCEP SRP Object - PcepSrpObject srpObject = null; - //PCEP LSP Object - PcepLspObject lspObject = null; - //PCEP Attribute list - PcepMsgPath msgPath = null; - - if (!this.bIsSRPObjectSet) { - throw new PcepParseException(" SRP Object NOT Set while building PcepUpdateRequest."); - } else { - srpObject = this.srpObject; - } - if (!this.bIsLSPObjectSet) { - throw new PcepParseException(" LSP Object NOT Set while building PcepUpdateRequest."); - } else { - lspObject = this.lspObject; - } - if (!this.bIsPcepMsgPathSet) { - throw new PcepParseException(" Msg Path NOT Set while building PcepUpdateRequest."); - } else { - msgPath = this.msgPath; - } - - return new PcepUpdateRequestVer1(srpObject, lspObject, msgPath); - } - - @Override - public PcepSrpObject getSrpObject() { - return this.srpObject; - } - - @Override - public PcepLspObject getLspObject() { - return this.lspObject; - } - - @Override - public PcepMsgPath getMsgPath() { - return this.msgPath; - } - - @Override - public Builder setSrpObject(PcepSrpObject srpobj) { - this.srpObject = srpobj; - this.bIsSRPObjectSet = true; - return this; - - } - - @Override - public Builder setLspObject(PcepLspObject lspObject) { - this.lspObject = lspObject; - this.bIsLSPObjectSet = true; - return this; - } - - @Override - public Builder setMsgPath(PcepMsgPath msgPath) { - this.msgPath = msgPath; - this.bIsPcepMsgPathSet = true; - return this; - } - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("SrpObject", srpObject) - .add("LspObject", lspObject) - .add("MsgPath", msgPath) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/package-info.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/package-info.java deleted file mode 100644 index 32d49ec9..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/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. - */ - -/** - * Implementation of PCEP messages. - */ -package org.onosproject.pcepio.protocol.ver1; diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/AdministrativeGroupTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/AdministrativeGroupTlv.java deleted file mode 100644 index 62ed4e7f..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/AdministrativeGroupTlv.java +++ /dev/null @@ -1,136 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides Administrative Group Tlv which contains value (32 Bit ). - */ -public class AdministrativeGroupTlv implements PcepValueType { - - /* REFERENCE :[RFC5305]/3.1 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TDB33] | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | value (32 Bit ) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(AdministrativeGroupTlv.class); - - public static final short TYPE = 3; //TDB33 - public static final short LENGTH = 4; - - private final int rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue of Administrative-Group-Tlv. - */ - public AdministrativeGroupTlv(int rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns newly created AdministrativeGroupTlv object. - * - * @param raw value. - * @return object of Administrative-Group-Tlv - */ - public static AdministrativeGroupTlv of(final int raw) { - return new AdministrativeGroupTlv(raw); - } - - /** - * Returns raw value. - * - * @return rawValue raw value - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof AdministrativeGroupTlv) { - AdministrativeGroupTlv other = (AdministrativeGroupTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of Administrative-Group-Tlv. - * - * @param c input channel buffer - * @return object of Administrative-Group-Tlv - */ - public static AdministrativeGroupTlv read(ChannelBuffer c) { - return AdministrativeGroupTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/AutonomousSystemTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/AutonomousSystemTlv.java deleted file mode 100644 index 3f213191..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/AutonomousSystemTlv.java +++ /dev/null @@ -1,136 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides Autonomous-System-Tlv which contains opaque value (32 Bit AS Number). - */ -public class AutonomousSystemTlv implements PcepValueType { - - /* Reference :RFC3209 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD10] | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | opaque value (32 Bit AS Number) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(AutonomousSystemTlv.class); - - public static final short TYPE = 100; //TODD:change this TBD10 - public static final short LENGTH = 4; - - private final int rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue Autonomous-System-Tlv - */ - public AutonomousSystemTlv(int rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns newly created AutonomousSystemTlv object. - * - * @param raw value of opaque. - * @return object of Autonomous-System-Tlv - */ - public static AutonomousSystemTlv of(final int raw) { - return new AutonomousSystemTlv(raw); - } - - /** - * Returns opaque value. - * - * @return rawValue opaque value. - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof AutonomousSystemTlv) { - AutonomousSystemTlv other = (AutonomousSystemTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of AutonomousSystemTlv. - * - * @param c input channel buffer - * @return object of Autonomous-System-Tlv - */ - public static AutonomousSystemTlv read(ChannelBuffer c) { - return AutonomousSystemTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("TYPE", TYPE) - .add("Length", LENGTH) - .add("value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/BGPLSidentifierTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/BGPLSidentifierTlv.java deleted file mode 100644 index 4981649f..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/BGPLSidentifierTlv.java +++ /dev/null @@ -1,136 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides BGP LS identifier which contains opaque value (32 Bit ID). - */ -public class BGPLSidentifierTlv implements PcepValueType { - - /* Reference :draft-ietf-idr-ls-distribution-10 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD11] | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | opaque value (32 Bit ID). | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(BGPLSidentifierTlv.class); - - public static final short TYPE = 17; //TODD:change this TBD11 - public static final short LENGTH = 4; - - private final int rawValue; - - /** - * constructor to initialize rawValue. - * - * @param rawValue BGP LS identifier Tlv - */ - public BGPLSidentifierTlv(int rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns newly created BGPLSidentifierTlv object. - * - * @param raw value - * @return object of BGPLSidentifierTlv - */ - public static BGPLSidentifierTlv of(final int raw) { - return new BGPLSidentifierTlv(raw); - } - - /** - * Returns opaque value. - * - * @return rawValue opaque value - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof BGPLSidentifierTlv) { - BGPLSidentifierTlv other = (BGPLSidentifierTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of BGPLSidentifierTlv. - * - * @param c input channel buffer - * @return object of BGP LS identifier Tlv - */ - public static BGPLSidentifierTlv read(ChannelBuffer c) { - return BGPLSidentifierTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/ErrorObjListWithOpen.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/ErrorObjListWithOpen.java deleted file mode 100644 index 40f89f4c..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/ErrorObjListWithOpen.java +++ /dev/null @@ -1,160 +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.pcepio.types; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepErrorObject; -import org.onosproject.pcepio.protocol.PcepOpenObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provide the error object list with open object. - */ -public class ErrorObjListWithOpen { - //errorObjList is mandatory - private LinkedList<PcepErrorObject> llerrorObjList; - // openObject is optional - private PcepOpenObject openObject; - // flag to check if open object is set or not - private boolean isOpenObjectSet; - protected static final Logger log = LoggerFactory.getLogger(ErrorObjListWithOpen.class); - - /** - * Constructor to initialize Error and OPEN object. - * - * @param errObj ERROR object list - * @param openObj OPEN object - */ - public ErrorObjListWithOpen(LinkedList<PcepErrorObject> errObj, PcepOpenObject openObj) { - this.llerrorObjList = errObj; - this.openObject = openObj; - if (openObj != null) { - isOpenObjectSet = true; - } else { - isOpenObjectSet = false; - } - } - - /** - * Constructor to initialize ERROR Object. - * - * @param errObj ERROR Object list - */ - public ErrorObjListWithOpen(LinkedList<PcepErrorObject> errObj) { - this.llerrorObjList = errObj; - this.openObject = null; - isOpenObjectSet = false; - } - - /** - * Return list of Error Types. - * - * @return error types list - */ - public LinkedList<Integer> getErrorType() { - LinkedList<Integer> errorType = new LinkedList<>(); - if (llerrorObjList != null) { - ListIterator<PcepErrorObject> errObjListIterator = llerrorObjList.listIterator(); - int error; - PcepErrorObject errorObj; - while (errObjListIterator.hasNext()) { - errorObj = errObjListIterator.next(); - error = errorObj.getErrorType(); - errorType.add(error); - } - } - return errorType; - } - - /** - * Return list of Error Values. - * - * @return error values list - */ - public LinkedList<Integer> getErrorValue() { - LinkedList<Integer> errorValue = new LinkedList<>(); - if (llerrorObjList != null) { - ListIterator<PcepErrorObject> errObjListIterator = llerrorObjList.listIterator(); - int error; - PcepErrorObject errorObj; - while (errObjListIterator.hasNext()) { - errorObj = errObjListIterator.next(); - error = errorObj.getErrorValue(); - errorValue.add(error); - } - } - return errorValue; - } - - /** - * Checks whether ERROR Object list is empty or not. - * - * @return true if ERROR Object list is empty otherwise false - */ - public boolean isErrorObjListWithOpenPresent() { - // ( <error-obj-list> [<Open>] - // At least in this case <error-obj-list> should be present. - return !this.llerrorObjList.isEmpty(); - } - - /** - * Write Error Object List and Open Object to channel buffer. - * - * @param cb output channel buffer - * @return length of written Error object list with open - * @throws PcepParseException when mandatory fields are not set - */ - public int write(ChannelBuffer cb) throws PcepParseException { - int iLenStartIndex = cb.writerIndex(); - boolean bIsErrObjListFound = false; - - //<error-obj-list> is mandatory , if not present throw exception. - if (llerrorObjList != null) { - ListIterator<PcepErrorObject> errObjListIterator = llerrorObjList.listIterator(); - while (errObjListIterator.hasNext()) { - errObjListIterator.next().write(cb); - bIsErrObjListFound = true; - } - } - - if (!bIsErrObjListFound) { - throw new PcepParseException("<error-obj-list> is mandatory."); - } - - //Open Object is optional , if present write. - if (openObject != null) { - openObject.write(cb); - } - - return cb.writerIndex() - iLenStartIndex; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .omitNullValues() - .add("ErrorObjList", llerrorObjList) - .add("Open", openObject) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/GmplsCapabilityTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/GmplsCapabilityTlv.java deleted file mode 100644 index 212aa3d3..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/GmplsCapabilityTlv.java +++ /dev/null @@ -1,138 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides GMPLS Capability Tlv. - */ -public class GmplsCapabilityTlv implements PcepValueType { - - /* - * GMPLS-CAPABILITY TLV format - * reference :draft-ietf-pce-gmpls-pcep-extensions -2.1.1 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=14 | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Flags | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - protected static final Logger log = LoggerFactory.getLogger(GmplsCapabilityTlv.class); - - public static final short TYPE = 14; - public static final short LENGTH = 4; - - private final int rawValue; - - /** - * Constructor to initialize raw value. - * - * @param rawValue of Gmpls-Capability-Tlv - */ - public GmplsCapabilityTlv(int rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns newly created GmplsCapabilityTlv object. - * - * @param raw Flags value - * @return object of Gmpls-Capability-Tlv - */ - public static GmplsCapabilityTlv of(final int raw) { - return new GmplsCapabilityTlv(raw); - } - - /** - * Returns value of Flags. - * - * @return rawValue Flags - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof GmplsCapabilityTlv) { - GmplsCapabilityTlv other = (GmplsCapabilityTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of Gmpls-Capability-Tlv. - * - * @param c input channel buffer - * @return object of Gmpls-Capability-Tlv - */ - public static GmplsCapabilityTlv read(ChannelBuffer c) { - return GmplsCapabilityTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IGPMetricTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IGPMetricTlv.java deleted file mode 100644 index ab3f1247..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IGPMetricTlv.java +++ /dev/null @@ -1,150 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides IGP Link Metric . - */ -public class IGPMetricTlv implements PcepValueType { - - /* Reference :[I-D.ietf-idr-ls-distribution] /3.3.2.4 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=TDB40 | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // IGP Link Metric (variable length) // - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(IGPMetricTlv.class); - - public static final short TYPE = 1095; //TODO:NEED TO HANDLE TDB40 - private short hLength; - - private final byte[] rawValue; - - /** - * Constructor to initialize raw value. - * - * @param rawValue IGP Link Metric - * @param hLength length - */ - public IGPMetricTlv(byte[] rawValue, short hLength) { - this.rawValue = rawValue; - this.hLength = hLength; - } - - /** - * Returns newly created IGPMetricTlv object. - * - * @param raw value of IGP Link Metric - * @param hLength length - * @return object of IGPMetricTlv - */ - public static IGPMetricTlv of(final byte[] raw, short hLength) { - return new IGPMetricTlv(raw, hLength); - } - - /** - * Returns value of IGP Link Metric. - * - * @return rawValue of IGP Link Metric - */ - public byte[] getValue() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof IGPMetricTlv) { - IGPMetricTlv other = (IGPMetricTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(hLength); - c.writeBytes(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of IGPMetricTlv. - * - * @param c input channel buffer - * @param hLength length - * @return object of IGPMetricTlv - */ - public static PcepValueType read(ChannelBuffer c, short hLength) { - byte[] iIGPMetric = new byte[hLength]; - c.readBytes(iIGPMetric, 0, hLength); - return new IGPMetricTlv(iIGPMetric, hLength); - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", hLength); - - StringBuffer result = new StringBuffer(); - for (byte b : rawValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("Value", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4InterfaceAddressTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4InterfaceAddressTlv.java deleted file mode 100644 index d1a30157..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4InterfaceAddressTlv.java +++ /dev/null @@ -1,137 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides IPv4 Interface Address . - */ -public class IPv4InterfaceAddressTlv implements PcepValueType { - - /* - * reference :[RFC5305]/3.2 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=6 | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 Interface Address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(IPv4InterfaceAddressTlv.class); - - public static final short TYPE = 6; - public static final short LENGTH = 4; - - private final int rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue of IPv4-Interface-Address. - */ - public IPv4InterfaceAddressTlv(int rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns newly created IPv4InterfaceAddressTlv object. - * - * @param raw value of IPv4-Interface-Address - * @return object of IPv4-Interface-Address-Tlv - */ - public static IPv4InterfaceAddressTlv of(final int raw) { - return new IPv4InterfaceAddressTlv(raw); - } - - /** - * Returns value of IPv4 Interface Address. - * - * @return rawValue IPv4 Interface Address - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof IPv4InterfaceAddressTlv) { - IPv4InterfaceAddressTlv other = (IPv4InterfaceAddressTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of IPv4InterfaceAddressTlv. - * - * @param c input channel buffer - * @return object of IPv4-Interface-Address-Tlv - */ - public static IPv4InterfaceAddressTlv read(ChannelBuffer c) { - return IPv4InterfaceAddressTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4NeighborAddressTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4NeighborAddressTlv.java deleted file mode 100644 index 0f98777f..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4NeighborAddressTlv.java +++ /dev/null @@ -1,137 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides IPv4 Neighbor Address . - */ -public class IPv4NeighborAddressTlv implements PcepValueType { - - /* Reference :[RFC5305]/3.3 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=8 | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 Neighbor Address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(IPv4NeighborAddressTlv.class); - - public static final short TYPE = 8; - public static final short LENGTH = 4; - - private final int rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue IPv4-Neighbor-Address-Tlv - */ - public IPv4NeighborAddressTlv(int rawValue) { - log.debug("IPv4NeighborAddressTlv"); - this.rawValue = rawValue; - } - - /** - * Returns newly created IPv4NeighborAddressTlv object. - * - * @param raw value of IPv4-Neighbor-Address - * @return object of IPv4NeighborAddressTlv - */ - public static IPv4NeighborAddressTlv of(final int raw) { - return new IPv4NeighborAddressTlv(raw); - } - - /** - * Returns value of IPv4 Neighbor Address. - * - * @return rawValue IPv4 Neighbor Address - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof IPv4NeighborAddressTlv) { - IPv4NeighborAddressTlv other = (IPv4NeighborAddressTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of IPv4-Neighbor-Address-Tlv. - * - * @param c input channel buffer - * @return object of IPv4-Neighbor-Address-Tlv - */ - public static IPv4NeighborAddressTlv read(ChannelBuffer c) { - return IPv4NeighborAddressTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4SubObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4SubObject.java deleted file mode 100644 index 031b5db6..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4SubObject.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. - */ - -/** - * @author b00295750 - * - */ -package org.onosproject.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides IPv4 Sub Object. - */ -public class IPv4SubObject implements PcepValueType { - - /*Reference : RFC 4874:3.1.1 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L| Type | Length | IPv4 address (4 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 address (continued) | Prefix Length | Resvd | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - protected static final Logger log = LoggerFactory.getLogger(IPv4SubObject.class); - - public static final byte TYPE = 0x01; - public static final byte LENGTH = 8; - public static final byte VALUE_LENGTH = 6; - public static final byte OBJ_LENGTH = 8; - public static final byte LBIT = 0; - public static final int SHIFT_LBIT_POSITION = 7; - private int ipAddress; - private byte prefixLen; - private byte resvd; - - /** - * Constructor to initialize ipv4 address. - * - * @param ipAddr ipv4 address - */ - public IPv4SubObject(int ipAddr) { - this.ipAddress = ipAddr; - } - - /** - * constructor to initialize ipAddress, prefixLen and resvd. - * - * @param ipAddress ipv4 address - * @param prefixLen prefix length - * @param resvd reserved flags value - */ - public IPv4SubObject(int ipAddress, byte prefixLen, byte resvd) { - this.ipAddress = ipAddress; - this.prefixLen = prefixLen; - this.resvd = resvd; - } - - /** - * Returns a new instance of IPv4SubObject. - * - * @param ipAddress ipv4 address - * @param prefixLen prefix length - * @param resvd reserved flags value - * @return object of IPv4SubObject - */ - public static IPv4SubObject of(int ipAddress, byte prefixLen, byte resvd) { - return new IPv4SubObject(ipAddress, prefixLen, resvd); - } - - /** - * Returns prefixLen of IPv4 IP address. - * - * @return byte value of rawValue - */ - public byte getPrefixLen() { - return prefixLen; - } - - /** - * Returns value of IPv4 IP address. - * - * @return int value of ipv4 address - */ - public int getIpAddress() { - return ipAddress; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(ipAddress, prefixLen, resvd); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof IPv4SubObject) { - IPv4SubObject other = (IPv4SubObject) obj; - return Objects.equals(this.ipAddress, other.ipAddress) && Objects.equals(this.prefixLen, other.prefixLen) - && Objects.equals(this.resvd, other.resvd); - } - return false; - } - - /** - * Reads the channel buffer and returns object of IPv4SubObject. - * - * @param c type of channel buffer - * @return object of IPv4SubObject - */ - public static PcepValueType read(ChannelBuffer c) { - int ipAddess = c.readInt(); - byte prefixLen = c.readByte(); - byte resvd = c.readByte(); - return new IPv4SubObject(ipAddess, prefixLen, resvd); - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - byte bValue = LBIT; - bValue = (byte) (bValue << SHIFT_LBIT_POSITION); - bValue = (byte) (bValue | TYPE); - c.writeByte(bValue); - c.writeByte(OBJ_LENGTH); - c.writeInt(ipAddress); - c.writeByte(prefixLen); - c.writeByte(resvd); - - return c.writerIndex() - iLenStartIndex; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("IPv4Address", ipAddress) - .add("PrefixLength", prefixLen) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4TERouterIdOfLocalNodeTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4TERouterIdOfLocalNodeTlv.java deleted file mode 100644 index 2abf4cdc..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4TERouterIdOfLocalNodeTlv.java +++ /dev/null @@ -1,136 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides IPv4 TE Router Id Of Local Node. - */ -public class IPv4TERouterIdOfLocalNodeTlv implements PcepValueType { - - /* Reference:[RFC5305]/4.3 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TDB25] | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 TE Router Id Of Local Node | - +-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+- - */ - - protected static final Logger log = LoggerFactory.getLogger(IPv4TERouterIdOfLocalNodeTlv.class); - - public static final short TYPE = 134; //TDB25 - public static final short LENGTH = 4; - - private final int rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue IPv4-TE-RouterId-Of-Local-Node-Tlv - */ - public IPv4TERouterIdOfLocalNodeTlv(int rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns newly created IPv4TERouterIdOfLocalNodeTlv object. - * - * @param raw value of IPv4-TE-RouterId-Of-Local-Node - * @return object of IPv4TERouterIdOfLocalNodeTlv - */ - public static IPv4TERouterIdOfLocalNodeTlv of(final int raw) { - return new IPv4TERouterIdOfLocalNodeTlv(raw); - } - - /** - * Returns value of IPv4 TE Router Id Of Local Node. - * - * @return rawValue IPv4 TE Router Id Of Local Node - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof IPv4TERouterIdOfLocalNodeTlv) { - IPv4TERouterIdOfLocalNodeTlv other = (IPv4TERouterIdOfLocalNodeTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of IPv4TERouterIdOfLocalNodeTlv. - * - * @param c input channel buffer - * @return object of IPv4TERouterIdOfLocalNodeTlv - */ - public static IPv4TERouterIdOfLocalNodeTlv read(ChannelBuffer c) { - return IPv4TERouterIdOfLocalNodeTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4TERouterIdOfRemoteNodeTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4TERouterIdOfRemoteNodeTlv.java deleted file mode 100644 index 21e09890..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv4TERouterIdOfRemoteNodeTlv.java +++ /dev/null @@ -1,137 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides IPv4 TE Router Id Of Remote Node. - */ -public class IPv4TERouterIdOfRemoteNodeTlv implements PcepValueType { - - /* Reference :[RFC5305]/4.3 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TDB28] | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 TE Router Id Of Remote Node | - +-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+- - */ - - protected static final Logger log = LoggerFactory.getLogger(IPv4TERouterIdOfRemoteNodeTlv.class); - - public static final short TYPE = 1340; //TDB28 - public static final short LENGTH = 4; - - private final int rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue IPv4 TE RouterId Of Remote Node Tlv - */ - public IPv4TERouterIdOfRemoteNodeTlv(int rawValue) { - log.debug("IPv4TERouterIdOfRemoteNodeTlv"); - this.rawValue = rawValue; - } - - /** - * Returns newly created IPv4TERouterIdOfRemoteNodeTlv object. - * - * @param raw IPv4 TE RouterId Of Remote Node - * @return object of IPv4TERouterIdOfRemoteNodeTlv - */ - public static IPv4TERouterIdOfRemoteNodeTlv of(final int raw) { - return new IPv4TERouterIdOfRemoteNodeTlv(raw); - } - - /** - * Returns value of IPv4 TE Router Id Of Remote Node. - * - * @return rawValue IPv4 TE Router Id Of Remote Node - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof IPv4TERouterIdOfRemoteNodeTlv) { - IPv4TERouterIdOfRemoteNodeTlv other = (IPv4TERouterIdOfRemoteNodeTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of IPv4TERouterIdOfRemoteNodeTlv. - * - * @param c input channel buffer - * @return object of IPv4TERouterIdOfRemoteNodeTlv - */ - public static IPv4TERouterIdOfRemoteNodeTlv read(ChannelBuffer c) { - return IPv4TERouterIdOfRemoteNodeTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6InterfaceAddressTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6InterfaceAddressTlv.java deleted file mode 100644 index 2ebab1ad..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6InterfaceAddressTlv.java +++ /dev/null @@ -1,181 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides IPv6 Interface Address. REFERENCE :[RFC6119]/4.2. - */ -public class IPv6InterfaceAddressTlv implements PcepValueType { - - protected static final Logger log = LoggerFactory.getLogger(IPv6InterfaceAddressTlv.class); - - public static final short TYPE = 12; //TDB18 - public static final short LENGTH = 20; - public static final byte VALUE_LENGTH = 18; - - private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - public static final IPv6InterfaceAddressTlv NONE = new IPv6InterfaceAddressTlv(NONE_VAL); - - private static final byte[] NO_MASK_VAL = {(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, (byte) 0xFF, (byte) 0xFF}; - public static final IPv6InterfaceAddressTlv NO_MASK = new IPv6InterfaceAddressTlv(NO_MASK_VAL); - public static final IPv6InterfaceAddressTlv FULL_MASK = NONE; - - private final byte[] rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue IPv6 Interface Address Tlv - */ - public IPv6InterfaceAddressTlv(byte[] rawValue) { - log.debug("IPv6InterfaceAddressTlv"); - this.rawValue = rawValue; - } - - /** - * Returns newly created IPv6InterfaceAddressTlv object. - * - * @param raw IPv6 Interface Address - * @return object of IPv6InterfaceAddressTlv - */ - public static IPv6InterfaceAddressTlv of(final byte[] raw) { - //check NONE_VAL - boolean bFoundNONE = true; - //value starts from 3rd byte. - for (int i = 2; i < 20; ++i) { - if (NONE_VAL[i] != raw[i]) { - bFoundNONE = false; - } - } - - if (bFoundNONE) { - return NONE; - } - - //check NO_MASK_VAL - boolean bFoundNoMask = true; - //value starts from 3rd byte. - for (int i = 2; i < 20; ++i) { - if (0xFF != raw[i]) { - bFoundNoMask = false; - } - } - if (bFoundNoMask) { - return NO_MASK; - } - - return new IPv6InterfaceAddressTlv(raw); - } - - /** - * Returns value of IPv6 Interface Address. - * - * @return rawValue raw value - */ - public byte[] getBytes() { - return rawValue; - } - - /** - * Returns value of IPv6 Interface Address. - * - * @return rawValue raw value - */ - public byte[] getValue() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof IPv6InterfaceAddressTlv) { - IPv6InterfaceAddressTlv other = (IPv6InterfaceAddressTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeBytes(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of IPv6InterfaceAddressTlv. - * - * @param c input channel buffer - * @return object of IPv6InterfaceAddressTlv - */ - public static IPv6InterfaceAddressTlv read20Bytes(ChannelBuffer c) { - byte[] yTemp = new byte[20]; - c.readBytes(yTemp, 0, 20); - return IPv6InterfaceAddressTlv.of(yTemp); - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", LENGTH); - - StringBuffer result = new StringBuffer(); - for (byte b : rawValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("Value", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6NeighborAddressTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6NeighborAddressTlv.java deleted file mode 100644 index 8b3390b6..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6NeighborAddressTlv.java +++ /dev/null @@ -1,179 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides IPv6 Neighbor Address. Reference :[RFC6119]/4.3. - */ -public class IPv6NeighborAddressTlv implements PcepValueType { - protected static final Logger log = LoggerFactory.getLogger(IPv6NeighborAddressTlv.class); - - public static final short TYPE = 13; // TDB19 - public static final short LENGTH = 20; - public static final byte VALUE_LENGTH = 18; - - private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - public static final IPv6NeighborAddressTlv NONE = new IPv6NeighborAddressTlv(NONE_VAL); - - private static final byte[] NO_MASK_VAL = {(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, (byte) 0xFF, (byte) 0xFF}; - public static final IPv6NeighborAddressTlv NO_MASK = new IPv6NeighborAddressTlv(NO_MASK_VAL); - public static final IPv6NeighborAddressTlv FULL_MASK = NONE; - - private final byte[] rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue IPv6 Neighbor Address Tlv - */ - public IPv6NeighborAddressTlv(byte[] rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns newly created IPv6NeighborAddressTlv object. - * - * @param raw IPv6 Neighbor Address - * @return object of IPv6 Neighbor Address Tlv - */ - public static IPv6NeighborAddressTlv of(final byte[] raw) { - //check NONE_VAL - boolean bFoundNONE = true; - //value starts from 3rd byte. - for (int i = 2; i < 20; ++i) { - if (NONE_VAL[i] != raw[i]) { - bFoundNONE = false; - } - } - - if (bFoundNONE) { - return NONE; - } - - //check NO_MASK_VAL - boolean bFoundNoMask = true; - //value starts from 3rd byte. - for (int i = 2; i < 20; ++i) { - if (0xFF != raw[i]) { - bFoundNoMask = false; - } - } - if (bFoundNoMask) { - return NO_MASK; - } - - return new IPv6NeighborAddressTlv(raw); - } - - /** - * Returns value of IPv6 Neighbor Address. - * - * @return rawValue raw value - */ - public byte[] getBytes() { - return rawValue; - } - - /** - * Returns value of IPv6 Neighbor Address. - * - * @return rawValue raw value - */ - public byte[] getValue() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof IPv6NeighborAddressTlv) { - IPv6NeighborAddressTlv other = (IPv6NeighborAddressTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeBytes(rawValue); - return c.writerIndex() - iStartIndex; - } - - /** - * Reads the channel buffer and returns object of IPv6NeighborAddressTlv. - * - * @param c input channel buffer - * @return object of IPv6NeighborAddressTlv - */ - public static IPv6NeighborAddressTlv read20Bytes(ChannelBuffer c) { - byte[] yTemp = new byte[20]; - c.readBytes(yTemp, 0, 20); - return IPv6NeighborAddressTlv.of(yTemp); - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", LENGTH); - - StringBuffer result = new StringBuffer(); - for (byte b : rawValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("Value", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6SubObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6SubObject.java deleted file mode 100644 index 8e1719e0..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6SubObject.java +++ /dev/null @@ -1,222 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides IPv6 Sub Object. - */ -public class IPv6SubObject implements PcepValueType { - - /* reference :RFC 4874. - Subobject : IPv6 address - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type | Length | IPv6 address (16 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv6 address (continued) | Prefix Length | Flags | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Type - - 0x02 IPv6 address - - Length - - The Length contains the total length of the subobject in bytes, - including the Type and Length fields. The Length is always 20. - - IPv6 address - - A 128-bit unicast host address. - - Prefix length - - 128 - - Flags - - 0x01 Local protection available - - Indicates that the link downstream of this node is - protected via a local repair mechanism. This flag can - only be set if the Local protection flag was set in the - SESSION_ATTRIBUTE object of the corresponding Path - message. - - 0x02 Local protection in use - - Indicates that a local repair mechanism is in use to - maintain this tunnel (usually in the face of an outage - of the link it was previously routed over). - */ - protected static final Logger log = LoggerFactory.getLogger(IPv6SubObject.class); - - public static final short TYPE = 0x02; - public static final short LENGTH = 20; - public static final byte VALUE_LENGTH = 18; - - private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - public static final IPv6SubObject NONE = new IPv6SubObject(NONE_VAL); - - private static final byte[] NO_MASK_VAL = {(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, (byte) 0xFF, (byte) 0xFF }; - public static final IPv6SubObject NO_MASK = new IPv6SubObject(NO_MASK_VAL); - public static final IPv6SubObject FULL_MASK = NONE; - - private final byte[] rawValue; - - /** - * constructor to initialize rawValue with ipv6 address. - * - * @param rawValue ipv6 address - */ - public IPv6SubObject(byte[] rawValue) { - this.rawValue = rawValue; - } - - /** - * To create instance of IPv6SubObject. - * - * @param raw byte array of ipv6 address - * @return object of IPv6SubObject - */ - public static IPv6SubObject of(final byte[] raw) { - //check NONE_VAL - boolean bFoundNONE = true; - //value starts from 3rd byte. - for (int i = 2; i < 20; ++i) { - if (NONE_VAL[i] != raw[i]) { - bFoundNONE = false; - } - } - - if (bFoundNONE) { - return NONE; - } - - //check NO_MASK_VAL - boolean bFoundNoMask = true; - //value starts from 3rd byte. - for (int i = 2; i < 20; ++i) { - if (0xFF != raw[i]) { - bFoundNoMask = false; - } - } - if (bFoundNoMask) { - return NO_MASK; - } - - return new IPv6SubObject(raw); - } - - /** - * Returns value of IPv6 Sub Object. - * - * @return byte array of ipv6 address - */ - public byte[] getValue() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof IPv6SubObject) { - IPv6SubObject other = (IPv6SubObject) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeBytes(rawValue); - return c.writerIndex() - iStartIndex; - } - - /** - * Reads the channel buffer and returns object of IPv6SubObject. - * - * @param c type of channel buffer - * @return object of IPv6SubObject - */ - public static IPv6SubObject read20Bytes(ChannelBuffer c) { - byte[] yTemp = new byte[20]; - c.readBytes(yTemp, 0, 20); - return IPv6SubObject.of(yTemp); - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", LENGTH); - - StringBuffer result = new StringBuffer(); - for (byte b : rawValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("Value", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6TERouterIdofLocalNodeTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6TERouterIdofLocalNodeTlv.java deleted file mode 100644 index bc8eca65..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6TERouterIdofLocalNodeTlv.java +++ /dev/null @@ -1,179 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides IPv6 TE Router Id of Local Node. Reference :[RFC6119]/4.1. - */ -public class IPv6TERouterIdofLocalNodeTlv implements PcepValueType { - protected static final Logger log = LoggerFactory.getLogger(IPv6TERouterIdofLocalNodeTlv.class); - - public static final short TYPE = 140; //TDB26 - public static final short LENGTH = 20; - public static final byte VALUE_LENGTH = 18; - - private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - public static final IPv6TERouterIdofLocalNodeTlv NONE = new IPv6TERouterIdofLocalNodeTlv(NONE_VAL); - - private static final byte[] NO_MASK_VAL = {(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, (byte) 0xFF, (byte) 0xFF }; - public static final IPv6TERouterIdofLocalNodeTlv NO_MASK = new IPv6TERouterIdofLocalNodeTlv(NO_MASK_VAL); - public static final IPv6TERouterIdofLocalNodeTlv FULL_MASK = NONE; - - private final byte[] rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue IPv6TERouterIdofLocalNodeTlv - */ - public IPv6TERouterIdofLocalNodeTlv(byte[] rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns newly created IPv6TERouterIdofLocalNodeTlv object. - * - * @param raw IPv6 TE Router Id of Local Node - * @return object of IPv6TERouterIdofLocalNodeTlv - */ - public static IPv6TERouterIdofLocalNodeTlv of(final byte[] raw) { - //check NONE_VAL - boolean bFoundNONE = true; - //value starts from 3rd byte. - for (int i = 2; i < 20; ++i) { - if (NONE_VAL[i] != raw[i]) { - bFoundNONE = false; - } - } - - if (bFoundNONE) { - return NONE; - } - - //check NO_MASK_VAL - boolean bFoundNoMask = true; - //value starts from 3rd byte. - for (int i = 2; i < 20; ++i) { - if (0xFF != raw[i]) { - bFoundNoMask = false; - } - } - if (bFoundNoMask) { - return NO_MASK; - } - - return new IPv6TERouterIdofLocalNodeTlv(raw); - } - - /** - * Returns value of IPv6 TE Router Id of Local Node. - * - * @return byte array value of rawValue - */ - public byte[] getBytes() { - return rawValue; - } - - /** - * Returns value of IPv6 TE Router Id of Local Node. - * - * @return byte array value of rawValue - */ - public byte[] getValue() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof IPv6TERouterIdofLocalNodeTlv) { - IPv6TERouterIdofLocalNodeTlv other = (IPv6TERouterIdofLocalNodeTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeBytes(rawValue); - return c.writerIndex() - iStartIndex; - } - - /** - * Reads the channel buffer and returns object of IPv6TERouterIdofLocalNodeTlv. - * - * @param c input channel buffer - * @return object of IPv6TERouterIdofLocalNodeTlv - */ - public static IPv6TERouterIdofLocalNodeTlv read20Bytes(ChannelBuffer c) { - byte[] yTemp = new byte[20]; - c.readBytes(yTemp, 0, 20); - return IPv6TERouterIdofLocalNodeTlv.of(yTemp); - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", LENGTH); - - StringBuffer result = new StringBuffer(); - for (byte b : rawValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("Value", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6TERouterIdofRemoteNodeTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6TERouterIdofRemoteNodeTlv.java deleted file mode 100644 index 1fc7124c..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/IPv6TERouterIdofRemoteNodeTlv.java +++ /dev/null @@ -1,171 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides IPv6 TE Router Id of Remote Node. Reference :[RFC6119]/4.1. - */ -public class IPv6TERouterIdofRemoteNodeTlv implements PcepValueType { - protected static final Logger log = LoggerFactory.getLogger(IPv6TERouterIdofRemoteNodeTlv.class); - - public static final short TYPE = 1400; //TDB29 - public static final short LENGTH = 20; - public static final byte VALUE_LENGTH = 18; - - private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - public static final IPv6TERouterIdofRemoteNodeTlv NONE = new IPv6TERouterIdofRemoteNodeTlv(NONE_VAL); - - private static final byte[] NO_MASK_VAL = {(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, (byte) 0xFF, (byte) 0xFF}; - public static final IPv6TERouterIdofRemoteNodeTlv NO_MASK = new IPv6TERouterIdofRemoteNodeTlv(NO_MASK_VAL); - public static final IPv6TERouterIdofRemoteNodeTlv FULL_MASK = NONE; - - private final byte[] rawValue; - - /** - * constructor to initialize rawValue. - * - * @param rawValue IPv6TERouterIdofRemoteNodeTlv - */ - public IPv6TERouterIdofRemoteNodeTlv(byte[] rawValue) { - log.debug("IPv6TERouterIdofRemoteNodeTlv"); - this.rawValue = rawValue; - } - - /** - * Returns newly created IPv6TERouterIdofRemoteNodeTlv object. - * - * @param raw IPv6 TE Router Id of RemoteNode - * @return object of IPv6TERouterIdofRemoteNodeTlv - */ - public static IPv6TERouterIdofRemoteNodeTlv of(final byte[] raw) { - //check NONE_VAL - boolean bFoundNONE = true; - //value starts from 3rd byte. - for (int i = 2; i < 20; ++i) { - if (NONE_VAL[i] != raw[i]) { - bFoundNONE = false; - } - } - - if (bFoundNONE) { - return NONE; - } - - //check NO_MASK_VAL - boolean bFoundNoMask = true; - //value starts from 3rd byte. - for (int i = 2; i < 20; ++i) { - if (0xFF != raw[i]) { - bFoundNoMask = false; - } - } - if (bFoundNoMask) { - return NO_MASK; - } - - return new IPv6TERouterIdofRemoteNodeTlv(raw); - } - - /** - * Returns value of IPv6 TE Router Id of Remote Node. - * - * @return byte array value of rawValue - */ - public byte[] getBytes() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof IPv6TERouterIdofRemoteNodeTlv) { - IPv6TERouterIdofRemoteNodeTlv other = (IPv6TERouterIdofRemoteNodeTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeBytes(rawValue); - return c.writerIndex() - iStartIndex; - } - - /** - * Reads the channel buffer and returns object of IPv6TERouterIdofRemoteNodeTlv. - * - * @param c input channel buffer - * @return object of IPv6TERouterIdofRemoteNodeTlv - */ - public static IPv6TERouterIdofRemoteNodeTlv read20Bytes(ChannelBuffer c) { - byte[] yTemp = new byte[20]; - c.readBytes(yTemp, 0, 20); - return IPv6TERouterIdofRemoteNodeTlv.of(yTemp); - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", LENGTH); - - StringBuffer result = new StringBuffer(); - for (byte b : rawValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("Value", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/ISISAreaIdentifierTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/ISISAreaIdentifierTlv.java deleted file mode 100644 index 648dbb66..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/ISISAreaIdentifierTlv.java +++ /dev/null @@ -1,155 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides ISIS Area Identifier. - */ -public class ISISAreaIdentifierTlv implements PcepValueType { - - /* Reference :[I-D.ietf-idr- ls-distribution]/3.3.1.2 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD24] | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // Area Identifier (variable) // - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(ISISAreaIdentifierTlv.class); - - public static final short TYPE = 107; //TODO:NEED TO HANDLE TBD24 - private short hLength; - - private final byte[] rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue ISIS-Area-Identifier - * @param hLength length - */ - public ISISAreaIdentifierTlv(byte[] rawValue, short hLength) { - log.debug("ISISAreaIdentifierTlv"); - this.rawValue = rawValue; - if (0 == hLength) { - this.hLength = (short) rawValue.length; - } else { - this.hLength = hLength; - } - } - - /** - * Returns newly created ISISAreaIdentifierTlv object. - * - * @param raw ISIS-Area-Identifier - * @param hLength length - * @return object of ISISAreaIdentifierTlv - */ - public static ISISAreaIdentifierTlv of(final byte[] raw, short hLength) { - return new ISISAreaIdentifierTlv(raw, hLength); - } - - /** - * Returns value of ISIS-Area-Identifier. - * - * @return byte array of rawValue - */ - public byte[] getValue() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof ISISAreaIdentifierTlv) { - ISISAreaIdentifierTlv other = (ISISAreaIdentifierTlv) obj; - return Objects.equals(hLength, other.hLength) && Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(hLength); - c.writeBytes(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of ISISAreaIdentifierTlv. - * - * @param c input channel buffer - * @param hLength length - * @return object of ISISAreaIdentifierTlv - */ - public static PcepValueType read(ChannelBuffer c, short hLength) { - byte[] iISISAreaIdentifier = new byte[hLength]; - c.readBytes(iISISAreaIdentifier, 0, hLength); - return new ISISAreaIdentifierTlv(iISISAreaIdentifier, hLength); - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", hLength); - - StringBuffer result = new StringBuffer(); - for (byte b : rawValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("Value", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LabelSubObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LabelSubObject.java deleted file mode 100644 index 5b1c2438..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LabelSubObject.java +++ /dev/null @@ -1,171 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * LabelSubObject: Provides a LabelSubObject. - */ -public class LabelSubObject implements PcepValueType { - - /* Reference : RFC 3209 - * LABEL Sub Object - * - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type | Length | Flags | C-Type | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Contents of Label Object | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - protected static final Logger log = LoggerFactory.getLogger(LabelSubObject.class); - - public static final short TYPE = 0x03; - public static final short LENGTH = 8; - private final byte flags; - private final byte cType; - private final int contents; - - /** - * constructor to initialize parameters for LabelSubObject. - * - * @param flags flags - * @param cType C-Type - * @param contents Contents of label object - */ - public LabelSubObject(byte flags, byte cType, int contents) { - this.flags = flags; - this.cType = cType; - this.contents = contents; - } - - /** - * Return an object of LabelSubObject. - * - * @param flags flags - * @param cType C-type - * @param contents contents of label objects - * @return object of LabelSubObject - */ - public static LabelSubObject of(byte flags, byte cType, int contents) { - return new LabelSubObject(flags, cType, contents); - } - - /** - * Returns Flags. - * - * @return flags - */ - public byte getFlags() { - return flags; - } - - /** - * Returns cType. - * - * @return cType - */ - public byte getCtype() { - return cType; - } - - /** - * Returns contents. - * - * @return contents - */ - public int getContents() { - return contents; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(flags, cType, contents); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof LabelSubObject) { - LabelSubObject other = (LabelSubObject) obj; - return Objects.equals(this.flags, other.flags) && Objects.equals(this.cType, other.cType) - && Objects.equals(this.contents, other.contents); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeByte(flags); - c.writeByte(cType); - c.writeByte(contents); - return c.writerIndex() - iStartIndex; - } - - /** - * Reads the channel buffer and returns object of LabelSubObject. - * - * @param c type of channel buffer - * @return object of LabelSubObject - */ - public static PcepValueType read(ChannelBuffer c) { - byte flags = c.readByte(); - byte cType = c.readByte(); - int contents = c.readInt(); - return new LabelSubObject(flags, cType, contents); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("type", TYPE) - .add("Length", LENGTH) - .add("flags", flags) - .add("C-type", cType) - .add("contents", contents) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LinkLocalRemoteIdentifiersTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LinkLocalRemoteIdentifiersTlv.java deleted file mode 100644 index 5fa0a4c6..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LinkLocalRemoteIdentifiersTlv.java +++ /dev/null @@ -1,155 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides Local and remote Link Identifiers. - */ -public class LinkLocalRemoteIdentifiersTlv implements PcepValueType { - - /* Reference :RFC5307 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=4 | Length=8 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Link Local Identifier | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Link Remote Identifier | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - protected static final Logger log = LoggerFactory.getLogger(LinkLocalRemoteIdentifiersTlv.class); - - public static final short TYPE = 4; - public static final short LENGTH = 8; - private final int iLinkLocalIdentifier; - private final int iLinkRemoteIdentifier; - - /** - * Constructor to initialize iLinkLocalIdentifier , iLinkRemoteIdentifier. - * - * @param iLinkLocalIdentifier Link Local identifier - * @param iLinkRemoteIdentifier Link Remote identifier - */ - public LinkLocalRemoteIdentifiersTlv(int iLinkLocalIdentifier, int iLinkRemoteIdentifier) { - this.iLinkLocalIdentifier = iLinkLocalIdentifier; - this.iLinkRemoteIdentifier = iLinkRemoteIdentifier; - } - - /** - * Retruns an object of Link Local Remote Identifiers Tlv. - * - * @param iLinkLocalIdentifier Link Local identifier - * @param iLinkRemoteIdentifier Link Remote identifier - * @return object of LinkLocalRemoteIdentifiersTlv - */ - public static LinkLocalRemoteIdentifiersTlv of(int iLinkLocalIdentifier, int iLinkRemoteIdentifier) { - return new LinkLocalRemoteIdentifiersTlv(iLinkLocalIdentifier, iLinkRemoteIdentifier); - } - - /** - * Returns Link-Local-Identifier. - * - * @return iLinkLocalIdentifier Link Local Identifier - */ - public int getLinkLocalIdentifier() { - return iLinkLocalIdentifier; - } - - /** - * Returns Link-Remote-Identifier. - * - * @return iLinkRemoteIdentifier Link Remote Identifier. - */ - public int getLinkRemoteIdentifier() { - return iLinkRemoteIdentifier; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public int hashCode() { - return Objects.hash(iLinkLocalIdentifier, iLinkRemoteIdentifier); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof LinkLocalRemoteIdentifiersTlv) { - LinkLocalRemoteIdentifiersTlv other = (LinkLocalRemoteIdentifiersTlv) obj; - return Objects.equals(iLinkLocalIdentifier, other.iLinkLocalIdentifier) - && Objects.equals(iLinkRemoteIdentifier, other.iLinkRemoteIdentifier); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(iLinkLocalIdentifier); - c.writeInt(iLinkRemoteIdentifier); - return c.writerIndex() - iStartIndex; - } - - /** - * Reads the channel buffer and returns object of LinkLocalRemoteIdentifiersTlv. - * - * @param c input channel buffer - * @return object of LinkLocalRemoteIdentifiersTlv - */ - public static PcepValueType read(ChannelBuffer c) { - int iLinkLocalIdentifier = c.readInt(); - int iLinkRemoteIdentifier = c.readInt(); - return new LinkLocalRemoteIdentifiersTlv(iLinkLocalIdentifier, iLinkRemoteIdentifier); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("LinkLocalIdentifier", iLinkLocalIdentifier) - .add("LinkRemoteIdentifier", iLinkRemoteIdentifier) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LinkNameTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LinkNameTlv.java deleted file mode 100644 index aa0f11a7..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LinkNameTlv.java +++ /dev/null @@ -1,155 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides the Link Name. - */ -public class LinkNameTlv implements PcepValueType { - - /* Reference :[I-D.ietf-idr- ls-distribution] /3.3.2.7 - * Link name tlv format. - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=TDB43 | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // Link Name (variable) // - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(LinkNameTlv.class); - - public static final short TYPE = 1098; //TODO:NEED TO HANDLE TDB43 - private short hLength; - - private final byte[] rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue Link-Name - * @param hLength length - */ - public LinkNameTlv(byte[] rawValue, short hLength) { - this.rawValue = rawValue; - if (0 == hLength) { - this.hLength = (short) rawValue.length; - } else { - this.hLength = hLength; - } - } - - /** - * Returns newly created LinkNameTlv object. - * - * @param raw Link-Name - * @param hLength length - * @return object of LinkNameTlv - */ - public static LinkNameTlv of(final byte[] raw, short hLength) { - return new LinkNameTlv(raw, hLength); - } - - /** - * Returns value of Link-Name. - * - * @return raw value - */ - public byte[] getValue() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof LinkNameTlv) { - LinkNameTlv other = (LinkNameTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(hLength); - c.writeBytes(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of LinkNameTlv. - * - * @param c input channel buffer - * @param hLength length - * @return object of LinkNameTlv - */ - public static PcepValueType read(ChannelBuffer c, short hLength) { - byte[] linkName = new byte[hLength]; - c.readBytes(linkName, 0, hLength); - return new LinkNameTlv(linkName, hLength); - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", hLength); - - StringBuffer result = new StringBuffer(); - for (byte b : rawValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("Value", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LinkProtectionTypeTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LinkProtectionTypeTlv.java deleted file mode 100644 index a802d577..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LinkProtectionTypeTlv.java +++ /dev/null @@ -1,142 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provide Link Protection Type. - */ - -public class LinkProtectionTypeTlv implements PcepValueType { - - /* Reference :[RFC5307]/1.2 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TDB38] | Length=2 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |Protection Cap | Reserved | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - protected static final Logger log = LoggerFactory.getLogger(LinkProtectionTypeTlv.class); - - public static final short TYPE = 20; //TDB38 - public static final short LENGTH = 2; - private final byte protectionCap; - private final byte reserved; - - /** - * Constructor to initialize protectionCap. - * - * @param protectionCap Protection Cap - */ - public LinkProtectionTypeTlv(byte protectionCap) { - this.protectionCap = protectionCap; - this.reserved = 0; - } - - /** - * Constructor to initialize protectionCap, reserved. - * - * @param protectionCap Protection Cap - * @param reserved Reserved value - */ - public LinkProtectionTypeTlv(byte protectionCap, byte reserved) { - this.protectionCap = protectionCap; - this.reserved = reserved; - } - - /** - * Returns Protection Cap. - * - * @return protectionCap Protection Cap - */ - public byte getProtectionCap() { - return protectionCap; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(protectionCap, reserved); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof LinkProtectionTypeTlv) { - LinkProtectionTypeTlv other = (LinkProtectionTypeTlv) obj; - return Objects.equals(protectionCap, other.protectionCap) && Objects.equals(reserved, other.reserved); - } - - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeByte(protectionCap); - c.writeByte(reserved); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of LinkProtectionTypeTlv. - * - * @param c input channel buffer - * @return object of LinkProtectionTypeTlv - */ - public static PcepValueType read(ChannelBuffer c) { - byte protectionCap = c.readByte(); - byte reserved = c.readByte(); - return new LinkProtectionTypeTlv(protectionCap, reserved); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("ProtectionCap", protectionCap) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LocalTENodeDescriptorsTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LocalTENodeDescriptorsTlv.java deleted file mode 100644 index b31dac2c..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/LocalTENodeDescriptorsTlv.java +++ /dev/null @@ -1,246 +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.pcepio.types; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.ListIterator; -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides Local TE Node Descriptors TLV which contains Node Descriptor Sub-TLVs. - */ -public class LocalTENodeDescriptorsTlv implements PcepValueType { - - /* REFERENCE :draft-ietf-idr-ls-distribution-10 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD8] | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Node Descriptor Sub-TLVs (variable) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - Note: Length is including header here. Refer Routing Universe TLV. - */ - - protected static final Logger log = LoggerFactory.getLogger(LocalTENodeDescriptorsTlv.class); - - public static final short TYPE = 1637; //TODD:change this TBD8 - public short hLength; - - public static final int TLV_HEADER_LENGTH = 4; - // Node Descriptor Sub-TLVs (variable) - private LinkedList<PcepValueType> llNodeDescriptorSubTLVs; - - /** - * Constructor to initialize llNodeDescriptorSubTLVs. - * - * @param llNodeDescriptorSubTLVs LinkedList of PcepValueType - */ - public LocalTENodeDescriptorsTlv(LinkedList<PcepValueType> llNodeDescriptorSubTLVs) { - this.llNodeDescriptorSubTLVs = llNodeDescriptorSubTLVs; - } - - /** - * Returns a new object of LocalTENodeDescriptorsTLV. - * - * @param llNodeDescriptorSubTLVs linked list of Node Descriptor Sub TLVs - * @return object of LocalTENodeDescriptorsTLV - */ - public static LocalTENodeDescriptorsTlv of(final LinkedList<PcepValueType> llNodeDescriptorSubTLVs) { - return new LocalTENodeDescriptorsTlv(llNodeDescriptorSubTLVs); - } - - /** - * Returns Linked List of tlvs. - * - * @return llNodeDescriptorSubTLVs linked list of Node Descriptor Sub TLV - */ - public LinkedList<PcepValueType> getllNodeDescriptorSubTLVs() { - return llNodeDescriptorSubTLVs; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(llNodeDescriptorSubTLVs.hashCode()); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - /* - * Here we have a list of Tlv so to compare each sub tlv between the object - * we have to take a list iterator so one by one we can get each sub tlv object - * and can compare them. - * it may be possible that the size of 2 lists is not equal so we have to first check - * the size, if both are same then we should check for the subtlv objects otherwise - * we should return false. - */ - if (obj instanceof LocalTENodeDescriptorsTlv) { - int countObjSubTlv = 0; - int countOtherSubTlv = 0; - boolean isCommonSubTlv = true; - LocalTENodeDescriptorsTlv other = (LocalTENodeDescriptorsTlv) obj; - Iterator<PcepValueType> objListIterator = ((LocalTENodeDescriptorsTlv) obj).llNodeDescriptorSubTLVs - .iterator(); - countObjSubTlv = ((LocalTENodeDescriptorsTlv) obj).llNodeDescriptorSubTLVs.size(); - countOtherSubTlv = other.llNodeDescriptorSubTLVs.size(); - if (countObjSubTlv != countOtherSubTlv) { - return false; - } else { - while (objListIterator.hasNext() && isCommonSubTlv) { - PcepValueType subTlv = objListIterator.next(); - isCommonSubTlv = Objects.equals(llNodeDescriptorSubTLVs.contains(subTlv), - other.llNodeDescriptorSubTLVs.contains(subTlv)); - } - return isCommonSubTlv; - } - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int tlvStartIndex = c.writerIndex(); - c.writeShort(TYPE); - int tlvLenIndex = c.writerIndex(); - hLength = 0; - c.writeShort(0); - - ListIterator<PcepValueType> listIterator = llNodeDescriptorSubTLVs.listIterator(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - if (tlv == null) { - log.debug("TLV is null from subTlv list"); - continue; - } - tlv.write(c); - - // need to take care of padding - int pad = tlv.getLength() % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - c.writeByte((byte) 0); - } - } - } - hLength = (short) (c.writerIndex() - tlvStartIndex); - c.setShort(tlvLenIndex, (hLength - TLV_HEADER_LENGTH)); - return c.writerIndex() - tlvStartIndex; - } - - /** - * Reads the channel buffer and returns object of AutonomousSystemTlv. - * - * @param c input channel buffer - * @param hLength length of subtlvs. - * @return object of AutonomousSystemTlv - * @throws PcepParseException if mandatory fields are missing - */ - public static PcepValueType read(ChannelBuffer c, short hLength) throws PcepParseException { - - // Node Descriptor Sub-TLVs (variable) - LinkedList<PcepValueType> llNodeDescriptorSubTLVs = new LinkedList<>(); - - ChannelBuffer tempCb = c.readBytes(hLength); - - while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) { - - PcepValueType tlv; - short hType = tempCb.readShort(); - int iValue = 0; - short length = tempCb.readShort(); - - switch (hType) { - - case AutonomousSystemTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new AutonomousSystemTlv(iValue); - break; - case BGPLSidentifierTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new BGPLSidentifierTlv(iValue); - break; - case OSPFareaIDsubTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new OSPFareaIDsubTlv(iValue); - break; - case RouterIDSubTlv.TYPE: - tlv = RouterIDSubTlv.read(tempCb, length); - break; - - default: - throw new PcepParseException("Unsupported Sub TLV type :" + hType); - } - - // Check for the padding - int pad = length % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= tempCb.readableBytes()) { - tempCb.skipBytes(pad); - } - } - - llNodeDescriptorSubTLVs.add(tlv); - } - - if (0 < tempCb.readableBytes()) { - throw new PcepParseException("Sub Tlv parsing error. Extra bytes received."); - } - return new LocalTENodeDescriptorsTlv(llNodeDescriptorSubTLVs); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", hLength) - .add("NodeDescriptorSubTLVs", llNodeDescriptorSubTLVs) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/MPLSProtocolMaskTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/MPLSProtocolMaskTlv.java deleted file mode 100644 index fc0f8771..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/MPLSProtocolMaskTlv.java +++ /dev/null @@ -1,200 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides MPLS Protocol Mask. - */ -public class MPLSProtocolMaskTlv implements PcepValueType { - - /* Reference :[I-D.ietf-idr-ls-distribution]/3.3.2.2 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=TDB39 | Length =1 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L|R| Reserved | - +-+-+-+-+-+-+-+-+ - */ - protected static final Logger log = LoggerFactory.getLogger(MPLSProtocolMaskTlv.class); - - public static final short TYPE = 1094; //TDB39 - public static final short LENGTH = 1; - public static final byte LFLAG_SET = (byte) 0x80; - public static final byte RFLAG_SET = 0x40; - - private final byte rawValue; - private final boolean bLFlag; - private final boolean bRFlag; - private final boolean isRawValueSet; - - /** - * constructor to initialize rawValue. - * - * @param rawValue MPLS Protocol Mask Flag Bits - */ - public MPLSProtocolMaskTlv(byte rawValue) { - this.rawValue = rawValue; - this.isRawValueSet = true; - this.bLFlag = (rawValue & LFLAG_SET) == LFLAG_SET; - this.bRFlag = (rawValue & RFLAG_SET) == RFLAG_SET; - } - - /** - * constructor to initialize different Flags. - * - * @param bLFlag L-flag - * @param bRFlag R-flag - */ - public MPLSProtocolMaskTlv(boolean bLFlag, boolean bRFlag) { - this.bLFlag = bLFlag; - this.bRFlag = bRFlag; - this.rawValue = 0; - isRawValueSet = false; - } - - /** - * Returns newly created MPLSProtocolMaskTlv object. - * - * @param raw MPLS Protocol Mask Tlv - * @return new object of MPLS Protocol Mask Tlv - */ - public static MPLSProtocolMaskTlv of(final byte raw) { - return new MPLSProtocolMaskTlv(raw); - } - - /** - * Returns L-flag. - * - * @return bLFlag L-flag - */ - public boolean getbLFlag() { - return bLFlag; - } - - /** - * Returns R-flag. - * - * @return bRFlag R-flag - */ - public boolean getbRFlag() { - return bRFlag; - } - - /** - * Returns raw value. - * - * @return rawValue raw value - */ - public byte getByte() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - if (isRawValueSet) { - return Objects.hash(rawValue); - } else { - return Objects.hash(bLFlag, bRFlag); - } - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof MPLSProtocolMaskTlv) { - MPLSProtocolMaskTlv other = (MPLSProtocolMaskTlv) obj; - if (isRawValueSet) { - return Objects.equals(this.rawValue, other.rawValue); - } else { - return Objects.equals(this.bLFlag, other.bLFlag) && Objects.equals(this.bRFlag, other.bRFlag); - } - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - if (isRawValueSet) { - c.writeByte(rawValue); - } else { - byte temp = 0; - if (bLFlag) { - temp = (byte) (temp | LFLAG_SET); - } - if (bRFlag) { - temp = (byte) (temp | RFLAG_SET); - } - c.writeByte(temp); - } - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of MPLS Protocol Mask Tlv. - * - * @param c input channel buffer - * @return object of MPLS Protocol Mask Tlv - */ - public static PcepValueType read(ChannelBuffer c) { - byte temp = c.readByte(); - boolean bLFlag; - boolean bRFlag; - - bLFlag = (temp & LFLAG_SET) == LFLAG_SET; - bRFlag = (temp & RFLAG_SET) == RFLAG_SET; - - return new MPLSProtocolMaskTlv(bLFlag, bRFlag); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/MaximumLinkBandwidthTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/MaximumLinkBandwidthTlv.java deleted file mode 100644 index db1acf09..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/MaximumLinkBandwidthTlv.java +++ /dev/null @@ -1,137 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provide the Maximum Link Bandwidth. - */ -public class MaximumLinkBandwidthTlv implements PcepValueType { - - /* Reference :[RFC5305]/3.3. - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TDB34] | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Maximum Link Bandwidth | - +-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+- - */ - - protected static final Logger log = LoggerFactory.getLogger(MaximumLinkBandwidthTlv.class); - - public static final short TYPE = 9; //TDB34 - public static final short LENGTH = 4; - - private final int rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue Maximum-Link-Bandwidth - */ - - public MaximumLinkBandwidthTlv(int rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns newly created MaximumLinkBandwidthTlv object. - * - * @param raw value of Maximum-Link-Bandwidth - * @return object of MaximumLinkBandwidthTlv - */ - public static MaximumLinkBandwidthTlv of(final int raw) { - return new MaximumLinkBandwidthTlv(raw); - } - - /** - * Returns value of Maximum Link Bandwidth. - * - * @return rawValue Maximum Link Bandwidth - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof MaximumLinkBandwidthTlv) { - MaximumLinkBandwidthTlv other = (MaximumLinkBandwidthTlv) obj; - return Objects.equals(rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of MaximumLinkBandwidthTlv. - * - * @param c input channel buffer - * @return object of MaximumLinkBandwidthTlv - */ - public static MaximumLinkBandwidthTlv read(ChannelBuffer c) { - return MaximumLinkBandwidthTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/MaximumReservableLinkBandwidthTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/MaximumReservableLinkBandwidthTlv.java deleted file mode 100644 index 01d08cae..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/MaximumReservableLinkBandwidthTlv.java +++ /dev/null @@ -1,136 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provide the Maximum Reservable Link Bandwidth. - */ -public class MaximumReservableLinkBandwidthTlv implements PcepValueType { - - /* Reference :[RFC5305]/3.5. - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TDB35] | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Maximum Reservable Link Bandwidth | - +-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-++-+-+-+- - */ - - protected static final Logger log = LoggerFactory.getLogger(MaximumReservableLinkBandwidthTlv.class); - - public static final short TYPE = 10; // TDB35 - public static final short LENGTH = 4; - - private final int rawValue; - - /** - * constructor to initialize rawValue. - * - * @param rawValue MaximumReservableLinkBandwidth - */ - public MaximumReservableLinkBandwidthTlv(int rawValue) { - log.debug("MaximumReservableLinkBandwidthTlv"); - this.rawValue = rawValue; - } - - /** - * Returns newly created MaximumReservableLinkBandwidth object. - * - * @param raw MaximumReservableLinkBandwidth - * @return object of MaximumReservableLinkBandwidthTlv - */ - public static MaximumReservableLinkBandwidthTlv of(final int raw) { - return new MaximumReservableLinkBandwidthTlv(raw); - } - - /** - * Returns value of Maximum Reservable Link Bandwidth. - * @return rawValue Maximum Reservable Link Bandwidth - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof MaximumReservableLinkBandwidthTlv) { - MaximumReservableLinkBandwidthTlv other = (MaximumReservableLinkBandwidthTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of MaximumReservableLinkBandwidthTlv. - * - * @param c input channel buffer - * @return object of MaximumReservableLinkBandwidthTlv - */ - public static MaximumReservableLinkBandwidthTlv read(ChannelBuffer c) { - return MaximumReservableLinkBandwidthTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopIPv4addressTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopIPv4addressTlv.java deleted file mode 100644 index 6f193384..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopIPv4addressTlv.java +++ /dev/null @@ -1,143 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * NexthopIPv6addressTlv provides Ipv4 address of next hop. - */ -public class NexthopIPv4addressTlv implements PcepValueType { - - /* - Reference :draft-zhao-pce-pcep-extension-for-pce-controller-01 - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=TBD | Length = 8 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | nexthop IPv4 address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - NEXTHOP-IPV4-ADDRESS TLV - - */ - protected static final Logger log = LoggerFactory.getLogger(NexthopIPv4addressTlv.class); - - public static final short TYPE = 2; //to be defined - //Length is header + value - public static final short LENGTH = 8; - public static final short VALUE_LENGTH = 4; - - private final int rawValue; - - /** - * Constructor to initialize next hop IPv4 address. - * - * @param rawValue next hop IPv4 address - */ - public NexthopIPv4addressTlv(int rawValue) { - this.rawValue = rawValue; - } - - /** - * Return next hop IPv4 address tlv. - * - * @param raw of next hop IPv4 address - * @return object of NexthopIPv4addressTlv - */ - public static NexthopIPv4addressTlv of(final int raw) { - return new NexthopIPv4addressTlv(raw); - } - - /** - * Returns next hop IPv4 address. - * - * @return next hop IPv4 address - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof NexthopIPv4addressTlv) { - NexthopIPv4addressTlv other = (NexthopIPv4addressTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iStartIndex; - } - - /** - * Reads the channel buffer and returns object of NexthopIPv4addressTlv. - * - * @param c type of channel buffer - * @return object of NexthopIPv4addressTlv - */ - public static NexthopIPv4addressTlv read(ChannelBuffer c) { - return NexthopIPv4addressTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Ipv4Address ", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopIPv6addressTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopIPv6addressTlv.java deleted file mode 100644 index 45bf7ac5..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopIPv6addressTlv.java +++ /dev/null @@ -1,190 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * NexthopIPv6addressTlv provides Ipv6 address of next hop. - */ -public class NexthopIPv6addressTlv implements PcepValueType { - - /* - Reference: draft-zhao-pce-pcep-extension-for-pce-controller-01. - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=TBD | Length = 20 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // nexthop IPv6 address (16 bytes) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - NEXTHOP-IPV6-ADDRESS TLV: - - */ - protected static final Logger log = LoggerFactory.getLogger(NexthopIPv6addressTlv.class); - - public static final short TYPE = 100; //to be defined - //Length is header + value - public static final short LENGTH = 20; - public static final short VALUE_LENGTH = 16; - - private static final byte[] NONE_VAL = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - public static final NexthopIPv6addressTlv NONE = new NexthopIPv6addressTlv(NONE_VAL); - - private static final byte[] NO_MASK_VAL = {(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, (byte) 0xFF, (byte) 0xFF }; - public static final NexthopIPv6addressTlv NO_MASK = new NexthopIPv6addressTlv(NO_MASK_VAL); - public static final NexthopIPv6addressTlv FULL_MASK = NONE; - - private final byte[] rawValue; - - /** - * Constructor to initialize IP address for next hop IPv6 address tlv. - * - * @param rawValue value of Next hop ipAddress - */ - public NexthopIPv6addressTlv(byte[] rawValue) { - log.debug("NexthopIPv6addressTlv"); - this.rawValue = rawValue; - } - - /** - * Creates next hop IPv6 address tlv. - * - * @param raw value of Next hop ipAddress - * @return object of NexthopIPv6addressTlv - */ - //logic to be checked - public static NexthopIPv6addressTlv of(final byte[] raw) { - //check NONE_VAL - boolean bFoundNONE = true; - //value starts from 3rd byte. - for (int i = 5; i < 20; ++i) { - if (NONE_VAL[i] != raw[i]) { - bFoundNONE = false; - } - } - - if (bFoundNONE) { - return NONE; - } - - //check NO_MASK_VAL - boolean bFoundNoMask = true; - //value starts from 3rd byte. - for (int i = 5; i < 20; ++i) { - if (0xFF != raw[i]) { - bFoundNoMask = false; - } - } - if (bFoundNoMask) { - return NO_MASK; - } - return new NexthopIPv6addressTlv(raw); - } - - /** - * Returns next hop IPv6 address. - * - * @return next hop IPv6 address - */ - public byte[] getBytes() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof NexthopIPv6addressTlv) { - NexthopIPv6addressTlv other = (NexthopIPv6addressTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeBytes(rawValue); - return c.writerIndex() - iStartIndex; - } - - /** - * Reads the channel buffer and returns object of NexthopIPv6addressTlv. - * - * @param c type of channel buffer - * @return object of NexthopIPv6addressTlv - */ - public static NexthopIPv6addressTlv read(ChannelBuffer c) { - byte[] yTemp = new byte[20]; - c.readBytes(yTemp, 0, 20); - return NexthopIPv6addressTlv.of(yTemp); - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", LENGTH); - - StringBuffer result = new StringBuffer(); - for (byte b : rawValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("IpAddress", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopUnnumberedIPv4IDTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopUnnumberedIPv4IDTlv.java deleted file mode 100644 index fb4ceeff..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NexthopUnnumberedIPv4IDTlv.java +++ /dev/null @@ -1,163 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * NexthopUnnumberedIPv4IDTlv provides the next node's ID and Interface ID. - */ -public class NexthopUnnumberedIPv4IDTlv implements PcepValueType { - - /* - Reference : draft-zhao-pce-pcep-extension-for-pce-controller-01. - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=TBD | Length = 12 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Node-ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Interface ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - NEXTHOP-UNNUMBERED-IPV4-ID TLV - - */ - protected static final Logger log = LoggerFactory.getLogger(NexthopUnnumberedIPv4IDTlv.class); - - public static final short TYPE = 1; //to be defined - //Length is header + value - public static final short LENGTH = 12; - - private final int nodeID; - private final int interfaceID; - - /** - * constructor to initialize nodeID and interfaceID. - * - * @param nodeID node ID - * @param interfaceID interface ID - */ - public NexthopUnnumberedIPv4IDTlv(int nodeID, int interfaceID) { - this.nodeID = nodeID; - this.interfaceID = interfaceID; - } - - /** - * Returns new object of NexthopUnnumberedIPv4IDTlv. - * - * @param nodeID node ID - * @param interfaceID interface ID - * @return NexthopUnnumberedIPv4IDTlv - */ - public static NexthopUnnumberedIPv4IDTlv of(int nodeID, int interfaceID) { - return new NexthopUnnumberedIPv4IDTlv(nodeID, interfaceID); - } - - /** - * Returns Node Id. - * - * @return node ID - */ - public int getNodeID() { - return nodeID; - } - - /** - * Returns Interface Id. - * - * @return interface ID - */ - public int getInterfaceID() { - return interfaceID; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(nodeID, interfaceID); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof NexthopUnnumberedIPv4IDTlv) { - NexthopUnnumberedIPv4IDTlv other = (NexthopUnnumberedIPv4IDTlv) obj; - return Objects.equals(this.nodeID, other.nodeID) && Objects.equals(this.interfaceID, other.interfaceID); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - - c.writeInt(nodeID); - c.writeInt(interfaceID); - - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of NexthopUnnumberedIPv4IDTlv. - * - * @param cb type of channel buffer - * @return object of NexthopUnnumberedIPv4IDTlv - */ - public static NexthopUnnumberedIPv4IDTlv read(ChannelBuffer cb) { - int nodeID = cb.readInt(); - int interfaceID = cb.readInt(); - return new NexthopUnnumberedIPv4IDTlv(nodeID, interfaceID); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("NodeId", nodeID) - .add("InterfaceId", interfaceID) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NodeFlagBitsTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NodeFlagBitsTlv.java deleted file mode 100644 index 019daa14..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NodeFlagBitsTlv.java +++ /dev/null @@ -1,233 +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.pcepio.types; - -import java.util.Objects; -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provide node Flags bits. - */ -public class NodeFlagBitsTlv implements PcepValueType { - - /* Reference :[I-D.ietf-idr- ls-distribution] /3.3.1.1 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD21] | Length=1 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |O|T|E|B| Reserved| - +-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(NodeFlagBitsTlv.class); - - public static final short TYPE = 14; - public static final short LENGTH = 1; - public static final int SET = 1; - public static final byte OFLAG_SET = (byte) 0x80; - public static final byte TFLAG_SET = 0x40; - public static final byte EFLAG_SET = 0x20; - public static final byte BFLAG_SET = 0x10; - - private final byte rawValue; - private final boolean bOFlag; - private final boolean bTFlag; - private final boolean bEFlag; - private final boolean bBFlag; - private final boolean isRawValueSet; - - /** - * constructor to initialize rawValue. - * - * @param rawValue of Node Flag Bits TLV - */ - public NodeFlagBitsTlv(byte rawValue) { - this.rawValue = rawValue; - isRawValueSet = true; - this.bOFlag = (rawValue & OFLAG_SET) == OFLAG_SET; - this.bTFlag = (rawValue & TFLAG_SET) == TFLAG_SET; - this.bEFlag = (rawValue & EFLAG_SET) == EFLAG_SET; - this.bBFlag = (rawValue & BFLAG_SET) == BFLAG_SET; - } - - /** - * constructor to initialize different Flags. - * - * @param bOFlag O-flag - * @param bTFlag T-flag - * @param bEFlag E-flag - * @param bBFlag B-flag - */ - public NodeFlagBitsTlv(boolean bOFlag, boolean bTFlag, boolean bEFlag, boolean bBFlag) { - this.bOFlag = bOFlag; - this.bTFlag = bTFlag; - this.bEFlag = bEFlag; - this.bBFlag = bBFlag; - this.rawValue = 0; - this.isRawValueSet = false; - } - - /** - * Returns newly created NodeFlagBitsTlv object. - * - * @param raw of Node Flag Bits TLV - * @return new object of NodeFlagBitsTlv - */ - public static NodeFlagBitsTlv of(final byte raw) { - return new NodeFlagBitsTlv(raw); - } - - /** - * Returns raw value of NodeFlagBitsTlv. - * - * @return rawValue raw value - */ - public byte getbyte() { - return rawValue; - } - - /** - * Returns O-flag. - * - * @return bOFlag O-flag - */ - public boolean getOFlag() { - return bOFlag; - } - - /** - * Returns T-flag. - * - * @return bTFlag T-flag - */ - public boolean getTFlag() { - return bTFlag; - } - - /** - * Returns E-flag. - * - * @return bEFlag E-flag - */ - public boolean getEFlag() { - return bEFlag; - } - - /** - * Returns B-flag. - * - * @return bBFlag B-flag - */ - public boolean getBFlag() { - return bBFlag; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - if (isRawValueSet) { - return Objects.hash(rawValue); - } else { - return Objects.hash(bOFlag, bTFlag, bEFlag, bBFlag); - } - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof NodeFlagBitsTlv) { - NodeFlagBitsTlv other = (NodeFlagBitsTlv) obj; - if (isRawValueSet) { - return Objects.equals(this.rawValue, other.rawValue); - } else { - return Objects.equals(this.bOFlag, other.bOFlag) && Objects.equals(this.bTFlag, other.bTFlag) - && Objects.equals(this.bEFlag, other.bEFlag) && Objects.equals(this.bBFlag, other.bBFlag); - } - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - if (isRawValueSet) { - c.writeByte(rawValue); - } else { - byte temp = 0; - if (bOFlag) { - temp = (byte) (temp | OFLAG_SET); - } - if (bTFlag) { - temp = (byte) (temp | TFLAG_SET); - } - if (bEFlag) { - temp = (byte) (temp | EFLAG_SET); - } - if (bBFlag) { - temp = (byte) (temp | BFLAG_SET); - } - c.writeByte(temp); - } - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of NodeFlagBitsTlv. - * - * @param c input channel buffer - * @return object of NodeFlagBitsTlv - */ - public static PcepValueType read(ChannelBuffer c) { - - return NodeFlagBitsTlv.of(c.readByte()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("OFlag", (bOFlag) ? 1 : 0) - .add("TFlag", (bTFlag) ? 1 : 0) - .add("EFlag", (bEFlag) ? 1 : 0) - .add("BFlag", (bBFlag) ? 1 : 0) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NodeNameTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NodeNameTlv.java deleted file mode 100644 index e535a358..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/NodeNameTlv.java +++ /dev/null @@ -1,154 +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.pcepio.types; - -import java.util.Objects; -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provide the name for the node. - */ -public class NodeNameTlv implements PcepValueType { - - /* reference :[I-D.ietf-idr-ls-distribution]/3.3.1.3 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD23] | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // Node Name (variable) // - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(NodeNameTlv.class); - - public static final short TYPE = 1007; //TODO:check and change TBD23 - public final short hLength; - - private final byte[] rawValue; - - /** - * constructor to initialize rawValue. - * - * @param rawValue of Node Name - * @param hLength length - */ - public NodeNameTlv(byte[] rawValue, short hLength) { - log.debug("NodeNameTlv"); - this.rawValue = rawValue; - if (0 == hLength) { - this.hLength = (short) rawValue.length; - } else { - this.hLength = hLength; - } - } - - /** - * Returns newly created NodeNameTlv object. - * - * @param raw of NodeName - * @param hLength length - * @return new object of Node Name Tlv - */ - public static NodeNameTlv of(final byte[] raw, short hLength) { - return new NodeNameTlv(raw, hLength); - } - - /** - * Returns RawValue for NodeName. - * - * @return rawValue raw value - */ - public byte[] getValue() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof NodeNameTlv) { - NodeNameTlv other = (NodeNameTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(hLength); - c.writeBytes(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of NodeNameTlv. - * - * @param c input channel buffer - * @param hLength length - * @return object of Node Name TLV - */ - public static PcepValueType read(ChannelBuffer c, short hLength) { - byte[] iNodeName = new byte[hLength]; - c.readBytes(iNodeName, 0, hLength); - return new NodeNameTlv(iNodeName, hLength); - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", hLength); - - StringBuffer result = new StringBuffer(); - for (byte b : rawValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("Value", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/OSPFareaIDsubTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/OSPFareaIDsubTlv.java deleted file mode 100644 index 2233ab0d..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/OSPFareaIDsubTlv.java +++ /dev/null @@ -1,135 +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.pcepio.types; - -import java.util.Objects; -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides area ID for OSPF area. - */ -public class OSPFareaIDsubTlv implements PcepValueType { - - /* Reference :draft-ietf-idr-ls-distribution-10. - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD12] | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | opaque value (32 Bit AS Number) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(OSPFareaIDsubTlv.class); - - public static final short TYPE = 600; //TODD:change this TBD12 - public static final short LENGTH = 4; - - private final int rawValue; - - /** - * constructor to initialize rawValue. - * - * @param rawValue area ID for OSPF area. - */ - public OSPFareaIDsubTlv(int rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns newly created OSPFareaIDsubTlv object. - * - * @param raw opaque value of AreaID - * @return new object of OSPF area ID sub TLV - */ - public static OSPFareaIDsubTlv of(final int raw) { - return new OSPFareaIDsubTlv(raw); - } - - /** - * Returns RawValue opaque value of AreaID. - * - * @return rawValue Area ID - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof OSPFareaIDsubTlv) { - OSPFareaIDsubTlv other = (OSPFareaIDsubTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of OSPFAreaIdSubTlv. - * - * @param c input channel buffer - * @return object of OSPFAreaIdSubTlv - */ - public static OSPFareaIDsubTlv read(ChannelBuffer c) { - return OSPFareaIDsubTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/OpaqueLinkAttributeTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/OpaqueLinkAttributeTlv.java deleted file mode 100644 index 1af332eb..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/OpaqueLinkAttributeTlv.java +++ /dev/null @@ -1,155 +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.pcepio.types; - -import java.util.Objects; -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides Opaque Link Attribute. - */ -public class OpaqueLinkAttributeTlv implements PcepValueType { - - /* - * TLV format. - * Reference :[I-D.ietf-idr-attributesls-distribution] /3.3.2.6 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=TBD42 | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // Opaque link attributes (variable) // - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(OpaqueLinkAttributeTlv.class); - - public static final short TYPE = 1097; //TODO:NEED TO HANDLE TDB42 - private final short hLength; - - private final byte[] rawValue; - - /** - * constructor to initialize rawValue. - * - * @param rawValue of Opaque Link Attribute - * @param hLength length - */ - public OpaqueLinkAttributeTlv(byte[] rawValue, short hLength) { - log.debug("OpaqueLinkAttributeTlv"); - this.rawValue = rawValue; - if (0 == hLength) { - this.hLength = (short) rawValue.length; - } else { - this.hLength = hLength; - } - } - - /** - * Returns newly created OpaqueLinkAttributeTlv object. - * - * @param raw of Opaque Link Attribute - * @param hLength length - * @return new object of OpaqueLinkAttributeTlv - */ - public static OpaqueLinkAttributeTlv of(final byte[] raw, short hLength) { - return new OpaqueLinkAttributeTlv(raw, hLength); - } - - /** - * Returns raw value of Opaque Link Attribute Tlv. - * @return rawValue raw value - */ - public byte[] getValue() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof OpaqueLinkAttributeTlv) { - OpaqueLinkAttributeTlv other = (OpaqueLinkAttributeTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(hLength); - c.writeBytes(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of OpaqueLinkAttributeTlv. - * - * @param c input channel buffer - * @param hLength length - * @return object of Opaque Link Attribute Tlv - */ - public static PcepValueType read(ChannelBuffer c, short hLength) { - byte[] iOpaqueValue = new byte[hLength]; - c.readBytes(iOpaqueValue, 0, hLength); - return new OpaqueLinkAttributeTlv(iOpaqueValue, hLength); - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", hLength); - - StringBuffer result = new StringBuffer(); - for (byte b : rawValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("Value", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/OpaqueNodeAttributeTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/OpaqueNodeAttributeTlv.java deleted file mode 100644 index 5aec8c5f..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/OpaqueNodeAttributeTlv.java +++ /dev/null @@ -1,154 +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.pcepio.types; - -import java.util.Objects; -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides Opaque node attributes. - */ -public class OpaqueNodeAttributeTlv implements PcepValueType { - /* - * Reference [I-D.ietf-idr-Properties ls-distribution] /3.3.1.5 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD22] | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // Opaque node attributes (variable) // - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(OpaqueNodeAttributeTlv.class); - - public static final short TYPE = 1001; - private final short hLength; - - private final byte[] rawValue; - - /** - * constructor to initialize rawValue. - * - * @param rawValue Opaque Node Attribute - * @param hLength length - */ - public OpaqueNodeAttributeTlv(byte[] rawValue, short hLength) { - - this.rawValue = rawValue; - if (0 == hLength) { - this.hLength = (short) rawValue.length; - } else { - this.hLength = hLength; - } - } - - /** - * Returns newly created OpaqueNodeAttributeTlv object. - * - * @param raw value of Opaque Node Attribute - * @param hLength length - * @return new object of Opaque Node Attribute Tlv - */ - public static OpaqueNodeAttributeTlv of(final byte[] raw, short hLength) { - return new OpaqueNodeAttributeTlv(raw, hLength); - } - - /** - * Returns raw value of Opaque Node Attribute Tlv. - * - * @return rawValue of Opaque Node Attribute - */ - public byte[] getValue() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof OpaqueLinkAttributeTlv) { - OpaqueNodeAttributeTlv other = (OpaqueNodeAttributeTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(hLength); - c.writeBytes(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of Opaque Node Attribute Tlv. - * - * @param c input channel buffer - * @param hLength length - * @return object of OpaqueNodeAttributeTlv - */ - public static PcepValueType read(ChannelBuffer c, short hLength) { - byte[] iOpaqueValue = new byte[hLength]; - c.readBytes(iOpaqueValue, 0, hLength); - return new OpaqueNodeAttributeTlv(iOpaqueValue, hLength); - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", hLength); - - StringBuffer result = new StringBuffer(); - for (byte b : rawValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("Value", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PathKeySubObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PathKeySubObject.java deleted file mode 100644 index 86ad042a..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PathKeySubObject.java +++ /dev/null @@ -1,159 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Path Key SubObject: When a PCC needs to expand a path-key in order to expand a CPS, it - * issues a Path Computation Request (PCReq) to the PCE identified in - * the PKS in the RSVP-TE ERO that it is processing. The PCC supplies - * the PKS to be expanded in a PATH-KEY SubObject in the PCReq message. - */ -public class PathKeySubObject implements PcepValueType { - - /* - Pathkey subobject(RFC 5520): - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L| Type | Length | Path-Key | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | PCE ID (4 bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(PathKeySubObject.class); - - public static final byte TYPE = 0x40; - public static final byte LENGTH = 8; - private final short pathKey; - private final int pceID; - - /** - * Constructor for Path Key sub Object which initializes pathKey and pceId. - * - * @param pathKey path key provided by PCC - * @param pceID ID for the PCE - */ - public PathKeySubObject(short pathKey, int pceID) { - this.pathKey = pathKey; - this.pceID = pceID; - } - - /** - * Creates Path Key sub Object which initializes pathKey and pceId. - * - * @param pathKey path key provided by PCC - * @param pceID PCE id - * @return new object of type path key sub object - */ - public static PathKeySubObject of(short pathKey, int pceID) { - return new PathKeySubObject(pathKey, pceID); - } - - /** - * Returns Path Key. - * - * @return pathKey - */ - public short getPathKey() { - return pathKey; - } - - /** - * Returns pceID. - * - * @return pceID - */ - public int getPceId() { - return pceID; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(pathKey, pceID); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof PathKeySubObject) { - PathKeySubObject other = (PathKeySubObject) obj; - return Objects.equals(this.pathKey, other.pathKey) && Objects.equals(this.pceID, other.pceID); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - - c.writeShort(pathKey); - c.writeInt(pceID); - - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns new path key sub objects. - * - * @param c of type channel buffer - * @return object of type path key sub object - */ - public static PcepValueType read(ChannelBuffer c) { - Short pathKey = c.readShort(); - int pceID = c.readInt(); - return new PathKeySubObject(pathKey, pceID); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("PathKey", pathKey) - .add("PceID", pceID) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PathSetupTypeTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PathSetupTypeTlv.java deleted file mode 100644 index 3e8f9676..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PathSetupTypeTlv.java +++ /dev/null @@ -1,164 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PcepSetup type tlv. - */ -public class PathSetupTypeTlv implements PcepValueType { - - /* - Reference : draft-sivabalan-pce-lsp-setup-type-02. - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Reserved | PST | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Figure 1: PATH-SETUP-TYPE TLV - - */ - protected static final Logger log = LoggerFactory.getLogger(PathSetupTypeTlv.class); - - public static final short TYPE = 0; //TODO : need to reassign the value as per RFC - public static final short LENGTH = 4; - - private final byte pst; - private final int rawValue; - private final boolean isRawValueSet; - - /** - * Constructor to initialize parameters for path setup type tlv. - * - * @param rawValue parameter for path setup type tlv - */ - public PathSetupTypeTlv(final int rawValue) { - this.rawValue = rawValue; - this.isRawValueSet = true; - this.pst = (byte) rawValue; - } - - /** - * Constructor to initialize pst. - * - * @param pst PST - */ - public PathSetupTypeTlv(byte pst) { - this.pst = pst; - this.rawValue = 0; - this.isRawValueSet = false; - } - - /** - * Returns Object of path setup type tlv. - * - * @param raw parameter for path setup type tlv - * @return object of PathSetupTypeTlv - */ - public static PathSetupTypeTlv of(final int raw) { - return new PathSetupTypeTlv(raw); - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - /** - * Returns parameters for path setup type tlv. - * - * @return parameters for path setup type tlv - */ - public int getInt() { - return rawValue; - } - - /** - * Returns the pst value. - * - * @return pst value - */ - public byte getPst() { - return pst; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(pst); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof PathSetupTypeTlv) { - PathSetupTypeTlv other = (PathSetupTypeTlv) obj; - return Objects.equals(this.pst, other.pst); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(pst); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Returns the object of type PathSetupTypeTlv. - * - * @param c is type Channel buffer - * @return object of PathSetupTypeTlv - */ - public static PathSetupTypeTlv read(ChannelBuffer c) { - return PathSetupTypeTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("PST", pst) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PceccCapabilityTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PceccCapabilityTlv.java deleted file mode 100644 index b8ae1e87..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PceccCapabilityTlv.java +++ /dev/null @@ -1,194 +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.pcepio.types; - -import java.util.Objects; -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PceccCapabilityTlv. - */ -public class PceccCapabilityTlv implements PcepValueType { - - /* PCECC CAPABILITY TLV - * Reference : draft-zhao-pce-pcep-extension-for-pce-controller-01, section-7.1.1 - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=32 | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Flags |G|L| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - protected static final Logger log = LoggerFactory.getLogger(PceccCapabilityTlv.class); - - public static final short TYPE = 32; - public static final short LENGTH = 4; - public static final int SET = 1; - public static final byte LFLAG_CHECK = 0x01; - public static final byte GFLAG_CHECK = 0x02; - - private final boolean bGFlag; - private final boolean bLFlag; - - private final int rawValue; - private final boolean isRawValueSet; - - /** - * Constructor to initialize raw Value. - * - * @param rawValue raw value - */ - public PceccCapabilityTlv(final int rawValue) { - this.rawValue = rawValue; - this.isRawValueSet = true; - - bLFlag = (rawValue & LFLAG_CHECK) == LFLAG_CHECK; - bGFlag = (rawValue & GFLAG_CHECK) == GFLAG_CHECK; - } - - /** - * Constructor to initialize G-flag L-flag. - * @param bGFlag G-flag - * @param bLFlag L-flag - */ - public PceccCapabilityTlv(boolean bGFlag, boolean bLFlag) { - this.bGFlag = bGFlag; - this.bLFlag = bLFlag; - this.rawValue = 0; - this.isRawValueSet = false; - } - - /** - * Returns newly created PceccCapabilityTlv object. - * - * @param raw value - * @return object of Pcecc Capability Tlv - */ - public static PceccCapabilityTlv of(final int raw) { - return new PceccCapabilityTlv(raw); - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - /** - * Returns G-flag. - * @return bGFlag G-flag - */ - public boolean getGFlag() { - return bGFlag; - } - - /** - * Returns L-flag. - * @return bLFlag L-flag - */ - public boolean getLFlag() { - return bLFlag; - } - - /** - * Returns the raw value. - * @return rawValue Flags - */ - public int getInt() { - return rawValue; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - if (isRawValueSet) { - return Objects.hash(rawValue); - } else { - return Objects.hash(bLFlag, bGFlag); - } - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof PceccCapabilityTlv) { - PceccCapabilityTlv other = (PceccCapabilityTlv) obj; - if (isRawValueSet) { - return Objects.equals(this.rawValue, other.rawValue); - } else { - return Objects.equals(this.bGFlag, other.bGFlag) && Objects.equals(this.bLFlag, other.bLFlag); - } - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - int temp = 0; - c.writeShort(TYPE); - c.writeShort(LENGTH); - if (isRawValueSet) { - c.writeInt(rawValue); - } else { - if (bGFlag) { - temp = temp | GFLAG_CHECK; - } - if (bLFlag) { - temp = temp | LFLAG_CHECK; - } - c.writeInt(temp); - } - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads channel buffer and returns object of PceccCapabilityTlv. - * - * @param c input channel buffer - * @return object of PceccCapabilityTlv - */ - public static PceccCapabilityTlv read(ChannelBuffer c) { - return PceccCapabilityTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepErrorDetailInfo.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepErrorDetailInfo.java deleted file mode 100644 index 83a62103..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepErrorDetailInfo.java +++ /dev/null @@ -1,83 +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.pcepio.types; - -/** - * Provide the PCEP Error Info Details. - */ -public final class PcepErrorDetailInfo { - - private PcepErrorDetailInfo() { - } - - // Error Types - /** - Error- Meaning Reference:RFC 5440 - Type - 1 PCEP session establishment failure - Error-value=1: reception of an invalid Open message or a non Open message. - Error-value=2: no Open message received before the expiration of the OpenWait timer - Error-value=3: unacceptable and non-negotiable session characteristics - Error-value=4: unacceptable but negotiable session characteristics - Error-value=5: reception of a second Open message with still unacceptable session characteristics - Error-value=6: reception of a PCErr message proposing unacceptable session characteristics - Error-value=7: No Keepalive or PCErr message received before the expiration of the KeepWait timer - Error-value=8: PCEP version not supported - 2 Capability not supported - 3 Unknown Object - Error-value=1: Unrecognized object class - Error-value=2: Unrecognized object Type - 4 Not supported object - Error-value=1: Not supported object class - Error-value=2: Not supported object Type - 5 Policy violation - Error-value=1: C bit of the METRIC object set (request rejected) - Error-value=2: O bit of the RP object cleared (request rejected) - 6 Mandatory Object missing - Error-value=1: RP object missing - Error-value=2: RRO missing for a re-optimization request (R bit of the RP object set) - Error-value=3: END-POINTS object missing - 7 Synchronized path computation request missing - 8 Unknown request reference - 9 Attempt to establish a second PCEP session - 10 Reception of an invalid object - Error-value=1: reception of an object with P flag not set although the P flag must be - set according to this specification. - */ - public static final byte ERROR_TYPE_1 = 1; - public static final byte ERROR_TYPE_2 = 2; - public static final byte ERROR_TYPE_3 = 3; - public static final byte ERROR_TYPE_4 = 4; - public static final byte ERROR_TYPE_5 = 5; - public static final byte ERROR_TYPE_6 = 6; - public static final byte ERROR_TYPE_7 = 7; - public static final byte ERROR_TYPE_8 = 8; - public static final byte ERROR_TYPE_9 = 9; - public static final byte ERROR_TYPE_10 = 10; - - // Error Values - public static final byte ERROR_VALUE_1 = 1; - public static final byte ERROR_VALUE_2 = 2; - public static final byte ERROR_VALUE_3 = 3; - public static final byte ERROR_VALUE_4 = 4; - public static final byte ERROR_VALUE_5 = 5; - public static final byte ERROR_VALUE_6 = 6; - public static final byte ERROR_VALUE_7 = 7; - public static final byte ERROR_VALUE_8 = 8; - public static final byte ERROR_VALUE_9 = 9; - public static final byte ERROR_VALUE_10 = 10; -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepLabelDbVerTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepLabelDbVerTlv.java deleted file mode 100644 index 7a612454..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepLabelDbVerTlv.java +++ /dev/null @@ -1,137 +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.pcepio.types; - -import java.util.Objects; -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides CEP LABEL DB VERSION TLV which contains LSP State DB Version (32 Bit ). - */ -public class PcepLabelDbVerTlv implements PcepValueType { - - /* PCEP LABEL DB VERSION TLV format - - Reference : draft-ietf-pce-stateful-sync-optimizations-02, section 3.3.1 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=23 | Length=8 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | LSP State DB Version | - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - protected static final Logger log = LoggerFactory.getLogger(PcepLabelDbVerTlv.class); - - public static final short TYPE = 34; - public static final short LENGTH = 8; - private final long rawValue; - - /** - * constructor to initialize rawValue. - * - * @param rawValue of Pcep Label Db Version Tlv - */ - public PcepLabelDbVerTlv(final long rawValue) { - log.debug("PcepLabelDbVerTlv"); - this.rawValue = rawValue; - } - - /** - * Returns newly created PcepLabelDbVerTlv object. - * - * @param raw LSP State DB Version - * @return object of PcepLabelDbVerTlv - */ - public static PcepLabelDbVerTlv of(final long raw) { - return new PcepLabelDbVerTlv(raw); - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - /** - * Returns LSP State DB Version. - * @return raw value - */ - public long getLong() { - return rawValue; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof PceccCapabilityTlv) { - PcepLabelDbVerTlv other = (PcepLabelDbVerTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeLong(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of PcepLabelDbVerTlv. - * - * @param c input channel buffer - * @return object of PcepLabelDbVerTlv - */ - public static PcepLabelDbVerTlv read(ChannelBuffer c) { - return PcepLabelDbVerTlv.of(c.readLong()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepLabelDownload.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepLabelDownload.java deleted file mode 100644 index e2ad069c..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepLabelDownload.java +++ /dev/null @@ -1,105 +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.pcepio.types; - -import java.util.LinkedList; - -import org.onosproject.pcepio.protocol.PcepLabelObject; -import org.onosproject.pcepio.protocol.PcepLspObject; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides Pcep Label. - * REference :draft-zhao-pce-pcep-extension-for-pce-controller-01. - */ -public class PcepLabelDownload { - - protected static final Logger log = LoggerFactory.getLogger(PcepLabelDownload.class); - - //PCEP SPR Object - private PcepSrpObject srpObject; - //PCEP LSP Object - private PcepLspObject lspObject; - //LinkList of Labels - private LinkedList<PcepLabelObject> llLabelList; - - /** - * Returns SRP Object. - * - * @return PCEP SRP Object - */ - public PcepSrpObject getSrpObject() { - return srpObject; - } - - /** - * Sets the Pcep SRP Object. - * - * @param srpobj PCEP SRP Object - */ - public void setSrpObject(PcepSrpObject srpobj) { - this.srpObject = srpobj; - } - - /** - * Returns LSP Object. - * - * @return PCEP LSP Object - */ - public PcepLspObject getLspObject() { - return lspObject; - } - - /** - * Sets the Pcep LSP Object. - * - * @param lspObject PCEP LSP Object - */ - public void setLspObject(PcepLspObject lspObject) { - this.lspObject = lspObject; - } - - /** - * Returns a list of labels. - * - * @return llLabelList list of pcep label objects - */ - public LinkedList<PcepLabelObject> getLabelList() { - return llLabelList; - } - - /** - * set the llLabelList list of type PcepLableObject. - * - * @param llLabelList list of pcep label objects - */ - public void setLabelList(LinkedList<PcepLabelObject> llLabelList) { - this.llLabelList = llLabelList; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("SrpObject", srpObject) - .add("LspObject", lspObject) - .add("LabelObjectList", llLabelList) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepLabelMap.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepLabelMap.java deleted file mode 100644 index 2d3a953f..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepLabelMap.java +++ /dev/null @@ -1,103 +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.pcepio.types; - -import org.onosproject.pcepio.protocol.PcepFecObject; -import org.onosproject.pcepio.protocol.PcepLabelObject; -import org.onosproject.pcepio.protocol.PcepSrpObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provide PCEP Label Map. - * Reference :draft-zhao-pce-pcep-extension-for-pce-controller-01. - */ -public class PcepLabelMap { - - protected static final Logger log = LoggerFactory.getLogger(PcepLabelMap.class); - //PCEP SRP Object - private PcepSrpObject srpObject; - //PCEP Label Object - private PcepLabelObject labelObject; - //PCEP FEC Object - private PcepFecObject fecObject; - - /** - * Sets Fec Object. - * - * @param fecObject PCEP fec object - */ - public void setFECObject(PcepFecObject fecObject) { - this.fecObject = fecObject; - } - - /** - * Returns the PcepFecObject. - * - * @return PCEP fec object - */ - public PcepFecObject getFECObject() { - return this.fecObject; - } - - /** - * Returns SRP Object. - * - * @return PCEP SRP Object - */ - public PcepSrpObject getSrpObject() { - return srpObject; - } - - /** - * Sets the PCEP Srp Object. - * - * @param srpObject PCEP SRP Object - */ - public void setSrpObject(PcepSrpObject srpObject) { - this.srpObject = srpObject; - } - - /** - * Returns labelObject. - * - * @return PCEP label object - */ - public PcepLabelObject getLabelObject() { - return labelObject; - } - - /** - * Sets the Pcep labelObject. - * - * @param labelObject PCEP label object - */ - public void setLabelObject(PcepLabelObject labelObject) { - this.labelObject = labelObject; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("SrpObject", srpObject) - .add("LabelObject", labelObject) - .add("FecObject", fecObject) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv4Adjacency.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv4Adjacency.java deleted file mode 100644 index 1ed0ab14..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv4Adjacency.java +++ /dev/null @@ -1,107 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepNai; - -import com.google.common.base.MoreObjects; - -/** - * Provides Pcep Nai Ipv4 Adjacency. - */ -public class PcepNaiIpv4Adjacency implements PcepNai { - - public static final byte ST_TYPE = 0x03; - private final int localIpv4Addr; - private final int remoteIpv4Addr; - - /** - * Constructor to initialize variables. - * - * @param localIpv4 local ipv4 address - * @param remoteIpv4 remote ipv4 address - */ - public PcepNaiIpv4Adjacency(int localIpv4, int remoteIpv4) { - this.localIpv4Addr = localIpv4; - this.remoteIpv4Addr = remoteIpv4; - } - - /** - * Returns Object of Pcep nai Ipv4 Adjacency. - * - * @param localIpv4Addr local ipv4 address - * @param remoteIpv4Addr remote ipv4 address - * @return Object of Pcep nai Ipv4 Adjacency - */ - public static PcepNaiIpv4Adjacency of(int localIpv4Addr, int remoteIpv4Addr) { - return new PcepNaiIpv4Adjacency(localIpv4Addr, remoteIpv4Addr); - } - - @Override - public byte getType() { - return ST_TYPE; - } - - @Override - public int write(ChannelBuffer bb) { - int iLenStartIndex = bb.writerIndex(); - bb.writeInt(localIpv4Addr); - bb.writeInt(remoteIpv4Addr); - return bb.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of PcepNAIIpv4AdjacencyVer1. - * - * @param cb of channel buffer - * @return object of PcepNAIIpv4Adjacency - */ - public static PcepNaiIpv4Adjacency read(ChannelBuffer cb) { - int localIpv4 = cb.readInt(); - int remoteIpv4 = cb.readInt(); - return new PcepNaiIpv4Adjacency(localIpv4, remoteIpv4); - } - - @Override - public int hashCode() { - return Objects.hash(localIpv4Addr, remoteIpv4Addr); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof PcepNaiIpv4Adjacency) { - PcepNaiIpv4Adjacency other = (PcepNaiIpv4Adjacency) obj; - return Objects.equals(this.localIpv4Addr, other.localIpv4Addr) - && Objects.equals(this.remoteIpv4Addr, other.remoteIpv4Addr); - } - return false; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("localIPv4Address", localIpv4Addr) - .add("remoteIPv4Address", remoteIpv4Addr) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv4NodeId.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv4NodeId.java deleted file mode 100644 index 1d4ce5d4..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv4NodeId.java +++ /dev/null @@ -1,99 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepNai; - -import com.google.common.base.MoreObjects; - -/** - * Provides Pcep Nai Ipv4 Node Id. - */ -public class PcepNaiIpv4NodeId implements PcepNai { - - public static final byte ST_TYPE = 0x01; - - private final int ipv4NodeId; - - /** - * Constructor to initialize ipv4NodeId. - * - * @param value ipv4 node id - */ - public PcepNaiIpv4NodeId(int value) { - this.ipv4NodeId = value; - } - - /** - * Returns an object of PcepNaiIpv4NodeId. - * - * @param value ipv4 node id - * @return object of PcepNaiIpv4NodeId - */ - public static PcepNaiIpv4NodeId of(int value) { - return new PcepNaiIpv4NodeId(value); - } - - @Override - public byte getType() { - return ST_TYPE; - } - - @Override - public int write(ChannelBuffer bb) { - int iLenStartIndex = bb.writerIndex(); - bb.writeInt(ipv4NodeId); - return bb.writerIndex() - iLenStartIndex; - } - - /** - * Reads from the channel buffer and returns object of PcepNAIIpv4NodeIdVer1. - * - * @param bb of channel buffer. - * @return object of PcepNAIIpv4NodeIdVer1 - */ - public static PcepNaiIpv4NodeId read(ChannelBuffer bb) { - return new PcepNaiIpv4NodeId(bb.readInt()); - } - - @Override - public int hashCode() { - return Objects.hash(ipv4NodeId); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof PcepNaiIpv4NodeId) { - PcepNaiIpv4NodeId other = (PcepNaiIpv4NodeId) obj; - return Objects.equals(this.ipv4NodeId, other.ipv4NodeId); - } - return false; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("IPv4NodeId", ipv4NodeId) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv6Adjacency.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv6Adjacency.java deleted file mode 100644 index 3a177d99..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv6Adjacency.java +++ /dev/null @@ -1,113 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepNai; - -import com.google.common.base.MoreObjects; - -/** - * Provides Pcep Nai Ipv6 Adjacency. - */ -public class PcepNaiIpv6Adjacency implements PcepNai { - - public static final byte ST_TYPE = 0x04; - public static final byte IPV6_LEN = 0x10; - - private final byte[] localIpv6Addr; - private final byte[] remoteIpv6Addr; - - /** - * Constructor to initialize local ipv6 and remote ipv6. - * - * @param localIpv6 local ipv6 address - * @param remoteIpv6 remote ipv6 address - */ - public PcepNaiIpv6Adjacency(byte[] localIpv6, byte[] remoteIpv6) { - this.localIpv6Addr = localIpv6; - this.remoteIpv6Addr = remoteIpv6; - } - - @Override - public byte getType() { - return ST_TYPE; - } - - @Override - public int write(ChannelBuffer bb) { - int iLenStartIndex = bb.writerIndex(); - bb.writeBytes(localIpv6Addr); - bb.writeBytes(remoteIpv6Addr); - return bb.writerIndex() - iLenStartIndex; - } - - /** - * Reads from channel buffer and returns object of PcepNAIIpv6AdjacencyVer1. - * - * @param bb of type channel buffer - * @return object of PcepNAIIpv6AdjacencyVer1 - */ - public static PcepNaiIpv6Adjacency read(ChannelBuffer bb) { - byte[] localIpv6 = new byte[IPV6_LEN]; - bb.readBytes(localIpv6, 0, IPV6_LEN); - byte[] remoteIpv6 = new byte[IPV6_LEN]; - bb.readBytes(remoteIpv6, 0, IPV6_LEN); - return new PcepNaiIpv6Adjacency(localIpv6, remoteIpv6); - } - - @Override - public int hashCode() { - return Objects.hash(localIpv6Addr, remoteIpv6Addr); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof PcepNaiIpv6Adjacency) { - PcepNaiIpv6Adjacency other = (PcepNaiIpv6Adjacency) obj; - return Objects.equals(this.localIpv6Addr, other.localIpv6Addr) - && Objects.equals(this.remoteIpv6Addr, other.remoteIpv6Addr); - } - return false; - } - - /** - * Creates object of PcepNaiIpv6Adjacency with local ipv6 address and remote ipv6 address. - * - * @param localIpv6Addr local ipv6 address - * @param remoteIpv6Addr remote ipv6 address - * @return object of PcepNaiIpv6Adjacency - */ - - public static PcepNaiIpv6Adjacency of(final byte[] localIpv6Addr, final byte[] remoteIpv6Addr) { - return new PcepNaiIpv6Adjacency(localIpv6Addr, remoteIpv6Addr); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("localIPV6Address", localIpv6Addr) - .add("remoteIPV6Address", remoteIpv6Addr) - .toString(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv6NodeId.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv6NodeId.java deleted file mode 100644 index 3b7d52fd..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiIpv6NodeId.java +++ /dev/null @@ -1,102 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepNai; - -import com.google.common.base.MoreObjects; - -/** - * Provides Pcep Nai Ipv6 Node Id. - */ -public class PcepNaiIpv6NodeId implements PcepNai { - - public static final byte ST_TYPE = 0x02; - public static final byte IPV6_LEN = 0x10; - - private final byte[] ipv6NodeId; - - /** - * Constructor to initialize ipv6NodeId. - * - * @param value ipv6 node id - */ - public PcepNaiIpv6NodeId(byte[] value) { - this.ipv6NodeId = value; - } - - /** - * Return object of Pcep Nai Ipv6 Node ID. - * - * @param ipv6NodeId Ipv6 node ID. - * @return object of Pcep Nai Ipv6 Node ID. - */ - public static PcepNaiIpv6NodeId of(byte[] ipv6NodeId) { - return new PcepNaiIpv6NodeId(ipv6NodeId); - } - - @Override - public byte getType() { - return ST_TYPE; - } - - @Override - public int write(ChannelBuffer cb) { - int iLenStartIndex = cb.writerIndex(); - cb.writeBytes(ipv6NodeId); - return cb.writerIndex() - iLenStartIndex; - } - - /** - * Reads from the channel buffer and returns object of PcepNAIIpv6NodeId. - * - * @param cb of type channel buffer. - * @return object of PcepNAIIpv6NodeId - */ - public static PcepNaiIpv6NodeId read(ChannelBuffer cb) { - byte[] ipv6NodeId = new byte[IPV6_LEN]; - cb.readBytes(ipv6NodeId, 0, IPV6_LEN); - return new PcepNaiIpv6NodeId(ipv6NodeId); - } - - @Override - public int hashCode() { - return Objects.hash(ipv6NodeId); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof PcepNaiIpv6NodeId) { - PcepNaiIpv6NodeId other = (PcepNaiIpv6NodeId) obj; - return Objects.equals(this.ipv6NodeId, other.ipv6NodeId); - } - return false; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("IPV6NodeID", ipv6NodeId) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiUnnumberedAdjacencyIpv4.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiUnnumberedAdjacencyIpv4.java deleted file mode 100644 index 4e8926cf..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepNaiUnnumberedAdjacencyIpv4.java +++ /dev/null @@ -1,131 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepNai; - -import com.google.common.base.MoreObjects; - -/** - * Provides Pcep Nai Unnumbered Adjacency Ipv4. - */ -public class PcepNaiUnnumberedAdjacencyIpv4 implements PcepNai { - /** - * draft-ietf-pce-segment-routing-03 section 5.3.2. - */ - public static final byte ST_TYPE = 0x05; - - private final int localNodeId; - private final int localInterfaceId; - private final int remoteNodeId; - private final int remoteInterfaceId; - - /** - * Constructor to initialize all the member variables. - * - * @param localNodeId local node id - * @param localInterfaceId local interface id - * @param remoteNodeId remote node id - * @param remoteInterfaceId remote interface id - */ - public PcepNaiUnnumberedAdjacencyIpv4(int localNodeId, int localInterfaceId, int remoteNodeId, - int remoteInterfaceId) { - this.localNodeId = localNodeId; - this.localInterfaceId = localInterfaceId; - this.remoteNodeId = remoteNodeId; - this.remoteInterfaceId = remoteInterfaceId; - } - - /** - * Returns PCEP Nai Unnumbered Adjacency Ipv4 object. - * - * @param localNodeId local node id - * @param localInterfaceId local interface if - * @param remoteNodeId remote node id - * @param remoteInterfaceId remote interface id - * @return PCEP Nai Unnumbered Adjacency Ipv4 object - */ - public static PcepNaiUnnumberedAdjacencyIpv4 of(int localNodeId, int localInterfaceId, int remoteNodeId, - int remoteInterfaceId) { - return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId); - } - - @Override - public byte getType() { - return ST_TYPE; - } - - @Override - public int write(ChannelBuffer bb) { - int iLenStartIndex = bb.writerIndex(); - bb.writeInt(localNodeId); - bb.writeInt(localInterfaceId); - bb.writeInt(remoteNodeId); - bb.writeInt(remoteInterfaceId); - return bb.writerIndex() - iLenStartIndex; - } - - /** - * Reads from channel buffer and return object of PcepNAIUnnumberedAdjacencyIpv4. - * - * @param bb of type channel buffer - * @return object of PcepNAIUnnumberedAdjacencyIpv4 - */ - public static PcepNaiUnnumberedAdjacencyIpv4 read(ChannelBuffer bb) { - int localNodeId; - int localInterfaceId; - int remoteNodeId; - int remoteInterfaceId; - localNodeId = bb.readInt(); - localInterfaceId = bb.readInt(); - remoteNodeId = bb.readInt(); - remoteInterfaceId = bb.readInt(); - return new PcepNaiUnnumberedAdjacencyIpv4(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId); - } - - @Override - public int hashCode() { - return Objects.hash(localNodeId, localInterfaceId, remoteNodeId, remoteInterfaceId); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof PcepNaiUnnumberedAdjacencyIpv4) { - PcepNaiUnnumberedAdjacencyIpv4 other = (PcepNaiUnnumberedAdjacencyIpv4) obj; - return Objects.equals(this.localNodeId, other.localNodeId) - && Objects.equals(this.localInterfaceId, other.localInterfaceId) - && Objects.equals(this.remoteNodeId, other.remoteNodeId) - && Objects.equals(this.remoteInterfaceId, other.remoteInterfaceId); - } - return false; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("localNodeId", localNodeId) - .add("localInterfaceId", localInterfaceId) - .add("remoteNodeId", remoteNodeId) - .add("remoteInterfaceId", remoteInterfaceId) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepObjectHeader.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepObjectHeader.java deleted file mode 100644 index a4af6746..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepObjectHeader.java +++ /dev/null @@ -1,224 +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.pcepio.types; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PCEP Object Header which is common for all the objects. - * Reference : RFC 5440. - */ - -public class PcepObjectHeader { - - /* - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Object-Class | OT |Res|P|I| Object Length (bytes) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // (Object body) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - PCEP Common Object Header - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepObjectHeader.class); - - public static final boolean REQ_OBJ_MUST_PROCESS = true; - public static final boolean REQ_OBJ_OPTIONAL_PROCESS = false; - public static final boolean RSP_OBJ_IGNORED = true; - public static final boolean RSP_OBJ_PROCESSED = false; - public static final int OBJECT_TYPE_SHIFT_VALUE = 4; - public static final byte PFLAG_SET = 0x02; - public static final byte IFLAG_SET = 0x01; - public static final int SET = 1; - private byte objClass; - private byte objType; - private boolean bPFlag; - private boolean bIFlag; - private short objLen; - - /** - * Constructor to initialize all the variables in object header. - * - * @param objClass PCEP Object class - * @param objType PCEP Object type - * @param bPFlag P flag - * @param bIFlag I flag - * @param objLen PCEP object length - */ - - public PcepObjectHeader(byte objClass, byte objType, boolean bPFlag, boolean bIFlag, short objLen) { - this.objClass = objClass; - this.objType = objType; - this.bPFlag = bPFlag; - this.bIFlag = bIFlag; - this.objLen = objLen; - } - - /** - * Sets the Object class. - * - * @param value object class - */ - public void setObjClass(byte value) { - this.objClass = value; - } - - /** - * Sets the Object TYPE. - * - * @param value object type - */ - public void setObjType(byte value) { - this.objType = value; - } - - /** - * Sets the Object P flag. - * - * @param value p flag - */ - public void setPFlag(boolean value) { - this.bPFlag = value; - } - - /** - * Sets the Object I flag. - * - * @param value I flag - */ - public void setIFlag(boolean value) { - this.bIFlag = value; - } - - /** - * Sets the Object Length. - * - * @param value object length - */ - public void setObjLen(short value) { - this.objLen = value; - } - - /** - * Returns Object's P flag. - * - * @return bPFlag P flag - */ - public boolean getPFlag() { - return this.bPFlag; - } - - /** - * Returns Object's i flag. - * - * @return bIFlag I flag - */ - public boolean getIFlag() { - return this.bIFlag; - } - - /** - * Returns Object Length. - * - * @return objLen object length - */ - public short getObjLen() { - return this.objLen; - } - - /** - * Returns Object class. - * - * @return objClass object class - */ - public byte getObjClass() { - return this.objClass; - } - - /** - * Returns Object Type. - * - * @return objType object type - */ - public byte getObjType() { - return this.objType; - } - - /** - * Writes Byte stream of PCEP object header to channel buffer. - * - * @param cb output channel buffer - * @return objLenIndex object length index in channel buffer - */ - public int write(ChannelBuffer cb) { - - cb.writeByte(this.objClass); - byte temp = (byte) (this.objType << OBJECT_TYPE_SHIFT_VALUE); - if (this.bPFlag) { - temp = (byte) (temp | PFLAG_SET); - } - if (this.bIFlag) { - temp = (byte) (temp | IFLAG_SET); - } - cb.writeByte(temp); - int objLenIndex = cb.writerIndex(); - cb.writeShort((short) 0); - return objLenIndex; - } - - /** - * Read from channel buffer and Returns PCEP Objects header. - * - * @param cb of type channel buffer - * @return PCEP Object header - */ - public static PcepObjectHeader read(ChannelBuffer cb) { - - byte objClass; - byte objType; - boolean bPFlag; - boolean bIFlag; - short objLen; - objClass = cb.readByte(); - byte temp = cb.readByte(); - bIFlag = (temp & IFLAG_SET) == IFLAG_SET; - bPFlag = (temp & PFLAG_SET) == PFLAG_SET; - objType = (byte) (temp >> OBJECT_TYPE_SHIFT_VALUE); - objLen = cb.readShort(); - return new PcepObjectHeader(objClass, objType, bPFlag, bIFlag, objLen); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ObjectClass", objClass) - .add("ObjectType", objType) - .add("ObjectLength", objLen) - .add("PFlag", (bPFlag) ? 1 : 0) - .add("IFlag", (bIFlag) ? 1 : 0) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpIpv4ErrorSpec.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpIpv4ErrorSpec.java deleted file mode 100644 index 326b66b7..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpIpv4ErrorSpec.java +++ /dev/null @@ -1,160 +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.pcepio.types; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; - -import com.google.common.base.MoreObjects; - -/** - * Provides Pcep Rsvp Ipv4 Error Spec. - */ -public class PcepRsvpIpv4ErrorSpec implements PcepRsvpErrorSpec { - - /* - RSVP error spec object header. - 0 1 2 3 - +-------------+-------------+-------------+-------------+ - | Length (bytes) | Class-Num | C-Type | - +-------------+-------------+-------------+-------------+ - | | - // (Object contents) // - | | - +-------------+-------------+-------------+-------------+ - - Ref : ERROR_SPEC @ RFC2205 - - IPv4 ERROR_SPEC object: Class = 6, C-Type = 1 - +-------------+-------------+-------------+-------------+ - | IPv4 Error Node Address (4 bytes) | - +-------------+-------------+-------------+-------------+ - | Flags | Error Code | Error Value | - +-------------+-------------+-------------+-------------+ - - */ - - PcepRsvpSpecObjHeader objHeader; - public static final byte CLASS_NUM = 0x06; - public static final byte CLASS_TYPE = 0x01; - public static final byte CLASS_LENGTH = 0x0c; - private int ipv4Addr; - private byte flags; - private byte errCode; - private short errValue; - - /** - * Constructor to initialize obj header, ipv4 addr, flags, err code and err value. - * - * @param objHeader rsvp ipv4 error spec object header - * @param ipv4Addr ipv4 address - * @param flags flags value - * @param errCode error code value - * @param errValue error value - */ - public PcepRsvpIpv4ErrorSpec(PcepRsvpSpecObjHeader objHeader, int ipv4Addr, byte flags, byte errCode, - short errValue) { - this.objHeader = objHeader; - this.ipv4Addr = ipv4Addr; - this.flags = flags; - this.errCode = errCode; - this.errValue = errValue; - } - - /** - * Constructor to initialize ipv4 address, flags, err code and err value. - * - * @param ipv4Addr ipv4 address - * @param flags flags value - * @param errCode error code - * @param errValue error value - */ - public PcepRsvpIpv4ErrorSpec(int ipv4Addr, byte flags, byte errCode, short errValue) { - this.objHeader = new PcepRsvpSpecObjHeader(CLASS_LENGTH, CLASS_NUM, CLASS_TYPE); - this.ipv4Addr = ipv4Addr; - this.flags = flags; - this.errCode = errCode; - this.errValue = errValue; - } - - @Override - public int write(ChannelBuffer cb) { - int objLenIndex = objHeader.write(cb); - cb.writeInt(ipv4Addr); - cb.writeByte(flags); - cb.writeByte(errCode); - cb.writeShort(errValue); - short objLen = (short) (cb.writerIndex() - objLenIndex); - cb.setShort(objLenIndex, objLen); - return objLen; - } - - /** - * Reads PCPE RSVP error spec from channel buffer and returns PCEP rsvp IPv4 error spec object. - * - * @param cb channel buffer - * @return PCEP rsvp IPv4 error spec object - */ - public static PcepRsvpErrorSpec read(ChannelBuffer cb) { - PcepRsvpSpecObjHeader objHeader; - int ipv4Addr; - byte flags; - byte errCode; - short errValue; - - objHeader = PcepRsvpSpecObjHeader.read(cb); - ipv4Addr = cb.readInt(); - flags = cb.readByte(); - errCode = cb.readByte(); - errValue = cb.readShort(); - return new PcepRsvpIpv4ErrorSpec(objHeader, ipv4Addr, flags, errCode, errValue); - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return StatefulRsvpErrorSpecTlv.TYPE; - } - - @Override - public short getLength() { - return CLASS_LENGTH; - } - - @Override - public byte getClassNum() { - return CLASS_NUM; - } - - @Override - public byte getClassType() { - return CLASS_TYPE; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("IPv4Address", ipv4Addr) - .add("flags", flags) - .add("errorCode", errCode) - .add("errorValue", errValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpIpv6ErrorSpec.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpIpv6ErrorSpec.java deleted file mode 100644 index 4da1ec6d..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpIpv6ErrorSpec.java +++ /dev/null @@ -1,165 +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.pcepio.types; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; - -import com.google.common.base.MoreObjects; - -/** - * Provides Pcep Rsvp Ipv6 Error Spec. - */ -public class PcepRsvpIpv6ErrorSpec implements PcepRsvpErrorSpec { - - /* - 0 1 2 3 - +-------------+-------------+-------------+-------------+ - | Length (bytes) | Class-Num | C-Type | - +-------------+-------------+-------------+-------------+ - | | - // (Object contents) // - | | - +-------------+-------------+-------------+-------------+ - - Ref : ERROR_SPEC @ RFC2205 - - IPv6 ERROR_SPEC object: Class = 6, C-Type = 2 - +-------------+-------------+-------------+-------------+ - | | - + + - | | - + IPv6 Error Node Address (16 bytes) + - | | - + + - | | - +-------------+-------------+-------------+-------------+ - | Flags | Error Code | Error Value | - +-------------+-------------+-------------+-------------+ */ - - PcepRsvpSpecObjHeader objHeader; - public static final byte CLASS_NUM = 0x06; - public static final byte CLASS_TYPE = 0x02; - public static final byte CLASS_LENGTH = 0x18; - public static final byte IPV6_LEN = 0x10; - - private byte[] ipv6Addr; - private byte flags; - private byte errCode; - private short errValue; - - /** - * Constructor to initialize obj header, ipv6 addr, flags, err code and err value. - * - * @param objHeader rsvp ipv6 error spec object header - * @param ipv6Addr ipv6 address - * @param flags flags value - * @param errCode error code - * @param errValue error value - */ - public PcepRsvpIpv6ErrorSpec(PcepRsvpSpecObjHeader objHeader, byte[] ipv6Addr, byte flags, byte errCode, - short errValue) { - this.objHeader = objHeader; - this.ipv6Addr = ipv6Addr; - this.flags = flags; - this.errCode = errCode; - this.errValue = errValue; - } - - /** - * Constructor to initialize ipv6 addr, flags, err code and err value. - * - * @param ipv6Addr ipv6 address - * @param flags flags value - * @param errCode error code - * @param errValue error value - */ - public PcepRsvpIpv6ErrorSpec(byte[] ipv6Addr, byte flags, byte errCode, short errValue) { - this.objHeader = new PcepRsvpSpecObjHeader(CLASS_LENGTH, CLASS_NUM, CLASS_TYPE); - this.ipv6Addr = ipv6Addr; - this.flags = flags; - this.errCode = errCode; - this.errValue = errValue; - } - - @Override - public int write(ChannelBuffer cb) { - int objLenIndex = objHeader.write(cb); - cb.writeBytes(ipv6Addr); - cb.writeByte(flags); - cb.writeByte(errCode); - cb.writeShort(errValue); - short objLen = (short) (cb.writerIndex() - objLenIndex); - cb.setShort(objLenIndex, objLen); - return objLen; - } - - /** - * Returns PCEP rsvp IPv6 error spce object. - * - * @param cb channel buffer - * @return PCEP rsvp IPv6 error spce object - */ - public static PcepRsvpErrorSpec read(ChannelBuffer cb) { - PcepRsvpSpecObjHeader objHeader; - byte[] ipv6Addr = new byte[IPV6_LEN]; - byte flags; - byte errCode; - short errValue; - - objHeader = PcepRsvpSpecObjHeader.read(cb); - cb.readBytes(ipv6Addr, 0, IPV6_LEN); - flags = cb.readByte(); - errCode = cb.readByte(); - errValue = cb.readShort(); - return new PcepRsvpIpv6ErrorSpec(objHeader, ipv6Addr, flags, errCode, errValue); - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return StatefulRsvpErrorSpecTlv.TYPE; - } - - @Override - public short getLength() { - return CLASS_LENGTH; - } - - @Override - public byte getClassNum() { - return CLASS_NUM; - } - - @Override - public byte getClassType() { - return CLASS_TYPE; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("IPv6Address", ipv6Addr) - .add("flags", flags) - .add("errorCode", errCode) - .add("errorValue", errValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpObjectHeader.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpObjectHeader.java deleted file mode 100644 index bddcb898..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpObjectHeader.java +++ /dev/null @@ -1,161 +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.pcepio.types; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PcepRsvpObjectHeader. - */ -public class PcepRsvpObjectHeader { - - /* - 0 1 2 3 - +-------------+-------------+-------------+-------------+ - | Length (bytes) | Class-Num | C-Type | - +-------------+-------------+-------------+-------------+ - | | - // (Object contents) // - | | - +-------------+-------------+-------------+-------------+ - - ERROR_SPEC object Header - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepRsvpObjectHeader.class); - - public static final boolean REQ_OBJ_MUST_PROCESS = true; - public static final boolean REQ_OBJ_OPTIONAL_PROCESS = false; - public static final boolean RSP_OBJ_IGNORED = true; - public static final boolean RSP_OBJ_PROCESSED = false; - public static final int OBJECT_TYPE_SHIFT_VALUE = 4; - private byte objClassNum; - private byte objClassType; - private short objLen; - - /** - * Constructor to initialize class num, length and type. - * - * @param objClassNum object class number - * @param objClassType object class type - * @param objLen object length - */ - public PcepRsvpObjectHeader(byte objClassNum, byte objClassType, short objLen) { - this.objClassNum = objClassNum; - this.objClassType = objClassType; - this.objLen = objLen; - } - - /** - * Sets the Class-Num. - * - * @param value object class number - */ - public void setObjClassNum(byte value) { - this.objClassNum = value; - } - - /** - * Sets the Class type. - * - * @param value object class type - */ - public void setObjClassType(byte value) { - this.objClassType = value; - } - - /** - * Sets the Class Length. - * - * @param value object length - */ - public void setObjLen(short value) { - this.objLen = value; - } - - /** - * Returns Object Length. - * - * @return objLen - */ - public short getObjLen() { - return this.objLen; - } - - /** - * Returns Object num. - * - * @return objClassNum - */ - public byte getObjClassNum() { - return this.objClassNum; - } - - /** - * Returns Object type. - * - * @return objClassType - */ - public byte getObjClassType() { - return this.objClassType; - } - - /** - * Writes the byte stream of PcepRsvpObjectHeader to channel buffer. - * - * @param cb of type channel buffer - * @return object length index in channel buffer - */ - public int write(ChannelBuffer cb) { - int iLenStartIndex = cb.writerIndex(); - cb.writeShort((short) 0); - cb.writeByte(this.objClassNum); - cb.writeByte(this.objClassType); - return cb.writerIndex() - iLenStartIndex; - } - - /** - * Reads the PcepRsvpObjectHeader. - * - * @param cb input channel buffer - * @return PcepRsvpObjectHeader - */ - public static PcepRsvpObjectHeader read(ChannelBuffer cb) { - log.debug("read "); - byte objClassNum; - byte objClassType; - short objLen; - objLen = cb.readShort(); - objClassNum = cb.readByte(); - objClassType = cb.readByte(); - - return new PcepRsvpObjectHeader(objClassNum, objClassType, objLen); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ObjectClassNum", objClassNum) - .add("ObjectCType", objClassType) - .add("ObjectLength", objLen) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpSpecObjHeader.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpSpecObjHeader.java deleted file mode 100644 index 132ff862..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpSpecObjHeader.java +++ /dev/null @@ -1,156 +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.pcepio.types; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides PcepRsvpObjectHeader. - */ -public class PcepRsvpSpecObjHeader { - - /* - 0 1 2 3 - +-------------+-------------+-------------+-------------+ - | Length (bytes) | Class-Num | C-Type | - +-------------+-------------+-------------+-------------+ - | | - // (Object contents) // - | | - +-------------+-------------+-------------+-------------+ - - ERROR_SPEC object Header - */ - - protected static final Logger log = LoggerFactory.getLogger(PcepRsvpSpecObjHeader.class); - - private short objLen; - private byte objClassNum; - private byte objClassType; - - /** - * Constructor to initialize length, class num and type. - * - * @param objLen object length - * @param objClassNum pcep rsvp error spec object class num - * @param objClassType pcep rsvp error spec object class type - */ - public PcepRsvpSpecObjHeader(short objLen, byte objClassNum, byte objClassType) { - this.objLen = objLen; - this.objClassNum = objClassNum; - this.objClassType = objClassType; - } - - /** - * Sets the Class num. - * - * @param value pcep rsvp error spec object class num - */ - public void setObjClassNum(byte value) { - this.objClassNum = value; - } - - /** - * Sets the Class type. - * - * @param value pcep rsvp error spec object class type - */ - public void setObjClassType(byte value) { - this.objClassType = value; - } - - /** - * Sets the Class Length. - * - * @param value pcep rsvp error spec object length - */ - public void setObjLen(short value) { - this.objLen = value; - } - - /** - * Returns Object Length. - * - * @return objLen pcep rsvp error spec object length - */ - public short getObjLen() { - return this.objLen; - } - - /** - * Returns Object num. - * - * @return objClassNum pcep rsvp error spec object class num - */ - public byte getObjClassNum() { - return this.objClassNum; - } - - /** - * Returns Object type. - * - * @return objClassType pcep rsvp error spec object class type - */ - public byte getObjClassType() { - return this.objClassType; - } - - /** - * Writes the byte stream of PcepRsvpObjectHeader to channel buffer. - * - * @param cb of type channel buffer - * @return object length index - */ - public int write(ChannelBuffer cb) { - int objLenIndex = cb.writerIndex(); - objLen = 0; - cb.writeShort(objLen); - cb.writeByte(objClassNum); - cb.writeByte(objClassType); - return objLenIndex; - } - - /** - * Reads the PcepRsvpObjectHeader. - * - * @param cb of type channel buffer - * @return PcepRsvpObjectHeader - */ - public static PcepRsvpSpecObjHeader read(ChannelBuffer cb) { - byte objClassNum; - byte objClassType; - short objLen; - objLen = cb.readShort(); - objClassNum = cb.readByte(); - objClassType = cb.readByte(); - - return new PcepRsvpSpecObjHeader(objLen, objClassNum, objClassType); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("ObjectClassNum: ", objClassNum) - .add("ObjectCType: ", objClassType) - .add("ObjectLength: ", objLen) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpUserErrorSpec.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpUserErrorSpec.java deleted file mode 100644 index 4a9357de..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepRsvpUserErrorSpec.java +++ /dev/null @@ -1,220 +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.pcepio.types; - -import java.util.LinkedList; -import java.util.ListIterator; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepVersion; - -import com.google.common.base.MoreObjects; - -/** - * Provides Pcep Rsvp User Error Spec. - */ -public class PcepRsvpUserErrorSpec implements PcepRsvpErrorSpec { - - /* - RSVP error spec object header. - 0 1 2 3 - +-------------+-------------+-------------+-------------+ - | Length (bytes) | Class-Num | C-Type | - +-------------+-------------+-------------+-------------+ - | | - // (Object contents) // - | | - +-------------+-------------+-------------+-------------+ - - Ref : USER_ERROR_SPEC @ RFC5284. - USER_ERROR_SPEC object: Class = 194, C-Type = 1 - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +---------------+---------------+---------------+---------------+ - | Enterprise Number | - +---------------+---------------+---------------+---------------+ - | Sub Org | Err Desc Len | User Error Value | - +---------------+---------------+---------------+---------------+ - | | - ~ Error Description ~ - | | - +---------------+---------------+---------------+---------------+ - | | - ~ User-Defined Subobjects ~ - | | - +---------------+---------------+---------------+---------------+ - */ - - public static final byte CLASS_NUM = (byte) 0xc2; - public static final byte CLASS_TYPE = 0x01; - - private PcepRsvpSpecObjHeader objHeader; - private int enterpriseNum; - private byte subOrg; - private byte errDescLen; - private short userErrorValue; - private byte[] errDesc; - private LinkedList<PcepValueType> llRsvpUserSpecSubObj; - - /** - * Default constructor. - * - * @param objHeader pcep rsvp spec object header - * @param enterpriseNum enterprise number - * @param subOrg organization identifier value - * @param errDescLen error description length - * @param userErrorValue user error value - * @param errDesc error description - * @param llRsvpUserSpecSubObj list of subobjects - */ - public PcepRsvpUserErrorSpec(PcepRsvpSpecObjHeader objHeader, int enterpriseNum, byte subOrg, byte errDescLen, - short userErrorValue, byte[] errDesc, LinkedList<PcepValueType> llRsvpUserSpecSubObj) { - this.objHeader = objHeader; - this.enterpriseNum = enterpriseNum; - this.subOrg = subOrg; - this.errDescLen = errDescLen; - this.userErrorValue = userErrorValue; - this.errDesc = errDesc; - this.llRsvpUserSpecSubObj = llRsvpUserSpecSubObj; - } - - @Override - public int write(ChannelBuffer cb) { - int objLenIndex = objHeader.write(cb); - cb.writeInt(enterpriseNum); - cb.writeByte(subOrg); - cb.writeByte(errDescLen); - cb.writeShort(userErrorValue); - cb.writeBytes(errDesc); - - if (llRsvpUserSpecSubObj != null) { - - ListIterator<PcepValueType> listIterator = llRsvpUserSpecSubObj.listIterator(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - if (tlv == null) { - continue; - } - tlv.write(cb); - // need to take care of padding - int pad = tlv.getLength() % 4; - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - cb.writeByte((byte) 0); - } - } - } - } - short objLen = (short) (cb.writerIndex() - objLenIndex); - cb.setShort(objLenIndex, objLen); - return objLen; - } - - /** - * Reads the channel buffer and returns object of PcepRsvpErrorSpec. - * - * @param cb of type channel buffer - * @return object of PcepRsvpErrorSpec - * @throws PcepParseException when expected object is not received - */ - public static PcepRsvpErrorSpec read(ChannelBuffer cb) throws PcepParseException { - PcepRsvpSpecObjHeader objHeader; - int enterpriseNum; - byte subOrg; - byte errDescLen; - short userErrorValue; - byte[] errDesc; - LinkedList<PcepValueType> llRsvpUserSpecSubObj = null; - - objHeader = PcepRsvpSpecObjHeader.read(cb); - - if (objHeader.getObjClassNum() != CLASS_NUM || objHeader.getObjClassType() != CLASS_TYPE) { - throw new PcepParseException("Expected PcepRsvpUserErrorSpec object."); - } - enterpriseNum = cb.readInt(); - subOrg = cb.readByte(); - errDescLen = cb.readByte(); - userErrorValue = cb.readShort(); - errDesc = new byte[errDescLen]; - cb.readBytes(errDesc, 0, errDescLen); - - llRsvpUserSpecSubObj = parseErrSpecSubObj(cb); - - return new PcepRsvpUserErrorSpec(objHeader, enterpriseNum, subOrg, errDescLen, userErrorValue, errDesc, - llRsvpUserSpecSubObj); - } - - private static LinkedList<PcepValueType> parseErrSpecSubObj(ChannelBuffer cb) throws PcepParseException { - LinkedList<PcepValueType> llRsvpUserSpecSubObj = new LinkedList<>(); - while (0 < cb.readableBytes()) { - PcepValueType tlv = null; - short hType = cb.readShort(); - int iValue = 0; - //short hLength = cb.readShort(); - switch (hType) { - case AutonomousSystemTlv.TYPE: - iValue = cb.readInt(); - tlv = new AutonomousSystemTlv(iValue); - break; - default: - throw new PcepParseException("Unsupported Sub TLV type :" + hType); - } - llRsvpUserSpecSubObj.add(tlv); - } - return llRsvpUserSpecSubObj; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return StatefulRsvpErrorSpecTlv.TYPE; - } - - @Override - public short getLength() { - return objHeader.getObjLen(); - } - - @Override - public byte getClassNum() { - return CLASS_NUM; - } - - @Override - public byte getClassType() { - return CLASS_TYPE; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("enterpriseNumber", enterpriseNum) - .add("subOrganization", subOrg) - .add("errDescLength", errDescLen) - .add("userErrorValue", userErrorValue) - .add("errDesc", errDesc) - .add("RsvpUserSpecSubObject", llRsvpUserSpecSubObj) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepValueType.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepValueType.java deleted file mode 100755 index c960e7ac..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/PcepValueType.java +++ /dev/null @@ -1,55 +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.pcepio.types; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; - -/** - * Abstraction which Provides the PCEP Values of Type, Length ,Version. - */ -public interface PcepValueType { - - /** - * Returns the Version Of PCEP Message. - * - * @return Version of PcepVersion Type. - */ - PcepVersion getVersion(); - - /** - * Returns the Type of PCEP Message. - * - * @return value of type - */ - short getType(); - - /** - * Returns the Length of PCEP Message. - * - * @return value of Length - */ - short getLength(); - - /** - * Writes the byte Stream of PCEP Message to channel buffer. - * - * @param bb of type channel buffer - * @return length of bytes written to channel buffer - */ - int write(ChannelBuffer bb); -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/RemoteTENodeDescriptorsTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/RemoteTENodeDescriptorsTlv.java deleted file mode 100644 index aceb7ea0..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/RemoteTENodeDescriptorsTlv.java +++ /dev/null @@ -1,250 +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.pcepio.types; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.ListIterator; -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides Remote TE Node Descriptors TLV. - */ -public class RemoteTENodeDescriptorsTlv implements PcepValueType { - - /* Reference :PCEP Extension for Transporting TE Data - draft-dhodylee-pce-pcep-te-data-extn-02 - * - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD9] | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Node Descriptor Sub-TLVs (variable) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(RemoteTENodeDescriptorsTlv.class); - - public static final short TYPE = 1003; //TODD:change this TBD9 - public short hLength; - - public static final int TLV_HEADER_LENGTH = 4; - // Node Descriptor Sub-TLVs (variable) - private LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs; - - /** - * Constructor to initialize llRemoteTENodeDescriptorSubTLVs. - * - * @param llRemoteTENodeDescriptorSubTLVs LinkedList of PcepValueType - */ - public RemoteTENodeDescriptorsTlv(LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs) { - this.llRemoteTENodeDescriptorSubTLVs = llRemoteTENodeDescriptorSubTLVs; - } - - /** - * Returns object of Remote TE Node Descriptors TLV. - * - * @param llRemoteTENodeDescriptorSubTLVs LinkedList of PcepValueType - * @return object of RemoteTENodeDescriptorsTLV - */ - public static RemoteTENodeDescriptorsTlv of(final LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs) { - return new RemoteTENodeDescriptorsTlv(llRemoteTENodeDescriptorSubTLVs); - } - - /** - * Returns Remote TE Node Descriptor Sub TLVs. - * - * @return llRemoteTENodeDescriptorSubTLVs - */ - public LinkedList<PcepValueType> getllRemoteTENodeDescriptorSubTLVs() { - return llRemoteTENodeDescriptorSubTLVs; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(llRemoteTENodeDescriptorSubTLVs.hashCode()); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - /* - * Here we have a list of Tlv so to compare each sub tlv between the object - * we have to take a list iterator so one by one we can get each sub tlv object - * and can compare them. - * it may be possible that the size of 2 lists is not equal so we have to first check - * the size, if both are same then we should check for the subtlv objects otherwise - * we should return false. - */ - if (obj instanceof RemoteTENodeDescriptorsTlv) { - int countObjSubTlv = 0; - int countOtherSubTlv = 0; - boolean isCommonSubTlv = true; - RemoteTENodeDescriptorsTlv other = (RemoteTENodeDescriptorsTlv) obj; - Iterator<PcepValueType> objListIterator = ((RemoteTENodeDescriptorsTlv) obj).llRemoteTENodeDescriptorSubTLVs - .iterator(); - countObjSubTlv = ((RemoteTENodeDescriptorsTlv) obj).llRemoteTENodeDescriptorSubTLVs.size(); - countOtherSubTlv = other.llRemoteTENodeDescriptorSubTLVs.size(); - if (countObjSubTlv != countOtherSubTlv) { - return false; - } else { - while (objListIterator.hasNext() && isCommonSubTlv) { - PcepValueType subTlv = objListIterator.next(); - isCommonSubTlv = Objects.equals(llRemoteTENodeDescriptorSubTLVs.contains(subTlv), - other.llRemoteTENodeDescriptorSubTLVs.contains(subTlv)); - } - return isCommonSubTlv; - } - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - - int tlvStartIndex = c.writerIndex(); - c.writeShort(TYPE); - int tlvLenIndex = c.writerIndex(); - hLength = 0; - c.writeShort(hLength); - - ListIterator<PcepValueType> listIterator = llRemoteTENodeDescriptorSubTLVs.listIterator(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - if (tlv == null) { - log.debug("TLV is null from subTlv list"); - continue; - } - tlv.write(c); - - // need to take care of padding - int pad = tlv.getLength() % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - c.writeByte((byte) 0); - } - } - } - - hLength = (short) (c.writerIndex() - tlvStartIndex); - c.setShort(tlvLenIndex, (hLength - TLV_HEADER_LENGTH)); - - return c.writerIndex() - tlvStartIndex; - } - - /** - * Reads channel buffer and returns object of Remote TE Node Descriptors TLV. - * - * @param c input channel buffer - * @param length length of buffer - * @return object of RemoteTENodeDescriptorsTLV - * @throws PcepParseException if mandatory fields are missing - */ - public static PcepValueType read(ChannelBuffer c , short length) throws PcepParseException { - - // Node Descriptor Sub-TLVs (variable) - LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLVs = new LinkedList<>(); - - ChannelBuffer tempCb = c.readBytes(length); - - while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) { - - PcepValueType tlv; - short hType = tempCb.readShort(); - int iValue = 0; - short hLength = tempCb.readShort(); - switch (hType) { - - case AutonomousSystemTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new AutonomousSystemTlv(iValue); - break; - case BGPLSidentifierTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new BGPLSidentifierTlv(iValue); - break; - case OSPFareaIDsubTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new OSPFareaIDsubTlv(iValue); - break; - case RouterIDSubTlv.TYPE: - tlv = RouterIDSubTlv.read(tempCb, hLength); - break; - - default: - throw new PcepParseException("Unsupported Sub TLV type :" + hType); - } - - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= tempCb.readableBytes()) { - tempCb.skipBytes(pad); - } - } - - llRemoteTENodeDescriptorSubTLVs.add(tlv); - } - - if (0 < tempCb.readableBytes()) { - - throw new PcepParseException("Sub Tlv parsing error. Extra bytes received."); - } - return new RemoteTENodeDescriptorsTlv(llRemoteTENodeDescriptorSubTLVs); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", hLength) - .add("RemoteTeNodeDescriptorSubTLVs", llRemoteTENodeDescriptorSubTLVs) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/RouterIDSubTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/RouterIDSubTlv.java deleted file mode 100644 index 9b27ce13..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/RouterIDSubTlv.java +++ /dev/null @@ -1,154 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides router id. - */ -public class RouterIDSubTlv implements PcepValueType { - - /* reference :I-D.ietf-idr-ls-distribution. - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD13] | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | opaque value | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(RouterIDSubTlv.class); - - public static final short TYPE = 1000; //TODD:change this TBD13 - private final short hLength; - - private final byte[] rawValue; - - /** - * constructor to initialize rawValue. - * - * @param rawValue raw value - * @param hLength length - */ - public RouterIDSubTlv(byte[] rawValue, short hLength) { - this.rawValue = rawValue; - if (0 == hLength) { - this.hLength = (short) rawValue.length; - } else { - this.hLength = hLength; - } - } - - /** - * Returns object of Router ID Sub Tlv. - * - * @param raw value - * @param hLength length - * @return object of Router ID Sub Tlv - */ - public static RouterIDSubTlv of(final byte[] raw, short hLength) { - return new RouterIDSubTlv(raw, hLength); - } - - /** - * Returns raw value. - * - * @return rawValue value - */ - public byte[] getValue() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof RouterIDSubTlv) { - RouterIDSubTlv other = (RouterIDSubTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(hLength); - c.writeBytes(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads channel buffer and returns object of RouterIDSubTlv. - * - * @param c input channel buffer - * @param hLength length - * @return object of RouterIDSubTlv - */ - public static PcepValueType read(ChannelBuffer c, short hLength) { - byte[] iOpaqueValue = new byte[hLength]; - c.readBytes(iOpaqueValue, 0, hLength); - return new RouterIDSubTlv(iOpaqueValue, hLength); - } - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", hLength); - - StringBuffer result = new StringBuffer(); - for (byte b : rawValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("Value", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/RoutingUniverseTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/RoutingUniverseTlv.java deleted file mode 100644 index 924a3a32..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/RoutingUniverseTlv.java +++ /dev/null @@ -1,147 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides RoutingUniverseTLV identifiers. - */ -public class RoutingUniverseTlv implements PcepValueType { - - /* - * Reference : draft-dhodylee-pce-pcep-te-data-extn-02, section 9.2.1. - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD7] | Length=8 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Identifier | - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - * - * - * +------------+---------------------+ - | Identifier | Routing Universe | - +------------+---------------------+ - | 0 | L3 packet topology | - | 1 | L1 optical topology | - +------------+---------------------+ - */ - - protected static final Logger log = LoggerFactory.getLogger(RoutingUniverseTlv.class); - - public static final short TYPE = 14; // TODO:need to change TBD7 - public static final short LENGTH = 8; - - private final long rawValue; - - /** - * Constructor to initialize raw value. - * - * @param rawValue raw value - */ - public RoutingUniverseTlv(long rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns object of RoutingUniverseTLV. - * - * @param raw value - * @return object of RoutingUniverseTLV - */ - public static RoutingUniverseTlv of(final long raw) { - return new RoutingUniverseTlv(raw); - } - - /** - * Returns raw value as Identifier. - * - * @return rawValue Identifier - */ - public long getLong() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof RoutingUniverseTlv) { - RoutingUniverseTlv other = (RoutingUniverseTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeLong(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads from channel buffer and returns object of RoutingUniverseTLV. - * - * @param c input channel buffer - * @return object of RoutingUniverseTLV - */ - public static RoutingUniverseTlv read(ChannelBuffer c) { - return RoutingUniverseTlv.of(c.readLong()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/SharedRiskLinkGroupTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/SharedRiskLinkGroupTlv.java deleted file mode 100644 index 70c15ee6..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/SharedRiskLinkGroupTlv.java +++ /dev/null @@ -1,167 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; -import com.google.common.base.MoreObjects.ToStringHelper; - -/** - * Provides SharedRiskLinkGroupTlv. - */ -public class SharedRiskLinkGroupTlv implements PcepValueType { - - /* - * Reference :[I-D.ietf-idr- Group ls-distribution] /3.3.2.5 - * - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type =TDB41 | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Shared Risk Link Group Value | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // ............ // - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Shared Risk Link Group Value | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(SharedRiskLinkGroupTlv.class); - - public static final short TYPE = 1096; //TODO:NEED TO HANDLE TDB41 - - private final short hLength; - - private final int[] srlgValue; - - /** - * Constructor to initialize SRLG value. - * - * @param srlgValue Shared Risk Link Group Value - * @param hLength length - */ - public SharedRiskLinkGroupTlv(int[] srlgValue, short hLength) { - this.srlgValue = srlgValue; - if (0 == hLength) { - this.hLength = (short) ((srlgValue.length) * 4); - } else { - this.hLength = hLength; - } - } - - /** - * Returns object of SharedRiskLinkGroupTlv. - * - * @param raw value - * @param hLength length - * @return object of SharedRiskLinkGroupTlv - */ - public static SharedRiskLinkGroupTlv of(final int[] raw, short hLength) { - return new SharedRiskLinkGroupTlv(raw, hLength); - } - - /** - * Returns SRLG Value. - * - * @return srlgValue - */ - public int[] getValue() { - return srlgValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(srlgValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof SharedRiskLinkGroupTlv) { - SharedRiskLinkGroupTlv other = (SharedRiskLinkGroupTlv) obj; - return Objects.equals(this.srlgValue, other.srlgValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(hLength); - for (int b : srlgValue) { - c.writeInt(b); - } - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads from channel buffer and returns object of SharedRiskLinkGroupTlv. - * - * @param c input channel buffer - * @param hLength length - * @return object of SharedRiskLinkGroupTlv - */ - public static PcepValueType read(ChannelBuffer c, short hLength) { - int iLength = hLength / 4; - int[] iSharedRiskLinkGroup = new int[iLength]; - for (int i = 0; i < iLength; i++) { - iSharedRiskLinkGroup[i] = c.readInt(); - } - return new SharedRiskLinkGroupTlv(iSharedRiskLinkGroup, hLength); - } - - - @Override - public String toString() { - ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass()); - - toStrHelper.add("Type", TYPE); - toStrHelper.add("Length", hLength); - - StringBuffer result = new StringBuffer(); - for (int b : srlgValue) { - result.append(String.format("%02X ", b)); - } - toStrHelper.add("Value", result); - - return toStrHelper.toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/SrEroSubObject.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/SrEroSubObject.java deleted file mode 100644 index 3cbb82c8..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/SrEroSubObject.java +++ /dev/null @@ -1,324 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepNai; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides SrEroSubObject. - */ -public class SrEroSubObject implements PcepValueType { - /* - SR-ERO subobject: (draft-ietf-pce-segment-routing-00) - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |L| Type | Length | ST | Flags |F|S|C|M| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | SID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // NAI (variable) // - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - - - NAI - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Local IPv4 address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Remote IPv4 address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - NAI for IPv4 Adjacency - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // Local IPv6 address (16 bytes) // - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // Remote IPv6 address (16 bytes) // - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - NAI for IPv6 adjacency - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Local Node-ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Local Interface ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Remote Node-ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Remote Interface ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - NAI for Unnumbered adjacency with IPv4 Node IDs - - */ - protected static final Logger log = LoggerFactory.getLogger(SrEroSubObject.class); - - public static final short TYPE = 0x60; //TODO : type to be defined - public static final short LENGTH = 12; - public static final short VALUE_LENGTH = 10; - public static final int SET = 1; - public static final byte MFLAG_SET = 0x01; - public static final byte CFLAG_SET = 0x02; - public static final byte SFLAG_SET = 0x04; - public static final byte FFLAG_SET = 0x08; - public static final byte SHIFT_ST = 12; - - private final boolean bFFlag; - private final boolean bSFlag; - private final boolean bCFlag; - private final boolean bMFlag; - private final byte st; - - private final int sID; - private final PcepNai nai; - - /** - * Constructor to initialize member variables. - * - * @param st SID type - * @param bFFlag F flag - * @param bSFlag S flag - * @param bCFlag C flag - * @param bMFlag M flag - * @param sID segment identifier value - * @param nai NAI associated with SID - */ - public SrEroSubObject(byte st, boolean bFFlag, boolean bSFlag, boolean bCFlag, boolean bMFlag, int sID, - PcepNai nai) { - this.st = st; - this.bFFlag = bFFlag; - this.bSFlag = bSFlag; - this.bCFlag = bCFlag; - this.bMFlag = bMFlag; - this.sID = sID; - this.nai = nai; - } - - /** - * Creates object of SrEroSubObject. - * - * @param st SID type - * @param bFFlag F flag - * @param bSFlag S flag - * @param bCFlag C flag - * @param bMFlag M flag - * @param sID segment identifier value - * @param nai NAI associated with SID - * @return object of SrEroSubObject - */ - public static SrEroSubObject of(byte st, boolean bFFlag, boolean bSFlag, boolean bCFlag, boolean bMFlag, int sID, - PcepNai nai) { - return new SrEroSubObject(st, bFFlag, bSFlag, bCFlag, bMFlag, sID, nai); - } - - /** - * Returns SID type. - * @return st sid type - */ - public byte getSt() { - return st; - } - - /** - * Returns bFFlag. - * @return bFFlag - */ - public boolean getFFlag() { - return bFFlag; - } - - /** - * Returns bSFlag. - * @return bSFlag - */ - public boolean getSFlag() { - return bSFlag; - } - - /** - * Returns bCFlag. - * @return bCFlag - */ - public boolean getCFlag() { - return bCFlag; - } - - /** - * Returns bMFlag. - * @return bMFlag - */ - public boolean getMFlag() { - return bMFlag; - } - - /** - * Returns sID. - * @return sID - */ - public int getSID() { - return sID; - } - - /** - * Returns nai. - * @return nai - */ - public PcepNai getNai() { - return nai; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(st, bFFlag, bSFlag, bCFlag, bMFlag, sID, nai); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof SrEroSubObject) { - SrEroSubObject other = (SrEroSubObject) obj; - return Objects.equals(this.st, other.st) && Objects.equals(this.bFFlag, other.bFFlag) - && Objects.equals(this.bSFlag, other.bSFlag) && Objects.equals(this.bCFlag, other.bCFlag) - && Objects.equals(this.bMFlag, other.bMFlag) && Objects.equals(this.sID, other.sID) - && Objects.equals(this.nai, other.nai); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - - c.writeShort(TYPE); - c.writeShort(LENGTH); - - short temp = 0; - if (bMFlag) { - temp = (short) (temp | MFLAG_SET); - } - if (bCFlag) { - temp = (short) (temp | CFLAG_SET); - } - if (bSFlag) { - temp = (short) (temp | SFLAG_SET); - } - if (bFFlag) { - temp = (short) (temp | FFLAG_SET); - } - short tempST = (short) (st << SHIFT_ST); - temp = (short) (temp | tempST); - c.writeShort(temp); - c.writeInt(sID); - nai.write(c); - - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of SrEroSubObject. - * @param c of type channel buffer - * @return object of SrEroSubObject - */ - public static PcepValueType read(ChannelBuffer c) { - short temp = c.readShort(); - boolean bMFlag; - boolean bCFlag; - boolean bSFlag; - boolean bFFlag; - byte st; - PcepNai nai = null; - - bMFlag = (temp & MFLAG_SET) == MFLAG_SET; - bCFlag = (temp & CFLAG_SET) == CFLAG_SET; - bSFlag = (temp & SFLAG_SET) == SFLAG_SET; - bFFlag = (temp & FFLAG_SET) == FFLAG_SET; - - st = (byte) (temp >> SHIFT_ST); - - int sID = c.readInt(); - switch (st) { - case 0x01: - nai = PcepNaiIpv4NodeId.read(c); - break; - case 0x02: - nai = PcepNaiIpv6NodeId.read(c); - break; - case 0x03: - nai = PcepNaiIpv4Adjacency.read(c); - break; - case 0x04: - nai = PcepNaiIpv6Adjacency.read(c); - break; - case 0x05: - nai = PcepNaiUnnumberedAdjacencyIpv4.read(c); - break; - default: - nai = null; - break; - } - - return new SrEroSubObject(st, bFFlag, bSFlag, bCFlag, bMFlag, sID, nai); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("st", st) - .add("bFflag", bFFlag) - .add("bSFlag", bSFlag) - .add("bCFlag", bCFlag) - .add("bMFlag", bMFlag) - .add("sID", sID) - .add("nAI", nai) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentidiersTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentidiersTlv.java deleted file mode 100644 index 020d31d9..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulIPv4LspIdentidiersTlv.java +++ /dev/null @@ -1,210 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides StatefulIPv4LspIdentidiersTlv. - */ -public class StatefulIPv4LspIdentidiersTlv implements PcepValueType { - - /* IPV4-LSP-IDENTIFIERS TLV format - * - * Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10 - * - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=18 | Length=16 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 Tunnel Sender Address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | LSP ID | Tunnel ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Extended Tunnel ID | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | IPv4 Tunnel Endpoint Address | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - protected static final Logger log = LoggerFactory.getLogger(StatefulIPv4LspIdentidiersTlv.class); - - public static final short TYPE = 18; - public static final short LENGTH = 16; - public static final int VALUE_LENGTH = 16; - private final int ipv4IngressAddress; - private final short lspId; - private final short tunnelId; - private final int extendedTunnelId; - private final int ipv4EgressAddress; - - /** - * Constructor to initialize member variables. - * - * @param ipv4IngressAddress ingress ipv4 address - * @param lspId lsp id - * @param tunnelId tunnel id - * @param extendedTunnelId extended tunnel id - * @param ipv4EgressAddress egress ipv4 address - */ - public StatefulIPv4LspIdentidiersTlv(int ipv4IngressAddress, short lspId, short tunnelId, int extendedTunnelId, - int ipv4EgressAddress) { - - this.ipv4IngressAddress = ipv4IngressAddress; - this.lspId = lspId; - this.tunnelId = tunnelId; - this.extendedTunnelId = extendedTunnelId; - this.ipv4EgressAddress = ipv4EgressAddress; - } - - /** - * Creates object of StatefulIPv4LspIdentidiersTlv. - * - * @param ipv4IngressAddress ingress ipv4 address - * @param lspId lsp id - * @param tunnelId tunnel id - * @param extendedTunnelId extended tunnel id - * @param ipv4EgressAddress egress ipv4 address - * @return object of StatefulIPv4LspIdentidiersTlv - */ - public static StatefulIPv4LspIdentidiersTlv of(int ipv4IngressAddress, short lspId, short tunnelId, - int extendedTunnelId, int ipv4EgressAddress) { - return new StatefulIPv4LspIdentidiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId, - ipv4EgressAddress); - } - - /** - * Returns tunnel id. - * - * @return tunnelId - */ - public short getTunnelId() { - return this.tunnelId; - } - - /** - * Returns extendedTunnelId. - * - * @return extendedTunnelId - */ - public int getextendedTunnelId() { - return this.extendedTunnelId; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - /** - * Returns ipv4IngressAddress. - * - * @return ipv4IngressAddress - */ - public int getIpv4IngressAddress() { - return ipv4IngressAddress; - } - - /** - * Returns ipv4EgressAddress. - * - * @return ipv4EgressAddress - */ - public int getIpv4EgressAddress() { - return ipv4EgressAddress; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId, ipv4EgressAddress); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof StatefulIPv4LspIdentidiersTlv) { - StatefulIPv4LspIdentidiersTlv other = (StatefulIPv4LspIdentidiersTlv) obj; - return Objects.equals(this.ipv4IngressAddress, other.ipv4IngressAddress) - && Objects.equals(this.lspId, other.lspId) && Objects.equals(this.tunnelId, other.tunnelId) - && Objects.equals(this.extendedTunnelId, other.extendedTunnelId) - && Objects.equals(this.ipv4EgressAddress, other.ipv4EgressAddress); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(ipv4IngressAddress); - c.writeShort(lspId); - c.writeShort(tunnelId); - c.writeInt(extendedTunnelId); - c.writeInt(ipv4EgressAddress); - - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of StatefulIPv4LspIdentidiersTlv. - * - * @param c of type channel buffer - * @return object of StatefulIPv4LspIdentidiersTlv - */ - public static PcepValueType read(ChannelBuffer c) { - int ipv4IngressAddress = c.readInt(); - short lspId = c.readShort(); - short tunnelId = c.readShort(); - int extendedTunnelId = c.readInt(); - int ipv4EgressAddress = c.readInt(); - return new StatefulIPv4LspIdentidiersTlv(ipv4IngressAddress, lspId, tunnelId, extendedTunnelId, - ipv4EgressAddress); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type:", TYPE) - .add("Length:", LENGTH) - .add("Ipv4IngressAddress:", ipv4IngressAddress) - .add("LspId:", lspId).add("TunnelId:", tunnelId) - .add("ExtendedTunnelId:", extendedTunnelId) - .add("Ipv4EgressAddress:", ipv4EgressAddress).toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulLspDbVerTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulLspDbVerTlv.java deleted file mode 100644 index a667dccd..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulLspDbVerTlv.java +++ /dev/null @@ -1,142 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides StatefulLspDbVerTlv. - */ -public class StatefulLspDbVerTlv implements PcepValueType { - - /* LSP-DB-VERSION TLV format - * - * Reference : Optimizations of Label Switched Path State Synchronization Procedures - for a Stateful PCE draft-ietf-pce-stateful-sync-optimizations-02 - * - * - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=23 | Length=8 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | LSP State DB Version | - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - protected static final Logger log = LoggerFactory.getLogger(StatefulLspDbVerTlv.class); - - public static final short TYPE = 23; - public static final short LENGTH = 8; - private final long rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue value - */ - public StatefulLspDbVerTlv(final long rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns object of StatefulLspDbVerTlv. - * - * @param raw is LSP State DB Version - * @return object of StatefulLspDbVerTlv - */ - public static StatefulLspDbVerTlv of(final long raw) { - return new StatefulLspDbVerTlv(raw); - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - /** - * Returns LSP State DB Version. - * - * @return rawValue value - */ - public long getLong() { - return rawValue; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof StatefulLspDbVerTlv) { - StatefulLspDbVerTlv other = (StatefulLspDbVerTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeLong(rawValue); - return c.writerIndex(); - } - - /** - * Reads the channel buffer and returns object of StatefulLspDbVerTlv. - * - * @param c input channel buffer - * @return object of StatefulLspDbVerTlv - */ - public static StatefulLspDbVerTlv read(ChannelBuffer c) { - return StatefulLspDbVerTlv.of(c.readLong()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulLspErrorCodeTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulLspErrorCodeTlv.java deleted file mode 100644 index 5d323f6a..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulLspErrorCodeTlv.java +++ /dev/null @@ -1,142 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides StatefulLspErrorCodeTlv. - */ -public class StatefulLspErrorCodeTlv implements PcepValueType { - - /* LSP-ERROR-CODE TLV format - * - * Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10 - * - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=20 | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | LSP Error Code | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - - protected static final Logger log = LoggerFactory.getLogger(StatefulLspErrorCodeTlv.class); - - public static final short TYPE = 20; - public static final short LENGTH = 4; - private final int rawValue; - - /** - * Constructor to initialize raw Value. - * - * @param rawValue lsp error code value - */ - public StatefulLspErrorCodeTlv(int rawValue) { - this.rawValue = rawValue; - } - - /** - * Creates object of StatefulLspErrorCodeTlv. - * - * @param raw lsp error code value - * @return object of StatefulLspErrorCodeTlv - */ - public static StatefulLspErrorCodeTlv of(int raw) { - return new StatefulLspErrorCodeTlv(raw); - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - /** - * Returns lsp error code value. - * - * @return lsp error code value - */ - public int getInt() { - return rawValue; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof StatefulLspErrorCodeTlv) { - StatefulLspErrorCodeTlv other = (StatefulLspErrorCodeTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads the channel buffer and returns object of StatefulLspErrorCodeTlv. - * - * @param c of type channel buffer - * @return object of StatefulLspErrorCodeTlv - */ - public static StatefulLspErrorCodeTlv read(ChannelBuffer c) { - return StatefulLspErrorCodeTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulPceCapabilityTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulPceCapabilityTlv.java deleted file mode 100644 index 84f40e12..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulPceCapabilityTlv.java +++ /dev/null @@ -1,269 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides StatefulPceCapabilityTlv. - */ -public class StatefulPceCapabilityTlv implements PcepValueType { - - /* STATEFUL-PCE-CAPABILITY TLV format - * - * Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10 - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=16 | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Flags |D|T|I|S|U| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - protected static final Logger log = LoggerFactory.getLogger(StatefulPceCapabilityTlv.class); - - public static final short TYPE = 16; - public static final short LENGTH = 4; - public static final byte UFLAG_SET = 0x01; - public static final byte SFLAG_SET = 0x02; - public static final byte IFLAG_SET = 0x04; - public static final byte TFLAG_SET = 0x08; - public static final byte DFLAG_SET = 0x10; - public static final int SET = 1; - - private final int rawValue; - private final boolean bDFlag; - private final boolean bTFlag; - private final boolean bIFlag; - private final boolean bSFlag; - private final boolean bUFlag; - private final boolean isRawValueSet; - - /** - * Constructor to initialize variables. - * - * @param rawValue Flags - */ - public StatefulPceCapabilityTlv(int rawValue) { - this.rawValue = rawValue; - isRawValueSet = true; - this.bUFlag = (rawValue & UFLAG_SET) == UFLAG_SET; - this.bSFlag = (rawValue & SFLAG_SET) == SFLAG_SET; - this.bIFlag = (rawValue & IFLAG_SET) == IFLAG_SET; - this.bTFlag = (rawValue & TFLAG_SET) == TFLAG_SET; - this.bDFlag = (rawValue & DFLAG_SET) == DFLAG_SET; - } - - /** - * Constructor to initialize variables. - * - * @param bDFlag D-flag - * @param bTFlag T-flag - * @param bIFlag I-flag - * @param bSFlag S-flag - * @param bUFlag U-flag - */ - public StatefulPceCapabilityTlv(boolean bDFlag, boolean bTFlag, boolean bIFlag, boolean bSFlag, boolean bUFlag) { - this.bDFlag = bDFlag; - this.bTFlag = bTFlag; - this.bIFlag = bIFlag; - this.bSFlag = bSFlag; - this.bUFlag = bUFlag; - this.rawValue = 0; - isRawValueSet = false; - } - - /** - * Returns object of StatefulPceCapabilityTlv. - * - * @param raw value Flags - * @return object of StatefulPceCapabilityTlv - */ - public static StatefulPceCapabilityTlv of(final int raw) { - return new StatefulPceCapabilityTlv(raw); - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - /** - * Returns D-flag. - * - * @return bDFlag D-flag - */ - public boolean getDFlag() { - return bDFlag; - } - - /** - * Returns T-flag. - * - * @return bTFlag T-flag - */ - public boolean getTFlag() { - return bTFlag; - } - - /** - * Returns I-flag. - * - * @return bIFlag I-flag - */ - public boolean getIFlag() { - return bIFlag; - } - - /** - * Returns S-flag. - * - * @return bSFlag S-flag - */ - public boolean getSFlag() { - return bSFlag; - } - - /** - * Returns U-flag. - * - * @return bUFlag U-flag - */ - public boolean getUFlag() { - return bUFlag; - } - - /** - * Returns raw value Flags. - * - * @return rawValue Flags - */ - public int getInt() { - return rawValue; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - if (isRawValueSet) { - return Objects.hash(rawValue); - } else { - return Objects.hash(bDFlag, bTFlag, bIFlag, bSFlag, bUFlag); - } - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof StatefulPceCapabilityTlv) { - StatefulPceCapabilityTlv other = (StatefulPceCapabilityTlv) obj; - if (isRawValueSet) { - return Objects.equals(this.rawValue, other.rawValue); - } else { - return Objects.equals(this.bDFlag, other.bDFlag) && Objects.equals(this.bTFlag, other.bTFlag) - && Objects.equals(this.bIFlag, other.bIFlag) && Objects.equals(this.bSFlag, other.bSFlag) - && Objects.equals(this.bUFlag, other.bUFlag); - } - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - if (isRawValueSet) { - c.writeInt(rawValue); - } else { - int temp = 0; - if (bUFlag) { - temp = temp | UFLAG_SET; - } - if (bSFlag) { - temp = temp | SFLAG_SET; - } - if (bIFlag) { - temp = temp | IFLAG_SET; - } - if (bTFlag) { - temp = temp | TFLAG_SET; - } - if (bDFlag) { - temp = temp | DFLAG_SET; - } - c.writeInt(temp); - } - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads from channel buffer and returns object of StatefulPceCapabilityTlv. - * - * @param c input channel buffer - * @return object of StatefulPceCapabilityTlv - */ - public static PcepValueType read(ChannelBuffer c) { - int temp = c.readInt(); - boolean bDFlag; - boolean bTFlag; - boolean bIFlag; - boolean bSFlag; - boolean bUFlag; - - bUFlag = (temp & UFLAG_SET) == UFLAG_SET; - bSFlag = (temp & SFLAG_SET) == SFLAG_SET; - bIFlag = (temp & IFLAG_SET) == IFLAG_SET; - bTFlag = (temp & TFLAG_SET) == TFLAG_SET; - bDFlag = (temp & DFLAG_SET) == DFLAG_SET; - - return new StatefulPceCapabilityTlv(bDFlag, bTFlag, bIFlag, bSFlag, bUFlag); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("type", TYPE) - .add("Length", LENGTH) - .add("DFlag", bDFlag) - .add("TFlag", bTFlag) - .add("IFlag", bIFlag) - .add("SFlag", bSFlag) - .add("UFlag", bUFlag) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulRsvpErrorSpecTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulRsvpErrorSpecTlv.java deleted file mode 100644 index 9e1a074a..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/StatefulRsvpErrorSpecTlv.java +++ /dev/null @@ -1,216 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides StatefulRsvpErrorSpecTlv. - */ -public class StatefulRsvpErrorSpecTlv implements PcepValueType { - - protected static final Logger log = LoggerFactory.getLogger(StatefulRsvpErrorSpecTlv.class); - - /* RSVP-ERROR-SPEC TLV format - * Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10 - * - * - - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=21 | Length (variable) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - + RSVP ERROR_SPEC or USER_ERROR_SPEC Object + - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - 0 1 2 3 - +-------------+-------------+-------------+-------------+ - | Length (bytes) | Class-Num | C-Type | - +-------------+-------------+-------------+-------------+ - | | - // (Object contents) // - | | - +-------------+-------------+-------------+-------------+ - - Ref : ERROR_SPEC @ RFC2205 - - IPv4 ERROR_SPEC object: Class = 6, C-Type = 1 - +-------------+-------------+-------------+-------------+ - | IPv4 Error Node Address (4 bytes) | - +-------------+-------------+-------------+-------------+ - | Flags | Error Code | Error Value | - +-------------+-------------+-------------+-------------+ - - - IPv6 ERROR_SPEC object: Class = 6, C-Type = 2 - +-------------+-------------+-------------+-------------+ - | | - + + - | | - + IPv6 Error Node Address (16 bytes) + - | | - + + - | | - +-------------+-------------+-------------+-------------+ - | Flags | Error Code | Error Value | - +-------------+-------------+-------------+-------------+ - - - Ref : USER_ERROR_SPEC @ RFC5284 - USER_ERROR_SPEC object: Class = 194, C-Type = 1 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +---------------+---------------+---------------+---------------+ - | Enterprise Number | - +---------------+---------------+---------------+---------------+ - | Sub Org | Err Desc Len | User Error Value | - +---------------+---------------+---------------+---------------+ - | | - ~ Error Description ~ - | | - +---------------+---------------+---------------+---------------+ - | | - ~ User-Defined Subobjects ~ - | | - +---------------+---------------+---------------+---------------+ - - */ - - public static final short TYPE = 21; - public static final int OBJECT_HEADER_LENGTH = 4; - private short hLength; - - private final PcepRsvpErrorSpec rsvpErrSpecObj; - private final boolean isErrSpceObjSet; - - /** - * Constructor to initialize errSpecObj. - * - * @param rsvpErrSpecObj Rsvp error spec object - */ - public StatefulRsvpErrorSpecTlv(PcepRsvpErrorSpec rsvpErrSpecObj) { - this.rsvpErrSpecObj = rsvpErrSpecObj; - this.isErrSpceObjSet = true; - } - - /** - * Returns PcepRsvpErrorSpecObject. - * - * @return rsvpErrSpecObj - */ - public PcepRsvpErrorSpec getPcepRsvpErrorSpec() { - return this.rsvpErrSpecObj; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - /** - * Reads channel buffer and returns object of StatefulRsvpErrorSpecTlv. - * - * @param cb of type channel buffer - * @return object of StatefulRsvpErrorSpecTlv - * @throws PcepParseException while parsing this tlv from channel buffer - */ - public static PcepValueType read(ChannelBuffer cb) throws PcepParseException { - - PcepRsvpErrorSpec rsvpErrSpecObj = null; - PcepRsvpSpecObjHeader rsvpErrSpecObjHeader; - - cb.markReaderIndex(); - rsvpErrSpecObjHeader = PcepRsvpSpecObjHeader.read(cb); - cb.resetReaderIndex(); - - if (PcepRsvpIpv4ErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum() - && PcepRsvpIpv4ErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) { - rsvpErrSpecObj = PcepRsvpIpv4ErrorSpec.read(cb); - } else if (PcepRsvpIpv6ErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum() - && PcepRsvpIpv6ErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) { - rsvpErrSpecObj = PcepRsvpIpv6ErrorSpec.read(cb); - } else if (PcepRsvpUserErrorSpec.CLASS_NUM == rsvpErrSpecObjHeader.getObjClassNum() - && PcepRsvpUserErrorSpec.CLASS_TYPE == rsvpErrSpecObjHeader.getObjClassType()) { - rsvpErrSpecObj = PcepRsvpUserErrorSpec.read(cb); - } - return new StatefulRsvpErrorSpecTlv(rsvpErrSpecObj); - } - - @Override - public int hashCode() { - return Objects.hash(rsvpErrSpecObj.hashCode()); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof StatefulRsvpErrorSpecTlv) { - StatefulRsvpErrorSpecTlv other = (StatefulRsvpErrorSpecTlv) obj; - return Objects.equals(this.rsvpErrSpecObj, other.rsvpErrSpecObj); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iStartIndex = c.writerIndex(); - c.writeShort(TYPE); - int tlvLenIndex = c.writerIndex(); - hLength = 0; - c.writeShort(hLength); - if (isErrSpceObjSet) { - rsvpErrSpecObj.write(c); - } - hLength = (short) (c.writerIndex() - iStartIndex); - c.setShort(tlvLenIndex, (hLength - OBJECT_HEADER_LENGTH)); - - return c.writerIndex() - iStartIndex; - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .omitNullValues() - .add("Type", TYPE) - .add("Length", hLength) - .add("RSVPErrorSpecObject", rsvpErrSpecObj) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/SymbolicPathNameTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/SymbolicPathNameTlv.java deleted file mode 100644 index 27cf56a6..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/SymbolicPathNameTlv.java +++ /dev/null @@ -1,159 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides SymbolicPathNameTlv. - */ -public class SymbolicPathNameTlv implements PcepValueType { - - /* - * SYMBOLIC-PATH-NAME TLV format - * Reference :PCEP Extensions for Stateful PCE draft-ietf-pce-stateful-pce-10 - * - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=17 | Length (variable) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Symbolic Path Name // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - protected static final Logger log = LoggerFactory.getLogger(SymbolicPathNameTlv.class); - - public static final short TYPE = 17; - private short hLength; - - private final byte[] rawValue; - - /** - * Constructor to initialize raw Value. - * - * @param rawValue Symbolic path name - */ - public SymbolicPathNameTlv(byte[] rawValue) { - this.rawValue = rawValue; - this.hLength = (short) rawValue.length; - } - - /** - * Constructor to initialize raw Value. - * - * @param rawValue Symbolic path name - * @param hLength length of Symbolic path name - */ - public SymbolicPathNameTlv(byte[] rawValue, short hLength) { - this.rawValue = rawValue; - if (0 == hLength) { - this.hLength = (short) rawValue.length; - } else { - this.hLength = hLength; - } - } - - /** - * Creates an object of SymbolicPathNameTlv. - * - * @param raw Symbolic path name - * @param hLength length of Symbolic path name - * @return object of SymbolicPathNameTlv - */ - public static SymbolicPathNameTlv of(final byte[] raw, short hLength) { - return new SymbolicPathNameTlv(raw, hLength); - } - - /** - * Returns Symbolic path name. - * - * @return Symbolic path name byte array - */ - public byte[] getValue() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof SymbolicPathNameTlv) { - SymbolicPathNameTlv other = (SymbolicPathNameTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(hLength); - c.writeBytes(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads channel buffer and returns object of SymbolicPathNameTlv. - * - * @param c of type channel buffer - * @param hLength length of bytes to read - * @return object of SymbolicPathNameTlv - */ - public static SymbolicPathNameTlv read(ChannelBuffer c, short hLength) { - byte[] symbolicPathName = new byte[hLength]; - c.readBytes(symbolicPathName, 0, hLength); - return new SymbolicPathNameTlv(symbolicPathName, hLength); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("SymbolicPathName ", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TEDefaultMetricTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TEDefaultMetricTlv.java deleted file mode 100644 index 4429d223..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TEDefaultMetricTlv.java +++ /dev/null @@ -1,137 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides TEDefaultMetricTlv. - */ -public class TEDefaultMetricTlv implements PcepValueType { - - /* - * Reference :| [I-D.ietf-idr- ls-distribution] /3.3.2.3 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=TDB37 | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | TE Default Link Metric | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - protected static final Logger log = LoggerFactory.getLogger(TEDefaultMetricTlv.class); - - public static final short TYPE = 13400; //TDB37 - public static final short LENGTH = 4; - - private final int rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue TE Default Link Metric - */ - public TEDefaultMetricTlv(int rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns newly created TEDefaultMetricTlv object. - * - * @param raw raw value - * @return object of TEDefaultMetricTlv. - */ - public static TEDefaultMetricTlv of(final int raw) { - return new TEDefaultMetricTlv(raw); - } - - /** - * Returns raw value. - * - * @return rawValue TE Default Link Metric - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof TEDefaultMetricTlv) { - TEDefaultMetricTlv other = (TEDefaultMetricTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads channel buffer and returns object of TEDefaultMetricTlv. - * - * @param c input channel buffer - * @return object of TEDefaultMetricTlv - */ - public static TEDefaultMetricTlv read(ChannelBuffer c) { - return TEDefaultMetricTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TELinkAttributesTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TELinkAttributesTlv.java deleted file mode 100644 index b3b71aef..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TELinkAttributesTlv.java +++ /dev/null @@ -1,292 +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.pcepio.types; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.ListIterator; -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides TELinkAttributesTlv. - */ -public class TELinkAttributesTlv implements PcepValueType { - - /* - * Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD27] | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Link Attributes Sub-TLVs (variable) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(TELinkAttributesTlv.class); - - public static final short TYPE = 1897; //TODD:change this TBD27 - public short hLength; - - public static final int TLV_HEADER_LENGTH = 4; - - // LinkDescriptors Sub-TLVs (variable) - private LinkedList<PcepValueType> llLinkAttributesSubTLVs; - - /** - * Constructor to initialize Link Attributes Sub TLVs. - * - * @param llLinkAttributesSubTLVs linked list of PcepValueType - */ - public TELinkAttributesTlv(LinkedList<PcepValueType> llLinkAttributesSubTLVs) { - this.llLinkAttributesSubTLVs = llLinkAttributesSubTLVs; - } - - /** - * Returns object of TE Link Attributes TLV. - * - * @param llLinkAttributesSubTLVs linked list of Link Attribute of Sub TLV - * @return object of TELinkAttributesTlv - */ - public static TELinkAttributesTlv of(final LinkedList<PcepValueType> llLinkAttributesSubTLVs) { - return new TELinkAttributesTlv(llLinkAttributesSubTLVs); - } - - /** - * Returns linked list of Link Attribute of Sub TLV. - * - * @return llLinkAttributesSubTLVs linked list of Link Attribute of Sub TLV - */ - public LinkedList<PcepValueType> getllLinkAttributesSubTLVs() { - return llLinkAttributesSubTLVs; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(llLinkAttributesSubTLVs.hashCode()); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - /* - * Here we have a list of Tlv so to compare each sub tlv between the object - * we have to take a list iterator so one by one we can get each sub tlv object - * and can compare them. - * it may be possible that the size of 2 lists is not equal so we have to first check - * the size, if both are same then we should check for the subtlv objects otherwise - * we should return false. - */ - if (obj instanceof TELinkAttributesTlv) { - int countObjSubTlv = 0; - int countOtherSubTlv = 0; - boolean isCommonSubTlv = true; - TELinkAttributesTlv other = (TELinkAttributesTlv) obj; - Iterator<PcepValueType> objListIterator = ((TELinkAttributesTlv) obj).llLinkAttributesSubTLVs.iterator(); - countObjSubTlv = ((TELinkAttributesTlv) obj).llLinkAttributesSubTLVs.size(); - countOtherSubTlv = other.llLinkAttributesSubTLVs.size(); - if (countObjSubTlv != countOtherSubTlv) { - return false; - } else { - while (objListIterator.hasNext() && isCommonSubTlv) { - PcepValueType subTlv = objListIterator.next(); - isCommonSubTlv = Objects.equals(llLinkAttributesSubTLVs.contains(subTlv), - other.llLinkAttributesSubTLVs.contains(subTlv)); - } - return isCommonSubTlv; - } - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int tlvStartIndex = c.writerIndex(); - c.writeShort(TYPE); - int tlvLenIndex = c.writerIndex(); - hLength = 0; - c.writeShort(hLength); - - ListIterator<PcepValueType> listIterator = llLinkAttributesSubTLVs.listIterator(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - if (tlv == null) { - log.debug("TLV is null from subTlv list"); - continue; - } - tlv.write(c); - - // need to take care of padding - int pad = tlv.getLength() % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - c.writeByte((byte) 0); - } - } - } - - hLength = (short) (c.writerIndex() - tlvStartIndex); - c.setShort(tlvLenIndex, (hLength - TLV_HEADER_LENGTH)); - - return c.writerIndex() - tlvStartIndex; - } - - /** - * Reads channel buffer and returns object of TE Link Attributes TLV. - * - * @param c input channel buffer - * @param hLength length - * @return object of TELinkAttributesTlv - * @throws PcepParseException if mandatory fields are missing - */ - public static PcepValueType read(ChannelBuffer c, short hLength) throws PcepParseException { - - // Node Descriptor Sub-TLVs (variable) - LinkedList<PcepValueType> llLinkAttributesSubTLVs = new LinkedList<>(); - - ChannelBuffer tempCb = c.readBytes(hLength); - - while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) { - - PcepValueType tlv; - short hType = tempCb.readShort(); - int iValue = 0; - short length = tempCb.readShort(); - switch (hType) { - - case IPv4TERouterIdOfLocalNodeTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new IPv4TERouterIdOfLocalNodeTlv(iValue); - break; - case IPv6TERouterIdofLocalNodeTlv.TYPE: - byte[] ipv6LValue = new byte[IPv6TERouterIdofLocalNodeTlv.VALUE_LENGTH]; - tempCb.readBytes(ipv6LValue, 0, IPv6TERouterIdofLocalNodeTlv.VALUE_LENGTH); - tlv = new IPv6TERouterIdofLocalNodeTlv(ipv6LValue); - break; - case IPv4TERouterIdOfRemoteNodeTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new IPv4TERouterIdOfRemoteNodeTlv(iValue); - break; - case IPv6TERouterIdofRemoteNodeTlv.TYPE: - byte[] ipv6RValue = new byte[IPv6TERouterIdofRemoteNodeTlv.VALUE_LENGTH]; - tempCb.readBytes(ipv6RValue, 0, IPv6TERouterIdofRemoteNodeTlv.VALUE_LENGTH); - tlv = new IPv6TERouterIdofRemoteNodeTlv(ipv6RValue); - break; - case LinkLocalRemoteIdentifiersTlv.TYPE: - tlv = LinkLocalRemoteIdentifiersTlv.read(tempCb); - break; - case AdministrativeGroupTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new AdministrativeGroupTlv(iValue); - break; - case MaximumLinkBandwidthTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new MaximumLinkBandwidthTlv(iValue); - break; - case MaximumReservableLinkBandwidthTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new MaximumReservableLinkBandwidthTlv(iValue); - break; - case UnreservedBandwidthTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new UnreservedBandwidthTlv(iValue); - break; - case TEDefaultMetricTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new TEDefaultMetricTlv(iValue); - break; - case LinkProtectionTypeTlv.TYPE: - tlv = LinkProtectionTypeTlv.read(tempCb); - break; - case MPLSProtocolMaskTlv.TYPE: - byte cValue = tempCb.readByte(); - tlv = new MPLSProtocolMaskTlv(cValue); - break; - case IGPMetricTlv.TYPE: - tlv = IGPMetricTlv.read(tempCb, length); - break; - case SharedRiskLinkGroupTlv.TYPE: - tlv = SharedRiskLinkGroupTlv.read(tempCb, length); - break; - case OpaqueLinkAttributeTlv.TYPE: - tlv = OpaqueLinkAttributeTlv.read(tempCb, length); - break; - case LinkNameTlv.TYPE: - tlv = LinkNameTlv.read(tempCb, length); - break; - default: - throw new PcepParseException("Unsupported Sub TLV type :" + hType); - } - - // Check for the padding - int pad = length % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= tempCb.readableBytes()) { - tempCb.skipBytes(pad); - } - } - llLinkAttributesSubTLVs.add(tlv); - } - - if (0 < tempCb.readableBytes()) { - - throw new PcepParseException("Sub Tlv parsing error. Extra bytes received."); - } - - return new TELinkAttributesTlv(llLinkAttributesSubTLVs); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", hLength) - .add("LinkAttributesSubTLVs", llLinkAttributesSubTLVs) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TELinkDescriptorsTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TELinkDescriptorsTlv.java deleted file mode 100644 index b974cf82..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TELinkDescriptorsTlv.java +++ /dev/null @@ -1,251 +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.pcepio.types; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.ListIterator; -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides TE Link Descriptors TLV. - */ -public class TELinkDescriptorsTlv implements PcepValueType { - - /* - * Reference: PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD14] | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Link Descriptor Sub-TLVs (variable) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - */ - - protected static final Logger log = LoggerFactory.getLogger(TELinkDescriptorsTlv.class); - - public static final short TYPE = 1070; //TODD:change this TBD14 - public short hLength; - - public static final int TLV_HEADER_LENGTH = 4; - - // LinkDescriptors Sub-TLVs (variable) - private LinkedList<PcepValueType> llLinkDescriptorsSubTLVs; - - /** - * Constructor to initialize llLinkDescriptorsSubTLVs. - * - * @param llLinkDescriptorsSubTLVs of PcepValueType - */ - public TELinkDescriptorsTlv(LinkedList<PcepValueType> llLinkDescriptorsSubTLVs) { - this.llLinkDescriptorsSubTLVs = llLinkDescriptorsSubTLVs; - } - - /** - * Returns object of TELinkDescriptorsTLV. - * - * @param llLinkDescriptorsSubTLVs of PcepValueType - * @return object of TELinkDescriptorsTLV - */ - public static TELinkDescriptorsTlv of(final LinkedList<PcepValueType> llLinkDescriptorsSubTLVs) { - return new TELinkDescriptorsTlv(llLinkDescriptorsSubTLVs); - } - - /** - * Returns linked list of Link Attribute of Sub TLV. - * - * @return llLinkDescriptorsSubTLVs linked list of Link Attribute of Sub TLV - */ - public LinkedList<PcepValueType> getllLinkDescriptorsSubTLVs() { - return llLinkDescriptorsSubTLVs; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(llLinkDescriptorsSubTLVs.hashCode()); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - /* - * Here we have a list of Tlv so to compare each sub tlv between the object - * we have to take a list iterator so one by one we can get each sub tlv object - * and can compare them. - * it may be possible that the size of 2 lists is not equal so we have to first check - * the size, if both are same then we should check for the subtlv objects otherwise - * we should return false. - */ - if (obj instanceof TELinkDescriptorsTlv) { - int countObjSubTlv = 0; - int countOtherSubTlv = 0; - boolean isCommonSubTlv = true; - TELinkDescriptorsTlv other = (TELinkDescriptorsTlv) obj; - Iterator<PcepValueType> objListIterator = ((TELinkDescriptorsTlv) obj).llLinkDescriptorsSubTLVs.iterator(); - countObjSubTlv = ((TELinkDescriptorsTlv) obj).llLinkDescriptorsSubTLVs.size(); - countOtherSubTlv = other.llLinkDescriptorsSubTLVs.size(); - if (countObjSubTlv != countOtherSubTlv) { - return false; - } else { - while (objListIterator.hasNext() && isCommonSubTlv) { - PcepValueType subTlv = objListIterator.next(); - isCommonSubTlv = Objects.equals(llLinkDescriptorsSubTLVs.contains(subTlv), - other.llLinkDescriptorsSubTLVs.contains(subTlv)); - } - return isCommonSubTlv; - } - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int tlvStartIndex = c.writerIndex(); - c.writeShort(TYPE); - int tlvLenIndex = c.writerIndex(); - hLength = 0; - c.writeShort(hLength); - - ListIterator<PcepValueType> listIterator = llLinkDescriptorsSubTLVs.listIterator(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - tlv.write(c); - - // need to take care of padding - int pad = tlv.getLength() % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - c.writeByte((byte) 0); - } - } - } - - hLength = (short) (c.writerIndex() - tlvStartIndex); - c.setShort(tlvLenIndex, (hLength - TLV_HEADER_LENGTH)); - - return c.writerIndex() - tlvStartIndex; - } - - /** - * Reads channel buffer and returns object of TELinkDescriptorsTLV. - * - * @param c input channel buffer - * @param length length - * @return object of TELinkDescriptorsTLV - * @throws PcepParseException if mandatory fields are missing - */ - public static PcepValueType read(ChannelBuffer c, short length) throws PcepParseException { - - // Node Descriptor Sub-TLVs (variable) - LinkedList<PcepValueType> llLinkDescriptorsSubTLVs = new LinkedList<>(); - - ChannelBuffer tempCb = c.readBytes(length); - - while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) { - - PcepValueType tlv; - short hType = tempCb.readShort(); - int iValue = 0; - short hLength = tempCb.readShort(); - log.debug("sub Tlv Length" + hLength); - switch (hType) { - - case LinkLocalRemoteIdentifiersTlv.TYPE: - tlv = LinkLocalRemoteIdentifiersTlv.read(tempCb); - break; - case IPv4InterfaceAddressTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new IPv4InterfaceAddressTlv(iValue); - break; - case IPv4NeighborAddressTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new IPv4NeighborAddressTlv(iValue); - break; - case IPv6InterfaceAddressTlv.TYPE: - byte[] ipv6Value = new byte[IPv6InterfaceAddressTlv.VALUE_LENGTH]; - tempCb.readBytes(ipv6Value, 0, IPv6InterfaceAddressTlv.VALUE_LENGTH); - tlv = new IPv6InterfaceAddressTlv(ipv6Value); - break; - case IPv6NeighborAddressTlv.TYPE: - byte[] ipv6NeighborAdd = new byte[IPv6NeighborAddressTlv.VALUE_LENGTH]; - tempCb.readBytes(ipv6NeighborAdd, 0, IPv6NeighborAddressTlv.VALUE_LENGTH); - tlv = new IPv6NeighborAddressTlv(ipv6NeighborAdd); - break; - default: - throw new PcepParseException("Unsupported Sub TLV type:" + hType); - } - - // Check for the padding - int pad = hLength % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= tempCb.readableBytes()) { - tempCb.skipBytes(pad); - } - } - llLinkDescriptorsSubTLVs.add(tlv); - - } - - if (0 < tempCb.readableBytes()) { - - throw new PcepParseException("Sub Tlv parsing error. Extra bytes received."); - } - return new TELinkDescriptorsTlv(llLinkDescriptorsSubTLVs); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", hLength) - .add("LinkDescriptorsSubTLVs", llLinkDescriptorsSubTLVs) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TENodeAttributesTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TENodeAttributesTlv.java deleted file mode 100644 index f18b75b2..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TENodeAttributesTlv.java +++ /dev/null @@ -1,250 +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.pcepio.types; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.ListIterator; -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides TE Node Attributes Tlv. - */ -public class TENodeAttributesTlv implements PcepValueType { - /* - * Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02 - * - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD20] | Length | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - // Node Attributes Sub-TLVs (variable) // - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - - */ - - protected static final Logger log = LoggerFactory.getLogger(TENodeAttributesTlv.class); - - public static final short TYPE = 1267; //TODD:change this TBD20 - public short hLength; - - public static final int TLV_HEADER_LENGTH = 4; - // LinkDescriptors Sub-TLVs (variable) - private LinkedList<PcepValueType> llNodeAttributesSubTLVs; - - /** - * Constructor to initialize llNodeAttributesSubTLVs. - * - * @param llNodeAttributesSubTLVs linked list of Node Attributes Sub-TLVs - */ - public TENodeAttributesTlv(LinkedList<PcepValueType> llNodeAttributesSubTLVs) { - this.llNodeAttributesSubTLVs = llNodeAttributesSubTLVs; - } - - /** - * Returns object of TENodeAttributesTlv. - * - * @param llNodeAttributesSubTLVs LinkedList of PcepValueType - * @return object of TENodeAttributesTlv - */ - public static TENodeAttributesTlv of(LinkedList<PcepValueType> llNodeAttributesSubTLVs) { - return new TENodeAttributesTlv(llNodeAttributesSubTLVs); - } - - /** - * Returns Node Attributes Sub-TLVs. - * - * @return llNodeAttributesSubTLVs linked list of Node Attributes Sub-TLVs - */ - public LinkedList<PcepValueType> getllNodeAttributesSubTLVs() { - return llNodeAttributesSubTLVs; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return hLength; - } - - @Override - public int hashCode() { - return Objects.hash(llNodeAttributesSubTLVs.hashCode()); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - /* - * Here we have a list of Tlv so to compare each sub tlv between the object - * we have to take a list iterator so one by one we can get each sub tlv object - * and can compare them. - * it may be possible that the size of 2 lists is not equal so we have to first check - * the size, if both are same then we should check for the subtlv objects otherwise - * we should return false. - */ - if (obj instanceof TENodeAttributesTlv) { - int countObjSubTlv = 0; - int countOtherSubTlv = 0; - boolean isCommonSubTlv = true; - TENodeAttributesTlv other = (TENodeAttributesTlv) obj; - Iterator<PcepValueType> objListIterator = ((TENodeAttributesTlv) obj).llNodeAttributesSubTLVs.iterator(); - countObjSubTlv = ((TENodeAttributesTlv) obj).llNodeAttributesSubTLVs.size(); - countOtherSubTlv = other.llNodeAttributesSubTLVs.size(); - if (countObjSubTlv != countOtherSubTlv) { - return false; - } else { - while (objListIterator.hasNext() && isCommonSubTlv) { - PcepValueType subTlv = objListIterator.next(); - isCommonSubTlv = Objects.equals(llNodeAttributesSubTLVs.contains(subTlv), - other.llNodeAttributesSubTLVs.contains(subTlv)); - } - return isCommonSubTlv; - } - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int tlvStartIndex = c.writerIndex(); - c.writeShort(TYPE); - int tlvLenIndex = c.writerIndex(); - hLength = 0; - c.writeShort(hLength); - - ListIterator<PcepValueType> listIterator = llNodeAttributesSubTLVs.listIterator(); - - while (listIterator.hasNext()) { - PcepValueType tlv = listIterator.next(); - - tlv.write(c); - - // need to take care of padding - int pad = tlv.getLength() % 4; - - if (0 != pad) { - pad = 4 - pad; - for (int i = 0; i < pad; ++i) { - c.writeByte((byte) 0); - } - } - } - - hLength = (short) (c.writerIndex() - tlvStartIndex); - c.setShort(tlvLenIndex, (hLength - TLV_HEADER_LENGTH)); - - return c.writerIndex() - tlvStartIndex; - } - - /** - * Reads the channel buffer and returns object of TENodeAttributesTlv. - * - * @param c input channel buffer - * @param hLength length - * @return object of TENodeAttributesTlv - * @throws PcepParseException if mandatory fields are missing - */ - public static PcepValueType read(ChannelBuffer c, short hLength) throws PcepParseException { - - // Node Descriptor Sub-TLVs (variable) - LinkedList<PcepValueType> llNodeAttributesSubTLVs = new LinkedList<>(); - - ChannelBuffer tempCb = c.readBytes(hLength); - - while (TLV_HEADER_LENGTH <= tempCb.readableBytes()) { - PcepValueType tlv; - short hType = tempCb.readShort(); - int iValue = 0; - short length = tempCb.readShort(); - switch (hType) { - - case NodeFlagBitsTlv.TYPE: - byte cValue = tempCb.readByte(); - tlv = new NodeFlagBitsTlv(cValue); - break; - case OpaqueNodeAttributeTlv.TYPE: - tlv = OpaqueNodeAttributeTlv.read(tempCb, length); - break; - case NodeNameTlv.TYPE: - tlv = NodeNameTlv.read(tempCb, length); - break; - case ISISAreaIdentifierTlv.TYPE: - tlv = ISISAreaIdentifierTlv.read(tempCb, length); - break; - case IPv4TERouterIdOfLocalNodeTlv.TYPE: - iValue = tempCb.readInt(); - tlv = new IPv4TERouterIdOfLocalNodeTlv(iValue); - break; - case IPv6TERouterIdofLocalNodeTlv.TYPE: - byte[] ipv6Value = new byte[IPv6TERouterIdofLocalNodeTlv.VALUE_LENGTH]; - tempCb.readBytes(ipv6Value, 0, IPv6TERouterIdofLocalNodeTlv.VALUE_LENGTH); - tlv = new IPv6TERouterIdofLocalNodeTlv(ipv6Value); - break; - default: - throw new PcepParseException("Unsupported Sub TLV type :" + hType); - } - - // Check for the padding - int pad = length % 4; - if (0 < pad) { - pad = 4 - pad; - if (pad <= tempCb.readableBytes()) { - tempCb.skipBytes(pad); - } - } - - llNodeAttributesSubTLVs.add(tlv); - } - - if (0 < tempCb.readableBytes()) { - - throw new PcepParseException("Sub Tlv parsing error. Extra bytes received."); - } - return new TENodeAttributesTlv(llNodeAttributesSubTLVs); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", hLength) - .add("NodeAttributesSubTLVs", llNodeAttributesSubTLVs) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TedCapabilityTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TedCapabilityTlv.java deleted file mode 100644 index 189dcadc..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/TedCapabilityTlv.java +++ /dev/null @@ -1,181 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides TED Capability Tlv. - */ -public class TedCapabilityTlv implements PcepValueType { - - /* - * Reference :PCEP Extension for Transporting TE Data draft-dhodylee-pce-pcep-te-data-extn-02 - * 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TBD5] | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Flags |R| - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(TedCapabilityTlv.class); - - public static final short TYPE = 132; //TODO: need to change this TBD5 - public static final short LENGTH = 4; - public static final int SET = 1; - public static final byte RFLAG_CHECK = 0x01; - - private final boolean bRFlag; - private final int rawValue; - private final boolean isRawValueSet; - - /** - * Constructor to initialize raw Value. - * - * @param rawValue Flags - */ - public TedCapabilityTlv(final int rawValue) { - this.rawValue = rawValue; - this.isRawValueSet = true; - int temp = rawValue; - temp = temp & RFLAG_CHECK; - if (temp == SET) { - this.bRFlag = true; - } else { - this.bRFlag = false; - } - - } - - /** - * Constructor to initialize bRFlag. - * - * @param bRFlag R-flag - */ - public TedCapabilityTlv(boolean bRFlag) { - this.bRFlag = bRFlag; - this.rawValue = 0; - this.isRawValueSet = false; - } - - /** - * Returns R-flag. - * - * @return bRFlag - */ - public boolean getbRFlag() { - return bRFlag; - } - - /** - * Returns an object of TedCapabilityTlv. - * - * @param raw value Flags - * @return object of TedCapabilityTlv - */ - public static TedCapabilityTlv of(final int raw) { - return new TedCapabilityTlv(raw); - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - public int getInt() { - return rawValue; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - if (isRawValueSet) { - return Objects.hash(rawValue); - } else { - return Objects.hash(bRFlag); - } - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof TedCapabilityTlv) { - TedCapabilityTlv other = (TedCapabilityTlv) obj; - if (isRawValueSet) { - return Objects.equals(this.rawValue, other.rawValue); - } else { - return Objects.equals(this.bRFlag, other.bRFlag); - } - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iStartIndex = c.writerIndex(); - int temp = 0; - c.writeShort(TYPE); - c.writeShort(LENGTH); - if (isRawValueSet) { - c.writeInt(rawValue); - } else { - if (bRFlag) { - temp = temp | RFLAG_CHECK; - } - c.writeInt(temp); - } - return c.writerIndex() - iStartIndex; - } - - /** - * Reads channel buffer and returns object of TedCapabilityTlv. - * - * @param c input channel buffer - * @return object of TedCapabilityTlv - */ - public static TedCapabilityTlv read(ChannelBuffer c) { - return TedCapabilityTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/UnreservedBandwidthTlv.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/UnreservedBandwidthTlv.java deleted file mode 100644 index d44bf824..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/UnreservedBandwidthTlv.java +++ /dev/null @@ -1,136 +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.pcepio.types; - -import java.util.Objects; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.onosproject.pcepio.protocol.PcepVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.base.MoreObjects; - -/** - * Provides Unreserved Bandwidth Tlv. - */ -public class UnreservedBandwidthTlv implements PcepValueType { - - /* Reference :[RFC5305]/3.6 - 0 1 2 3 - 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Type=[TDB36] | Length=4 | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Unreserved Bandwidth | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - */ - - protected static final Logger log = LoggerFactory.getLogger(UnreservedBandwidthTlv.class); - - public static final short TYPE = 11; //TDB36 - public static final short LENGTH = 4; - - private final int rawValue; - - /** - * Constructor to initialize rawValue. - * - * @param rawValue Unreserved Bandwidth - */ - public UnreservedBandwidthTlv(int rawValue) { - this.rawValue = rawValue; - } - - /** - * Returns newly created UnreservedBandwidthTlv object. - * - * @param raw as Unreserved Bandwidth - * @return object of UnreservedBandwidthTlv - */ - public static UnreservedBandwidthTlv of(final int raw) { - return new UnreservedBandwidthTlv(raw); - } - - /** - * Returns Unreserved Bandwidth. - * - * @return rawValue Unreserved Bandwidth - */ - public int getInt() { - return rawValue; - } - - @Override - public PcepVersion getVersion() { - return PcepVersion.PCEP_1; - } - - @Override - public short getType() { - return TYPE; - } - - @Override - public short getLength() { - return LENGTH; - } - - @Override - public int hashCode() { - return Objects.hash(rawValue); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof UnreservedBandwidthTlv) { - UnreservedBandwidthTlv other = (UnreservedBandwidthTlv) obj; - return Objects.equals(this.rawValue, other.rawValue); - } - return false; - } - - @Override - public int write(ChannelBuffer c) { - int iLenStartIndex = c.writerIndex(); - c.writeShort(TYPE); - c.writeShort(LENGTH); - c.writeInt(rawValue); - return c.writerIndex() - iLenStartIndex; - } - - /** - * Reads byte stream from channel buffer and returns object of UnreservedBandwidthTlv. - * - * @param c input channel buffer - * @return object of UnreservedBandwidthTlv - */ - public static UnreservedBandwidthTlv read(ChannelBuffer c) { - return UnreservedBandwidthTlv.of(c.readInt()); - } - - @Override - public String toString() { - return MoreObjects.toStringHelper(getClass()) - .add("Type", TYPE) - .add("Length", LENGTH) - .add("Value", rawValue) - .toString(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/package-info.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/package-info.java deleted file mode 100644 index 12744de1..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/types/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. - */ - -/** - * Implementation of Tlvs and Pcep common objects. - */ -package org.onosproject.pcepio.types; diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/util/HexDump.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/util/HexDump.java deleted file mode 100644 index c39f606b..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/util/HexDump.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.pcepio.util; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Provides Hex Dump for debugging. - */ -public final class HexDump { - protected static final Logger log = LoggerFactory.getLogger(HexDump.class); - - private HexDump() { - } - - public static void pcepHexDump(ChannelBuffer buff) { - - log.debug("==================== HEX DUMP ======================"); - try { - byte[] yTemp; - yTemp = buff.array(); - - int iStartIndex = buff.readerIndex(); - int iEndIndex = buff.writerIndex(); - do { - StringBuilder sb = new StringBuilder(); - for (int k = 0; (k < 16) && (iStartIndex < iEndIndex); ++k) { - if (0 == k % 4) { - sb.append(String.format(" ")); //blank after 4 bytes - } - sb.append(String.format("%02X ", yTemp[iStartIndex++])); - } - log.debug(sb.toString()); - } while (iStartIndex < iEndIndex); - } catch (Exception e) { - log.error("[HexDump] Invalid buffer: " + e.toString()); - } - - log.debug("==================================================="); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/util/package-info.java b/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/util/package-info.java deleted file mode 100644 index b3756ffe..00000000 --- a/framework/src/onos/pcep/pcepio/src/main/java/org/onosproject/pcepio/util/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. - */ - -/** - * Provides utility functionality for PCEP messages. - */ -package org.onosproject.pcepio.util; diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IGPMetricTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IGPMetricTlvTest.java deleted file mode 100644 index 583b7049..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IGPMetricTlvTest.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.pcepio; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.pcepio.types.IGPMetricTlv; - -/** - * Test of the IGPMetricTlv. - */ -public class IGPMetricTlvTest { - private final byte[] b1 = new byte[] {0x01, 0x02}; - private final byte[] b2 = new byte[] {0x01, 0x02}; - private final IGPMetricTlv tlv1 = IGPMetricTlv.of(b1, (short) 2); - private final IGPMetricTlv sameAsTlv1 = IGPMetricTlv.of(b1, (short) 2); - private final IGPMetricTlv tlv2 = IGPMetricTlv.of(b2, (short) 2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4NeighborAddressTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4NeighborAddressTlvTest.java deleted file mode 100644 index 60a4f120..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4NeighborAddressTlvTest.java +++ /dev/null @@ -1,39 +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.pcepio; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.pcepio.types.IPv4NeighborAddressTlv; - -/** - * Test of the IPv4NeighborAddressTlv. - */ -public class IPv4NeighborAddressTlvTest { - - private final IPv4NeighborAddressTlv tlv1 = IPv4NeighborAddressTlv.of(2); - private final IPv4NeighborAddressTlv sameAsTlv1 = IPv4NeighborAddressTlv.of(2); - private final IPv4NeighborAddressTlv tlv2 = IPv4NeighborAddressTlv.of(3); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4SubObjectTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4SubObjectTest.java deleted file mode 100644 index 08b49879..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4SubObjectTest.java +++ /dev/null @@ -1,39 +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.pcepio; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.pcepio.types.IPv4SubObject; - -/** - * Test of the IPv4SubObject. - */ -public class IPv4SubObjectTest { - - private final IPv4SubObject subObj1 = IPv4SubObject.of(2, (byte) 16, (byte) 0); - private final IPv4SubObject sameAsSubObj1 = IPv4SubObject.of(2, (byte) 16, (byte) 0); - private final IPv4SubObject subObj2 = IPv4SubObject.of(3, (byte) 16, (byte) 0); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(subObj1, sameAsSubObj1) - .addEqualityGroup(subObj2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4TERouterIdOfLocalNodeTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4TERouterIdOfLocalNodeTlvTest.java deleted file mode 100644 index d04be239..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4TERouterIdOfLocalNodeTlvTest.java +++ /dev/null @@ -1,39 +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.pcepio; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.pcepio.types.IPv4TERouterIdOfLocalNodeTlv; - -/** - * Test of the IPv4TERouterIdOfLocalNodeTlv. - */ -public class IPv4TERouterIdOfLocalNodeTlvTest { - - private final IPv4TERouterIdOfLocalNodeTlv tlv1 = IPv4TERouterIdOfLocalNodeTlv.of(2); - private final IPv4TERouterIdOfLocalNodeTlv sameAsTlv1 = IPv4TERouterIdOfLocalNodeTlv.of(2); - private final IPv4TERouterIdOfLocalNodeTlv tlv2 = IPv4TERouterIdOfLocalNodeTlv.of(3); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4TERouterIdOfRemoteNodeTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4TERouterIdOfRemoteNodeTlvTest.java deleted file mode 100644 index fb8c9653..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv4TERouterIdOfRemoteNodeTlvTest.java +++ /dev/null @@ -1,39 +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.pcepio; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.pcepio.types.IPv4TERouterIdOfRemoteNodeTlv; - -/** - * Test of the IPv4TERouterIdOfRemoteNodeTlv. - */ -public class IPv4TERouterIdOfRemoteNodeTlvTest { - - private final IPv4TERouterIdOfRemoteNodeTlv tlv1 = IPv4TERouterIdOfRemoteNodeTlv.of(2); - private final IPv4TERouterIdOfRemoteNodeTlv sameAsTlv1 = IPv4TERouterIdOfRemoteNodeTlv.of(2); - private final IPv4TERouterIdOfRemoteNodeTlv tlv2 = IPv4TERouterIdOfRemoteNodeTlv.of(3); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6InterfaceAddressTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6InterfaceAddressTlvTest.java deleted file mode 100644 index 6eb771da..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6InterfaceAddressTlvTest.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.pcepio; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.pcepio.types.IPv6InterfaceAddressTlv; - -/** - * Test of the IPv6InterfaceAddressTlv. - */ -public class IPv6InterfaceAddressTlvTest { - - private final byte[] b1 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x29, 0x00, 0x02, 0x00, 0x00}; - private final byte[] b2 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x30, 0x00, 0x02, 0x00, 0x00 }; - - private final IPv6InterfaceAddressTlv tlv1 = IPv6InterfaceAddressTlv.of(b1); - private final IPv6InterfaceAddressTlv sameAsTlv1 = IPv6InterfaceAddressTlv.of(b1); - private final IPv6InterfaceAddressTlv tlv2 = IPv6InterfaceAddressTlv.of(b2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6NeighborAddressTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6NeighborAddressTlvTest.java deleted file mode 100644 index 17fa9a3b..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6NeighborAddressTlvTest.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.pcepio; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.pcepio.types.IPv6NeighborAddressTlv; - -/** - * Test of the IPv6NeighborAddressTlv. - */ -public class IPv6NeighborAddressTlvTest { - - private final byte[] b1 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x29, 0x00, 0x02, 0x00, 0x00}; - private final byte[] b2 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x30, 0x00, 0x02, 0x00, 0x00 }; - - private final IPv6NeighborAddressTlv tlv1 = IPv6NeighborAddressTlv.of(b1); - private final IPv6NeighborAddressTlv sameAsTlv1 = IPv6NeighborAddressTlv.of(b1); - private final IPv6NeighborAddressTlv tlv2 = IPv6NeighborAddressTlv.of(b2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6SubObjectTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6SubObjectTest.java deleted file mode 100644 index 08a47237..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6SubObjectTest.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.pcepio; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.pcepio.types.IPv6SubObject; - -/** - * Test of the IPv6SubObject. - */ -public class IPv6SubObjectTest { - - private final byte[] b1 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x29, 0x00, 0x02, 0x00, 0x00}; - private final byte[] b2 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x30, 0x00, 0x02, 0x00, 0x00 }; - - private final IPv6SubObject subObj1 = IPv6SubObject.of(b1); - private final IPv6SubObject sameAsSubObj1 = IPv6SubObject.of(b1); - private final IPv6SubObject subObj2 = IPv6SubObject.of(b2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(subObj1, sameAsSubObj1).addEqualityGroup(subObj2).testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6TERouterIdofLocalNodeTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6TERouterIdofLocalNodeTlvTest.java deleted file mode 100644 index b37cb3d8..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6TERouterIdofLocalNodeTlvTest.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.pcepio; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.pcepio.types.IPv6TERouterIdofLocalNodeTlv; - -/** - * Test of the IPv6TERouterIdofLocalNodeTlv. - */ -public class IPv6TERouterIdofLocalNodeTlvTest { - - private final byte[] b1 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x29, 0x00, 0x02, 0x00, 0x00}; - private final byte[] b2 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x30, 0x00, 0x02, 0x00, 0x00 }; - - private final IPv6TERouterIdofLocalNodeTlv tlv1 = IPv6TERouterIdofLocalNodeTlv.of(b1); - private final IPv6TERouterIdofLocalNodeTlv sameAsTlv1 = IPv6TERouterIdofLocalNodeTlv.of(b1); - private final IPv6TERouterIdofLocalNodeTlv tlv2 = IPv6TERouterIdofLocalNodeTlv.of(b2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6TERouterIdofRemoteNodeTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6TERouterIdofRemoteNodeTlvTest.java deleted file mode 100644 index e572e358..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/IPv6TERouterIdofRemoteNodeTlvTest.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.pcepio; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.pcepio.types.IPv6TERouterIdofRemoteNodeTlv; - -/** - * Test of the IPv6TERouterIdofRemoteNodeTlv. - */ -public class IPv6TERouterIdofRemoteNodeTlvTest { - - private final byte[] b1 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x29, 0x00, 0x02, 0x00, 0x00}; - private final byte[] b2 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x30, 0x00, 0x02, 0x00, 0x00 }; - - private final IPv6TERouterIdofRemoteNodeTlv tlv1 = IPv6TERouterIdofRemoteNodeTlv.of(b1); - private final IPv6TERouterIdofRemoteNodeTlv sameAsTlv1 = IPv6TERouterIdofRemoteNodeTlv.of(b1); - private final IPv6TERouterIdofRemoteNodeTlv tlv2 = IPv6TERouterIdofRemoteNodeTlv.of(b2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/ISISAreaIdentifierTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/ISISAreaIdentifierTlvTest.java deleted file mode 100644 index 7bea1a9b..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/ISISAreaIdentifierTlvTest.java +++ /dev/null @@ -1,42 +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.pcepio; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.pcepio.types.ISISAreaIdentifierTlv; - -/** - * Test of the ISISAreaIdentifierTlv. - */ -public class ISISAreaIdentifierTlvTest { - - private final byte[] b1 = new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; - private final byte[] b2 = new byte[] {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; - - private final ISISAreaIdentifierTlv tlv1 = ISISAreaIdentifierTlv.of(b1, (short) 20); - private final ISISAreaIdentifierTlv sameAsTlv1 = ISISAreaIdentifierTlv.of(b1, (short) 20); - private final ISISAreaIdentifierTlv tlv2 = ISISAreaIdentifierTlv.of(b2, (short) 20); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LabelSubObjectTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LabelSubObjectTest.java deleted file mode 100644 index 41d1f4ba..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LabelSubObjectTest.java +++ /dev/null @@ -1,39 +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.pcepio; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; -import org.onosproject.pcepio.types.LabelSubObject; - -/** - * Test of the LabelSubObject. - */ -public class LabelSubObjectTest { - - private final LabelSubObject subObj1 = LabelSubObject.of((byte) 0, (byte) 1, 20); - private final LabelSubObject sameAsSubObj1 = LabelSubObject.of((byte) 0, (byte) 1, 20); - private final LabelSubObject subObj2 = LabelSubObject.of((byte) 0, (byte) 1, 30); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(subObj1, sameAsSubObj1) - .addEqualityGroup(subObj2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LinkNameTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LinkNameTlvTest.java deleted file mode 100644 index 5236be9d..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LinkNameTlvTest.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.LinkNameTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Equality test for LinkNameTlv. - */ -public class LinkNameTlvTest { - private final byte[] rawValue1 = new byte[] {0x01, 0x00}; - private final byte[] rawValue2 = new byte[] {0x02, 0x00}; - - private final LinkNameTlv tlv1 = new LinkNameTlv(rawValue1, (short) rawValue1.length); - private final LinkNameTlv sameAsTlv1 = LinkNameTlv.of(tlv1.getValue(), tlv1.getLength()); - private final LinkNameTlv tlv2 = new LinkNameTlv(rawValue2, (short) 0); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LinkProtectionTypeTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LinkProtectionTypeTlvTest.java deleted file mode 100644 index 4eea1b00..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LinkProtectionTypeTlvTest.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.LinkProtectionTypeTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test of the LinkProtectionTypeTlv. - */ -public class LinkProtectionTypeTlvTest { - private final byte rawValue1 = 0x0A; - private final byte rawValue2 = 0x0B; - - private final LinkProtectionTypeTlv tlv1 = new LinkProtectionTypeTlv(rawValue1); - private final LinkProtectionTypeTlv sameAsTlv1 = new LinkProtectionTypeTlv(rawValue1); - private final LinkProtectionTypeTlv tlv2 = new LinkProtectionTypeTlv(rawValue2, (byte) 0); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LocalTENodeDescriptorsTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LocalTENodeDescriptorsTlvTest.java deleted file mode 100644 index 3311a96c..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/LocalTENodeDescriptorsTlvTest.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.pcepio; - -import com.google.common.testing.EqualsTester; - -import org.junit.Test; - -import java.util.LinkedList; - -import org.onosproject.pcepio.types.LocalTENodeDescriptorsTlv; -import org.onosproject.pcepio.types.AutonomousSystemTlv; -import org.onosproject.pcepio.types.BGPLSidentifierTlv; -import org.onosproject.pcepio.types.PcepValueType; - -/** - * Test of the LocalTENodeDescriptorsTlv. - */ -public class LocalTENodeDescriptorsTlvTest { - - private final AutonomousSystemTlv baAutoSysTlvRawValue1 = new AutonomousSystemTlv(1); - private final BGPLSidentifierTlv baBgplsIdRawValue1 = new BGPLSidentifierTlv(1); - - private final AutonomousSystemTlv baAutoSysTlvRawValue2 = new AutonomousSystemTlv(2); - private final BGPLSidentifierTlv baBgplsIdRawValue2 = new BGPLSidentifierTlv(2); - - private final LinkedList<PcepValueType> llNodeDescriptorSubTLVs1 = new LinkedList<PcepValueType>(); - private final boolean a = llNodeDescriptorSubTLVs1.add(baAutoSysTlvRawValue1); - private final boolean b = llNodeDescriptorSubTLVs1.add(baBgplsIdRawValue1); - - private final LinkedList<PcepValueType> llNodeDescriptorSubTLVs2 = new LinkedList<PcepValueType>(); - private final boolean c = llNodeDescriptorSubTLVs2.add(baAutoSysTlvRawValue2); - private final boolean d = llNodeDescriptorSubTLVs2.add(baBgplsIdRawValue2); - - private final LocalTENodeDescriptorsTlv tlv1 = LocalTENodeDescriptorsTlv.of(llNodeDescriptorSubTLVs1); - private final LocalTENodeDescriptorsTlv sameAstlv1 = LocalTENodeDescriptorsTlv.of(llNodeDescriptorSubTLVs1); - private final LocalTENodeDescriptorsTlv tlv2 = LocalTENodeDescriptorsTlv.of(llNodeDescriptorSubTLVs2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, sameAstlv1).addEqualityGroup(tlv2).testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/MPLSProtocolMaskTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/MPLSProtocolMaskTlvTest.java deleted file mode 100644 index eda99a38..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/MPLSProtocolMaskTlvTest.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.MPLSProtocolMaskTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test of the MPLSProtocolMaskTlv. - */ -public class MPLSProtocolMaskTlvTest { - private final byte rawValue1 = 0x0A; - private final byte rawValue2 = 0x0B; - - private final MPLSProtocolMaskTlv tlv1 = new MPLSProtocolMaskTlv(rawValue1); - private final MPLSProtocolMaskTlv sameAsTlv1 = new MPLSProtocolMaskTlv(rawValue1); - private final MPLSProtocolMaskTlv tlv2 = MPLSProtocolMaskTlv.of(rawValue2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/MaximumLinkBandwidthTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/MaximumLinkBandwidthTlvTest.java deleted file mode 100644 index 50902acb..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/MaximumLinkBandwidthTlvTest.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.MaximumLinkBandwidthTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test of the MaximumLinkBandwidthTlv. - */ -public class MaximumLinkBandwidthTlvTest { - private final int rawValue1 = 0x0A; - private final int rawValue2 = 0x0B; - - private final MaximumLinkBandwidthTlv tlv1 = new MaximumLinkBandwidthTlv(rawValue1); - private final MaximumLinkBandwidthTlv sameAsTlv1 = new MaximumLinkBandwidthTlv(rawValue1); - private final MaximumLinkBandwidthTlv tlv2 = MaximumLinkBandwidthTlv.of(rawValue2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/MaximumReservableLinkBandwidthTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/MaximumReservableLinkBandwidthTlvTest.java deleted file mode 100644 index da72c5ff..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/MaximumReservableLinkBandwidthTlvTest.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.MaximumReservableLinkBandwidthTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test of the MaximumReservableLinkBandwidthTlv. - */ -public class MaximumReservableLinkBandwidthTlvTest { - private final int rawValue1 = 0x0A; - private final int rawValue2 = 0x0B; - - private final MaximumReservableLinkBandwidthTlv tlv1 = new MaximumReservableLinkBandwidthTlv(rawValue1); - private final MaximumReservableLinkBandwidthTlv sameAsTlv1 = new MaximumReservableLinkBandwidthTlv(rawValue1); - private final MaximumReservableLinkBandwidthTlv tlv2 = MaximumReservableLinkBandwidthTlv.of(rawValue2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NexthopIPv4addressTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NexthopIPv4addressTlvTest.java deleted file mode 100644 index 27539fae..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NexthopIPv4addressTlvTest.java +++ /dev/null @@ -1,39 +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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.NexthopIPv4addressTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Equality test for NexthopIPv4addressTlv. - */ -public class NexthopIPv4addressTlvTest { - - private final NexthopIPv4addressTlv tlv1 = new NexthopIPv4addressTlv(0x0A); - private final NexthopIPv4addressTlv sameAsTlv1 = new NexthopIPv4addressTlv(0x0A); - private final NexthopIPv4addressTlv tlv2 = NexthopIPv4addressTlv.of(0x0B); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NexthopIPv6addressTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NexthopIPv6addressTlvTest.java deleted file mode 100644 index a543d651..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NexthopIPv6addressTlvTest.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.NexthopIPv6addressTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Equality test for NexthopIPv6addressTlv. - */ -public class NexthopIPv6addressTlvTest { - - private final byte[] b1 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x29, 0x00, 0x02, 0x00, 0x00 }; - private final byte[] b2 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x30, 0x00, 0x02, 0x00, 0x00 }; - - private final NexthopIPv6addressTlv tlv1 = NexthopIPv6addressTlv.of(b1); - private final NexthopIPv6addressTlv sameAsTlv1 = NexthopIPv6addressTlv.of(b1); - private final NexthopIPv6addressTlv tlv2 = NexthopIPv6addressTlv.of(b2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, sameAsTlv1).addEqualityGroup(tlv2).testEquals(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NexthopUnnumberedIPv4IDTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NexthopUnnumberedIPv4IDTlvTest.java deleted file mode 100644 index 457b9347..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NexthopUnnumberedIPv4IDTlvTest.java +++ /dev/null @@ -1,39 +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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.NexthopUnnumberedIPv4IDTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Equality test for NexthopUnnumberedIPv4IDTlv. - */ -public class NexthopUnnumberedIPv4IDTlvTest { - - private final NexthopUnnumberedIPv4IDTlv tlv1 = new NexthopUnnumberedIPv4IDTlv(0x0A, 0x0A); - private final NexthopUnnumberedIPv4IDTlv sameAsTlv1 = new NexthopUnnumberedIPv4IDTlv(0x0A, 0x0A); - private final NexthopUnnumberedIPv4IDTlv tlv2 = NexthopUnnumberedIPv4IDTlv.of(0x0B, 0x0B); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NodeFlagBitsTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NodeFlagBitsTlvTest.java deleted file mode 100644 index a50062ae..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NodeFlagBitsTlvTest.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.NodeFlagBitsTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test of the NodeFlagBitsTlv. - */ -public class NodeFlagBitsTlvTest { - private final byte rawValue1 = 0x0A; - private final byte rawValue2 = 0x0B; - - private final NodeFlagBitsTlv tlv1 = new NodeFlagBitsTlv(rawValue1); - private final NodeFlagBitsTlv sameAsTlv1 = new NodeFlagBitsTlv(rawValue1); - private final NodeFlagBitsTlv tlv2 = NodeFlagBitsTlv.of(rawValue2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NodeNameTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NodeNameTlvTest.java deleted file mode 100644 index bb35ed90..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/NodeNameTlvTest.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.NodeNameTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test of the NodeNameTlv. - */ -public class NodeNameTlvTest { - private final byte[] rawValue1 = new byte[] {0x01, 0x02}; - private final byte[] rawValue2 = new byte[] {0x14, 0x15}; - - private final NodeNameTlv tlv1 = new NodeNameTlv(rawValue1, (short) rawValue1.length); - private final NodeNameTlv sameAsTlv1 = NodeNameTlv.of(tlv1.getValue(), tlv1.getLength()); - private final NodeNameTlv tlv2 = new NodeNameTlv(rawValue2, (short) 0); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/OpaqueLinkAttributeTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/OpaqueLinkAttributeTlvTest.java deleted file mode 100644 index cda77a02..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/OpaqueLinkAttributeTlvTest.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.OpaqueLinkAttributeTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test of the OpaqueLinkAttributeTlv. - */ -public class OpaqueLinkAttributeTlvTest { - private final byte[] rawValue1 = new byte[] {0x01, 0x02}; - private final byte[] rawValue2 = new byte[] {0x14, 0x15}; - - private final OpaqueLinkAttributeTlv tlv1 = new OpaqueLinkAttributeTlv(rawValue1, (short) rawValue1.length); - private final OpaqueLinkAttributeTlv sameAsTlv1 = OpaqueLinkAttributeTlv.of(tlv1.getValue(), tlv1.getLength()); - private final OpaqueLinkAttributeTlv tlv2 = new OpaqueLinkAttributeTlv(rawValue2, (short) 0); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PathSetupTypeTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PathSetupTypeTlvTest.java deleted file mode 100644 index e56c96e5..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PathSetupTypeTlvTest.java +++ /dev/null @@ -1,36 +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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.PathSetupTypeTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test of the PathSetupTypeTlv. - */ -public class PathSetupTypeTlvTest { - - private final PathSetupTypeTlv tlv1 = PathSetupTypeTlv.of(0x0A); - private final PathSetupTypeTlv sameAsTlv1 = PathSetupTypeTlv.of(0x0A); - private final PathSetupTypeTlv tlv2 = PathSetupTypeTlv.of(0x0B); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, sameAsTlv1).addEqualityGroup(tlv2).testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PceccCapabilityTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PceccCapabilityTlvTest.java deleted file mode 100644 index a8d521a9..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PceccCapabilityTlvTest.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.PceccCapabilityTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test of the PceccCapabilityTlv. - */ -public class PceccCapabilityTlvTest { - private final int rawValue1 = 0x0A; - private final int rawValue2 = 0x0B; - - private final PceccCapabilityTlv tlv1 = new PceccCapabilityTlv(rawValue1); - private final PceccCapabilityTlv sameAsTlv1 = new PceccCapabilityTlv(rawValue1); - private final PceccCapabilityTlv tlv2 = PceccCapabilityTlv.of(rawValue2); - - @Test - public void basics() { - new EqualsTester() - .addEqualityGroup(tlv1, sameAsTlv1) - .addEqualityGroup(tlv2) - .testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepCloseMsgTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepCloseMsgTest.java deleted file mode 100644 index 8faab559..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepCloseMsgTest.java +++ /dev/null @@ -1,60 +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.pcepio; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.junit.Test; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepCloseMsg; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.core.Is.is; - -public class PcepCloseMsgTest { - - /** - * Common header, reason to close. - */ - @Test - public void closeMessageTest1() throws PcepParseException { - - byte[] closeMsg = new byte[] {0x20, 0x07, 0x00, 0x0C, 0x0f, 0x10, 0x00, 0x08, 0x00, 0x00, 0x00, 0x02 }; - - byte[] testCloseMsg = {0 }; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(closeMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message; - - message = reader.readFrom(buffer); - assertThat(message, instanceOf(PcepCloseMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testCloseMsg = buf.array(); - - int readLen = buf.writerIndex(); - testCloseMsg = new byte[readLen]; - buf.readBytes(testCloseMsg, 0, readLen); - assertThat(testCloseMsg, is(closeMsg)); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepErrorMsgTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepErrorMsgTest.java deleted file mode 100644 index 2fc1fedf..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepErrorMsgTest.java +++ /dev/null @@ -1,739 +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.pcepio; - - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.junit.Test; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepErrorMsg; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.core.Is.is; - -/** - * Test cases for PCEP ERROR Message. - */ -public class PcepErrorMsgTest { - - /** - * This test case checks for - * PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, - * PCECC-CAPABILITY-TLV, TED Capability TLV) - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest1() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x34, // common header - 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x01, 0x01, 0x10, 0x00, 0x28, // OPEN object header - 0x20, 0x05, 0x1E, 0x01, // OPEN object - 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY - 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV - 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV - 0x00, 0x00, 0x00, 0x03, 0x00, (byte) 0x84, 0x00, 0x04, // TED Capability TLV - 0x00, 0x00, 0x00, 0x00}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, - * PCECC-CAPABILITY-TLV, TED Capability TLV) - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest2() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x3C, // common header - 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x28, // OPEN object header - 0x20, 0x05, 0x1E, 0x01, // OPEN object - 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY - 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV - 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV - 0x00, 0x00, 0x00, 0x03, 0x00, (byte) 0x84, 0x00, 0x04, // TED Capability TLV - 0x00, 0x00, 0x00, 0x00}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, - * PCECC-CAPABILITY-TLV) - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest3() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x34, // common header - 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x20, // OPEN object header - 0x20, 0x05, 0x1E, 0x01, // OPEN object - 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY - 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV - 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV - 0x00, 0x00, 0x00, 0x03}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV) - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest4() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x2c, // common header - 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x18, // OPEN object header - 0x20, 0x05, 0x1E, 0x01, // OPEN object - 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY - 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV - 0x00, 0x00, 0x00, 0x00}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object (STATEFUL-PCE-CAPABILITY) - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest5() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x24, // common header - 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x10, // OPEN object header - 0x20, 0x05, 0x1E, 0x01, // OPEN object - 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY - 0x00, 0x00, 0x00, 0x05}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, PCEP-ERROR Object, OPEN Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest6() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x1C, // common header - 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x03, 0x01, 0x10, 0x00, 0x08, // OPEN object header - 0x20, 0x05, 0x1E, 0x01 // OPEN object - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, OPEN Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest7() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x14, // common header - 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x01, 0x01, 0x10, 0x00, 0x08, // OPEN object header - 0x20, 0x05, 0x1E, 0x01 // OPEN object - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, RP Object, PCEP-ERROR Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest8() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x20, // common header - 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x01, 0x02, 0x10, 0x00, 0x0C, // RP Object Header - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x03}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, PCEP-ERROR Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest9() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x14, // common header - 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x01}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, PCEP-ERROR Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest10() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x14, // common header - 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x01}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * TE Object, PCEP-ERROR Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest11() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x18, // common header - 0x65, 0x13, 0x00, 0x0C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x01}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * RP Object, PCEP-ERROR Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest12() throws PcepParseException { - - //RP Object, PCEP-ERROR Object - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x18, // common header - 0x02, 0x10, 0x00, 0x0C, // RP Object Header - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x01}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * RP Object, RP Object, PCEP-ERROR Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest13() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x24, // common header - 0x02, 0x10, 0x00, 0x0C, // RP Object Header - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x10, 0x00, 0x0C, // RP Object Header - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x01}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * TE Object, TE Object, PCEP-ERROR Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest14() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x24, // common header - 0x65, 0x10, 0x00, 0x0C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x65, 0x10, 0x00, 0x0C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x11, // TE-ID - 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x01}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, TE Object, PCEP-ERROR Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest15() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x20, // common header - 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x01, 0x65, 0x10, 0x00, 0x0C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x03}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, RP Object, RP Object, PCEP-ERROR Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest16() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x2C, // common header - 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x01, 0x02, 0x10, 0x00, 0x0C, // RP Object Header - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x10, 0x00, 0x0C, // RP Object Header - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x03}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, TE Object, TE Object, PCEP-ERROR Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest17() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x2C, // common header - 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x01, 0x65, 0x10, 0x00, 0x0C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x65, 0x10, 0x00, 0x0C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x11, // TE-ID - 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x03}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, PCEP-ERROR Object, RP Object, RP Object, PCEP-ERROR Object, PCEP-ERROR Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest18() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x3C, // common header - 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x03, 0x02, 0x10, 0x00, 0x0C, // RP Object Header - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x10, 0x00, 0x0C, // RP Object Header - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x04, 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x06}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, PCEP-ERROR Object, TE Object, TE Object, PCEP-ERROR Object, PCEP-ERROR Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest19() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x3C, // common header - 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x01, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x03, 0x65, 0x10, 0x00, 0x0C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x65, 0x10, 0x00, 0x0C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x11, // TE-ID - 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x04, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x06}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } - - /** - * This test case checks for - * PCEP-ERROR Object, RP Object, RP Object, PCEP-ERROR Object, PCEP-ERROR Object, - * TE Object, PCEP-ERROR Object - * in PcepErrorMsg message. - */ - @Test - public void errorMessageTest20() throws PcepParseException { - - byte[] errorMsg = new byte[]{0x20, 0x06, 0x00, 0x48, // common header - 0x0D, 0x10, 0x00, 0x08, // PCEP-ERROR Object Header - 0x00, 0x00, 0x01, 0x01, 0x02, 0x10, 0x00, 0x0C, // RP Object Header - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x10, 0x00, 0x0C, // RP Object Header - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x04, 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x06, 0x65, 0x10, 0x00, 0x0C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x0D, 0x10, 0x00, 0x08, // PCERR Object Header - 0x00, 0x00, 0x01, 0x06}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(errorMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testErrorMsg = {0}; - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - assertThat(message, instanceOf(PcepErrorMsg.class)); - - message.writeTo(buf); - int iReadLen = buf.writerIndex(); - testErrorMsg = new byte[iReadLen]; - buf.readBytes(testErrorMsg, 0, iReadLen); - - assertThat(testErrorMsg, is(errorMsg)); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepInitiateMsgExtTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepInitiateMsgExtTest.java deleted file mode 100644 index 9da4c62e..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepInitiateMsgExtTest.java +++ /dev/null @@ -1,1686 +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.pcepio; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.junit.Test; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepInitiateMsg; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.Matchers.instanceOf; - -public class PcepInitiateMsgExtTest { - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv, StatefulLspDbVerTlv, StatefulLspErrorCodeTlv, StatefulRsvpErrorSpecTlv), - * END-POINTS, ERO, LSPA, BANDWIDTH, METRIC-LIST objects in PcInitiate message. - */ - @Test - public void initiateMessageTest1() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, StatefulLspDbVerTlv, - * StatefulLspErrorCodeTlv, StatefulRsvpErrorSpecTlv), END-POINTS, ERO, LSPA, BANDWIDTH, METRIC-LIST. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0xA4, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x38, 0x00, 0x00, 0x10, 0x03, - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, //Metric object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20}; //Metric object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv, StatefulLspDbVerTlv, StatefulLspErrorCodeTlv, - * StatefulRsvpErrorSpecTlv), END-POINTS, ERO, LSPA, BANDWIDTH, METRIC OBJECT - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest2() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, StatefulLspDbVerTlv, - * StatefulLspErrorCodeTlv, StatefulRsvpErrorSpecTlv), END-POINTS, ERO, LSPA, BANDWIDTH, METRIC OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0xA8, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x48, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x00, 0x15, 0x00, 0x0c, //StatefulRsvpErrorSpecTlv - 0x00, 0x0c, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x05, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspDbVerTlv, StatefulLspErrorCodeTlv, StatefulRsvpErrorSpecTlv), END-POINTS, - * ERO, LSPA, BANDWIDTH objects in PcInitiate message. - */ - @Test - public void initiateMessageTest3() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, StatefulLspDbVerTlv, - * StatefulLspErrorCodeTlv, StatefulRsvpErrorSpecTlv), END-POINTS, ERO, LSPA, BANDWIDTH. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x8c, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x38, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - // 0x00, 0x15, 0x00, 0x0c, //StatefulRsvpErrorSpecTlv - //0x00, 0x0c, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x05, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv, StatefulLspDbVerTlv, StatefulLspErrorCodeTlv, StatefulRsvpErrorSpecTlv), - * END-POINTS, ERO, LSPA objects in PcInitiate message. - */ - @Test - public void initiateMessageTest4() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, StatefulLspDbVerTlv, - * StatefulLspErrorCodeTlv, StatefulRsvpErrorSpecTlv), END-POINTS, ERO, LSPA. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x84, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x38, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - // 0x00, 0x15, 0x00, 0x0c, //StatefulRsvpErrorSpecTlv - // 0x00, 0x0c, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x05, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv, StatefulLspDbVerTlv, StatefulLspErrorCodeTlv), END-POINTS, ERO, LSPA - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest5() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, StatefulLspDbVerTlv, - * StatefulLspErrorCodeTlv), END-POINTS, ERO, LSPA. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x84, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x38, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv, StatefulLspDbVerTlv, StatefulLspErrorCodeTlv), END-POINTS, ERO, LSPA, - * BANDWIDTH OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest6() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, StatefulLspDbVerTlv, - * StatefulLspErrorCodeTlv), END-POINTS, ERO, LSPA, BANDWIDTH OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x8c, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x38, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv, StatefulLspDbVerTlv, StatefulLspErrorCodeTlv), END-POINTS, ERO, - * LSPA, BANDWIDTH, METRIC OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest7() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, StatefulLspDbVerTlv, - * StatefulLspErrorCodeTlv), END-POINTS, ERO, LSPA, BANDWIDTH, METRIC OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x98, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x38, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv, StatefulLspDbVerTlv), END-POINTS, ERO, LSPA, BANDWIDTH, METRIC OBJECT - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest8() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, StatefulLspDbVerTlv), - * END-POINTS, ERO, LSPA, BANDWIDTH, METRIC OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x90, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x30, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv, StatefulLspDbVerTlv), END-POINTS, ERO, LSPA, BANDWIDTH OBJECT - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest9() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, StatefulLspDbVerTlv), - * END-POINTS, ERO, LSPA, BANDWIDTH OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x84, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x30, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}; //Bandwidth object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv), END-POINTS, ERO, LSPA OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest10() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv), - * END-POINTS, ERO, LSPA OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x70, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv, StatefulLspDbVerTlv), END-POINTS, ERO, LSPA OBJECT - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest11() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, StatefulLspDbVerTlv), - * END-POINTS, ERO, LSPA OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x7C, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x30, 0x00, 0x00, 0x10, 0x03, - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv), END-POINTS, ERO, LSPA, BANDWIDTH OBJECT - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest12() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv), - * END-POINTS, ERO, LSPA, BANDWIDTH OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x78, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}; //Bandwidth object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv, StatefulLspDbVerTlv), END-POINTS, ERO, LSPA, BANDWIDTH , METRIC OBJECT - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest13() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, StatefulLspDbVerTlv), - * END-POINTS, ERO, LSPA, BANDWIDTH , METRIC OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x84, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), - * END-POINTS, ERO, LSPA, BANDWIDTH , METRIC OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest14() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), - * END-POINTS, ERO, LSPA, BANDWIDTH , METRIC OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x7c, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), - * END-POINTS, ERO, LSPA, BANDWIDTH OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest15() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), - * END-POINTS, ERO, LSPA, BANDWIDTH OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x70, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}; //Bandwidth object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), - * END-POINTS, ERO, LSPA OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest16() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), - * END-POINTS, ERO, LSPA OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x68, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA OBJECT - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest17() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x60, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA, - * BANDWIDTH OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest18() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA, BANDWIDTH OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x68, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}; //Bandwidth object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA, - * BANDWIDTH, METRIC OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest19() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA, BANDWIDTH, METRIC OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x74, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA, - * BANDWIDTH, METRIC OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest20() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA, BANDWIDTH, METRIC OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x64, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA, - * BANDWIDTH OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest21() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA, BANDWIDTH OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x58, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}; //Bandwidth object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, - * LSPA OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest22() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x50, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), - * END-POINTS, ERO, LSPA OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest23() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x58, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), - * END-POINTS, ERO, LSPA BANDWIDTH OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest25() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), END-POINTS, ERO, LSPA BANDWIDTH OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x60, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}; //Bandwidth object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), END-POINTS, - * ERO, LSPA, BANDWIDTH, METRIC OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest26() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), END-POINTS, - * ERO, LSPA, BANDWIDTH, METRIC OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x6C, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01}; //Metric object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, SymbolicPathNameTlv), END-POINTS, ERO, LSPA, - * BANDWIDTH, METRIC OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest27() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, SymbolicPathNameTlv), END-POINTS, ERO, LSPA, BANDWIDTH, METRIC OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x60, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01}; //Metric object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, SymbolicPathNameTlv), END-POINTS, ERO, - * LSPA, BANDWIDTH OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest28() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, SymbolicPathNameTlv), END-POINTS, ERO, LSPA, BANDWIDTH OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x54, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}; //Bandwidth object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, SymbolicPathNameTlv), - * END-POINTS, ERO, LSPA OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest29() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, SymbolicPathNameTlv), END-POINTS, ERO, LSPA OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x4C, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, SymbolicPathNameTlv), - * END-POINTS, ERO, LSPA OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest30() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, SymbolicPathNameTlv), END-POINTS, ERO, LSPA OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x5C, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv), END-POINTS, ERO, LSPA OBJECT - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest31() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv), END-POINTS, ERO, LSPA OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x54, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP ( StatefulLspDbVerTlv), END-POINTS, - * ERO, LSPA, BANDWIDTH, METRIC OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest32() throws PcepParseException { - - /* SRP, LSP ( StatefulLspDbVerTlv), END-POINTS, - * ERO, LSPA, BANDWIDTH, METRIC OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x64, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01}; //Metric object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP ( StatefulLspDbVerTlv), END-POINTS, - * ERO, LSPA, BANDWIDTH OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest33() throws PcepParseException { - - /* SRP, LSP ( StatefulLspDbVerTlv), END-POINTS, - * ERO, LSPA, BANDWIDTH OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x58, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}; //Bandwidth object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP ( StatefulLspDbVerTlv), END-POINTS, - * ERO, LSPA OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest34() throws PcepParseException { - - /* SRP, LSP ( StatefulLspDbVerTlv), END-POINTS, - * ERO, LSPA OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x50, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP ( StatefulLspDbVerTlv), END-POINTS, - * ERO, LSPA OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest35() throws PcepParseException { - - /* SRP, LSP ( StatefulLspDbVerTlv), END-POINTS, - * ERO, LSPA OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x60, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP ( StatefulLspDbVerTlv), END-POINTS, - * ERO, LSPA OBJECT objects in PcInitiate message. - */ - @Test - public void initiateMessageTest36() throws PcepParseException { - - /* SRP, LSP ( StatefulLspDbVerTlv), END-POINTS, - * ERO, LSPA OBJECT. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x58, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x0C, 0x01, //ERO object - 0x01, 0x01, 0x00, 0x00, 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } -} - diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepInitiateMsgTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepInitiateMsgTest.java deleted file mode 100644 index a27b781f..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepInitiateMsgTest.java +++ /dev/null @@ -1,1335 +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.pcepio; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.junit.Test; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepInitiateMsg; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.core.Is.is; - -public class PcepInitiateMsgTest { - - /** - * This test case checks for srp, lsp, end-point, ERO objects in PcInitiate message. - */ - @Test - public void initiateMessageTest1() throws PcepParseException { - - /* srp, lsp, end-point, ERO. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, 0x54, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x00, 0x08, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for srp and lsp objects in PcInitiate message. - */ - @Test - public void initiateMessageTest2() throws PcepParseException { - /* srp, lsp. - */ - byte[] initiateDeletionMsg = new byte[]{0x20, 0x0C, 0x00, 0x34, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x20, 0x10, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - 0x01, 0x01, 0x01, 0x01, 0x00, 0x43, (byte) 0x83, 0x01, - 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33}; //SymbolicPathTlv - - byte[] testInitiateDeletionMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateDeletionMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testInitiateDeletionMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateDeletionMsg = new byte[iReadLen]; - buf.readBytes(testInitiateDeletionMsg, 0, iReadLen); - - assertThat(testInitiateDeletionMsg, is(initiateDeletionMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv, StatefulRsvpErrorSpecTlv), END-POINTS, ERO objects - * in PcInitiate message. - */ - @Test - public void initiateMessageTest3() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv, StatefulRsvpErrorSpecTlv), END-POINTS, ERO. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x64, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv), END-POINT, ERO objects in PcInitiate message. - */ - @Test - public void initiateMessageTest4() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv), END-POINT, ERO. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x64, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv), - * END-POINT, ERO objects in PcInitiate message. - */ - @Test - public void initiateMessageTest5() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv), - * END-POINT, ERO. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x5c, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv), - * END-POINT, ERO objects in PcInitiate message. - */ - @Test - public void initiateMessageTest6() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv), - * END-POINT, ERO. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x5c, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), - * END-POINT, ERO objects in PcInitiate message. - */ - @Test - public void initiateMessageTest7() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), - * END-POINT, ERO. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x54, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), - * END-POINT, ERO objects in PcInitiate message. - */ - @Test - public void initiateMessageTest8() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv), - * END-POINT, ERO. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x4c, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), - * END-POINT, ERO objects in PcInitiate message. - */ - @Test - public void initiateMessageTest9() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv), - * END-POINT, ERO. - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x3c, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, StatefulRsvpErrorSpecTlv) - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest10() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv, StatefulRsvpErrorSpecTlv). - */ - byte[] initiateDeletionMsg = new byte[]{0x20, 0x0C, 0x00, 0x44, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathTlv - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, (byte) 0xb6, 0x02, 0x4e, 0x1f, - (byte) 0xb6, 0x02, 0x4e, 0x20, 0x00, 0x11, 0x00, 0x04, 0x54, 0x31, 0x32, 0x33, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08 //StatefulLspErrorCodeTlv - }; - - byte[] testInitiateDeletionMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateDeletionMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateDeletionMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateDeletionMsg = new byte[iReadLen]; - buf.readBytes(testInitiateDeletionMsg, 0, iReadLen); - - assertThat(testInitiateDeletionMsg, is(initiateDeletionMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv) objects in PcInitiate message. - */ - @Test - public void initiateMessageTest11() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - StatefulLspErrorCodeTlv).*/ - byte[] initiateDeletionMsg = new byte[]{0x20, 0x0C, 0x00, 0x44, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathTlv - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08}; //StatefulLspErrorCodeTlv - - byte[] testInitiateDeletionMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateDeletionMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateDeletionMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateDeletionMsg = new byte[iReadLen]; - buf.readBytes(testInitiateDeletionMsg, 0, iReadLen); - - assertThat(testInitiateDeletionMsg, is(initiateDeletionMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv) - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest12() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv). - */ - byte[] initiateDeletionMsg = new byte[]{0x20, 0x0C, 0x00, 0x3c, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathTlv - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00 //SymbolicPathNameTlv - }; - - byte[] testInitiateDeletionMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateDeletionMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateDeletionMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateDeletionMsg = new byte[iReadLen]; - buf.readBytes(testInitiateDeletionMsg, 0, iReadLen); - - assertThat(testInitiateDeletionMsg, is(initiateDeletionMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv) - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest13() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv). - */ - byte[] initiateDeletionMsg = new byte[]{0x20, 0x0C, 0x00, 0x3c, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathTlv - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00}; //SymbolicPathNameTlv - - byte[] testInitiateDeletionMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateDeletionMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateDeletionMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateDeletionMsg = new byte[iReadLen]; - buf.readBytes(testInitiateDeletionMsg, 0, iReadLen); - - assertThat(testInitiateDeletionMsg, is(initiateDeletionMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv) - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest14() throws PcepParseException { - - /* SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv). - */ - byte[] initiateDeletionMsg = new byte[]{0x20, 0x0C, 0x00, 0x34, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathTlv - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20}; - - byte[] testInitiateDeletionMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateDeletionMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateDeletionMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateDeletionMsg = new byte[iReadLen]; - buf.readBytes(testInitiateDeletionMsg, 0, iReadLen); - - assertThat(testInitiateDeletionMsg, is(initiateDeletionMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv) - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest15() throws PcepParseException { - - /* SRP, LSP (StatefulIPv4LspIdentidiersTlv). - */ - byte[] initiateDeletionMsg = new byte[]{0x20, 0x0C, 0x00, 0x2c, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20}; - - byte[] testInitiateDeletionMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateDeletionMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateDeletionMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateDeletionMsg = new byte[iReadLen]; - buf.readBytes(testInitiateDeletionMsg, 0, iReadLen); - - assertThat(testInitiateDeletionMsg, is(initiateDeletionMsg)); - } - - /** - * This test case checks for srp,lsp (StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest16() throws PcepParseException { - - //srp,lsp (StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x50, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for srp,lsp (StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa,bandwidth - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest17() throws PcepParseException { - - //srp,lsp (StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa,bandwidth - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x58, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}; //Bandwidth object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for srp,lsp (StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa,bandwidth,metric-list - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest18() throws PcepParseException { - //srp,lsp (StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa,bandwidth,metric-list - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x64, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20}; //Metric object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for srp,lsp(all tlvs),end-point,ero,lspa,bandwidth,metric-list - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest19() throws PcepParseException { - //srp,lsp(all tlvs),end-point,ero,lspa,bandwidth,metric-list - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x74, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x04, //ERO object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20}; //Metric object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for srp,lsp (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, srp, - * lsp(SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv) objects in PcInitiate message. - */ - @Test - public void initiateMessageTest20() throws PcepParseException { - /* srp,lsp (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, srp, - * lsp(SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv). - */ - byte[] initiateDeletionMsg = new byte[]{0x20, 0x0C, 0x00, 0x64, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20}; - - byte[] testInitiateDeletionMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateDeletionMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateDeletionMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateDeletionMsg = new byte[iReadLen]; - buf.readBytes(testInitiateDeletionMsg, 0, iReadLen); - - assertThat(testInitiateDeletionMsg, is(initiateDeletionMsg)); - } - - /** - * This test case checks for srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest21() throws PcepParseException { - /*srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero, - * srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0x94, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest22() throws PcepParseException { - /*srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero, - * srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0xA8, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa,bandwidth - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest23() throws PcepParseException { - /*srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero, - * srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa,bandwidth - */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0xB0, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}; //Bandwidth object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa,bandwidth - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest24() throws PcepParseException { - /*srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero, - * srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa,bandwidth*/ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0xBC, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20}; //Metric object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero,bandwidth, - * srp,lsp(StatefulIPv4LspIdentidiersTlv), end-point,ero,lspa,bandwidth,metric-list - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest25() throws PcepParseException { - - /*srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero,bandwidth, - * srp,lsp(StatefulIPv4LspIdentidiersTlv), - * end-point,ero,lspa,bandwidth,metric-list */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0xC4, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20}; //Metric object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero,bandwidth,metric-list, - * srp,lsp(StatefulIPv4LspIdentidiersTlv), end-point,ero,lspa,bandwidth,metric-list - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest26() throws PcepParseException { - - /*srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero,bandwidth,metric-list, - * srp,lsp(StatefulIPv4LspIdentidiersTlv), - * end-point,ero,lspa,bandwidth,metric-list */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0xD0, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20}; //Metric object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } - - /** - * This test case checks for srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa,bandwidth,metric-list, - * srp,lsp(StatefulIPv4LspIdentidiersTlv), end-point,ero,lspa,bandwidth,metric-list - * objects in PcInitiate message. - */ - @Test - public void initiateMessageTest27() throws PcepParseException { - - /*srp,lsp(StatefulIPv4LspIdentidiersTlv),end-point,ero,lspa,bandwidth,metric-list, - * srp,lsp(StatefulIPv4LspIdentidiersTlv), - * end-point,ero,lspa,bandwidth,metric-list */ - byte[] initiateCreationMsg = new byte[]{0x20, 0x0C, 0x00, (byte) 0xE4, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x04, 0x12, 0x00, 0x0C, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, //Endpoints Object - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x01, 0x00, 0x00, - 0x01, 0x08, 0x0C, 0x01, 0x01, 0x02, 0x00, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20}; //Metric object - - byte[] testInitiateCreationMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(initiateCreationMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepInitiateMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testInitiateCreationMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testInitiateCreationMsg = new byte[iReadLen]; - buf.readBytes(testInitiateCreationMsg, 0, iReadLen); - - assertThat(testInitiateCreationMsg, is(initiateCreationMsg)); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepKeepaliveMsgTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepKeepaliveMsgTest.java deleted file mode 100644 index a35c8af5..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepKeepaliveMsgTest.java +++ /dev/null @@ -1,63 +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.pcepio; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.junit.Assert; -import org.junit.Test; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepKeepaliveMsg; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.core.Is.is; - -public class PcepKeepaliveMsgTest { - - /** - * Common header for keep alive message. - */ - @Test - public void keepaliveMessageTest1() throws PcepParseException { - - byte[] keepaliveMsg = new byte[] {0x20, 0x02, 0x00, 0x04 }; - - byte[] testKeepaliveMsg = {0 }; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(keepaliveMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - assertThat(message, instanceOf(PcepKeepaliveMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - - message.writeTo(buf); - - testKeepaliveMsg = buf.array(); - - int iReadLen = buf.writerIndex(); - testKeepaliveMsg = new byte[iReadLen]; - buf.readBytes(testKeepaliveMsg, 0, iReadLen); - - Assert.assertThat(testKeepaliveMsg, is(keepaliveMsg)); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepLabelUpdateMsgTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepLabelUpdateMsgTest.java deleted file mode 100644 index d6ec350c..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepLabelUpdateMsgTest.java +++ /dev/null @@ -1,406 +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.pcepio; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.junit.Test; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepLabelUpdateMsg; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.is; - -public class PcepLabelUpdateMsgTest { - - /** - * This test case checks for - * <pce-label-download> SRP, LSP, LABEL Object. - * in PcepLabelUpdate message. - */ - @Test - public void labelUpdateMessageTest1() throws PcepParseException { - - byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x24, // common header - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x10, - 0x20, 0x10, 0x00, 0x08, // LSP Object Header - 0x00, 0x01, 0x00, 0x00, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x66}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(labelUpdate); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testLabelUpdateMsg = {0}; - assertThat(message, instanceOf(PcepLabelUpdateMsg.class)); - - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testLabelUpdateMsg = new byte[readLen]; - buf.readBytes(testLabelUpdateMsg, 0, readLen); - - assertThat(testLabelUpdateMsg, is(labelUpdate)); - } - - /** - * This test case checks for - * <pce-label-download> SRP, LSP, LABEL Object, LABEL Object. - * in PcepLabelUpdate message. - */ - @Test - public void labelUpdateMessageTest2() throws PcepParseException { - - byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x30, // common header - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x10, - 0x20, 0x10, 0x00, 0x08, // LSP Object Header - 0x00, 0x01, 0x00, 0x00, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x66, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x77}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(labelUpdate); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testLabelUpdateMsg = {0}; - assertThat(message, instanceOf(PcepLabelUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testLabelUpdateMsg = new byte[readLen]; - buf.readBytes(testLabelUpdateMsg, 0, readLen); - - assertThat(testLabelUpdateMsg, is(labelUpdate)); - } - - /** - * This test case checks for - * <pce-label-map> SRP, LABEL, FEC Object. - * in PcepLabelUpdate message. - */ - @Test - public void labelUpdateMessageTest3() throws PcepParseException { - - byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x24, // common header - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x10, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x66, - 0x24, 0x10, 0x00, 0x08, // FEC Object Header - 0x0A, 0x0A, 0x0B, 0x0B}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(labelUpdate); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testLabelUpdateMsg = {0}; - assertThat(message, instanceOf(PcepLabelUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testLabelUpdateMsg = new byte[readLen]; - buf.readBytes(testLabelUpdateMsg, 0, readLen); - - assertThat(testLabelUpdateMsg, is(labelUpdate)); - } - - /** - * This test case checks for - * <pce-label-download> SRP, LSP, LABEL, LABEL, <pce-label-download> SRP, LSP, LABEL - * in PcepLabelUpdate message. - */ - @Test - public void labelUpdateMessageTest4() throws PcepParseException { - - byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x50, // common header - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x10, - 0x20, 0x10, 0x00, 0x08, // LSP Object Header - 0x00, 0x01, 0x00, 0x00, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x66, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x77, - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x11, - 0x20, 0x10, 0x00, 0x08, // LSP Object Header - 0x00, 0x02, 0x00, 0x00, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x44}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(labelUpdate); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testLabelUpdateMsg = {0}; - assertThat(message, instanceOf(PcepLabelUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testLabelUpdateMsg = new byte[readLen]; - buf.readBytes(testLabelUpdateMsg, 0, readLen); - - assertThat(testLabelUpdateMsg, is(labelUpdate)); - } - - /** - * This test case checks for - * <pce-label-map> SRP, LABEL, FEC, <pce-label-map> SRP, LABEL, FEC. - * in PcepLabelUpdate message. - */ - @Test - public void labelUpdateMessageTest5() throws PcepParseException { - - byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x44, // common header - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x10, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x01, - 0x00, 0x00, 0x00, 0x66, - 0x24, 0x10, 0x00, 0x08, // FEC Object Header - 0x0A, 0x0A, 0x0B, 0x0B, - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x11, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x66, - 0x24, 0x10, 0x00, 0x08, // FEC Object Header - 0x0A, 0x0A, 0x0C, 0x0C}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(labelUpdate); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testLabelUpdateMsg = {0}; - assertThat(message, instanceOf(PcepLabelUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testLabelUpdateMsg = new byte[readLen]; - buf.readBytes(testLabelUpdateMsg, 0, readLen); - - assertThat(testLabelUpdateMsg, is(labelUpdate)); - } - - /** - * This test case checks for - * <pce-label-download> SRP, LSP, LABEL, LABEL, <pce-label-download> SRP, LABEL, FEC. - * in PcepLabelUpdate message. - */ - @Test - public void labelUpdateMessageTest6() throws PcepParseException { - - byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x50, // common header - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x10, - 0x20, 0x10, 0x00, 0x08, // LSP Object Header - 0x00, 0x01, 0x00, 0x00, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x66, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x77, - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x12, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x66, - 0x24, 0x10, 0x00, 0x08, // FEC Object Header - 0x0A, 0x0A, 0x0D, 0x0D}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(labelUpdate); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testLabelUpdateMsg = {0}; - assertThat(message, instanceOf(PcepLabelUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testLabelUpdateMsg = new byte[readLen]; - buf.readBytes(testLabelUpdateMsg, 0, readLen); - - assertThat(testLabelUpdateMsg, is(labelUpdate)); - } - - /** - * This test case checks for - * <pce-label-download> SRP, LABEL, FEC, <pce-label-download> SRP, LSP, LABEL, LABEL. - * in PcepLabelUpdate message. - */ - @Test - public void labelUpdateMessageTest7() throws PcepParseException { - - byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x50, // common header - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x12, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x66, - 0x24, 0x10, 0x00, 0x08, // FEC Object Header - 0x0A, 0x0A, 0x0D, 0x0D, - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x10, - 0x20, 0x10, 0x00, 0x08, // LSP Object Header - 0x00, 0x01, 0x00, 0x00, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x66, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x77}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(labelUpdate); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testLabelUpdateMsg = {0}; - assertThat(message, instanceOf(PcepLabelUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testLabelUpdateMsg = new byte[readLen]; - buf.readBytes(testLabelUpdateMsg, 0, readLen); - - assertThat(testLabelUpdateMsg, is(labelUpdate)); - } - - /** - * This test case checks for - * <pce-label-download> SRP, LABEL, FEC, <pce-label-download> SRP, LSP, LABEL, LABEL. - * <pce-label-download> SRP, LSP, LABEL, LABEL. - * in PcepLabelUpdate message. - */ - @Test - public void labelUpdateMessageTest8() throws PcepParseException { - - byte[] labelUpdate = new byte[]{0x20, 0x0D, 0x00, 0x7C, // common header - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x12, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x66, - 0x24, 0x10, 0x00, 0x08, // FEC Object Header - 0x0A, 0x0A, 0x0D, 0x0D, - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x10, - 0x20, 0x10, 0x00, 0x08, // LSP Object Header - 0x00, 0x01, 0x00, 0x00, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x66, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x77, - 0x21, 0x10, 0x00, 0x0C, // SRP Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x10, - 0x20, 0x10, 0x00, 0x08, // LSP Object Header - 0x00, 0x01, 0x00, 0x00, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x66, - 0x23, 0x10, 0x00, 0x0C, // LABEL Object Header - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x77}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(labelUpdate); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testLabelUpdateMsg = {0}; - - assertThat(message, instanceOf(PcepLabelUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testLabelUpdateMsg = new byte[readLen]; - buf.readBytes(testLabelUpdateMsg, 0, readLen); - - assertThat(testLabelUpdateMsg, is(labelUpdate)); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepNaiIpv6AdjacencyTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepNaiIpv6AdjacencyTest.java deleted file mode 100644 index 5b68193d..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepNaiIpv6AdjacencyTest.java +++ /dev/null @@ -1,39 +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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.PcepNaiIpv6Adjacency; - -import com.google.common.testing.EqualsTester; - -public class PcepNaiIpv6AdjacencyTest { - private final byte[] localIpv6Addr1 = {(byte) 0x01010101 }; - private final byte[] remoteIpv6Addr1 = {(byte) 0x02020202 }; - private final byte[] localIpv6Addr2 = {(byte) 0x01010101 }; - private final byte[] remoteIpv6Addr2 = {(byte) 0x02020202 }; - private final byte[] localIpv6Addr3 = {(byte) 0x05050505 }; - private final byte[] remoteIpv6Addr3 = {(byte) 0x06060606 }; - - private final PcepNaiIpv6Adjacency tlv1 = PcepNaiIpv6Adjacency.of(localIpv6Addr1, remoteIpv6Addr1); - private final PcepNaiIpv6Adjacency tlv2 = PcepNaiIpv6Adjacency.of(localIpv6Addr1, remoteIpv6Addr1); - private final PcepNaiIpv6Adjacency tlv3 = PcepNaiIpv6Adjacency.of(localIpv6Addr3, remoteIpv6Addr3); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); - } -}
\ No newline at end of file diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepNaiIpv6NodeIdTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepNaiIpv6NodeIdTest.java deleted file mode 100644 index bf458940..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepNaiIpv6NodeIdTest.java +++ /dev/null @@ -1,45 +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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.PcepNaiIpv6NodeId; - -import com.google.common.testing.EqualsTester; - -/** - * Equality test for PcepNaiIpv6NodeId. - */ -public class PcepNaiIpv6NodeIdTest { - - private final byte[] b1 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x29, 0x00, 0x02, - 0x00, 0x00 }; - private final byte[] b2 = new byte[] {(byte) 0xFE, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, - (byte) 0xB3, (byte) 0xFF, (byte) 0xFE, 0x1E, (byte) 0x83, 0x30, 0x00, 0x02, - 0x00, 0x00 }; - - private final PcepNaiIpv6NodeId tlv1 = PcepNaiIpv6NodeId.of(b1); - private final PcepNaiIpv6NodeId sameAsTlv1 = PcepNaiIpv6NodeId.of(b1); - private final PcepNaiIpv6NodeId tlv2 = PcepNaiIpv6NodeId.of(b2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, sameAsTlv1).addEqualityGroup(tlv2).testEquals(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepNaiUnnumberedAdjacencyIpv4Test.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepNaiUnnumberedAdjacencyIpv4Test.java deleted file mode 100644 index d45bae8b..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepNaiUnnumberedAdjacencyIpv4Test.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.PcepNaiUnnumberedAdjacencyIpv4; - -import com.google.common.testing.EqualsTester; - -public class PcepNaiUnnumberedAdjacencyIpv4Test { - - private final int localNodeId1 = 1; - private final int localInterfaceId1 = 1; - private final int remoteNodeId1 = 1; - private final int remoteInterfaceId1 = 1; - private final PcepNaiUnnumberedAdjacencyIpv4 tlv1 = PcepNaiUnnumberedAdjacencyIpv4.of(localNodeId1, - localInterfaceId1, remoteNodeId1, remoteInterfaceId1); - - private final int localNodeId2 = 1; - private final int localInterfaceId2 = 1; - private final int remoteNodeId2 = 1; - private final int remoteInterfaceId2 = 1; - private final PcepNaiUnnumberedAdjacencyIpv4 tlv2 = PcepNaiUnnumberedAdjacencyIpv4.of(localNodeId2, - localInterfaceId2, remoteNodeId2, remoteInterfaceId2); - - private final int localNodeId3 = 2; - private final int localInterfaceId3 = 2; - private final int remoteNodeId3 = 2; - private final int remoteInterfaceId3 = 2; - - private final PcepNaiUnnumberedAdjacencyIpv4 tlv3 = PcepNaiUnnumberedAdjacencyIpv4.of(localNodeId3, - localInterfaceId3, remoteNodeId3, remoteInterfaceId3); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepOpenMsgTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepOpenMsgTest.java deleted file mode 100644 index 1aff4962..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepOpenMsgTest.java +++ /dev/null @@ -1,562 +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.pcepio; - -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.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepOpenMsg; -/** - * Test cases for PCEP OPEN Message. - */ -public class PcepOpenMsgTest { - - /** - * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, - * PCECC-CAPABILITY-TLV in Pcep Open message. - */ - @Test - public void openMessageTest1() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x10, 0x00, 0x20, 0x20, 0x1e, 0x78, (byte) 0xbd, - 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY - 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV - 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV - }; - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with STATEFUL-PCE-CAPABILITY-TLV in Pcep Open message. - */ - @Test - public void openMessageTest2() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header - 0x01, 0x10, 0x00, 0x10, // common object header - 0x20, 0x1E, 0x78, 0x01, // OPEN object - 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f}; // STATEFUL-PCE-CAPABILITY - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with GmplsCapability tlv in Pcep Open message. - */ - @Test - public void openMessageTest3() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header - 0x01, 0x10, 0x00, 0x10, // common object header - 0x20, 0x1E, 0x78, 0x01, // OPEN object - 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00}; //GMPLS-CAPABILITY-TLV - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with StatefulLspDbVer Tlv in Pcep Open message. - */ - @Test - public void openMessageTest4() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x18, - 0x01, 0x10, 0x00, 0x14, 0x20, 0x1e, 0x78, 0x20, - 0x00, 0x17, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }; //StatefulLspDbVerTlv - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with no tlv's in Pcep Open message. - */ - @Test - public void openMessageTest5() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x0C, - 0x01, 0x10, 0x00, 0x08, 0x20, 0x1e, 0x78, (byte) 0xbd }; // no Tlvs in open messsage - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV - * with I bit set in Pcep Open message. - */ - @Test - public void openMessageTest6() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x11, 0x00, 0x20, //p bit not set & i bit set - 0x20, 0x1e, 0x78, (byte) 0xbd, - 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, // STATEFUL-PCE-CAPABILITY - 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV - 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV - }; - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV - * with P bit set in Pcep Open message. - */ - @Test - public void openMessageTest7() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x12, 0x00, 0x20, //p bit set & i bit not set - 0x20, 0x1e, 0x78, (byte) 0xbd, - 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY - 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV - 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV - }; - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV - * with P & I bits set in Pcep Open message. - */ - @Test - public void openMessageTest8() throws PcepParseException { - - /* OPEN OBJECT (STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV) - with p bit set & i bit set. - */ - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x13, 0x00, 0x20, //p bit set & i bit set - 0x20, 0x1e, 0x78, (byte) 0xbd, - 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY - 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV - 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV - }; - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, PCECC-CAPABILITY-TLV - * with P & I bits set and invalid session id in Pcep Open message. - */ - @Test - public void openMessageTest9() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, 0x01, 0x13, 0x00, 0x20, //p bit set & i bit set - 0x20, 0x1e, 0x78, 0x00, //invalid sessionID - 0x00, 0x10, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0f, //STATEFUL-PCE-CAPABILITY - 0x00, 0x0e, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, //GMPLS-CAPABILITY-TLV - 0x00, 0x20, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, //PCECC-CAPABILITY-TLV - }; - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV - * in Pcep Open message. - */ - @Test - public void openMessageTest10() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x1C, // common header - 0x01, 0x10, 0x00, 0x18, // common object header - 0x20, 0x05, 0x1E, 0x01, // OPEN object - 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY - 0x00, 0x00, 0x00, 0x05, - 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV - 0x00, 0x00, 0x00, 0x00}; - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, - * PCECC-CAPABILITY-TLV, TED Capability TLV in Pcep Open message. - */ - @Test - public void openMessageTest11() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x2C, // common header - 0x01, 0x10, 0x00, 0x28, // common object header - 0x20, 0x05, 0x1E, 0x01, // OPEN object - 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY - 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV - 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV - 0x00, 0x00, 0x00, 0x03, 0x00, (byte) 0x84, 0x00, 0x04, // TED Capability TLV - 0x00, 0x00, 0x00, 0x00 }; - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV, - * PCECC-CAPABILITY-TLV in Pcep Open message. - */ - @Test - public void openMessageTest12() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x24, // common header - 0x01, 0x10, 0x00, 0x20, // common object header - 0x20, 0x05, 0x1E, 0x01, // OPEN object - 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY - 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV - 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, // PCECC-CAPABILITY-TLV - 0x00, 0x00, 0x00, 0x03}; - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with STATEFUL-PCE-CAPABILITY, GMPLS-CAPABILITY-TLV - * in Pcep Open message. - */ - @Test - public void openMessageTest13() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x1c, // common header - 0x01, 0x10, 0x00, 0x18, // common object header - 0x20, 0x05, 0x1E, 0x01, // OPEN object - 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY - 0x00, 0x00, 0x00, 0x05, 0x00, 0x0E, 0x00, 0x04, // GMPLS-CAPABILITY-TLV - 0x00, 0x00, 0x00, 0x00}; - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with STATEFUL-PCE-CAPABILITY in Pcep Open message. - */ - @Test - public void openMessageTest14() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x14, // common header - 0x01, 0x10, 0x00, 0x10, // common object header - 0x20, 0x05, 0x1E, 0x01, // OPEN object - 0x00, 0x10, 0x00, 0x04, // STATEFUL-PCE-CAPABILITY - 0x00, 0x00, 0x00, 0x05}; - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - - assertThat(testOpenMsg, is(openMsg)); - - } - - /** - * This test case checks open object with no tlv Pcep Open message. - */ - @Test - public void openMessageTest15() throws PcepParseException { - - byte[] openMsg = new byte[] {0x20, 0x01, 0x00, 0x0c, // common header - 0x01, 0x10, 0x00, 0x08, // common object header - 0x20, 0x05, 0x1E, 0x01 // OPEN object - }; - - byte[] testOpenMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(openMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepOpenMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testOpenMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testOpenMsg = new byte[readLen]; - buf.readBytes(testOpenMsg, 0, readLen); - assertThat(testOpenMsg, is(openMsg)); - - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepReportMsgExtTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepReportMsgExtTest.java deleted file mode 100644 index 346caf87..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepReportMsgExtTest.java +++ /dev/null @@ -1,221 +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.pcepio; - -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.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepReportMsg; - -public class PcepReportMsgExtTest { - - /** - * This test case checks forSRP Object,LSP Object(symbolic path tlv),ERO Object - * SRP Object,LSP Object(symbolic path tlv,ERO Object,LSPA Object,BandWidth Object,Metric-list,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest39() throws PcepParseException { - - byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x98, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object - * SRP Object,LSP Object(symbolic path tlv),ERO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest40() throws PcepParseException { - - byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x64, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object - * SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object - * in PcRpt message. - */ - @Test - public void reportMessageTest41() throws PcepParseException { - - byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0x8c, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object,BandWidth Object, - * Metric-list SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object,BandWidth Object,Metric-list, - * RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest42() throws PcepParseException { - - byte[] reportMsg = new byte[] {0x20, 0x0a, 0x00, (byte) 0xE8, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //symbolic path tlv - 0x07, 0x10, 0x00, 0x14, //ERO object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepReportMsgTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepReportMsgTest.java deleted file mode 100644 index 237e617f..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepReportMsgTest.java +++ /dev/null @@ -1,1601 +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.pcepio; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.junit.Test; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepReportMsg; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.core.Is.is; - -public class PcepReportMsgTest { - - /** - * This test case checks for SRP object, LSP object(Symbolic path name tlv), ERO object - * in PcRpt message. - */ - @Test - public void reportMessageTest1() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, 0x24, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x04}; //ERO Object - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object, LSP Object(StatefulIPv4LspIdentidiersTlv,SymbolicPathNameTlv - * StatefulLspErrorCodeTlv) ERO Object, LSPA Object, Metric-list, IRO object - * in PcRpt message. - */ - @Test - public void reportMessageTest2() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x7c, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object // LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, // IPv4SubObjects - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, //Metric Object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - }; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for LSP Object(StatefulIPv4LspIdentidiersTlv,SymbolicPathNameTlv,StatefulLspErrorCodeTlv) - * ERO Object, LSPA Object, Metric-list, IRO object - * in PcRpt message. - */ - @Test - public void reportMessageTest3() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x70, - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, //Ipv4SubObjects - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, //Metric Objects - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - }; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for LSP Object(StatefulIPv4LspIdentidiersTlv,SymbolicPathNameTlv,StatefulLspErrorCodeTlv) - * ERO Object, LSPA Object, Metric-list - * in PcRpt message. - */ - @Test - public void reportMessageTest4() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x64, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object, LSP Object(StatefulIPv4LspIdentidiersTlv,SymbolicPathNameTlv - * StatefulLspErrorCodeTlv) ERO Object, IRO object - * in PcRpt message. - */ - @Test - public void reportMessageTest5() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x50, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object, LSP Object(StatefulIPv4LspIdentidiersTlv,SymbolicPathNameTlv - * StatefulLspErrorCodeTlv) ERO Object, LSPA Object, Metric-list. - * in PcRpt message. - */ - @Test - public void reportMessageTest6() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x6c, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x04, //ERO Object - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, //Metric object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - }; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for LSP Object, ERO Object, LSPA Object, Metric-list, IRO object - * in PcRpt message. - */ - @Test - public void reportMessageTest7() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x58, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x08, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, // Metric objects - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP object, LSP object( StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv) ERO object, LSPA object, Metric object - * in PcRpt message. - */ - @Test - public void reportMessageTest8() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x70, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20}; //Metric Object - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for LSP Object(Symbolic path tlv, StatefulIPv4LspIdentidiersTlv, - * StatefulLspErrorCodeTlv ),ERO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest9() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x44, - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(StatefulIPv4LspIdentidiersTlv)ERO Object,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest10() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x74, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(SymbolicPathNameTlv)ERO Object,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest11() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x68, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object, ERO Object,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest12() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x60, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x08, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(StatefulLspErrorCodeTlv)ERO Object,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest13() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x68, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(StatefulRsvpErrorSpecTlv),ERO Object,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest14() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x60, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x08, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(symbolic path tlv),LSPA Object,ERO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest15() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x7C, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(symbolic path tlv),BandWidth Object,ERO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest16() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x70, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object,ERO Object,LSPA Object,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest17() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x74, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x08, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object,ERO Object,BandWidth Object,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest18() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x68, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x08, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object,ERO Object,Metric-list,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest19() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x6C, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x08, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object,ERO Object,LSPA Object,BandWidth Object,Metric-list,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest20() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x88, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x08, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(Symbolic path tlv, StatefulIPv4LspIdentidiersTlv, - * StatefulLspErrorCodeTlv ) ERO Object,LSPA Object,BandWidth Object,Metric-list,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest21() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0xac, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for LSP Object(Symbolic path tlv, StatefulIPv4LspIdentidiersTlv,StatefulLspErrorCodeTlv ) - * ERO Object,LSPA Object,BandWidth Object,Metric-list,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest22() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0xA0, - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for LSP Object(Symbolic path tlv, StatefulIPv4LspIdentidiersTlv,StatefulLspErrorCodeTlv ) - * ERO Object,BandWidth Object,Metric-list,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest23() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x8c, - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for LSP Object(Symbolic path tlv, StatefulIPv4LspIdentidiersTlv,StatefulLspErrorCodeTlv ) - * ERO Object,Metric-list,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest24() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x84, - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for LSP Object(Symbolic path tlv, StatefulIPv4LspIdentidiersTlv,StatefulLspErrorCodeTlv ) - * ERO Object,LSPA Object,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest25() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x8c, - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for LSP Object(Symbolic path tlv, StatefulIPv4LspIdentidiersTlv,StatefulLspErrorCodeTlv ) - * ERO Object,LSPA Object - * in PcRpt message. - */ - @Test - public void reportMessageTest26() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x58, - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for LSP Object(Symbolic path tlv, StatefulIPv4LspIdentidiersTlv,StatefulLspErrorCodeTlv) - * ERO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest27() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x44, - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for LSP Object(Symbolic path tlv, StatefulIPv4LspIdentidiersTlv,StatefulLspErrorCodeTlv ) - * LSPA Object,BandWidth Object,Metric-list,ERO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest28() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x6c, - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,Metric-list,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest29() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x74, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,Metric-list,RRO Object - * SRP Object,LSP Object(symbolic path tlv),ERO Object,Metric-list,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest30() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0xE4, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object - * BandWidth Object,Metric-list,RRO Object,SRP Object,LSP Object(symbolic path tlv) - * ERO Object,Metric-list,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest31() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x01, 0x00, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object - * BandWidth Object,Metric-list,RRO Object,SRP Object,LSP Object(symbolic path tlv) - * ERO Object,LSPA Object,Metric-list,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest32() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x01, (byte) 0x14, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(symbolic path tlv),ERO Object,LSPA Object - * BandWidth Object,Metric-list,RRO Object,SRP Object,LSP Object(symbolic path tlv) - * ERO Object,LSPA Object,BandWidth Object,Metric-list,RRO Object - * in PcRpt message. - */ - @Test - public void reportMessageTest33() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x01, (byte) 0x1c, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x08, 0x10, 0x00, 0x34, 0x01, 0x08, 0x11, 0x01, //RRO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x06, 0x06, - 0x06, 0x06, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x05, 0x05, 0x05, 0x05, 0x04, 0x00}; - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object(symbolic path Tlv),ERO Object,LSPA Object - * BandWidth Object,Metric-list,SRP Object,LSP Object(symbolic path tlv) - * ERO Object,LSPA Object,BandWidth Object,Metric-list - * in PcRpt message. - */ - @Test - public void reportMessageTest34() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0xB4, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric Object - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x04, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20}; //Metric Object - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } - - /** - * This test case checks for SRP Object,LSP Object)Symbolic path tlv),ERO Object,SRP Object - * LSP Object(symbolic path tlv) ERO Object,LSPA Object, BandWidth Object,Metric-list - * in PcRpt message. - */ - @Test - public void reportMessageTest35() throws PcepParseException { - - byte[] reportMsg = new byte[]{0x20, 0x0a, 0x00, (byte) 0x8C, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x21, 0x10, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, //SRP Object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP Object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, //ERO Object - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x04, 0x00, - 0x01, 0x08, (byte) 0xb6, 0x02, 0x4e, 0x20, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, //LSPA Object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth Object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20}; //Metric Object - - byte[] testReportMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(reportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(reportMsg)); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepTEReportMsgTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepTEReportMsgTest.java deleted file mode 100644 index b800e05e..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepTEReportMsgTest.java +++ /dev/null @@ -1,1600 +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.pcepio; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.junit.Test; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepTEReportMsg; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.core.Is.is; - -public class PcepTEReportMsgTest { - - /** - * This test case checks for - * TE Object (Routing Universe TLV, Local TE Node Descriptors TLV(AutonomousSystemTlv)). - * in PcTERpt message. - */ - @Test - public void teReportMessageTest1() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, 0x28, // common header - 0x0E, 0x10, 0x00, 0x24, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x08, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystem Tlv - 0x00, 0x00, 0x00, 0x11}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * T E Object (Routing Universe TLV, Local TE Node Descriptors TLV(AutonomousSystemTlv)) with different TE-ID. - * in PcTERpt message. - */ - @Test - public void teReportMessageTest2() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, 0x28, // common header - 0x0E, 0x10, 0x00, 0x24, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x08, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for TE Object (Routing Universe TLV) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest3() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, 0x1c, // common header - 0x0E, 0x10, 0x00, 0x18, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv. - * OSPFareaIDsubTlv, RouterIDSubTlv)). - * in PcTERpt message. - */ - @Test - public void teReportMessageTest4() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, 0x44, // common header - 0x0E, 0x10, 0x00, 0x40, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest5() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, 0x3C, // common header - 0x0E, 0x10, 0x00, 0x38, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x1C, // Local TE Node Descriptors TLV - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(OSPFareaIDsubTlv, - * RouterIDSubTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest6() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, 0x34, // common header - 0x0E, 0x10, 0x00, 0x30, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x14, // Local TE Node Descriptors TLV - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(RouterIDSubTlv)). - * in PcTERpt message. - */ - @Test - public void teReportMessageTest7() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, 0x2C, // common header - 0x0E, 0x10, 0x00, 0x28, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x0C, // Local TE Node Descriptors TLV - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11}; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for TE Object (Routing Universe TLV,Local TE Node Descriptors TLV) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest8() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, 0x20, // common header - 0x0E, 0x10, 0x00, 0x1C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x00 // Local TE Node Descriptors TLV - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv. - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(AutonomousSystemTlv, BGPLSidentifierTlv. - * OSPFareaIDsubTlv, RouterIDSubTlv)). - * in PcTERpt message. - */ - @Test - public void teReportMessageTest9() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, 0x6C, // common header - 0x0E, 0x10, 0x00, 0x68, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x24, //RemoteTENodeDescriptorsTLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest10() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, 0x64, // common header - 0x0E, 0x10, 0x00, 0x60, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x1C, //RemoteTENodeDescriptorsTLV - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(OSPFareaIDsubTlv, RouterIDSubTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest11() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, 0x5C, // common header - 0x0E, 0x10, 0x00, 0x58, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x14, //RemoteTENodeDescriptorsTLV - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(RouterIDSubTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest12() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, 0x54, // common header - 0x0E, 0x10, 0x00, 0x50, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x0c, //RemoteTENodeDescriptorsTLV - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest13() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, 0x48, // common header - 0x0E, 0x10, 0x00, 0x44, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x00, //RemoteTENodeDescriptorsTLV - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), TELinkDescriptorsTLV(LinkLocalRemoteIdentifiersTlv - * IPv4InterfaceAddressTlv, IPv4NeighborAddressTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest14() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, (byte) 0x8C, // common header - 0x0E, 0x10, 0x00, (byte) 0x88, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x24, //RemoteTENodeDescriptorsTLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x04, 0x2E, 0x00, 0x1C, //TELinkDescriptorsTLV - 0x00, 0x04, 0x00, 0x08, //LinkLocalRemoteIdentifiersTlv - 0x01, 0x11, 0x00, 0x09, - 0x01, 0x21, 0x00, 0x09, - 0x00, 0x06, 0x00, 0x04, //IPv4InterfaceAddressTlv - 0x01, 0x01, 0x01, 0x01, - 0x00, 0x08, 0x00, 0x04, //IPv4NeighborAddressTlv - 0x01, 0x011, 0x01, 0x10 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), TELinkDescriptorsTLV( - * IPv4InterfaceAddressTlv, IPv4NeighborAddressTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest15() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, (byte) 0x80, // common header - 0x0E, 0x10, 0x00, (byte) 0x7C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x24, //RemoteTENodeDescriptorsTLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x04, 0x2E, 0x00, 0x10, //TELinkDescriptorsTLV - 0x00, 0x06, 0x00, 0x04, //IPv4InterfaceAddressTlv - 0x01, 0x01, 0x01, 0x01, - 0x00, 0x08, 0x00, 0x04, //IPv4NeighborAddressTlv - 0x01, 0x011, 0x01, 0x10 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), TELinkDescriptorsTLV(IPv4NeighborAddressTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest16() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, (byte) 0x78, // common header - 0x0E, 0x10, 0x00, (byte) 0x74, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x24, //RemoteTENodeDescriptorsTLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x04, 0x2E, 0x00, 0x08, //TELinkDescriptorsTLV - 0x00, 0x08, 0x00, 0x04, //IPv4NeighborAddressTlv - 0x01, 0x011, 0x01, 0x10 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), TELinkDescriptorsTLV) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest17() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, (byte) 0x70, // common header - 0x0E, 0x10, 0x00, (byte) 0x6C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x24, //RemoteTENodeDescriptorsTLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x04, 0x2E, 0x00, 0x00, //TELinkDescriptorsTLV - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), TELinkDescriptorsTLV(LinkLocalRemoteIdentifiersTlv - * IPv4InterfaceAddressTlv, IPv4NeighborAddressTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest18() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, (byte) 0xC0, // common header - 0x0E, 0x10, 0x00, (byte) 0xbC, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x24, //RemoteTENodeDescriptorsTLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x04, 0x2E, 0x00, 0x1C, //TELinkDescriptorsTLV - 0x00, 0x04, 0x00, 0x08, //LinkLocalRemoteIdentifiersTlv - 0x01, 0x11, 0x00, 0x09, - 0x01, 0x21, 0x00, 0x09, - 0x00, 0x06, 0x00, 0x04, //IPv4InterfaceAddressTlv - 0x01, 0x01, 0x01, 0x01, - 0x00, 0x08, 0x00, 0x04, //IPv4NeighborAddressTlv - 0x01, 0x011, 0x01, 0x10, - 0x04, (byte) 0xF3, 0x00, 0x30, //TENodeAttributesTlv - 0x00, 0x0E, 0x00, 0x01, //NodeFlagBitsTlv - (byte) 0x90, 0x00, 0x00, 0x00, - 0x03, (byte) 0xE9, 0x00, 0x04, //OpaqueNodeAttributeTlv - 0x01, 0x011, 0x01, 0x10, - 0x03, (byte) 0xEF, 0x00, 0x08, //NodeNameTlv - 0x08, 0x00, 0x01, 0x09, - 0x08, 0x00, 0x01, 0x09, - 0x00, 0x6B, 0x00, 0x08, //ISISAreaIdentifierTlv - 0x20, 0x01, 0x22, 0x01, - 0x20, 0x01, 0x22, 0x01, - 0x00, (byte) 0x86, 0x00, 0x04, //IPv4TERouterIdOfLocalNodeTlv - 0x00, 0x01, 0x01, 0x02 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), TELinkDescriptorsTLV(LinkLocalRemoteIdentifiersTlv - * IPv4InterfaceAddressTlv, IPv4NeighborAddressTlv), TENodeAttributesTlv(NodeFlagBitsTlv - * OpaqueNodeAttributeTlv, NodeNameTlv, ISISAreaIdentifierTlv, IPv4TERouterIdOfLocalNodeTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest19() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, (byte) 0xC0, // common header - 0x0E, 0x10, 0x00, (byte) 0xBC, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x24, //RemoteTENodeDescriptorsTLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x04, 0x2E, 0x00, 0x1C, //TELinkDescriptorsTLV - 0x00, 0x04, 0x00, 0x08, //LinkLocalRemoteIdentifiersTlv - 0x01, 0x11, 0x00, 0x09, - 0x01, 0x21, 0x00, 0x09, - 0x00, 0x06, 0x00, 0x04, //IPv4InterfaceAddressTlv - 0x01, 0x01, 0x01, 0x01, - 0x00, 0x08, 0x00, 0x04, //IPv4NeighborAddressTlv - 0x01, 0x011, 0x01, 0x10, - 0x04, (byte) 0xF3, 0x00, 0x30, //TENodeAttributesTlv - 0x00, 0x0E, 0x00, 0x01, //NodeFlagBitsTlv - (byte) 0x90, 0x00, 0x00, 0x00, - 0x03, (byte) 0xE9, 0x00, 0x04, //OpaqueNodeAttributeTlv - 0x01, 0x011, 0x01, 0x10, - 0x03, (byte) 0xEF, 0x00, 0x08, //NodeNameTlv - 0x08, 0x00, 0x01, 0x09, - 0x08, 0x00, 0x01, 0x09, - 0x00, 0x6B, 0x00, 0x08, //ISISAreaIdentifierTlv - 0x20, 0x01, 0x22, 0x01, - 0x20, 0x01, 0x22, 0x01, - 0x00, (byte) 0x86, 0x00, 0x04, //IPv4TERouterIdOfLocalNodeTlv - 0x00, 0x01, 0x01, 0x02 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), TELinkDescriptorsTLV(LinkLocalRemoteIdentifiersTlv - * IPv4InterfaceAddressTlv, IPv4NeighborAddressTlv), TENodeAttributesTlv(OpaqueNodeAttributeTlv - * NodeNameTlv, ISISAreaIdentifierTlv, IPv4TERouterIdOfLocalNodeTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest20() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, (byte) 0xB8, // common header - 0x0E, 0x10, 0x00, (byte) 0xB4, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x24, //RemoteTENodeDescriptorsTLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x04, 0x2E, 0x00, 0x1C, //TELinkDescriptorsTLV - 0x00, 0x04, 0x00, 0x08, //LinkLocalRemoteIdentifiersTlv - 0x01, 0x11, 0x00, 0x09, - 0x01, 0x21, 0x00, 0x09, - 0x00, 0x06, 0x00, 0x04, //IPv4InterfaceAddressTlv - 0x01, 0x01, 0x01, 0x01, - 0x00, 0x08, 0x00, 0x04, //IPv4NeighborAddressTlv - 0x01, 0x011, 0x01, 0x10, - 0x04, (byte) 0xF3, 0x00, 0x28, //TENodeAttributesTlv - 0x03, (byte) 0xE9, 0x00, 0x04, //OpaqueNodeAttributeTlv - 0x01, 0x011, 0x01, 0x10, - 0x03, (byte) 0xEF, 0x00, 0x08, //NodeNameTlv - 0x08, 0x00, 0x01, 0x09, - 0x08, 0x00, 0x01, 0x09, - 0x00, 0x6B, 0x00, 0x08, //ISISAreaIdentifierTlv - 0x20, 0x01, 0x22, 0x01, - 0x20, 0x01, 0x22, 0x01, - 0x00, (byte) 0x86, 0x00, 0x04, //IPv4TERouterIdOfLocalNodeTlv - 0x00, 0x01, 0x01, 0x02 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), TELinkDescriptorsTLV(LinkLocalRemoteIdentifiersTlv. - * IPv4InterfaceAddressTlv, IPv4NeighborAddressTlv), TENodeAttributesTlv(OpaqueNodeAttributeTlv - * ISISAreaIdentifierTlv, IPv4TERouterIdOfLocalNodeTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest21() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x00, (byte) 0xAC, // common header - 0x0E, 0x10, 0x00, (byte) 0xA8, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x24, //RemoteTENodeDescriptorsTLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x04, 0x2E, 0x00, 0x1C, //TELinkDescriptorsTLV - 0x00, 0x04, 0x00, 0x08, //LinkLocalRemoteIdentifiersTlv - 0x01, 0x11, 0x00, 0x09, - 0x01, 0x21, 0x00, 0x09, - 0x00, 0x06, 0x00, 0x04, //IPv4InterfaceAddressTlv - 0x01, 0x01, 0x01, 0x01, - 0x00, 0x08, 0x00, 0x04, //IPv4NeighborAddressTlv - 0x01, 0x011, 0x01, 0x10, - 0x04, (byte) 0xF3, 0x00, 0x1C, //TENodeAttributesTlv - 0x03, (byte) 0xE9, 0x00, 0x04, //OpaqueNodeAttributeTlv - 0x01, 0x011, 0x01, 0x10, - 0x00, 0x6B, 0x00, 0x08, //ISISAreaIdentifierTlv - 0x20, 0x01, 0x22, 0x01, - 0x20, 0x01, 0x22, 0x01, - 0x00, (byte) 0x86, 0x00, 0x04, //IPv4TERouterIdOfLocalNodeTlv - 0x00, 0x01, 0x01, 0x02 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv. - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(AutonomousSystemTlv, BGPLSidentifierTlv. - * OSPFareaIDsubTlv, RouterIDSubTlv), TELinkDescriptorsTLV(LinkLocalRemoteIdentifiersTlv. - * IPv4InterfaceAddressTlv, IPv4NeighborAddressTlv), TENodeAttributesTlv(NodeFlagBitsTlv. - * OpaqueNodeAttributeTlv, NodeNameTlv, ISISAreaIdentifierTlv, IPv4TERouterIdOfLocalNodeTlv). - * TELinkAttributesTlv(IPv4TERouterIdOfRemoteNodeTlv, IPv6TERouterIdofRemoteNodeTlv, AdministrativeGroupTlv. - * MaximumLinkBandwidthTlv, MaximumReservableLinkBandwidthTlv, UnreservedBandwidthTlv, TEDefaultMetricTlv. - * LinkProtectionTypeTlv, MPLSProtocolMaskTlv, IGPMetricTlv:, SharedRiskLinkGroupTlv. - * OpaqueLinkAttributeTlv, LinkNameTlv)). - * in PcTERpt message. - */ - @Test - public void teReportMessageTest22() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x01, (byte) 0x120, // common header - 0x0E, 0x10, 0x01, (byte) 0x1C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x24, //RemoteTENodeDescriptorsTLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x04, 0x2E, 0x00, 0x1C, //TELinkDescriptorsTLV - 0x00, 0x04, 0x00, 0x08, //LinkLocalRemoteIdentifiersTlv - 0x01, 0x11, 0x00, 0x09, - 0x01, 0x21, 0x00, 0x09, - 0x00, 0x06, 0x00, 0x04, //IPv4InterfaceAddressTlv - 0x01, 0x01, 0x01, 0x01, - 0x00, 0x08, 0x00, 0x04, //IPv4NeighborAddressTlv - 0x01, 0x011, 0x01, 0x10, - 0x04, (byte) 0xF3, 0x00, 0x28, //TENodeAttributesTlv - 0x03, (byte) 0xE9, 0x00, 0x04, //OpaqueNodeAttributeTlv - 0x01, 0x011, 0x01, 0x10, - 0x03, (byte) 0xEF, 0x00, 0x08, //NodeNameTlv - 0x08, 0x00, 0x01, 0x09, - 0x08, 0x00, 0x01, 0x09, - 0x00, 0x6B, 0x00, 0x08, //ISISAreaIdentifierTlv - 0x20, 0x01, 0x22, 0x01, - 0x20, 0x01, 0x22, 0x01, - 0x00, (byte) 0x86, 0x00, 0x04, //IPv4TERouterIdOfLocalNodeTlv - 0x00, 0x01, 0x01, 0x02, - 0x07, 0x69, 0x00, 0x64, //TELinkAttributesTlv - 0x05, 0x3C, 0x00, 0x04, //IPv4TERouterIdOfRemoteNodeTlv - 0x00, 0x07, 0x08, 0x00, - 0x00, 0x03, 0x00, 0x04, //AdministrativeGroupTlv - 0x00, 0x09, 0x08, 0x00, - 0x00, 0x09, 0x00, 0x04, //MaximumLinkBandwidthTlv - 0x00, 0x09, 0x00, 0x00, - 0x00, 0x0a, 0x00, 0x04, //MaximumReservableLinkBandwidthTlv - 0x00, 0x10, 0x00, 0x00, - 0x00, 0x0b, 0x00, 0x04, //UnreservedBandwidthTlv - 0x00, 0x00, (byte) 0x90, 0x00, - 0x34, 0x58, 0x00, 0x04, //TEDefaultMetricTlv - 0x00, (byte) 0x99, 0x09, 0x00, - 0x00, 0x14, 0x00, 0x02, //LinkProtectionTypeTlv - 0x09, 0x00, 0x00, 0x00, - 0x04, 0x46, 0x00, 0x01, //MPLSProtocolMaskTlv - (byte) 0x80, 0x00, 0x00, 0x00, - 0x04, 0x47, 0x00, 0x03, //IGPMetricTlv - 0x09, (byte) 0x89, 0x07, 0x00, - 0x04, 0x48, 0x00, 0x08, //SharedRiskLinkGroupTlv - 0x04, 0x47, 0x00, 0x03, - 0x04, 0x47, 0x00, 0x03, //OpaqueLinkAttributeTlv - 0x04, 0x49, 0x00, 0x04, - 0x04, 0x47, 0x00, 0x03, - 0x04, 0x4A, 0x00, 0x04, //LinkNameTlv - 0x04, 0x47, 0x00, 0x03 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), TELinkDescriptorsTLV(LinkLocalRemoteIdentifiersTlv - * IPv4InterfaceAddressTlv, IPv4NeighborAddressTlv), TENodeAttributesTlv(NodeFlagBitsTlv - * OpaqueNodeAttributeTlv, NodeNameTlv, ISISAreaIdentifierTlv, IPv4TERouterIdOfLocalNodeTlv) - * TELinkAttributesTlv(IPv4TERouterIdOfRemoteNodeTlv, IPv6TERouterIdofRemoteNodeTlv, AdministrativeGroupTlv - * MaximumLinkBandwidthTlv, MaximumReservableLinkBandwidthTlv, UnreservedBandwidthTlv, TEDefaultMetricTlv - * LinkProtectionTypeTlv, MPLSProtocolMaskTlv, IGPMetricTlv:, SharedRiskLinkGroupTlv - * OpaqueLinkAttributeTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest23() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x01, (byte) 0x118, // common header - 0x0E, 0x10, 0x01, (byte) 0x14, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x24, //RemoteTENodeDescriptorsTLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x04, 0x2E, 0x00, 0x1C, //TELinkDescriptorsTLV - 0x00, 0x04, 0x00, 0x08, //LinkLocalRemoteIdentifiersTlv - 0x01, 0x11, 0x00, 0x09, - 0x01, 0x21, 0x00, 0x09, - 0x00, 0x06, 0x00, 0x04, //IPv4InterfaceAddressTlv - 0x01, 0x01, 0x01, 0x01, - 0x00, 0x08, 0x00, 0x04, //IPv4NeighborAddressTlv - 0x01, 0x011, 0x01, 0x10, - 0x04, (byte) 0xF3, 0x00, 0x28, //TENodeAttributesTlv - 0x03, (byte) 0xE9, 0x00, 0x04, //OpaqueNodeAttributeTlv - 0x01, 0x011, 0x01, 0x10, - 0x03, (byte) 0xEF, 0x00, 0x08, //NodeNameTlv - 0x08, 0x00, 0x01, 0x09, - 0x08, 0x00, 0x01, 0x09, - 0x00, 0x6B, 0x00, 0x08, //ISISAreaIdentifierTlv - 0x20, 0x01, 0x22, 0x01, - 0x20, 0x01, 0x22, 0x01, - 0x00, (byte) 0x86, 0x00, 0x04, //IPv4TERouterIdOfLocalNodeTlv - 0x00, 0x01, 0x01, 0x02, - 0x07, 0x69, 0x00, 0x5C, //TELinkAttributesTlv - 0x05, 0x3C, 0x00, 0x04, //IPv4TERouterIdOfRemoteNodeTlv - 0x00, 0x07, 0x08, 0x00, - 0x00, 0x03, 0x00, 0x04, //AdministrativeGroupTlv - 0x00, 0x09, 0x08, 0x00, - 0x00, 0x09, 0x00, 0x04, //MaximumLinkBandwidthTlv - 0x00, 0x09, 0x00, 0x00, - 0x00, 0x0a, 0x00, 0x04, //MaximumReservableLinkBandwidthTlv - 0x00, 0x10, 0x00, 0x00, - 0x00, 0x0b, 0x00, 0x04, //UnreservedBandwidthTlv - 0x00, 0x00, (byte) 0x90, 0x00, - 0x34, 0x58, 0x00, 0x04, //TEDefaultMetricTlv - 0x00, (byte) 0x99, 0x09, 0x00, - 0x00, 0x14, 0x00, 0x02, //LinkProtectionTypeTlv - 0x09, 0x00, 0x00, 0x00, - 0x04, 0x46, 0x00, 0x01, //MPLSProtocolMaskTlv - (byte) 0x80, 0x00, 0x00, 0x00, - 0x04, 0x47, 0x00, 0x03, //IGPMetricTlv - 0x09, (byte) 0x89, 0x07, 0x00, - 0x04, 0x48, 0x00, 0x08, //SharedRiskLinkGroupTlv - 0x04, 0x47, 0x00, 0x03, - 0x04, 0x47, 0x00, 0x03, //OpaqueLinkAttributeTlv - 0x04, 0x49, 0x00, 0x04, - 0x04, 0x47, 0x00, 0x03 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), TELinkDescriptorsTLV(LinkLocalRemoteIdentifiersTlv - * IPv4InterfaceAddressTlv, IPv4NeighborAddressTlv), TENodeAttributesTlv(NodeFlagBitsTlv - * OpaqueNodeAttributeTlv, NodeNameTlv, ISISAreaIdentifierTlv, IPv4TERouterIdOfLocalNodeTlv) - * TELinkAttributesTlv(IPv4TERouterIdOfRemoteNodeTlv, IPv6TERouterIdofRemoteNodeTlv, AdministrativeGroupTlv - * MaximumLinkBandwidthTlv, MaximumReservableLinkBandwidthTlv, UnreservedBandwidthTlv, TEDefaultMetricTlv - * LinkProtectionTypeTlv, MPLSProtocolMaskTlv, IGPMetricTlv:, SharedRiskLinkGroupTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest24() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x01, (byte) 0x110, // common header - 0x0E, 0x10, 0x01, (byte) 0x0C, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x24, //RemoteTENodeDescriptorsTLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x04, 0x2E, 0x00, 0x1C, //TELinkDescriptorsTLV - 0x00, 0x04, 0x00, 0x08, //LinkLocalRemoteIdentifiersTlv - 0x01, 0x11, 0x00, 0x09, - 0x01, 0x21, 0x00, 0x09, - 0x00, 0x06, 0x00, 0x04, //IPv4InterfaceAddressTlv - 0x01, 0x01, 0x01, 0x01, - 0x00, 0x08, 0x00, 0x04, //IPv4NeighborAddressTlv - 0x01, 0x011, 0x01, 0x10, - 0x04, (byte) 0xF3, 0x00, 0x28, //TENodeAttributesTlv - 0x03, (byte) 0xE9, 0x00, 0x04, //OpaqueNodeAttributeTlv - 0x01, 0x011, 0x01, 0x10, - 0x03, (byte) 0xEF, 0x00, 0x08, //NodeNameTlv - 0x08, 0x00, 0x01, 0x09, - 0x08, 0x00, 0x01, 0x09, - 0x00, 0x6B, 0x00, 0x08, //ISISAreaIdentifierTlv - 0x20, 0x01, 0x22, 0x01, - 0x20, 0x01, 0x22, 0x01, - 0x00, (byte) 0x86, 0x00, 0x04, //IPv4TERouterIdOfLocalNodeTlv - 0x00, 0x01, 0x01, 0x02, - 0x07, 0x69, 0x00, 0x54, //TELinkAttributesTlv - 0x05, 0x3C, 0x00, 0x04, //IPv4TERouterIdOfRemoteNodeTlv - 0x00, 0x07, 0x08, 0x00, - 0x00, 0x03, 0x00, 0x04, //AdministrativeGroupTlv - 0x00, 0x09, 0x08, 0x00, - 0x00, 0x09, 0x00, 0x04, //MaximumLinkBandwidthTlv - 0x00, 0x09, 0x00, 0x00, - 0x00, 0x0a, 0x00, 0x04, //MaximumReservableLinkBandwidthTlv - 0x00, 0x10, 0x00, 0x00, - 0x00, 0x0b, 0x00, 0x04, //UnreservedBandwidthTlv - 0x00, 0x00, (byte) 0x90, 0x00, - 0x34, 0x58, 0x00, 0x04, //TEDefaultMetricTlv - 0x00, (byte) 0x99, 0x09, 0x00, - 0x00, 0x14, 0x00, 0x02, //LinkProtectionTypeTlv - 0x09, 0x00, 0x00, 0x00, - 0x04, 0x46, 0x00, 0x01, //MPLSProtocolMaskTlv - (byte) 0x80, 0x00, 0x00, 0x00, - 0x04, 0x47, 0x00, 0x03, //IGPMetricTlv - 0x09, (byte) 0x89, 0x07, 0x00, - 0x04, 0x48, 0x00, 0x08, //SharedRiskLinkGroupTlv - 0x04, 0x47, 0x00, 0x03, - 0x04, 0x47, 0x00, 0x03 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } - - /** - * This test case checks for - * TE Object (Routing Universe TLV,Local TE Node Descriptors TLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), RemoteTENodeDescriptorsTLV(AutonomousSystemTlv, BGPLSidentifierTlv - * OSPFareaIDsubTlv, RouterIDSubTlv), TELinkDescriptorsTLV(LinkLocalRemoteIdentifiersTlv - * IPv4InterfaceAddressTlv, IPv4NeighborAddressTlv), TENodeAttributesTlv(NodeFlagBitsTlv - * OpaqueNodeAttributeTlv, NodeNameTlv, ISISAreaIdentifierTlv, IPv4TERouterIdOfLocalNodeTlv) - * TELinkAttributesTlv(IPv4TERouterIdOfRemoteNodeTlv, IPv6TERouterIdofRemoteNodeTlv, AdministrativeGroupTlv - * MaximumLinkBandwidthTlv, MaximumReservableLinkBandwidthTlv, UnreservedBandwidthTlv, TEDefaultMetricTlv - * LinkProtectionTypeTlv, MPLSProtocolMaskTlv, IGPMetricTlv)) - * in PcTERpt message. - */ - @Test - public void teReportMessageTest25() throws PcepParseException { - - byte[] teReportMsg = new byte[]{0x20, 0x0E, 0x01, (byte) 0x104, // common header - 0x0E, 0x10, 0x01, 0x00, // TE Object Header - 0x01, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x10, // TE-ID - 0x00, 0x0E, 0x00, 0x08, // Routing Universe TLV - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x01, - 0x06, 0x65, 0x00, 0x24, // Local TE Node Descriptors TLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xEB, 0x00, 0x24, //RemoteTENodeDescriptorsTLV - 0x00, 0x64, 0x00, 0x04, //AutonomousSystemTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x11, 0x00, 0x04, //BGPLSidentifierTlv - 0x00, 0x00, 0x00, 0x11, - 0x02, 0x58, 0x00, 0x04, //OSPFareaIDsubTlv - 0x00, 0x00, 0x00, 0x11, - 0x03, (byte) 0xE8, 0x00, 0x08, //RouterIDSubTlv - 0x00, 0x00, 0x00, 0x11, - 0x00, 0x00, 0x00, 0x11, - 0x04, 0x2E, 0x00, 0x1C, //TELinkDescriptorsTLV - 0x00, 0x04, 0x00, 0x08, //LinkLocalRemoteIdentifiersTlv - 0x01, 0x11, 0x00, 0x09, - 0x01, 0x21, 0x00, 0x09, - 0x00, 0x06, 0x00, 0x04, //IPv4InterfaceAddressTlv - 0x01, 0x01, 0x01, 0x01, - 0x00, 0x08, 0x00, 0x04, //IPv4NeighborAddressTlv - 0x01, 0x011, 0x01, 0x10, - 0x04, (byte) 0xF3, 0x00, 0x28, //TENodeAttributesTlv - 0x03, (byte) 0xE9, 0x00, 0x04, //OpaqueNodeAttributeTlv - 0x01, 0x011, 0x01, 0x10, - 0x03, (byte) 0xEF, 0x00, 0x08, //NodeNameTlv - 0x08, 0x00, 0x01, 0x09, - 0x08, 0x00, 0x01, 0x09, - 0x00, 0x6B, 0x00, 0x08, //ISISAreaIdentifierTlv - 0x20, 0x01, 0x22, 0x01, - 0x20, 0x01, 0x22, 0x01, - 0x00, (byte) 0x86, 0x00, 0x04, //IPv4TERouterIdOfLocalNodeTlv - 0x00, 0x01, 0x01, 0x02, - 0x07, 0x69, 0x00, 0x48, //TELinkAttributesTlv - 0x05, 0x3C, 0x00, 0x04, //IPv4TERouterIdOfRemoteNodeTlv - 0x00, 0x07, 0x08, 0x00, - 0x00, 0x03, 0x00, 0x04, //AdministrativeGroupTlv - 0x00, 0x09, 0x08, 0x00, - 0x00, 0x09, 0x00, 0x04, //MaximumLinkBandwidthTlv - 0x00, 0x09, 0x00, 0x00, - 0x00, 0x0a, 0x00, 0x04, //MaximumReservableLinkBandwidthTlv - 0x00, 0x10, 0x00, 0x00, - 0x00, 0x0b, 0x00, 0x04, //UnreservedBandwidthTlv - 0x00, 0x00, (byte) 0x90, 0x00, - 0x34, 0x58, 0x00, 0x04, //TEDefaultMetricTlv - 0x00, (byte) 0x99, 0x09, 0x00, - 0x00, 0x14, 0x00, 0x02, //LinkProtectionTypeTlv - 0x09, 0x00, 0x00, 0x00, - 0x04, 0x46, 0x00, 0x01, //MPLSProtocolMaskTlv - (byte) 0x80, 0x00, 0x00, 0x00, - 0x04, 0x47, 0x00, 0x03, //IGPMetricTlv - 0x09, (byte) 0x89, 0x07, 0x00 - }; - - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(teReportMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - byte[] testReportMsg = {0}; - - assertThat(message, instanceOf(PcepTEReportMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - - int readLen = buf.writerIndex(); - testReportMsg = new byte[readLen]; - buf.readBytes(testReportMsg, 0, readLen); - - assertThat(testReportMsg, is(teReportMsg)); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepUpdateMsgExtTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepUpdateMsgExtTest.java deleted file mode 100644 index 1f956173..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepUpdateMsgExtTest.java +++ /dev/null @@ -1,1275 +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.pcepio; - -import static org.hamcrest.core.Is.is; -import static org.hamcrest.Matchers.instanceOf; - -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; - -import static org.hamcrest.MatcherAssert.assertThat; - -import org.junit.Test; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepUpdateMsg; - -/** - * Test cases for PCEP update message. - */ -public class PcepUpdateMsgExtTest { - - /** - * This test case is for SRP object(symbolic path tlv), LSP object(StatefulLspDbVerTlv), ERO object, - * Metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest1() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x8c, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x38, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulIPv4LspIdentidiersTlv), ERO object, - * LSPA, Bandwidth object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest2() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x68, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSP object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object, ERO object, LSPA, bandwidth object - * Metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest3() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x54, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x08, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulLspErrorCodeTlv), ERO object,bandwidth object - * Metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest4() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x5c, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulLspDbVerTlv), ERO object,bandwidth object - * Metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest5() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x60, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(SymbolicPathNameTlv), ERO object, LSPA, bandwidth object - * Metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest6() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x5c, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object(SymbolicPathNameTlv), LSP object(SymbolicPathNameTlv), ERO object, - * bandwidth object Metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest7() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x64, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulIPv4LspIdentidiersTlv), ERO object,LSPA - * bandwidth object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest8() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x5c, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }; //Bandwidth object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulRsvpErrorSpecTlv), ERO object,LSPA - * bandwidth object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest9() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x58, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x18, 0x00, 0x00, 0x10, 0x03, - 0x00, 0x15, 0x00, 0x0c, //StatefulRsvpErrorSpecTlv - 0x00, 0x0c, 0x06, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x05, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }; //Bandwidth object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulRsvpErrorSpecTlv), ERO object,LSPA - * bandwidth object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest10() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x50, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPa object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }; //Bandwidth object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulLspDbVerTlv), ERO object,LSPA - * bandwidth object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest11() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x54, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00}; //Bandwidth object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(SymbolicPathNameTlv), ERO object,LSPA - * bandwidth object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest12() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x50, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }; //Bandwidth object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object(SymbolicPathNameTlv), LSP object(SymbolicPathNameTlv), ERO object,LSPA - * bandwidth object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest13() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x58, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }; //Bandwidth object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulIPv4LspIdentidiersTlv), ERO object,LSPA - * metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest14() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x60, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object, ERO object,LSPA - * metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest15() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x4c, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x08, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //lspa object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulLspErrorCodeTlv), ERO object,LSPA - * metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest16() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x54, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulLspDbVerTlv), ERO object,LSPA - * metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest17() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x58, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(SymbolicPathNameTlv), ERO object,LSPA - * metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest18() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x54, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object(SymbolicPathNameTlv), LSP object(SymbolicPathNameTlv), ERO object, - * metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest19() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x5c, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulIPv4LspIdentidiersTlv), ERO object, - * Bandwidth , metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest20() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x54, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object, ERO object, - * Bandwidth , metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest21() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x40, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x08, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulLspErrorCodeTlv), ERO object, - * Bandwidth , metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest22() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x48, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulLspDbVerTlv), ERO object, - * Bandwidth , metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest23() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x4c, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(SymbolicPathNameTlv), ERO object, - * Bandwidth , metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest24() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x48, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object(SymbolicPathNameTlv), LSP object(SymbolicPathNameTlv), ERO object, - * Bandwidth , metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest25() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x50, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulIPv4LspIdentidiersTlv), ERO object, - * LSPA object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest26() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x54, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00 }; - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object, ERO object, - * bandwidth object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest27() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x34, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x08, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }; //Bandwidth object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object, LSP object(StatefulLspErrorCodeTlv), ERO object, - * metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest28() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x40, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object(SymbolicPathNameTlv), LSP object(StatefulLspErrorCodeTlv), ERO object, - * lspa object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest29() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x54, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00 }; - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object(SymbolicPathNameTlv), LSP object(StatefulLspErrorCodeTlv), ERO object, - * bandwidth object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest30() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x48, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }; //Bandwidth object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object(SymbolicPathNameTlv), LSP object(StatefulLspErrorCodeTlv), ERO object, - * metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest31() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x4c, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case is for SRP object(symbolic path tlv), LSP object(StatefulLspDbVerTlv), ERO object, - * Metric object in PcepUpdate message. - */ - @Test - public void pcepUpdateMsgTest32() throws PcepParseException { - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x64, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x14, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x17, 0x00, 0x08, //StatefulLspDbVerTlv - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO Object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } -} - diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepUpdateMsgTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepUpdateMsgTest.java deleted file mode 100644 index e965bfeb..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/PcepUpdateMsgTest.java +++ /dev/null @@ -1,1427 +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.pcepio; - -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 static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; -import org.onosproject.pcepio.exceptions.PcepParseException; -import org.onosproject.pcepio.protocol.PcepFactories; -import org.onosproject.pcepio.protocol.PcepMessage; -import org.onosproject.pcepio.protocol.PcepMessageReader; -import org.onosproject.pcepio.protocol.PcepUpdateMsg; - -public class PcepUpdateMsgTest { - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), ERO in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest1() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x30, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, (byte) 0xb6, 0x02, 0x4e, 0x1f, //StatefulIPv4LspIdentidiersTlv - 0x00, 0x01, (byte) 0x80, 0x01, (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x04 }; //ERO object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP(SymbolicPathNameTlv), LSP (StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv, StatefulLspErrorCodeTlv), ERO, LSPA, Metric-list in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest2() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x94, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object // lsp object - 0x00, 0x12, 0x00, 0x10, (byte) 0xb6, 0x02, 0x4e, 0x1f, //StatefulIPv4LspIdentidiersTlv - 0x00, 0x01, (byte) 0x80, 0x01, (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x24, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, - 0x01, 0x02, 0x04, 0x00, 0x01, 0x08, 0x12, 0x01, 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv), - * ERO objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest3() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x38, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x04 }; //ERO object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv), ERO objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest4() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x40, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x04 }; //ERO object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv), ERO objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest5() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x40, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x04 }; //ERO object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv), ERO objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest6() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x48, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x04 }; - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv), ERO objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest7() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x48, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x04}; //ERO object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv), ERO (IPv4SubObject) objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest8() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x50, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x0c, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00 }; - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv), ERO (IPv4SubObject, IPv4SubObject) objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest9() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x58, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00 }; - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv), ERO (IPv4SubObject, IPv4SubObject), LSPA objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest10() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x6c, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00 }; - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv), ERO (IPv4SubObject, IPv4SubObject),LSPA, Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest11() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x78, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv), ERO (IPv4SubObject, IPv4SubObject),LSPA, metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest12() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x70, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv), ERO (IPv4SubObject, IPv4SubObject),LSPA, metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest13() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x70, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv), - * ERO (IPv4SubObject, IPv4SubObject),LSPA, metric Object objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest14() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x68, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv), - * ERO (IPv4SubObject, IPv4SubObject),LSPA, metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest15() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x68, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), - * ERO (IPv4SubObject, IPv4SubObject),LSPA, metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest16() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x60, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), - * ERO (IPv4SubObject, IPv4SubObject),LSPA objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest17() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x54, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1c, 0x00, 0x00, 0x10, 0x05, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00 }; - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), - * ERO (IPv4SubObject, IPv4SubObject),Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest18() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x4c, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), - * ERO (IPv4SubObject, IPv4SubObject),Metric-list objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest19() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x58, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20, //Metric object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv),ERO (IPv4SubObject, IPv4SubObject),LSPA, Bandwidth, Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest20() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x80, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), - * ERO (IPv4SubObject, IPv4SubObject), Bandwidth objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest21() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x48, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }; //Bandwidth object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), - * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest22() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x5C, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00 }; //Bandwidth object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), - * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest23() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x68, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv) - * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest24() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x70, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv) - * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest25() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x70, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x24, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv) ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, - * Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest26() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x78, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv, SymbolicPathNameTlv, - * StatefulLspErrorCodeTlv) ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, - * Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest27() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x78, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, StatefulIPv4LspIdentidiersTlv, - * SymbolicPathNameTlv, StatefulLspErrorCodeTlv), ERO (IPv4SubObject, IPv4SubObject), - * LSPA, Bandwidth, Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest28() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x80, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x2c, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulIPv4LspIdentidiersTlv), - * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest29() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x68, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x1C, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x12, 0x00, 0x10, //StatefulIPv4LspIdentidiersTlv - (byte) 0xb6, 0x02, 0x4e, 0x1f, 0x00, 0x01, (byte) 0x80, 0x01, - (byte) 0xb6, 0x02, 0x4e, 0x1f, (byte) 0xb6, 0x02, 0x4e, 0x20, - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP, - * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest30() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x54, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x08, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20}; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (StatefulLspErrorCodeTlv), - * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest31() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x5c, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x14, 0x00, 0x04, 0x00, 0x00, 0x00, 0x08, //StatefulLspErrorCodeTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP, - * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest32() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x54, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x8, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv), - * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest33() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x5c, - 0x21, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } - - /** - * This test case checks for SRP, LSP (SymbolicPathNameTlv, SymbolicPathNameTlv), - * ERO (IPv4SubObject, IPv4SubObject), LSPA, Bandwidth, Metric objects in PcUpd message. - */ - @Test - public void pcepUpdateMsgTest34() throws PcepParseException { - - byte[] updateMsg = new byte[] {0x20, 0x0b, 0x00, (byte) 0x64, - 0x21, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, //SRP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x20, 0x10, 0x00, 0x10, 0x00, 0x00, 0x10, 0x03, //LSP object - 0x00, 0x11, 0x00, 0x02, 0x54, 0x31, 0x00, 0x00, //SymbolicPathNameTlv - 0x07, 0x10, 0x00, 0x14, 0x01, 0x08, 0x11, 0x01, //ERO object - 0x01, 0x01, 0x04, 0x00, 0x01, 0x08, 0x11, 0x01, - 0x01, 0x01, 0x04, 0x00, - 0x09, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, //LSPA object - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x07, 0x00, 0x00, - 0x05, 0x20, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, //Bandwidth object - 0x06, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, 0x20 }; //Metric object - - byte[] testupdateMsg = {0}; - ChannelBuffer buffer = ChannelBuffers.dynamicBuffer(); - buffer.writeBytes(updateMsg); - - PcepMessageReader<PcepMessage> reader = PcepFactories.getGenericReader(); - PcepMessage message = null; - - message = reader.readFrom(buffer); - - assertThat(message, instanceOf(PcepUpdateMsg.class)); - ChannelBuffer buf = ChannelBuffers.dynamicBuffer(); - message.writeTo(buf); - testupdateMsg = buf.array(); - - int readLen = buf.writerIndex() - 0; - testupdateMsg = new byte[readLen]; - buf.readBytes(testupdateMsg, 0, readLen); - - assertThat(testupdateMsg, is(updateMsg)); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/RemoteTENodeDescriptorsTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/RemoteTENodeDescriptorsTlvTest.java deleted file mode 100644 index 3b189c0b..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/RemoteTENodeDescriptorsTlvTest.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.pcepio; - -import java.util.LinkedList; - -import org.junit.Test; -import org.onosproject.pcepio.types.AutonomousSystemTlv; -import org.onosproject.pcepio.types.BGPLSidentifierTlv; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.RemoteTENodeDescriptorsTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test case for Remote TE Node Descriptors tlv. - */ -public class RemoteTENodeDescriptorsTlvTest { - - private final AutonomousSystemTlv autonomousSystemTlv1 = new AutonomousSystemTlv(10); - private final BGPLSidentifierTlv bGPLSidentifierTlv1 = new BGPLSidentifierTlv(20); - - private final AutonomousSystemTlv autonomousSystemTlv2 = new AutonomousSystemTlv(20); - private final BGPLSidentifierTlv bGPLSidentifierTlv2 = new BGPLSidentifierTlv(30); - - private final LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLV1 = new LinkedList<>(); - private final boolean a = llRemoteTENodeDescriptorSubTLV1.add(autonomousSystemTlv1); - private final boolean b = llRemoteTENodeDescriptorSubTLV1.add(bGPLSidentifierTlv1); - - private final LinkedList<PcepValueType> llRemoteTENodeDescriptorSubTLV2 = new LinkedList<>(); - private final boolean c = llRemoteTENodeDescriptorSubTLV2.add(autonomousSystemTlv2); - private final boolean d = llRemoteTENodeDescriptorSubTLV2.add(bGPLSidentifierTlv2); - - private final RemoteTENodeDescriptorsTlv tlv1 = RemoteTENodeDescriptorsTlv.of(llRemoteTENodeDescriptorSubTLV1); - private final RemoteTENodeDescriptorsTlv sameAsTlv1 = - RemoteTENodeDescriptorsTlv.of(llRemoteTENodeDescriptorSubTLV1); - private final RemoteTENodeDescriptorsTlv tlv2 = RemoteTENodeDescriptorsTlv.of(llRemoteTENodeDescriptorSubTLV2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, sameAsTlv1).addEqualityGroup(tlv2).testEquals(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/RouterIDSubTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/RouterIDSubTlvTest.java deleted file mode 100644 index 022fd414..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/RouterIDSubTlvTest.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.RouterIDSubTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test case for Router ID Sub tlv. - */ -public class RouterIDSubTlvTest { - - private final byte[] value1 = {1, 2 }; - private final Short length1 = 2; - private final RouterIDSubTlv tlv1 = RouterIDSubTlv.of(value1, length1); - - private final Short length2 = 2; - private final RouterIDSubTlv tlv2 = RouterIDSubTlv.of(value1, length2); - - private final byte[] value3 = {1, 2, 3 }; - private final Short length3 = 3; - private final RouterIDSubTlv tlv3 = RouterIDSubTlv.of(value3, length3); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/SharedRiskLinkGroupTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/SharedRiskLinkGroupTlvTest.java deleted file mode 100644 index ad62f61b..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/SharedRiskLinkGroupTlvTest.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.SharedRiskLinkGroupTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test case for Shared Risk Link Group tlv. - */ -public class SharedRiskLinkGroupTlvTest { - - private final int[] raw = {1 }; - private final Short hLength = 2; - private final SharedRiskLinkGroupTlv tlv1 = SharedRiskLinkGroupTlv.of(raw, hLength); - - private final SharedRiskLinkGroupTlv sameAsTlv1 = SharedRiskLinkGroupTlv.of(raw, hLength); - - private final int[] raw2 = {2 }; - private final Short hLength2 = 3; - private final SharedRiskLinkGroupTlv tlv2 = SharedRiskLinkGroupTlv.of(raw2, hLength2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, sameAsTlv1).addEqualityGroup(tlv2).testEquals(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/SrEroSubObjectTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/SrEroSubObjectTest.java deleted file mode 100644 index 47ea5842..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/SrEroSubObjectTest.java +++ /dev/null @@ -1,61 +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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.protocol.PcepNai; -import org.onosproject.pcepio.types.SrEroSubObject; - -import com.google.common.testing.EqualsTester; - -public class SrEroSubObjectTest { - - private final boolean bFFlag = false; - private final boolean bSFlag = false; - private final boolean bCFlag = false; - private final boolean bMFlag = false; - private final byte st = 1; - private final int sID = 1; - private final PcepNai nai = null; - - private final SrEroSubObject tlv1 = SrEroSubObject.of(st, bFFlag, bSFlag, bCFlag, bMFlag, sID, nai); - - private final boolean bFFlag1 = false; - private final boolean bSFlag1 = false; - private final boolean bCFlag1 = false; - private final boolean bMFlag1 = false; - private final byte st1 = 1; - private final int sID1 = 1; - private final PcepNai nai1 = null; - - private final SrEroSubObject tlv2 = SrEroSubObject.of(st1, bFFlag1, bSFlag1, bCFlag1, bMFlag1, sID1, nai1); - - private final boolean bFFlag2 = true; - private final boolean bSFlag2 = true; - private final boolean bCFlag2 = true; - private final boolean bMFlag2 = true; - private final byte st2 = 2; - private final int sID2 = 2; - private final PcepNai nai2 = null; - - private final SrEroSubObject tlv3 = SrEroSubObject.of(st2, bFFlag2, bSFlag2, bCFlag2, bMFlag2, sID2, nai2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/StatefulIPv4LspIdentidiersTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/StatefulIPv4LspIdentidiersTlvTest.java deleted file mode 100644 index f03c8ba3..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/StatefulIPv4LspIdentidiersTlvTest.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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.StatefulIPv4LspIdentidiersTlv; - -import com.google.common.testing.EqualsTester; - -public class StatefulIPv4LspIdentidiersTlvTest { - - private final int ipv4IngressAddress = 1; - private final short lspId = 1; - private final short tunnelId = 1; - private final int extendedTunnelId = 1; - private final int ipv4EgressAddress = 1; - - private final StatefulIPv4LspIdentidiersTlv tlv1 = StatefulIPv4LspIdentidiersTlv.of(ipv4IngressAddress, lspId, - tunnelId, extendedTunnelId, ipv4EgressAddress); - - private final int ipv4IngressAddress1 = 1; - private final short lspId1 = 1; - private final short tunnelId1 = 1; - private final int extendedTunnelId1 = 1; - private final int ipv4EgressAddress1 = 1; - - private final StatefulIPv4LspIdentidiersTlv tlv2 = StatefulIPv4LspIdentidiersTlv.of(ipv4IngressAddress1, lspId1, - tunnelId1, extendedTunnelId1, ipv4EgressAddress1); - - private final int ipv4IngressAddress2 = 2; - private final short lspId2 = 2; - private final short tunnelId2 = 2; - private final int extendedTunnelId2 = 2; - private final int ipv4EgressAddress2 = 2; - - private final StatefulIPv4LspIdentidiersTlv tlv3 = StatefulIPv4LspIdentidiersTlv.of(ipv4IngressAddress2, lspId2, - tunnelId2, extendedTunnelId2, ipv4EgressAddress2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); - - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/StatefulLspDbVerTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/StatefulLspDbVerTlvTest.java deleted file mode 100644 index 21bb3468..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/StatefulLspDbVerTlvTest.java +++ /dev/null @@ -1,37 +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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.StatefulLspDbVerTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test case for Stateful Lsp Db Ver tlv. - */ -public class StatefulLspDbVerTlvTest { - - private final StatefulLspDbVerTlv tlv1 = StatefulLspDbVerTlv.of(1); - private final StatefulLspDbVerTlv tlv2 = StatefulLspDbVerTlv.of(1); - private final StatefulLspDbVerTlv tlv3 = StatefulLspDbVerTlv.of(2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/StatefulLspErrorCodeTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/StatefulLspErrorCodeTlvTest.java deleted file mode 100644 index 8137ca0c..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/StatefulLspErrorCodeTlvTest.java +++ /dev/null @@ -1,32 +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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.StatefulLspErrorCodeTlv; -import com.google.common.testing.EqualsTester; - -public class StatefulLspErrorCodeTlvTest { - - private final StatefulLspErrorCodeTlv tlv1 = StatefulLspErrorCodeTlv.of(1); - private final StatefulLspErrorCodeTlv tlv2 = StatefulLspErrorCodeTlv.of(1); - private final StatefulLspErrorCodeTlv tlv3 = StatefulLspErrorCodeTlv.of(2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/StatefulPceCapabilityTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/StatefulPceCapabilityTlvTest.java deleted file mode 100644 index 29018d55..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/StatefulPceCapabilityTlvTest.java +++ /dev/null @@ -1,35 +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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.StatefulPceCapabilityTlv; -import com.google.common.testing.EqualsTester; - -/** - * Test case for Stateful Pce Capability tlv. - */ -public class StatefulPceCapabilityTlvTest { - - private final StatefulPceCapabilityTlv tlv1 = StatefulPceCapabilityTlv.of(1); - private final StatefulPceCapabilityTlv tlv2 = StatefulPceCapabilityTlv.of(1); - private final StatefulPceCapabilityTlv tlv3 = StatefulPceCapabilityTlv.of(2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/SymbolicPathNameTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/SymbolicPathNameTlvTest.java deleted file mode 100644 index 718bbb66..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/SymbolicPathNameTlvTest.java +++ /dev/null @@ -1,45 +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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.SymbolicPathNameTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test case for Symbolic path tlv. - */ -public class SymbolicPathNameTlvTest { - - private final byte[] value1 = {0x41 }; - private final Short length1 = 2; - private final SymbolicPathNameTlv tlv1 = SymbolicPathNameTlv.of(value1, length1); - - private final byte[] value2 = {0x41 }; - private final Short length2 = 2; - private final SymbolicPathNameTlv tlv2 = SymbolicPathNameTlv.of(value1, length2); - - private final byte[] value3 = {0x41, 0x43 }; - private final Short length3 = 3; - private final SymbolicPathNameTlv tlv3 = SymbolicPathNameTlv.of(value3, length3); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TEDefaultMetricTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TEDefaultMetricTlvTest.java deleted file mode 100644 index 32fa0af8..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TEDefaultMetricTlvTest.java +++ /dev/null @@ -1,36 +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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.TEDefaultMetricTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test case for TE Default Metric tlv. - */ -public class TEDefaultMetricTlvTest { - - private final TEDefaultMetricTlv tlv1 = TEDefaultMetricTlv.of(1); - private final TEDefaultMetricTlv tlv2 = TEDefaultMetricTlv.of(1); - private final TEDefaultMetricTlv tlv3 = TEDefaultMetricTlv.of(2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); - } -}
\ No newline at end of file diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TELinkAttributesTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TELinkAttributesTlvTest.java deleted file mode 100644 index 1e2101a9..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TELinkAttributesTlvTest.java +++ /dev/null @@ -1,59 +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.pcepio; - -import java.util.LinkedList; - -import org.junit.Test; -import org.onosproject.pcepio.types.AdministrativeGroupTlv; -import org.onosproject.pcepio.types.MaximumReservableLinkBandwidthTlv; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.TELinkAttributesTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test case for TE Link Attribute Tlv. - */ -public class TELinkAttributesTlvTest { - - private final AdministrativeGroupTlv administrativeGroupTlv1 = new AdministrativeGroupTlv(10); - private final MaximumReservableLinkBandwidthTlv maximumReservableLinkBandwidthTlv1 = - new MaximumReservableLinkBandwidthTlv(20); - - private final AdministrativeGroupTlv administrativeGroupTlv2 = new AdministrativeGroupTlv(20); - private final MaximumReservableLinkBandwidthTlv maximumReservableLinkBandwidthTlv2 = - new MaximumReservableLinkBandwidthTlv(30); - - private final LinkedList<PcepValueType> llLinkAttributesSubTLV1 = new LinkedList<>(); - private final boolean a = llLinkAttributesSubTLV1.add(administrativeGroupTlv1); - private final boolean b = llLinkAttributesSubTLV1.add(maximumReservableLinkBandwidthTlv1); - - private final LinkedList<PcepValueType> llLinkAttributesSubTLV2 = new LinkedList<>(); - - private final boolean c = llLinkAttributesSubTLV2.add(administrativeGroupTlv2); - private final boolean d = llLinkAttributesSubTLV2.add(maximumReservableLinkBandwidthTlv2); - - private final TELinkAttributesTlv tlv1 = TELinkAttributesTlv.of(llLinkAttributesSubTLV1); - private final TELinkAttributesTlv sameAsTlv1 = TELinkAttributesTlv.of(llLinkAttributesSubTLV1); - private final TELinkAttributesTlv tlv2 = TELinkAttributesTlv.of(llLinkAttributesSubTLV2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, sameAsTlv1).addEqualityGroup(tlv2).testEquals(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TELinkDescriptorsTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TELinkDescriptorsTlvTest.java deleted file mode 100644 index 89565b3f..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TELinkDescriptorsTlvTest.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.pcepio; - -import java.util.LinkedList; - -import org.junit.Test; -import org.onosproject.pcepio.types.IPv4InterfaceAddressTlv; -import org.onosproject.pcepio.types.LinkLocalRemoteIdentifiersTlv; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.TELinkDescriptorsTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test case for TE link descriptors Tlv. - */ -public class TELinkDescriptorsTlvTest { - private final LinkLocalRemoteIdentifiersTlv linkLocalRemoteIdentifiersTlv1 = new - LinkLocalRemoteIdentifiersTlv(10, 10); - private final IPv4InterfaceAddressTlv iPv4InterfaceAddressTlv1 = new IPv4InterfaceAddressTlv(0x01010101); - - private final LinkLocalRemoteIdentifiersTlv linkLocalRemoteIdentifiersTlv2 = new - LinkLocalRemoteIdentifiersTlv(20, 20); - private final IPv4InterfaceAddressTlv iPv4InterfaceAddressTlv2 = new IPv4InterfaceAddressTlv(0x02020202); - - private final LinkedList<PcepValueType> llLinkDescriptorsSubTLVs1 = new LinkedList<>(); - private final boolean a = llLinkDescriptorsSubTLVs1.add(linkLocalRemoteIdentifiersTlv1); - private final boolean b = llLinkDescriptorsSubTLVs1.add(iPv4InterfaceAddressTlv1); - - private final LinkedList<PcepValueType> llLinkDescriptorsSubTLVs2 = new LinkedList<>(); - private final boolean c = llLinkDescriptorsSubTLVs2.add(linkLocalRemoteIdentifiersTlv2); - private final boolean d = llLinkDescriptorsSubTLVs2.add(iPv4InterfaceAddressTlv2); - - private final TELinkDescriptorsTlv tlv1 = TELinkDescriptorsTlv.of(llLinkDescriptorsSubTLVs1); - private final TELinkDescriptorsTlv sameAstlv1 = TELinkDescriptorsTlv.of(llLinkDescriptorsSubTLVs1); - private final TELinkDescriptorsTlv tlv2 = TELinkDescriptorsTlv.of(llLinkDescriptorsSubTLVs2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, sameAstlv1).addEqualityGroup(tlv2).testEquals(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TENodeAttributesTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TENodeAttributesTlvTest.java deleted file mode 100644 index 17d44091..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TENodeAttributesTlvTest.java +++ /dev/null @@ -1,59 +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.pcepio; - -import java.util.LinkedList; - -import org.junit.Test; -import org.onosproject.pcepio.types.IPv4TERouterIdOfLocalNodeTlv; -import org.onosproject.pcepio.types.NodeFlagBitsTlv; -import org.onosproject.pcepio.types.PcepValueType; -import org.onosproject.pcepio.types.TENodeAttributesTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test case for TE Node Attribute tlv. - */ -public class TENodeAttributesTlvTest { - - private final NodeFlagBitsTlv nodeFlagBitsTlv1 = new NodeFlagBitsTlv((byte) 10); - private final IPv4TERouterIdOfLocalNodeTlv iPv4TERouterIdOfLocalNodeTlv1 = new - IPv4TERouterIdOfLocalNodeTlv(0x01010101); - - private final NodeFlagBitsTlv nodeFlagBitsTlv2 = new NodeFlagBitsTlv((byte) 20); - private final IPv4TERouterIdOfLocalNodeTlv iPv4TERouterIdOfLocalNodeTlv2 = new - IPv4TERouterIdOfLocalNodeTlv(0x02020202); - - private final LinkedList<PcepValueType> llNodeAttributesSubTLV1 = new LinkedList<>(); - private final boolean a = llNodeAttributesSubTLV1.add(nodeFlagBitsTlv1); - private final boolean b = llNodeAttributesSubTLV1.add(iPv4TERouterIdOfLocalNodeTlv1); - - private final LinkedList<PcepValueType> llNodeAttributesSubTLV2 = new LinkedList<>(); - - private final boolean c = llNodeAttributesSubTLV2.add(nodeFlagBitsTlv2); - private final boolean d = llNodeAttributesSubTLV2.add(iPv4TERouterIdOfLocalNodeTlv2); - - private final TENodeAttributesTlv tlv1 = TENodeAttributesTlv.of(llNodeAttributesSubTLV1); - private final TENodeAttributesTlv sameAsTlv1 = TENodeAttributesTlv.of(llNodeAttributesSubTLV1); - private final TENodeAttributesTlv tlv2 = TENodeAttributesTlv.of(llNodeAttributesSubTLV2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, sameAsTlv1).addEqualityGroup(tlv2).testEquals(); - } - -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TedCapabilityTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TedCapabilityTlvTest.java deleted file mode 100644 index 4e18e867..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/TedCapabilityTlvTest.java +++ /dev/null @@ -1,36 +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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.TedCapabilityTlv; - -import com.google.common.testing.EqualsTester; - -/** - * Test case for TED Capability tlv. - */ -public class TedCapabilityTlvTest { - - private final TedCapabilityTlv tlv1 = TedCapabilityTlv.of(1); - private final TedCapabilityTlv tlv2 = TedCapabilityTlv.of(1); - private final TedCapabilityTlv tlv3 = TedCapabilityTlv.of(2); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); - } -} diff --git a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/UnreservedBandwidthTlvTest.java b/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/UnreservedBandwidthTlvTest.java deleted file mode 100644 index e4cb9b15..00000000 --- a/framework/src/onos/pcep/pcepio/src/test/java/org/onosproject/pcepio/UnreservedBandwidthTlvTest.java +++ /dev/null @@ -1,37 +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.pcepio; - -import org.junit.Test; -import org.onosproject.pcepio.types.UnreservedBandwidthTlv; -import com.google.common.testing.EqualsTester; - -/** - * Unit Test case for Unreserved Bandwidth Tlv. - */ -public class UnreservedBandwidthTlvTest { - - // Objects of unreserved bandwidth tlv - private final UnreservedBandwidthTlv tlv1 = UnreservedBandwidthTlv.of(100); - private final UnreservedBandwidthTlv tlv2 = UnreservedBandwidthTlv.of(100); - private final UnreservedBandwidthTlv tlv3 = UnreservedBandwidthTlv.of(200); - - @Test - public void basics() { - new EqualsTester().addEqualityGroup(tlv1, tlv2).addEqualityGroup(tlv3).testEquals(); - } - -} diff --git a/framework/src/onos/pcep/pom.xml b/framework/src/onos/pcep/pom.xml deleted file mode 100755 index f0b9f8c3..00000000 --- a/framework/src/onos/pcep/pom.xml +++ /dev/null @@ -1,60 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Copyright 2014 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. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>onos-pcep-controller</artifactId> - <packaging>pom</packaging> - - <description>ONOS Pcep Protocol subsystem</description> - - <modules> - <module>api</module> - <module>ctl</module> - <module>pcepio</module> - </modules> - - <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onlab-misc</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onlab-junit</artifactId> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - </plugin> - </plugins> - </build> - -</project> diff --git a/framework/src/onos/pom.xml b/framework/src/onos/pom.xml index 4686e3f3..78fbcf2d 100644 --- a/framework/src/onos/pom.xml +++ b/framework/src/onos/pom.xml @@ -39,15 +39,16 @@ <description>Open Network Operating System root project</description> <modules> + <module>tools/package/maven-plugin</module> <module>utils</module> <module>core</module> <module>web</module> <module>cli</module> - <module>openflow</module> + <module>protocols</module> + <!-- FIXME move to protocols/ --> <module>ovsdb</module> - <module>netconf</module> - <module>pcep</module> + <module>bgp</module> <module>providers</module> <module>drivers</module> @@ -59,7 +60,6 @@ <module>tools/package/archetypes</module> <module>tools/package/branding</module> <module>tools/build/conf</module> - <module>bgp</module> </modules> <url>http://onosproject.org/</url> @@ -536,6 +536,7 @@ <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> + <argLine>-Duser.language=en -Duser.region=US</argLine> <redirectTestOutputToFile>true </redirectTestOutputToFile> <printSummary>true</printSummary> @@ -544,7 +545,20 @@ <rerunFailingTestsCount>1</rerunFailingTestsCount> </configuration> </plugin> - + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <version>2.10.3</version> + <configuration> + <tags> + <tag> + <name>rsModel</name> + <placement>m</placement> + <head>Json model for REST api:</head> + </tag> + </tags> + </configuration> + </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> @@ -630,8 +644,8 @@ <plugin> <groupId>org.onosproject</groupId> <artifactId>onos-maven-plugin</artifactId> - <version>1.5</version> - <executions> + <version>1.6-SNAPSHOT</version> + <executions> <execution> <id>cfg</id> <phase>generate-resources</phase> diff --git a/framework/src/onos/providers/host/pom.xml b/framework/src/onos/providers/host/pom.xml index e8f32ca1..ddbdbfc5 100644 --- a/framework/src/onos/providers/host/pom.xml +++ b/framework/src/onos/providers/host/pom.xml @@ -29,7 +29,11 @@ <artifactId>onos-host-provider</artifactId> <packaging>bundle</packaging> - <description>ONOS host tracking provider</description> + <properties> + <onos.app.name>org.onosproject.hostprovider</onos.app.name> + </properties> + + <description>ONOS host location provider</description> <dependencies> <dependency> <groupId>org.onosproject</groupId> diff --git a/framework/src/onos/providers/host/src/test/java/org/onosproject/provider/host/impl/HostLocationProviderTest.java b/framework/src/onos/providers/host/src/test/java/org/onosproject/provider/host/impl/HostLocationProviderTest.java index 6cbb623b..566eb0c4 100644 --- a/framework/src/onos/providers/host/src/test/java/org/onosproject/provider/host/impl/HostLocationProviderTest.java +++ b/framework/src/onos/providers/host/src/test/java/org/onosproject/provider/host/impl/HostLocationProviderTest.java @@ -196,16 +196,16 @@ public class HostLocationProviderTest { providerService.clear(); // new host - testProcessor.process(new TestNAPacketContext(DEV4)); + testProcessor.process(new TestNaPacketContext(DEV4)); assertNotNull("new host expected", providerService.added); assertNull("host motion unexpected", providerService.moved); // the host moved to new switch - testProcessor.process(new TestNAPacketContext(DEV5)); + testProcessor.process(new TestNaPacketContext(DEV5)); assertNotNull("host motion expected", providerService.moved); // the host was misheard on a spine - testProcessor.process(new TestNAPacketContext(DEV6)); + testProcessor.process(new TestNaPacketContext(DEV6)); assertNull("host misheard on spine switch", providerService.spine); } @@ -213,7 +213,7 @@ public class HostLocationProviderTest { public void removeHostByDeviceRemove() { provider.modified(CTX_FOR_REMOVE); testProcessor.process(new TestArpPacketContext(DEV1)); - testProcessor.process(new TestNAPacketContext(DEV4)); + testProcessor.process(new TestNaPacketContext(DEV4)); Device device = new DefaultDevice(ProviderId.NONE, deviceId(DEV1), SWITCH, "m", "h", "s", "n", new ChassisId(0L)); @@ -292,8 +292,8 @@ public class HostLocationProviderTest { * When receiving NeighborAdvertisement, updates location and IP. */ @Test - public void testReceiveNA() { - testProcessor.process(new TestNAPacketContext(DEV4)); + public void testReceiveNa() { + testProcessor.process(new TestNaPacketContext(DEV4)); assertNotNull(providerService.added); HostDescription descr = providerService.added; assertThat(descr.location(), is(LOCATION2)); @@ -306,8 +306,8 @@ public class HostLocationProviderTest { * When receiving NeighborSolicitation, updates location and IP. */ @Test - public void testReceiveNS() { - testProcessor.process(new TestNSPacketContext(DEV4)); + public void testReceiveNs() { + testProcessor.process(new TestNsPacketContext(DEV4)); HostDescription descr = providerService.added; assertThat(descr.location(), is(LOCATION2)); assertThat(descr.hwAddress(), is(MAC2)); @@ -319,7 +319,7 @@ public class HostLocationProviderTest { * When receiving RouterAdvertisement, ignores it. */ @Test - public void testReceivesRA() { + public void testReceivesRa() { testProcessor.process(new TestRAPacketContext(DEV4)); assertNull(providerService.added); } @@ -328,7 +328,7 @@ public class HostLocationProviderTest { * When receiving RouterSolicitation, ignores it. */ @Test - public void testReceiveRS() { + public void testReceiveRs() { testProcessor.process(new TestRSPacketContext(DEV4)); assertNull(providerService.added); } @@ -337,8 +337,8 @@ public class HostLocationProviderTest { * When receiving Duplicate Address Detection (DAD), ignores it. */ @Test - public void testReceiveDAD() { - testProcessor.process(new TestDADPacketContext(DEV4)); + public void testReceiveDad() { + testProcessor.process(new TestDadPacketContext(DEV4)); assertNull(providerService.added); } @@ -415,7 +415,7 @@ public class HostLocationProviderTest { public void hostDetected(HostId hostId, HostDescription hostDescription, boolean replaceIps) { if (added == null) { added = hostDescription; - } else if ((moved == null) && !hostDescription.equals(added)) { + } else if ((moved == null) && hostDescription != added) { moved = hostDescription; } else { spine = hostDescription; @@ -575,10 +575,10 @@ public class HostLocationProviderTest { /** * Generates NeighborAdvertisement packet. */ - private class TestNAPacketContext implements PacketContext { + private class TestNaPacketContext implements PacketContext { private final String deviceId; - public TestNAPacketContext(String deviceId) { + public TestNaPacketContext(String deviceId) { this.deviceId = deviceId; } @@ -637,10 +637,10 @@ public class HostLocationProviderTest { /** * Generates NeighborSolicitation packet. */ - private class TestNSPacketContext implements PacketContext { + private class TestNsPacketContext implements PacketContext { private final String deviceId; - public TestNSPacketContext(String deviceId) { + public TestNsPacketContext(String deviceId) { this.deviceId = deviceId; } @@ -699,10 +699,10 @@ public class HostLocationProviderTest { /** * Generates Duplicate Address Detection packet. */ - private class TestDADPacketContext implements PacketContext { + private class TestDadPacketContext implements PacketContext { private final String deviceId; - public TestDADPacketContext(String deviceId) { + public TestDadPacketContext(String deviceId) { this.deviceId = deviceId; } diff --git a/framework/src/onos/providers/lldp/pom.xml b/framework/src/onos/providers/lldp/pom.xml index e47d26c7..7bf92ed2 100644 --- a/framework/src/onos/providers/lldp/pom.xml +++ b/framework/src/onos/providers/lldp/pom.xml @@ -30,7 +30,11 @@ <artifactId>onos-lldp-provider</artifactId> <packaging>bundle</packaging> - <description>ONOS LLDP Link Discovery</description> + <properties> + <onos.app.name>org.onosproject.lldpprovider</onos.app.name> + </properties> + + <description>ONOS LLDP link provider</description> <dependencies> <dependency> diff --git a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java b/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java index 0cd19242..a9da92ab 100644 --- a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java +++ b/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/DiscoveryContext.java @@ -58,7 +58,7 @@ interface DiscoveryContext { * * @return true to emit BDDP */ - boolean useBDDP(); + boolean useBddp(); /** * Touches the link identified by the given key to indicate that it's active. diff --git a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LLDPLinkProvider.java b/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LLDPLinkProvider.java deleted file mode 100644 index 98442033..00000000 --- a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LLDPLinkProvider.java +++ /dev/null @@ -1,637 +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.provider.lldp.impl; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -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.Modified; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.ReferenceCardinality; -import org.onlab.packet.Ethernet; -import org.onosproject.cfg.ComponentConfigService; -import org.onosproject.cluster.ClusterService; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.mastership.MastershipEvent; -import org.onosproject.mastership.MastershipListener; -import org.onosproject.mastership.MastershipService; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.LinkKey; -import org.onosproject.net.Port; -import org.onosproject.net.config.NetworkConfigRegistry; -import org.onosproject.net.device.DeviceEvent; -import org.onosproject.net.device.DeviceListener; -import org.onosproject.net.device.DeviceService; -import org.onosproject.net.flow.DefaultTrafficSelector; -import org.onosproject.net.flow.TrafficSelector; -import org.onosproject.net.link.DefaultLinkDescription; -import org.onosproject.net.link.LinkProvider; -import org.onosproject.net.link.LinkProviderRegistry; -import org.onosproject.net.link.LinkProviderService; -import org.onosproject.net.link.LinkService; -import org.onosproject.net.packet.PacketContext; -import org.onosproject.net.packet.PacketPriority; -import org.onosproject.net.packet.PacketProcessor; -import org.onosproject.net.packet.PacketService; -import org.onosproject.net.provider.AbstractProvider; -import org.onosproject.net.provider.ProviderId; -import org.osgi.service.component.ComponentContext; -import org.slf4j.Logger; - -import java.io.IOException; -import java.util.Dictionary; -import java.util.EnumSet; -import java.util.Map; -import java.util.Optional; -import java.util.Properties; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ScheduledExecutorService; - -import static com.google.common.base.Strings.isNullOrEmpty; -import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.onlab.packet.Ethernet.TYPE_BSN; -import static org.onlab.packet.Ethernet.TYPE_LLDP; -import static org.onlab.util.Tools.get; -import static org.onlab.util.Tools.groupedThreads; -import static org.onosproject.net.Link.Type.DIRECT; -import static org.slf4j.LoggerFactory.getLogger; - -/** - * Provider which uses LLDP and BDDP packets to detect network infrastructure links. - */ -@Component(immediate = true) -public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { - - private static final String PROVIDER_NAME = "org.onosproject.provider.lldp"; - - private static final String FORMAT = - "Settings: enabled={}, useBDDP={}, probeRate={}, " + - "staleLinkAge={}, lldpSuppression={}"; - - // When a Device/Port has this annotation, do not send out LLDP/BDDP - public static final String NO_LLDP = "no-lldp"; - - - private final Logger log = getLogger(getClass()); - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected CoreService coreService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected LinkProviderRegistry providerRegistry; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected DeviceService deviceService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected LinkService linkService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected PacketService packetService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected MastershipService masterService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ComponentConfigService cfgService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ClusterService clusterService; - - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected NetworkConfigRegistry cfgRegistry; - - private LinkProviderService providerService; - - private ScheduledExecutorService executor; - - // TODO: Add sanity checking for the configurable params based on the delays - private static final long DEVICE_SYNC_DELAY = 5; - private static final long LINK_PRUNER_DELAY = 3; - - private static final String PROP_ENABLED = "enabled"; - @Property(name = PROP_ENABLED, boolValue = true, - label = "If false, link discovery is disabled") - private boolean enabled = false; - - private static final String PROP_USE_BDDP = "useBDDP"; - @Property(name = PROP_USE_BDDP, boolValue = true, - label = "Use BDDP for link discovery") - private boolean useBDDP = true; - - private static final String PROP_PROBE_RATE = "probeRate"; - private static final int DEFAULT_PROBE_RATE = 3_000; - @Property(name = PROP_PROBE_RATE, intValue = DEFAULT_PROBE_RATE, - label = "LLDP and BDDP probe rate specified in millis") - private int probeRate = DEFAULT_PROBE_RATE; - - private static final String PROP_STALE_LINK_AGE = "staleLinkAge"; - private static final int DEFAULT_STALE_LINK_AGE = 10_000; - @Property(name = PROP_STALE_LINK_AGE, intValue = DEFAULT_STALE_LINK_AGE, - label = "Number of millis beyond which links will be considered stale") - private int staleLinkAge = DEFAULT_STALE_LINK_AGE; - - // FIXME: convert to use network config subsystem instead - private static final String PROP_LLDP_SUPPRESSION = "lldpSuppression"; - private static final String DEFAULT_LLDP_SUPPRESSION_CONFIG = "../config/lldp_suppression.json"; - @Property(name = PROP_LLDP_SUPPRESSION, value = DEFAULT_LLDP_SUPPRESSION_CONFIG, - label = "Path to LLDP suppression configuration file") - private String lldpSuppression = DEFAULT_LLDP_SUPPRESSION_CONFIG; - - private final DiscoveryContext context = new InternalDiscoveryContext(); - private final InternalRoleListener roleListener = new InternalRoleListener(); - private final InternalDeviceListener deviceListener = new InternalDeviceListener(); - private final InternalPacketProcessor packetProcessor = new InternalPacketProcessor(); - - // Device link discovery helpers. - protected final Map<DeviceId, LinkDiscovery> discoverers = new ConcurrentHashMap<>(); - - // Most recent time a tracked link was seen; links are tracked if their - // destination connection point is mastered by this controller instance. - private final Map<LinkKey, Long> linkTimes = Maps.newConcurrentMap(); - - private SuppressionRules rules; - private ApplicationId appId; - - /** - * Creates an OpenFlow link provider. - */ - public LLDPLinkProvider() { - super(new ProviderId("lldp", PROVIDER_NAME)); - } - - @Activate - public void activate(ComponentContext context) { - cfgService.registerProperties(getClass()); - appId = coreService.registerApplication(PROVIDER_NAME); - modified(context); - log.info("Started"); - } - - @Deactivate - public void deactivate() { - cfgService.unregisterProperties(getClass(), false); - disable(); - log.info("Stopped"); - } - - @Modified - public void modified(ComponentContext context) { - Dictionary<?, ?> properties = context != null ? context.getProperties() : new Properties(); - - boolean newEnabled, newUseBddp; - int newProbeRate, newStaleLinkAge; - String newLldpSuppression; - try { - String s = get(properties, PROP_ENABLED); - newEnabled = isNullOrEmpty(s) || Boolean.parseBoolean(s.trim()); - - s = get(properties, PROP_USE_BDDP); - newUseBddp = isNullOrEmpty(s) || Boolean.parseBoolean(s.trim()); - - s = get(properties, PROP_PROBE_RATE); - newProbeRate = isNullOrEmpty(s) ? probeRate : Integer.parseInt(s.trim()); - - s = get(properties, PROP_STALE_LINK_AGE); - newStaleLinkAge = isNullOrEmpty(s) ? staleLinkAge : Integer.parseInt(s.trim()); - - s = get(properties, PROP_LLDP_SUPPRESSION); - newLldpSuppression = isNullOrEmpty(s) ? DEFAULT_LLDP_SUPPRESSION_CONFIG : s; - - } catch (NumberFormatException e) { - log.warn("Component configuration had invalid values", e); - newEnabled = enabled; - newUseBddp = useBDDP; - newProbeRate = probeRate; - newStaleLinkAge = staleLinkAge; - newLldpSuppression = lldpSuppression; - } - - boolean wasEnabled = enabled; - - enabled = newEnabled; - useBDDP = newUseBddp; - probeRate = newProbeRate; - staleLinkAge = newStaleLinkAge; - lldpSuppression = newLldpSuppression; - - if (!wasEnabled && enabled) { - enable(); - } else if (wasEnabled && !enabled) { - disable(); - } else { - // reflect changes in suppression rules to discovery helpers - // FIXME: After migrating to Network Configuration Subsystem, - // it should be possible to update only changed subset - if (enabled) { - // update all discovery helper state - loadDevices(); - } - } - - log.info(FORMAT, enabled, useBDDP, probeRate, staleLinkAge, lldpSuppression); - } - - /** - * Enables link discovery processing. - */ - private void enable() { - providerService = providerRegistry.register(this); - masterService.addListener(roleListener); - deviceService.addListener(deviceListener); - packetService.addProcessor(packetProcessor, PacketProcessor.advisor(0)); - - loadSuppressionRules(); - loadDevices(); - - executor = newSingleThreadScheduledExecutor(groupedThreads("onos/link", "discovery-%d")); - executor.scheduleAtFixedRate(new SyncDeviceInfoTask(), - DEVICE_SYNC_DELAY, DEVICE_SYNC_DELAY, SECONDS); - executor.scheduleAtFixedRate(new LinkPrunerTask(), - LINK_PRUNER_DELAY, LINK_PRUNER_DELAY, SECONDS); - - requestIntercepts(); - } - - /** - * Disables link discovery processing. - */ - private void disable() { - withdrawIntercepts(); - - providerRegistry.unregister(this); - masterService.removeListener(roleListener); - deviceService.removeListener(deviceListener); - packetService.removeProcessor(packetProcessor); - - if (executor != null) { - executor.shutdownNow(); - } - discoverers.values().forEach(LinkDiscovery::stop); - discoverers.clear(); - - providerService = null; - } - - /** - * Loads available devices and registers their ports to be probed. - */ - private void loadDevices() { - deviceService.getAvailableDevices() - .forEach(d -> updateDevice(d) - .ifPresent(ld -> updatePorts(ld, d.id()))); - } - - /** - * Updates discovery helper for specified device. - * - * Adds and starts a discovery helper for specified device if enabled, - * calls {@link #removeDevice(DeviceId)} otherwise. - * - * @param device device to add - * @return discovery helper if discovery is enabled for the device - */ - private Optional<LinkDiscovery> updateDevice(Device device) { - if (rules.isSuppressed(device)) { - log.trace("LinkDiscovery from {} disabled by configuration", device.id()); - removeDevice(device.id()); - return Optional.empty(); - } - LinkDiscovery ld = discoverers.computeIfAbsent(device.id(), - did -> new LinkDiscovery(device, context)); - if (ld.isStopped()) { - ld.start(); - } - return Optional.of(ld); - } - - /** - * Removes after stopping discovery helper for specified device. - * @param deviceId device to remove - */ - private void removeDevice(final DeviceId deviceId) { - discoverers.computeIfPresent(deviceId, (did, ld) -> { - ld.stop(); - providerService.linksVanished(deviceId); - return null; - }); - - } - - /** - * Updates ports of the specified device to the specified discovery helper. - */ - private void updatePorts(LinkDiscovery discoverer, DeviceId deviceId) { - deviceService.getPorts(deviceId).forEach(p -> updatePort(discoverer, p)); - } - - /** - * Updates discovery helper state of the specified port. - * - * Adds a port to the discovery helper if up and discovery is enabled, - * or calls {@link #removePort(Port)} otherwise. - */ - private void updatePort(LinkDiscovery discoverer, Port port) { - if (rules.isSuppressed(port)) { - log.trace("LinkDiscovery from {} disabled by configuration", port); - removePort(port); - return; - } - - // check if enabled and turn off discovery? - if (!port.isEnabled()) { - removePort(port); - return; - } - - if (!port.number().isLogical()) { - discoverer.addPort(port); - } - } - - /** - * Removes a port from the specified discovery helper. - * @param port the port - */ - private void removePort(Port port) { - if (port.element() instanceof Device) { - Device d = (Device) port.element(); - LinkDiscovery ld = discoverers.get(d.id()); - if (ld != null) { - ld.removePort(port.number()); - } - - ConnectPoint point = new ConnectPoint(d.id(), port.number()); - providerService.linksVanished(point); - } else { - log.warn("Attempted to remove non-Device port", port); - } - } - - /** - * Loads LLDP suppression rules. - */ - private void loadSuppressionRules() { - // FIXME: convert to use network configuration - SuppressionRulesStore store = new SuppressionRulesStore(lldpSuppression); - try { - log.info("Reading suppression rules from {}", lldpSuppression); - rules = store.read(); - } catch (IOException e) { - log.info("Failed to load {}, using built-in rules", lldpSuppression); - // default rule to suppress ROADM to maintain compatibility - rules = new SuppressionRules(ImmutableSet.of(), - EnumSet.of(Device.Type.ROADM), - ImmutableMap.of(NO_LLDP, SuppressionRules.ANY_VALUE)); - } - - // should refresh discoverers when we need dynamic reconfiguration - } - - /** - * Requests packet intercepts. - */ - private void requestIntercepts() { - TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); - selector.matchEthType(TYPE_LLDP); - packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId); - - selector.matchEthType(TYPE_BSN); - if (useBDDP) { - packetService.requestPackets(selector.build(), PacketPriority.CONTROL, appId); - } else { - packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); - } - } - - /** - * Withdraws packet intercepts. - */ - private void withdrawIntercepts() { - TrafficSelector.Builder selector = DefaultTrafficSelector.builder(); - selector.matchEthType(TYPE_LLDP); - packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); - selector.matchEthType(TYPE_BSN); - packetService.cancelPackets(selector.build(), PacketPriority.CONTROL, appId); - } - - /** - * Processes device mastership role changes. - */ - private class InternalRoleListener implements MastershipListener { - @Override - public void event(MastershipEvent event) { - if (MastershipEvent.Type.BACKUPS_CHANGED.equals(event.type())) { - // only need new master events - return; - } - - DeviceId deviceId = event.subject(); - Device device = deviceService.getDevice(deviceId); - if (device == null) { - log.debug("Device {} doesn't exist, or isn't there yet", deviceId); - return; - } - if (clusterService.getLocalNode().id().equals(event.roleInfo().master())) { - updateDevice(device).ifPresent(ld -> updatePorts(ld, device.id())); - } - } - - } - - /** - * Processes device events. - */ - private class InternalDeviceListener implements DeviceListener { - @Override - public void event(DeviceEvent event) { - Device device = event.subject(); - Port port = event.port(); - if (device == null) { - log.error("Device is null."); - return; - } - log.trace("{} {} {}", event.type(), event.subject(), event); - final DeviceId deviceId = device.id(); - switch (event.type()) { - case DEVICE_ADDED: - case DEVICE_UPDATED: - updateDevice(device).ifPresent(ld -> updatePorts(ld, deviceId)); - break; - case PORT_ADDED: - case PORT_UPDATED: - if (port.isEnabled()) { - updateDevice(device).ifPresent(ld -> updatePort(ld, port)); - } else { - log.debug("Port down {}", port); - removePort(port); - } - break; - case PORT_REMOVED: - log.debug("Port removed {}", port); - removePort(port); - break; - case DEVICE_REMOVED: - case DEVICE_SUSPENDED: - log.debug("Device removed {}", deviceId); - removeDevice(deviceId); - break; - case DEVICE_AVAILABILITY_CHANGED: - if (deviceService.isAvailable(deviceId)) { - log.debug("Device up {}", deviceId); - updateDevice(device); - } else { - log.debug("Device down {}", deviceId); - removeDevice(deviceId); - } - break; - case PORT_STATS_UPDATED: - break; - default: - log.debug("Unknown event {}", event); - } - } - } - - /** - * Processes incoming packets. - */ - private class InternalPacketProcessor implements PacketProcessor { - @Override - public void process(PacketContext context) { - if (context == null || context.isHandled()) { - return; - } - - Ethernet eth = context.inPacket().parsed(); - if (eth == null || (eth.getEtherType() != TYPE_LLDP && eth.getEtherType() != TYPE_BSN)) { - return; - } - - LinkDiscovery ld = discoverers.get(context.inPacket().receivedFrom().deviceId()); - if (ld == null) { - return; - } - - if (ld.handleLLDP(context)) { - context.block(); - } - } - } - - /** - * Auxiliary task to keep device ports up to date. - */ - private final class SyncDeviceInfoTask implements Runnable { - @Override - public void run() { - if (Thread.currentThread().isInterrupted()) { - log.info("Interrupted, quitting"); - return; - } - // check what deviceService sees, to see if we are missing anything - try { - loadDevices(); - } catch (Exception e) { - // Catch all exceptions to avoid task being suppressed - log.error("Exception thrown during synchronization process", e); - } - } - } - - /** - * Auxiliary task for pruning stale links. - */ - private class LinkPrunerTask implements Runnable { - @Override - public void run() { - if (Thread.currentThread().isInterrupted()) { - log.info("Interrupted, quitting"); - return; - } - - try { - // TODO: There is still a slight possibility of mastership - // change occurring right with link going stale. This will - // result in the stale link not being pruned. - Maps.filterEntries(linkTimes, e -> { - if (!masterService.isLocalMaster(e.getKey().dst().deviceId())) { - return true; - } - if (isStale(e.getValue())) { - providerService.linkVanished(new DefaultLinkDescription(e.getKey().src(), - e.getKey().dst(), - DIRECT)); - return true; - } - return false; - }).clear(); - - } catch (Exception e) { - // Catch all exceptions to avoid task being suppressed - log.error("Exception thrown during link pruning process", e); - } - } - - private boolean isStale(long lastSeen) { - return lastSeen < System.currentTimeMillis() - staleLinkAge; - } - } - - /** - * Provides processing context for the device link discovery helpers. - */ - private class InternalDiscoveryContext implements DiscoveryContext { - @Override - public MastershipService mastershipService() { - return masterService; - } - - @Override - public LinkProviderService providerService() { - return providerService; - } - - @Override - public PacketService packetService() { - return packetService; - } - - @Override - public long probeRate() { - return probeRate; - } - - @Override - public boolean useBDDP() { - return useBDDP; - } - - @Override - public void touchLink(LinkKey key) { - linkTimes.put(key, System.currentTimeMillis()); - } - } - -} diff --git a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java b/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java index 7dc9aed0..4b962ae5 100644 --- a/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java +++ b/framework/src/onos/providers/lldp/src/main/java/org/onosproject/provider/lldp/impl/LinkDiscovery.java @@ -155,7 +155,7 @@ class LinkDiscovery implements TimerTask { * @param packetContext packet context * @return true if handled */ - boolean handleLLDP(PacketContext packetContext) { + boolean handleLldp(PacketContext packetContext) { Ethernet eth = packetContext.inPacket().parsed(); if (eth == null) { return false; @@ -216,7 +216,7 @@ class LinkDiscovery implements TimerTask { * @param port the port * @return Packet_out message with LLDP data */ - private OutboundPacket createOutBoundLLDP(Long port) { + private OutboundPacket createOutBoundLldp(Long port) { if (port == null) { return null; } @@ -233,7 +233,7 @@ class LinkDiscovery implements TimerTask { * @param port the port * @return Packet_out message with LLDP data */ - private OutboundPacket createOutBoundBDDP(Long port) { + private OutboundPacket createOutBoundBddp(Long port) { if (port == null) { return null; } @@ -246,10 +246,10 @@ class LinkDiscovery implements TimerTask { private void sendProbes(Long portNumber) { log.trace("Sending probes out to {}@{}", portNumber, device.id()); - OutboundPacket pkt = createOutBoundLLDP(portNumber); + OutboundPacket pkt = createOutBoundLldp(portNumber); context.packetService().emit(pkt); - if (context.useBDDP()) { - OutboundPacket bpkt = createOutBoundBDDP(portNumber); + if (context.useBddp()) { + OutboundPacket bpkt = createOutBoundBddp(portNumber); context.packetService().emit(bpkt); } } diff --git a/framework/src/onos/providers/lldp/src/test/java/org/onosproject/provider/lldp/impl/LLDPLinkProviderTest.java b/framework/src/onos/providers/lldp/src/test/java/org/onosproject/provider/lldp/impl/LLDPLinkProviderTest.java deleted file mode 100644 index 6070b857..00000000 --- a/framework/src/onos/providers/lldp/src/test/java/org/onosproject/provider/lldp/impl/LLDPLinkProviderTest.java +++ /dev/null @@ -1,630 +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.provider.lldp.impl; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.onlab.packet.ChassisId; -import org.onlab.packet.Ethernet; -import org.onlab.packet.ONOSLLDP; -import org.onosproject.cfg.ComponentConfigAdapter; -import org.onosproject.cluster.NodeId; -import org.onosproject.cluster.RoleInfo; -import org.onosproject.core.ApplicationId; -import org.onosproject.core.CoreService; -import org.onosproject.core.DefaultApplicationId; -import org.onosproject.mastership.MastershipListener; -import org.onosproject.mastership.MastershipService; -import org.onosproject.net.Annotations; -import org.onosproject.net.ConnectPoint; -import org.onosproject.net.DefaultAnnotations; -import org.onosproject.net.DefaultDevice; -import org.onosproject.net.DefaultPort; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.MastershipRole; -import org.onosproject.net.Port; -import org.onosproject.net.PortNumber; -import org.onosproject.net.device.DeviceEvent; -import org.onosproject.net.device.DeviceListener; -import org.onosproject.net.device.DeviceServiceAdapter; -import org.onosproject.net.flow.TrafficTreatment; -import org.onosproject.net.link.LinkDescription; -import org.onosproject.net.link.LinkProvider; -import org.onosproject.net.link.LinkProviderRegistry; -import org.onosproject.net.link.LinkProviderService; -import org.onosproject.net.link.LinkServiceAdapter; -import org.onosproject.net.packet.DefaultInboundPacket; -import org.onosproject.net.packet.InboundPacket; -import org.onosproject.net.packet.OutboundPacket; -import org.onosproject.net.packet.PacketContext; -import org.onosproject.net.packet.PacketProcessor; -import org.onosproject.net.packet.PacketServiceAdapter; -import org.onosproject.net.provider.AbstractProviderService; -import org.onosproject.net.provider.ProviderId; - -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.CompletableFuture; - -import static org.easymock.EasyMock.*; -import static org.junit.Assert.*; - -public class LLDPLinkProviderTest { - - private static final DeviceId DID1 = DeviceId.deviceId("of:0000000000000001"); - private static final DeviceId DID2 = DeviceId.deviceId("of:0000000000000002"); - private static final DeviceId DID3 = DeviceId.deviceId("of:0000000000000003"); - - private static Port pd1; - private static Port pd2; - private static Port pd3; - private static Port pd4; - - private final LLDPLinkProvider provider = new LLDPLinkProvider(); - private final TestLinkRegistry linkRegistry = new TestLinkRegistry(); - private final TestLinkService linkService = new TestLinkService(); - private final TestPacketService packetService = new TestPacketService(); - private final TestDeviceService deviceService = new TestDeviceService(); - private final TestMasterShipService masterService = new TestMasterShipService(); - - private CoreService coreService; - private TestLinkProviderService providerService; - - private PacketProcessor testProcessor; - private DeviceListener deviceListener; - - private ApplicationId appId = - new DefaultApplicationId(100, "org.onosproject.provider.lldp"); - - @Before - public void setUp() { - coreService = createMock(CoreService.class); - expect(coreService.registerApplication(appId.name())) - .andReturn(appId).anyTimes(); - replay(coreService); - - provider.cfgService = new ComponentConfigAdapter(); - provider.coreService = coreService; - - provider.deviceService = deviceService; - provider.linkService = linkService; - provider.packetService = packetService; - provider.providerRegistry = linkRegistry; - provider.masterService = masterService; - - provider.activate(null); - } - - @Test - public void basics() { - assertNotNull("registration expected", providerService); - assertEquals("incorrect provider", provider, providerService.provider()); - } - - @Test - public void switchAdd() { - DeviceEvent de = deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1); - deviceListener.event(de); - - assertFalse("Device not added", provider.discoverers.isEmpty()); - } - - @Test - public void switchRemove() { - deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1)); - deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_REMOVED, DID1)); - - final LinkDiscovery linkDiscovery = provider.discoverers.get(DID1); - if (linkDiscovery != null) { - // If LinkDiscovery helper is there after DEVICE_REMOVED, - // it should be stopped - assertTrue("Discoverer is not stopped", linkDiscovery.isStopped()); - } - assertTrue("Device is not gone.", vanishedDpid(DID1)); - } - - /** - * Checks that links on a reconfigured switch are properly removed. - */ - @Test - public void switchSuppressed() { - // add device to stub DeviceService - deviceService.putDevice(device(DID3)); - deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID3)); - - assertFalse("Device not added", provider.discoverers.isEmpty()); - - // update device in stub DeviceService with suppression config - deviceService.putDevice(device(DID3, DefaultAnnotations.builder() - .set(LLDPLinkProvider.NO_LLDP, "true") - .build())); - deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_UPDATED, DID3)); - - assertTrue("Links on suppressed Device was expected to vanish.", vanishedDpid(DID3)); - } - - @Test - public void portUp() { - deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1)); - deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID1, port(DID1, 3, true))); - - assertTrue("Port not added to discoverer", - provider.discoverers.get(DID1).containsPort(3L)); - } - - @Test - public void portDown() { - - deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1)); - deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID1, port(DID1, 1, false))); - - assertFalse("Port added to discoverer", - provider.discoverers.get(DID1).containsPort(1L)); - assertTrue("Port is not gone.", vanishedPort(1L)); - } - - @Test - public void portRemoved() { - deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1)); - deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID1, port(DID1, 3, true))); - deviceListener.event(portEvent(DeviceEvent.Type.PORT_REMOVED, DID1, port(DID1, 3, true))); - - assertTrue("Port is not gone.", vanishedPort(3L)); - assertFalse("Port was not removed from discoverer", - provider.discoverers.get(DID1).containsPort(3L)); - } - - /** - * Checks that discovery on reconfigured switch are properly restarted. - */ - @Test - public void portSuppressedByDeviceConfig() { - - /// When Device is configured with suppression:ON, Port also is same - - // add device in stub DeviceService with suppression configured - deviceService.putDevice(device(DID3, DefaultAnnotations.builder() - .set(LLDPLinkProvider.NO_LLDP, "true") - .build())); - deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID3)); - - // non-suppressed port added to suppressed device - final long portno3 = 3L; - deviceService.putPorts(DID3, port(DID3, portno3, true)); - deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID3, port(DID3, portno3, true))); - - // discovery on device is expected to be stopped - LinkDiscovery linkDiscovery = provider.discoverers.get(DID3); - if (linkDiscovery != null) { - assertTrue("Discovery expected to be stopped", linkDiscovery.isStopped()); - } - - /// When Device is reconfigured without suppression:OFF, - /// Port should be included for discovery - - // update device in stub DeviceService without suppression configured - deviceService.putDevice(device(DID3)); - // update the Port in stub DeviceService. (Port has reference to Device) - deviceService.putPorts(DID3, port(DID3, portno3, true)); - deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_UPDATED, DID3)); - - // discovery should come back on - assertFalse("Discoverer is expected to start", provider.discoverers.get(DID3).isStopped()); - assertTrue("Discoverer should contain the port there", provider.discoverers.get(DID3).containsPort(portno3)); - } - - /** - * Checks that discovery on reconfigured port are properly restarted. - */ - @Test - public void portSuppressedByPortConfig() { - // add device in stub DeviceService without suppression configured - deviceService.putDevice(device(DID3)); - deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID3)); - - // suppressed port added to non-suppressed device - final long portno3 = 3L; - final Port port3 = port(DID3, portno3, true, - DefaultAnnotations.builder() - .set(LLDPLinkProvider.NO_LLDP, "true") - .build()); - deviceService.putPorts(DID3, port3); - deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID3, port3)); - - // discovery helper should be there turned on - assertFalse("Discoverer is expected to start", provider.discoverers.get(DID3).isStopped()); - assertFalse("Discoverer should not contain the port there", - provider.discoverers.get(DID3).containsPort(portno3)); - } - - @Test - public void portUnknown() { - deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1)); - // Note: DID3 hasn't been added to TestDeviceService, but only port is added - deviceListener.event(portEvent(DeviceEvent.Type.PORT_ADDED, DID3, port(DID3, 1, false))); - - - assertNull("DeviceId exists", - provider.discoverers.get(DID3)); - } - - @Test - public void unknownPktCtx() { - - // Note: DID3 hasn't been added to TestDeviceService - PacketContext pktCtx = new TestPacketContext(device(DID3)); - - testProcessor.process(pktCtx); - assertFalse("Context should still be free", pktCtx.isHandled()); - } - - @Test - public void knownPktCtx() { - deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID1)); - deviceListener.event(deviceEvent(DeviceEvent.Type.DEVICE_ADDED, DID2)); - PacketContext pktCtx = new TestPacketContext(deviceService.getDevice(DID2)); - - - testProcessor.process(pktCtx); - - assertTrue("Link not detected", detectedLink(DID1, DID2)); - - } - - - @After - public void tearDown() { - provider.deactivate(); - provider.coreService = null; - provider.providerRegistry = null; - provider.deviceService = null; - provider.packetService = null; - } - - private DeviceEvent deviceEvent(DeviceEvent.Type type, DeviceId did) { - return new DeviceEvent(type, deviceService.getDevice(did)); - - } - - private DefaultDevice device(DeviceId did) { - return new DefaultDevice(ProviderId.NONE, did, Device.Type.SWITCH, - "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId()); - } - - private DefaultDevice device(DeviceId did, Annotations annotations) { - return new DefaultDevice(ProviderId.NONE, did, Device.Type.SWITCH, - "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId(), annotations); - } - - @SuppressWarnings(value = { "unused" }) - private DeviceEvent portEvent(DeviceEvent.Type type, DeviceId did, PortNumber port) { - return new DeviceEvent(type, deviceService.getDevice(did), - deviceService.getPort(did, port)); - } - - private DeviceEvent portEvent(DeviceEvent.Type type, DeviceId did, Port port) { - return new DeviceEvent(type, deviceService.getDevice(did), port); - } - - private Port port(DeviceId did, long port, boolean enabled) { - return new DefaultPort(deviceService.getDevice(did), - PortNumber.portNumber(port), enabled); - } - - private Port port(DeviceId did, long port, boolean enabled, Annotations annotations) { - return new DefaultPort(deviceService.getDevice(did), - PortNumber.portNumber(port), enabled, annotations); - } - - private boolean vanishedDpid(DeviceId... dids) { - for (int i = 0; i < dids.length; i++) { - if (!providerService.vanishedDpid.contains(dids[i])) { - return false; - } - } - return true; - } - - private boolean vanishedPort(Long... ports) { - for (int i = 0; i < ports.length; i++) { - if (!providerService.vanishedPort.contains(ports[i])) { - return false; - } - } - return true; - } - - private boolean detectedLink(DeviceId src, DeviceId dst) { - for (DeviceId key : providerService.discoveredLinks.keySet()) { - if (key.equals(src)) { - return providerService.discoveredLinks.get(src).equals(dst); - } - } - return false; - } - - - private class TestLinkRegistry implements LinkProviderRegistry { - - @Override - public LinkProviderService register(LinkProvider provider) { - providerService = new TestLinkProviderService(provider); - return providerService; - } - - @Override - public void unregister(LinkProvider provider) { - } - - @Override - public Set<ProviderId> getProviders() { - return null; - } - - } - - private class TestLinkProviderService - extends AbstractProviderService<LinkProvider> - implements LinkProviderService { - - List<DeviceId> vanishedDpid = Lists.newLinkedList(); - List<Long> vanishedPort = Lists.newLinkedList(); - Map<DeviceId, DeviceId> discoveredLinks = Maps.newHashMap(); - - protected TestLinkProviderService(LinkProvider provider) { - super(provider); - } - - @Override - public void linkDetected(LinkDescription linkDescription) { - DeviceId sDid = linkDescription.src().deviceId(); - DeviceId dDid = linkDescription.dst().deviceId(); - discoveredLinks.put(sDid, dDid); - } - - @Override - public void linkVanished(LinkDescription linkDescription) { - } - - @Override - public void linksVanished(ConnectPoint connectPoint) { - vanishedPort.add(connectPoint.port().toLong()); - - } - - @Override - public void linksVanished(DeviceId deviceId) { - vanishedDpid.add(deviceId); - } - - - } - - - - private class TestPacketContext implements PacketContext { - - protected Device device; - protected boolean blocked = false; - - public TestPacketContext(Device dev) { - device = dev; - } - - @Override - public long time() { - return 0; - } - - @Override - public InboundPacket inPacket() { - ONOSLLDP lldp = new ONOSLLDP(); - lldp.setChassisId(device.chassisId()); - lldp.setPortId((int) pd1.number().toLong()); - lldp.setDevice(deviceService.getDevice(DID1).id().toString()); - - - Ethernet ethPacket = new Ethernet(); - ethPacket.setEtherType(Ethernet.TYPE_LLDP); - ethPacket.setDestinationMACAddress(ONOSLLDP.LLDP_NICIRA); - ethPacket.setPayload(lldp); - ethPacket.setPad(true); - - - - ethPacket.setSourceMACAddress("DE:AD:BE:EF:BA:11"); - - ConnectPoint cp = new ConnectPoint(device.id(), pd3.number()); - - return new DefaultInboundPacket(cp, ethPacket, - ByteBuffer.wrap(ethPacket.serialize())); - - } - - @Override - public OutboundPacket outPacket() { - return null; - } - - @Override - public TrafficTreatment.Builder treatmentBuilder() { - return null; - } - - @Override - public void send() { - - } - - @Override - public boolean block() { - blocked = true; - return blocked; - } - - @Override - public boolean isHandled() { - return blocked; - } - - } - - private class TestPacketService extends PacketServiceAdapter { - @Override - public void addProcessor(PacketProcessor processor, int priority) { - testProcessor = processor; - } - } - - private class TestDeviceService extends DeviceServiceAdapter { - - private final Map<DeviceId, Device> devices = new HashMap<>(); - private final ArrayListMultimap<DeviceId, Port> ports = - ArrayListMultimap.create(); - public TestDeviceService() { - Device d1 = new DefaultDevice(ProviderId.NONE, DID1, Device.Type.SWITCH, - "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId()); - Device d2 = new DefaultDevice(ProviderId.NONE, DID2, Device.Type.SWITCH, - "TESTMF", "TESTHW", "TESTSW", "TESTSN", new ChassisId()); - devices.put(DID1, d1); - devices.put(DID2, d2); - pd1 = new DefaultPort(d1, PortNumber.portNumber(1), true); - pd2 = new DefaultPort(d1, PortNumber.portNumber(2), true); - pd3 = new DefaultPort(d2, PortNumber.portNumber(1), true); - pd4 = new DefaultPort(d2, PortNumber.portNumber(2), true); - - ports.putAll(DID1, Lists.newArrayList(pd1, pd2)); - ports.putAll(DID2, Lists.newArrayList(pd3, pd4)); - } - - private void putDevice(Device device) { - DeviceId deviceId = device.id(); - devices.put(deviceId, device); - } - - private void putPorts(DeviceId did, Port...ports) { - this.ports.putAll(did, Lists.newArrayList(ports)); - } - - @Override - public int getDeviceCount() { - return devices.values().size(); - } - - @Override - public Iterable<Device> getDevices() { - return ImmutableList.copyOf(devices.values()); - } - - @Override - public Device getDevice(DeviceId deviceId) { - return devices.get(deviceId); - } - - @Override - public MastershipRole getRole(DeviceId deviceId) { - return MastershipRole.MASTER; - } - - @Override - public List<Port> getPorts(DeviceId deviceId) { - return ports.get(deviceId); - } - - @Override - public Port getPort(DeviceId deviceId, PortNumber portNumber) { - for (Port p : ports.get(deviceId)) { - if (p.number().equals(portNumber)) { - return p; - } - } - return null; - } - - @Override - public boolean isAvailable(DeviceId deviceId) { - return true; - } - - @Override - public void addListener(DeviceListener listener) { - deviceListener = listener; - - } - - @Override - public void removeListener(DeviceListener listener) { - - } - } - - private final class TestMasterShipService implements MastershipService { - - @Override - public MastershipRole getLocalRole(DeviceId deviceId) { - return MastershipRole.MASTER; - } - - @Override - public CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId) { - return CompletableFuture.completedFuture(null); - } - - @Override - public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) { - return null; - } - - @Override - public NodeId getMasterFor(DeviceId deviceId) { - return null; - } - - @Override - public Set<DeviceId> getDevicesOf(NodeId nodeId) { - return null; - } - - @Override - public void addListener(MastershipListener listener) { - - } - - @Override - public void removeListener(MastershipListener listener) { - - } - - @Override - public RoleInfo getNodesFor(DeviceId deviceId) { - return new RoleInfo(new NodeId("foo"), Collections.<NodeId>emptyList()); - } - } - - - private class TestLinkService extends LinkServiceAdapter { - } -} diff --git a/framework/src/onos/providers/netconf/app/app.xml b/framework/src/onos/providers/netconf/app/app.xml index f2d47627..d920d240 100644 --- a/framework/src/onos/providers/netconf/app/app.xml +++ b/framework/src/onos/providers/netconf/app/app.xml @@ -19,6 +19,13 @@ features="${project.artifactId}"> <description>${project.description}</description> + <artifact>mvn:${project.groupId}/onos-netconf-rfc/${project.version}</artifact> + <artifact>mvn:${project.groupId}/onos-netconf-api/${project.version}</artifact> + <artifact>mvn:${project.groupId}/onos-netconf-ctl/${project.version}</artifact> + <artifact>mvn:${project.groupId}/onos-drivers/${project.version}</artifact> + <artifact>mvn:${project.groupId}/onos-netconf-provider-device/${project.version}</artifact> + + <!--<artifact>mvn:${project.groupId}/onos-netconf-provider-device/${project.version}</artifact>--> <!-- Question: should there be the jnc stuff here? Or is it just for testing --> </app> diff --git a/framework/src/onos/providers/netconf/app/features.xml b/framework/src/onos/providers/netconf/app/features.xml index bc7491e6..ef0fb738 100644 --- a/framework/src/onos/providers/netconf/app/features.xml +++ b/framework/src/onos/providers/netconf/app/features.xml @@ -20,6 +20,9 @@ description="${project.description}"> <feature>onos-api</feature> <bundle>mvn:io.netty/netty/3.9.2.Final</bundle> + <bundle>mvn:${project.groupId}/onos-netconf-api/${project.version}</bundle> + <bundle>mvn:${project.groupId}/onos-netconf-ctl/${project.version}</bundle> + <bundle>mvn:${project.groupId}/onos-netconf-provider-device/${project.version}</bundle> <!-- Question: should there be the jnc stuff here? Or is it just for testing --> </feature> diff --git a/framework/src/onos/providers/netconf/device/pom.xml b/framework/src/onos/providers/netconf/device/pom.xml index 3465bc3a..15ad475a 100644 --- a/framework/src/onos/providers/netconf/device/pom.xml +++ b/framework/src/onos/providers/netconf/device/pom.xml @@ -33,129 +33,29 @@ <dependencies> <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - </dependency> - <dependency> - <groupId>ch.ethz.ganymed</groupId> - <artifactId>ganymed-ssh2</artifactId> - <version>262</version> - </dependency> - <dependency> - <!-- TODO: change this appropriately when the official TailF JNC is available --> <groupId>org.onosproject</groupId> - <artifactId>jnc</artifactId> - <version>1.0</version> - </dependency> - <dependency> - <groupId>org.jdom</groupId> - <artifactId>jdom2</artifactId> - <version>2.0.5</version> - </dependency> - <dependency> - <groupId>jaxen</groupId> - <artifactId>jaxen</artifactId> - <version>1.1.4</version> - <optional>true</optional> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> + <artifactId>onlab-junit</artifactId> + <scope>test</scope> </dependency> <dependency> <groupId>org.onosproject</groupId> - <artifactId>onlab-junit</artifactId> - <scope>test</scope> + <artifactId>onos-netconf-api</artifactId> + <version>${project.version}</version> </dependency> <dependency> - <groupId>org.easymock</groupId> - <artifactId>easymock</artifactId> - <scope>test</scope> + <groupId>org.onosproject</groupId> + <artifactId>onos-netconf-ctl</artifactId> + <version>${project.version}</version> </dependency> </dependencies> <build> <plugins> <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-shade-plugin</artifactId> - <version>2.3</version> - <configuration> - <filters> - <filter> - <artifact>com.tailf:JNC</artifact> - <includes> - <include>com/tailf/jnc/**</include> - </includes> - </filter> - <filter> - <artifact>ch.ethz.ganymed:ganymed-ssh2</artifact> - <includes> - <include>ch/ethz/ssh2/**</include> - </includes> - </filter> - <filter> - <artifact>org.jdom:jdom2</artifact> - <includes> - <include>org/jdom2/**</include> - </includes> - </filter> - </filters> - </configuration> - <executions> - <execution> - <phase>package</phase> - <goals> - <goal>shade</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> <groupId>org.apache.felix</groupId> <artifactId>maven-scr-plugin</artifactId> </plugin> <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <configuration> - <instructions> - <Export-Package> - com.tailf.jnc, - ch.ethz.ssh2, - ch.ethz.ssh2.auth, - ch.ethz.ssh2.channel, - ch.ethz.ssh2.crypto, - ch.ethz.ssh2.crypto.cipher, - ch.ethz.ssh2.crypto.dh, - ch.ethz.ssh2.crypto.digest, - ch.ethz.ssh2.log, - ch.ethz.ssh2.packets, - ch.ethz.ssh2.server, - ch.ethz.ssh2.sftp, - ch.ethz.ssh2.signature, - ch.ethz.ssh2.transport, - ch.ethz.ssh2.util, - org.jdom2, - org.jdom2.input, - org.jdom2.output, - org.jdom2.adapters, - org.jdom2.filter, - org.jdom2.internal, - org.jdom2.located, - org.jdom2.transform, - org.jdom2.util, - org.jdom2.xpath, - org.jdom2.input.sax, - org.jdom2.input.stax, - org.jdom2.output.support, - org.jdom2.xpath.jaxen, - org.jdom2.xpath.util - </Export-Package> - </instructions> - </configuration> - </plugin> - <plugin> <groupId>org.onosproject</groupId> <artifactId>onos-maven-plugin</artifactId> </plugin> diff --git a/framework/src/onos/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDevice.java b/framework/src/onos/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDevice.java deleted file mode 100644 index b3d26b06..00000000 --- a/framework/src/onos/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDevice.java +++ /dev/null @@ -1,304 +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.provider.netconf.device.impl; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.onlab.util.Tools.delay; -import static org.slf4j.LoggerFactory.getLogger; - -import java.io.IOException; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.List; - -import org.jdom2.Document; -import org.jdom2.Element; -import org.jdom2.input.SAXBuilder; -import org.jdom2.output.Format; -import org.jdom2.output.XMLOutputter; -import org.slf4j.Logger; - -import com.tailf.jnc.Capabilities; -import com.tailf.jnc.JNCException; -import com.tailf.jnc.SSHConnection; -import com.tailf.jnc.SSHSession; - -/** - * This is a logical representation of actual NETCONF device, carrying all the - * necessary information to connect and execute NETCONF operations. - */ -public class NetconfDevice { - private final Logger log = getLogger(NetconfDevice.class); - - /** - * The Device State is used to determine whether the device is active or - * inactive. This state infomation will help Device Creator to add or delete - * the device from the core. - */ - public static enum DeviceState { - /* Used to specify Active state of the device */ - ACTIVE, - /* Used to specify inactive state of the device */ - INACTIVE, - /* Used to specify invalid state of the device */ - INVALID - } - - private static final int DEFAULT_SSH_PORT = 22; - private static final int DEFAULT_CON_TIMEOUT = 0; - private static final String XML_CAPABILITY_KEY = "capability"; - private static final int EVENTINTERVAL = 2000; - private static final int CONNECTION_CHECK_INTERVAL = 3; - private static final String INPUT_HELLO_XML_MSG = new StringBuilder( - "<?xml version=\"1.0\" encoding=\"UTF-8\"?>") - .append("<hello xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">") - .append("<capabilities><capability>urn:ietf:params:netconf:base:1.0</capability>") - .append("</capabilities></hello>").toString(); - - private String sshHost; - private int sshPort = DEFAULT_SSH_PORT; - private int connectTimeout = DEFAULT_CON_TIMEOUT; - private String username; - private String password; - private boolean reachable = false; - - private List<String> capabilities = new ArrayList<String>(); - private SSHConnection sshConnection = null; - - private DeviceState deviceState = DeviceState.INVALID; - - protected NetconfDevice(String sshHost, int sshPort, String username, - String password) { - this.username = checkNotNull(username, - "Netconf Username Cannot be null"); - this.sshHost = checkNotNull(sshHost, "Netconf Device IP cannot be null"); - this.sshPort = checkNotNull(sshPort, - "Netconf Device SSH port cannot be null"); - this.password = password; - } - - /** - * This will try to connect to NETCONF device and find all the capabilities. - * - * @throws Exception if unable to connect to the device - */ - // FIXME: this should not be a generic Exception; perhaps wrap in some RuntimeException - public void init() throws Exception { - try { - if (sshConnection == null) { - sshConnection = new SSHConnection(sshHost, sshPort, connectTimeout); - sshConnection.authenticateWithPassword(username, password); - } - // Send hello message to retrieve capabilities. - } catch (IOException e) { - log.error("Fatal Error while creating connection to the device: " - + deviceInfo(), e); - throw e; - } catch (JNCException e) { - log.error("Failed to connect to the device: " + deviceInfo(), e); - throw e; - } - - hello(); - } - - private void hello() { - SSHSession ssh = null; - try { - ssh = new SSHSession(sshConnection); - String helloRequestXML = INPUT_HELLO_XML_MSG.trim(); - - log.debug("++++++++++++++++++++++++++++++++++Sending Hello: " - + sshConnection.getGanymedConnection().getHostname() - + "++++++++++++++++++++++++++++++++++"); - printPrettyXML(helloRequestXML); - ssh.print(helloRequestXML); - // ssh.print(endCharSeq); - ssh.flush(); - String xmlResponse = null; - int i = CONNECTION_CHECK_INTERVAL; - while (!ssh.ready() && i > 0) { - delay(EVENTINTERVAL); - i--; - } - - if (ssh.ready()) { - StringBuffer readOne = ssh.readOne(); - if (readOne == null) { - log.error("The Hello Contains No Capabilites"); - throw new JNCException( - JNCException.SESSION_ERROR, - "server does not support NETCONF base capability: " - + Capabilities.NETCONF_BASE_CAPABILITY); - } else { - xmlResponse = readOne.toString().trim(); - - log.debug("++++++++++++++++++++++++++++++++++Reading Capabilities: " - + sshConnection.getGanymedConnection() - .getHostname() - + "++++++++++++++++++++++++++++++++++"); - - printPrettyXML(xmlResponse); - processCapabilities(xmlResponse); - } - } - reachable = true; - } catch (IOException e) { - log.error("Fatal Error while sending Hello Message to the device: " - + deviceInfo(), e); - } catch (JNCException e) { - log.error("Fatal Error while sending Hello Message to the device: " - + deviceInfo(), e); - } finally { - log.debug("Closing the session after successful execution"); - if (ssh != null) { - ssh.close(); - } - } - } - - private void processCapabilities(String xmlResponse) throws JNCException { - if (xmlResponse.isEmpty()) { - log.error("The capability response cannot be empty"); - throw new JNCException( - JNCException.SESSION_ERROR, - "server does not support NETCONF base capability: " - + Capabilities.NETCONF_BASE_CAPABILITY); - } - try { - Document doc = new SAXBuilder() - .build(new StringReader(xmlResponse)); - Element rootElement = doc.getRootElement(); - processCapabilities(rootElement); - } catch (Exception e) { - log.error("ERROR while parsing the XML " + xmlResponse); - } - } - - private void processCapabilities(Element rootElement) { - List<Element> children = rootElement.getChildren(); - if (children.isEmpty()) { - return; - } - for (Element child : children) { - - if (child.getName().equals(XML_CAPABILITY_KEY)) { - capabilities.add(child.getValue()); - } - if (!child.getChildren().isEmpty()) { - processCapabilities(child); - } - } - } - - private void printPrettyXML(String xmlstring) { - try { - Document doc = new SAXBuilder().build(new StringReader(xmlstring)); - XMLOutputter xmOut = new XMLOutputter(Format.getPrettyFormat()); - String outputString = xmOut.outputString(doc); - log.debug(outputString); - } catch (Exception e) { - log.error("ERROR while parsing the XML " + xmlstring, e); - - } - } - - /** - * This would return host IP and host Port, used by this particular Netconf - * Device. - * @return Device Information. - */ - public String deviceInfo() { - return new StringBuilder("host: ").append(sshHost).append(". port: ") - .append(sshPort).toString(); - } - - /** - * This will terminate the device connection. - */ - public void disconnect() { - sshConnection.close(); - reachable = false; - } - - /** - * This will list down all the capabilities supported on the device. - * @return Capability list. - */ - public List<String> getCapabilities() { - return capabilities; - } - - /** - * This api is intended to know whether the device is connected or not. - * @return true if connected - */ - public boolean isReachable() { - return reachable; - } - - /** - * This will return the IP used connect ssh on the device. - * @return Netconf Device IP - */ - public String getSshHost() { - return sshHost; - } - - /** - * This will return the SSH Port used connect the device. - * @return SSH Port number - */ - public int getSshPort() { - return sshPort; - } - - /** - * The usename used to connect Netconf Device. - * @return Device Username - */ - public String getUsername() { - return username; - } - - /** - * Retrieve current state of the device. - * @return Current Device State - */ - public DeviceState getDeviceState() { - return deviceState; - } - - /** - * This is set the state information for the device. - * @param deviceState Next Device State - */ - public void setDeviceState(DeviceState deviceState) { - this.deviceState = deviceState; - } - - /** - * Check whether the device is in Active state. - * @return true if the device is Active - */ - public boolean isActive() { - return deviceState == DeviceState.ACTIVE ? true : false; - } - - public void setConnectTimeout(int connectTimeout) { - this.connectTimeout = connectTimeout; - } -} diff --git a/framework/src/onos/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java b/framework/src/onos/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java index f9194a7e..d12c6474 100644 --- a/framework/src/onos/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java +++ b/framework/src/onos/providers/netconf/device/src/main/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProvider.java @@ -13,39 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onosproject.provider.netconf.device.impl; - -import static com.google.common.base.Strings.isNullOrEmpty; -import static org.onlab.util.Tools.delay; -import static org.onlab.util.Tools.get; -import static org.onlab.util.Tools.groupedThreads; -import static org.slf4j.LoggerFactory.getLogger; -import java.io.IOException; -import java.net.SocketTimeoutException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Dictionary; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; +package org.onosproject.provider.netconf.device.impl; +import com.google.common.base.Preconditions; 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.Modified; -import org.apache.felix.scr.annotations.Property; import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.ReferenceCardinality; import org.onlab.packet.ChassisId; -import org.onosproject.cfg.ComponentConfigService; -import org.onosproject.cluster.ClusterService; +import org.onosproject.core.ApplicationId; +import org.onosproject.core.CoreService; +import org.onosproject.incubator.net.config.basics.ConfigException; +import org.onosproject.net.DefaultAnnotations; import org.onosproject.net.Device; import org.onosproject.net.DeviceId; import org.onosproject.net.MastershipRole; +import org.onosproject.net.SparseAnnotations; +import org.onosproject.net.config.ConfigFactory; +import org.onosproject.net.config.NetworkConfigEvent; +import org.onosproject.net.config.NetworkConfigListener; +import org.onosproject.net.config.NetworkConfigRegistry; import org.onosproject.net.device.DefaultDeviceDescription; import org.onosproject.net.device.DeviceDescription; import org.onosproject.net.device.DeviceProvider; @@ -54,305 +43,180 @@ import org.onosproject.net.device.DeviceProviderService; import org.onosproject.net.device.DeviceService; import org.onosproject.net.provider.AbstractProvider; import org.onosproject.net.provider.ProviderId; -import org.onosproject.provider.netconf.device.impl.NetconfDevice.DeviceState; -import org.osgi.service.component.ComponentContext; +import org.onosproject.netconf.NetconfController; +import org.onosproject.netconf.NetconfDevice; +import org.onosproject.netconf.NetconfDeviceInfo; +import org.onosproject.netconf.NetconfDeviceListener; import org.slf4j.Logger; +import java.util.Map; + +import static org.onosproject.net.config.basics.SubjectFactories.APP_SUBJECT_FACTORY; +import static org.slf4j.LoggerFactory.getLogger; + /** - * Provider which will try to fetch the details of NETCONF devices from the core - * and run a capability discovery on each of the device. + * Provider which uses an NETCONF controller to detect device. */ @Component(immediate = true) public class NetconfDeviceProvider extends AbstractProvider implements DeviceProvider { - - private final Logger log = getLogger(NetconfDeviceProvider.class); - - protected Map<DeviceId, NetconfDevice> netconfDeviceMap = new ConcurrentHashMap<DeviceId, NetconfDevice>(); - - private DeviceProviderService providerService; + private final Logger log = getLogger(getClass()); @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected DeviceProviderRegistry providerRegistry; @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected DeviceService deviceService; - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ClusterService clusterService; + protected NetconfController controller; //where is initiated ? @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) - protected ComponentConfigService cfgService; - - private ExecutorService deviceBuilder = Executors - .newFixedThreadPool(1, groupedThreads("onos/netconf", "device-creator")); + protected NetworkConfigRegistry cfgService; - // Delay between events in ms. - private static final int EVENTINTERVAL = 5; - - private static final String SCHEME = "netconf"; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected CoreService coreService; - @Property(name = "devConfigs", value = "", label = "Instance-specific configurations") - private String devConfigs = null; - @Property(name = "devPasswords", value = "", label = "Instance-specific password") - private String devPasswords = null; + private DeviceProviderService providerService; + private NetconfDeviceListener innerNodeListener = new InnerNetconfDeviceListener(); + protected static final String ISNOTNULL = "NetconfDeviceInfo is not null"; + private static final String UNKNOWN = "unknown"; + + private final ConfigFactory factory = + new ConfigFactory<ApplicationId, NetconfProviderConfig>(APP_SUBJECT_FACTORY, + NetconfProviderConfig.class, + "devices", + true) { + @Override + public NetconfProviderConfig createConfig() { + return new NetconfProviderConfig(); + } + }; + private final NetworkConfigListener cfgLister = new InternalNetworkConfigListener(); + private ApplicationId appId; - /** - * Creates a provider with the supplier identifier. - */ - public NetconfDeviceProvider() { - super(new ProviderId("netconf", "org.onosproject.provider.netconf")); - } @Activate - public void activate(ComponentContext context) { - cfgService.registerProperties(getClass()); + public void activate() { providerService = providerRegistry.register(this); - modified(context); + cfgService.registerConfigFactory(factory); + cfgService.addListener(cfgLister); + controller.addDeviceListener(innerNodeListener); + connectExistingDevices(); log.info("Started"); } + @Deactivate - public void deactivate(ComponentContext context) { - cfgService.unregisterProperties(getClass(), false); - try { - for (Entry<DeviceId, NetconfDevice> deviceEntry : netconfDeviceMap - .entrySet()) { - deviceBuilder.submit(new DeviceCreator(deviceEntry.getValue(), - false)); - } - deviceBuilder.awaitTermination(1000, TimeUnit.MILLISECONDS); - } catch (InterruptedException e) { - log.error("Device builder did not terminate"); - } - deviceBuilder.shutdownNow(); - netconfDeviceMap.clear(); + public void deactivate() { providerRegistry.unregister(this); providerService = null; + cfgService.unregisterConfigFactory(factory); log.info("Stopped"); } - @Modified - public void modified(ComponentContext context) { - if (context == null) { - log.info("No configuration file"); - return; - } - Dictionary<?, ?> properties = context.getProperties(); - String deviceCfgValue = get(properties, "devConfigs"); - log.info("Settings: devConfigs={}", deviceCfgValue); - if (!isNullOrEmpty(deviceCfgValue)) { - addOrRemoveDevicesConfig(deviceCfgValue); - } - } - - private void addOrRemoveDevicesConfig(String deviceConfig) { - for (String deviceEntry : deviceConfig.split(",")) { - NetconfDevice device = processDeviceEntry(deviceEntry); - if (device != null) { - log.info("Device Detail: username: {}, host={}, port={}, state={}", - device.getUsername(), device.getSshHost(), - device.getSshPort(), device.getDeviceState().name()); - if (device.isActive()) { - deviceBuilder.submit(new DeviceCreator(device, true)); - } else { - deviceBuilder.submit(new DeviceCreator(device, false)); - } - } - } - } - - private NetconfDevice processDeviceEntry(String deviceEntry) { - if (deviceEntry == null) { - log.info("No content for Device Entry, so cannot proceed further."); - return null; - } - log.info("Trying to convert Device Entry String: " + deviceEntry - + " to a Netconf Device Object"); - NetconfDevice device = null; - try { - String userInfo = deviceEntry.substring(0, deviceEntry - .lastIndexOf('@')); - String hostInfo = deviceEntry.substring(deviceEntry - .lastIndexOf('@') + 1); - String[] infoSplit = userInfo.split(":"); - String username = infoSplit[0]; - String password = infoSplit[1]; - infoSplit = hostInfo.split(":"); - String hostIp = infoSplit[0]; - Integer hostPort; - try { - hostPort = Integer.parseInt(infoSplit[1]); - } catch (NumberFormatException nfe) { - log.error("Bad Configuration Data: Failed to parse host port number string: " - + infoSplit[1]); - throw nfe; - } - String deviceState = infoSplit[2]; - if (isNullOrEmpty(username) || isNullOrEmpty(password) - || isNullOrEmpty(hostIp) || hostPort == 0) { - log.warn("Bad Configuration Data: both user and device information parts of Configuration " - + deviceEntry + " should be non-nullable"); - } else { - device = new NetconfDevice(hostIp, hostPort, username, password); - if (!isNullOrEmpty(deviceState)) { - if (deviceState.toUpperCase().equals(DeviceState.ACTIVE - .name())) { - device.setDeviceState(DeviceState.ACTIVE); - } else if (deviceState.toUpperCase() - .equals(DeviceState.INACTIVE.name())) { - device.setDeviceState(DeviceState.INACTIVE); - } else { - log.warn("Device State Information can not be empty, so marking the state as INVALID"); - device.setDeviceState(DeviceState.INVALID); - } - } else { - log.warn("The device entry do not specify state information, so marking the state as INVALID"); - device.setDeviceState(DeviceState.INVALID); - } - } - } catch (ArrayIndexOutOfBoundsException aie) { - log.error("Error while reading config infromation from the config file: " - + "The user, host and device state infomation should be " - + "in the order 'userInfo@hostInfo:deviceState'" - + deviceEntry, aie); - } catch (Exception e) { - log.error("Error while parsing config information for the device entry: " - + deviceEntry, e); - } - return device; + public NetconfDeviceProvider() { + super(new ProviderId("netconf", "org.onosproject.netconf.provider.device")); } @Override public void triggerProbe(DeviceId deviceId) { - // TODO Auto-generated method stub + // TODO: This will be implemented later. + log.info("Triggering probe on device {}", deviceId); } @Override public void roleChanged(DeviceId deviceId, MastershipRole newRole) { - + // TODO: This will be implemented later. } @Override public boolean isReachable(DeviceId deviceId) { - NetconfDevice netconfDevice = netconfDeviceMap.get(deviceId); + Map<DeviceId, NetconfDevice> devices = controller.getDevicesMap(); + + NetconfDevice netconfDevice = null; + for (DeviceId key : devices.keySet()) { + if (key.equals(deviceId)) { + netconfDevice = controller.getDevicesMap().get(key); + } + } if (netconfDevice == null) { log.warn("BAD REQUEST: the requested device id: " - + deviceId.toString() - + " is not associated to any NETCONF Device"); + + deviceId.toString() + + " is not associated to any NETCONF Device"); return false; } - return netconfDevice.isReachable(); + return netconfDevice.isActive(); } - /** - * This class is intended to add or remove Configured Netconf Devices. - * Functionality relies on 'createFlag' and 'NetconfDevice' content. The - * functionality runs as a thread and dependening on the 'createFlag' value - * it will create or remove Device entry from the core. - */ - private class DeviceCreator implements Runnable { + private class InnerNetconfDeviceListener implements NetconfDeviceListener { - private NetconfDevice device; - private boolean createFlag; + @Override + public void deviceAdded(NetconfDeviceInfo nodeId) { + Preconditions.checkNotNull(nodeId, ISNOTNULL); + DeviceId deviceId = nodeId.getDeviceId(); + //TODO filter for not netconf devices + //Netconf configuration object + ChassisId cid = new ChassisId(); + String ipAddress = nodeId.ip().toString(); + SparseAnnotations annotations = DefaultAnnotations.builder() + .set("ipaddress", ipAddress).build(); + DeviceDescription deviceDescription = new DefaultDeviceDescription( + deviceId.uri(), + Device.Type.SWITCH, + UNKNOWN, UNKNOWN, + UNKNOWN, UNKNOWN, + cid, + annotations); + providerService.deviceConnected(deviceId, deviceDescription); - public DeviceCreator(NetconfDevice device, boolean createFlag) { - this.device = device; - this.createFlag = createFlag; } @Override - public void run() { - if (createFlag) { - log.info("Trying to create Device Info on ONOS core"); - advertiseDevices(); - } else { - log.info("Trying to remove Device Info on ONOS core"); - removeDevices(); - } + public void deviceRemoved(NetconfDeviceInfo nodeId) { + Preconditions.checkNotNull(nodeId, ISNOTNULL); + DeviceId deviceId = nodeId.getDeviceId(); + providerService.deviceDisconnected(deviceId); + } + } - /** - * For each Netconf Device, remove the entry from the device store. - */ - private void removeDevices() { - if (device == null) { - log.warn("The Request Netconf Device is null, cannot proceed further"); - return; - } + private void connectExistingDevices() { + //TODO consolidate + appId = coreService.registerApplication("org.onosproject.netconf"); + connectDevices(); + } + + private void connectDevices() { + NetconfProviderConfig cfg = cfgService.getConfig(appId, NetconfProviderConfig.class); + if (cfg != null) { + log.info("cfg {}", cfg); try { - DeviceId did = getDeviceId(); - if (!netconfDeviceMap.containsKey(did)) { - log.error("BAD Request: 'Currently device is not discovered, " - + "so cannot remove/disconnect the device: " - + device.deviceInfo() + "'"); - return; - } - providerService.deviceDisconnected(did); - device.disconnect(); - netconfDeviceMap.remove(did); - delay(EVENTINTERVAL); - } catch (URISyntaxException uriSyntaxExcpetion) { - log.error("Syntax Error while creating URI for the device: " - + device.deviceInfo() - + " couldn't remove the device from the store", - uriSyntaxExcpetion); + cfg.getDevicesAddresses().stream().forEach(addr -> controller + .connectDevice(new NetconfDeviceInfo(addr.name(), + addr.password(), + addr.ip(), + addr.port()))); + } catch (ConfigException e) { + log.error("Cannot read config error " + e); } } + } - /** - * Initialize Netconf Device object, and notify core saying device - * connected. - */ - private void advertiseDevices() { - try { - if (device == null) { - log.warn("The Request Netconf Device is null, cannot proceed further"); - return; - } - device.init(); - DeviceId did = getDeviceId(); - ChassisId cid = new ChassisId(); - DeviceDescription desc = new DefaultDeviceDescription( - did.uri(), - Device.Type.OTHER, - "", "", - "", "", - cid); - log.info("Persisting Device" + did.uri().toString()); - - netconfDeviceMap.put(did, device); - providerService.deviceConnected(did, desc); - log.info("Done with Device Info Creation on ONOS core. Device Info: " - + device.deviceInfo() + " " + did.uri().toString()); - delay(EVENTINTERVAL); - } catch (URISyntaxException e) { - log.error("Syntax Error while creating URI for the device: " - + device.deviceInfo() - + " couldn't persist the device onto the store", e); - } catch (SocketTimeoutException e) { - log.error("Error while setting connection for the device: " - + device.deviceInfo(), e); - } catch (IOException e) { - log.error("Error while setting connection for the device: " - + device.deviceInfo(), e); - } catch (Exception e) { - log.error("Error while initializing session for the device: " - + (device != null ? device.deviceInfo() : null), e); - } + private class InternalNetworkConfigListener implements NetworkConfigListener { + + + @Override + public void event(NetworkConfigEvent event) { + connectDevices(); } - /** - * This will build a device id for the device. - */ - private DeviceId getDeviceId() throws URISyntaxException { - String additionalSSP = new StringBuilder(device.getUsername()) - .append("@").append(device.getSshHost()).append(":") - .append(device.getSshPort()).toString(); - DeviceId did = DeviceId.deviceId(new URI(SCHEME, additionalSSP, - null)); - return did; + @Override + public boolean isRelevant(NetworkConfigEvent event) { + //TODO refactor + return event.configClass().equals(NetconfProviderConfig.class) && + (event.type() == NetworkConfigEvent.Type.CONFIG_ADDED || + event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED); } } } diff --git a/framework/src/onos/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTest.java b/framework/src/onos/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTest.java deleted file mode 100644 index e56c5959..00000000 --- a/framework/src/onos/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTest.java +++ /dev/null @@ -1,421 +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.provider.netconf.device.impl; - -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.junit.Assert.assertFalse; -import static org.onlab.util.Tools.delay; -import static org.onosproject.provider.netconf.device.impl.NetconfDeviceProviderTestConstant.*; -import static org.slf4j.LoggerFactory.getLogger; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Collection; -import java.util.Dictionary; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -import org.easymock.EasyMock; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.onlab.packet.ChassisId; -import org.onosproject.cfg.ComponentConfigService; -import org.onosproject.net.Device; -import org.onosproject.net.DeviceId; -import org.onosproject.net.MastershipRole; -import org.onosproject.net.device.DefaultDeviceDescription; -import org.onosproject.net.device.DeviceDescription; -import org.onosproject.net.device.DeviceProvider; -import org.onosproject.net.device.DeviceProviderRegistry; -import org.onosproject.net.device.DeviceProviderService; -import org.onosproject.net.device.PortDescription; -import org.onosproject.net.device.PortStatistics; -import org.onosproject.net.provider.ProviderId; -import org.osgi.service.component.ComponentContext; -import org.slf4j.Logger; - -import com.tailf.jnc.JNCException; - -/** - * Test Case to Validate Netconf Device Provider. - */ -public class NetconfDeviceProviderTest { - TestDeviceCreator create; - - private final Logger log = getLogger(NetconfDeviceProviderTest.class); - - private Map<DeviceId, NetconfDevice> netconfDeviceMap = new ConcurrentHashMap<DeviceId, NetconfDevice>(); - - private DeviceProviderService providerService; - - private static final DeviceId DID1 = DeviceId.deviceId(DEVICE_ID); - - private final NetconfDeviceProvider provider = new NetconfDeviceProvider(); - private final TestDeviceRegistry registry = new TestDeviceRegistry(); - - private ComponentConfigService mockCfgService; - - @Before - public void setUp() { - mockCfgService = EasyMock.createMock(ComponentConfigService.class); - provider.cfgService = mockCfgService; - provider.providerRegistry = registry; - } - - @SuppressWarnings("unchecked") - private Dictionary<String, String> getDictionaryMockWithoutValues(ComponentContext componentContext) { - Dictionary<String, String> dictionary = EasyMock - .createMock(Dictionary.class); - expect(dictionary.get(DEV_CONFIG)).andReturn(NULL); - replay(dictionary); - expect(componentContext.getProperties()).andReturn(dictionary); - return dictionary; - } - - @SuppressWarnings("unchecked") - private Dictionary<String, String> getDictionaryMockWithDeviceEntryNull(ComponentContext componentContext) { - Dictionary<String, String> dictionary = EasyMock - .createMock(Dictionary.class); - expect(dictionary.get(DEV_CONFIG)).andReturn(NULL_NULL); - replay(dictionary); - expect(componentContext.getProperties()).andReturn(dictionary); - return dictionary; - } - - @SuppressWarnings("unchecked") - private Dictionary<String, String> getDictionaryMockDeviceEntryNumberFomatEx(ComponentContext componentContext) { - Dictionary<String, String> dictionary = EasyMock - .createMock(Dictionary.class); - expect(dictionary.get(DEV_CONFIG)) - .andReturn(CONFIG_WITH_INVALID_ENTRY_NUMBER) - .andThrow(new NumberFormatException()); - replay(dictionary); - expect(componentContext.getProperties()).andReturn(dictionary); - return dictionary; - } - - @SuppressWarnings("unchecked") - private Dictionary<String, String> getDictionaryMockWithoutUsernameAndPassword(ComponentContext componentContext) { - Dictionary<String, String> dictionary = EasyMock - .createMock(Dictionary.class); - expect(dictionary.get(DEV_CONFIG)).andReturn(CONFIG_WITH_NULL_ENTRY); - replay(dictionary); - expect(componentContext.getProperties()).andReturn(dictionary); - return dictionary; - } - - @SuppressWarnings("unchecked") - private Dictionary<String, String> getDictionaryMockWithDifferentDeviceState(ComponentContext componentContext) { - Dictionary<String, String> dictionary = EasyMock - .createMock(Dictionary.class); - expect(dictionary.get(DEV_CONFIG)) - .andReturn(CONFIG_WITH_DIFFERENT_DEVICE_STATE); - replay(dictionary); - expect(componentContext.getProperties()).andReturn(dictionary); - return dictionary; - } - - @SuppressWarnings("unchecked") - private Dictionary<String, String> getDictionaryMockDeviceWithArrayOutOFBoundEx(ComponentContext componentContext) { - Dictionary<String, String> dictionary = EasyMock - .createMock(Dictionary.class); - expect(dictionary.get(DEV_CONFIG)) - .andReturn(CONFIG_WITH_ARRAY_OUT_OF_BOUNDEX) - .andThrow(new ArrayIndexOutOfBoundsException()); - replay(dictionary); - expect(componentContext.getProperties()).andReturn(dictionary); - return dictionary; - } - - @SuppressWarnings("unchecked") - private Dictionary<String, String> getDictionaryMockDeviceEntryForDeactivate(ComponentContext componentContext) { - Dictionary<String, String> dictionary = EasyMock - .createMock(Dictionary.class); - expect(dictionary.get(DEV_CONFIG)) - .andReturn(CONFIG_ENTRY_FOR_DEACTIVATE) - .andThrow(new ArrayIndexOutOfBoundsException()); - replay(dictionary); - expect(componentContext.getProperties()).andReturn(dictionary); - return dictionary; - } - - @Ignore - @Test(expected = IOException.class) - public void testSSHAuthentication() throws IOException, JNCException { - TestDeviceCreator objForTestDev = new TestDeviceCreator( - new NetconfDevice( - DEVICE_IP, - DEVICE_PORT, - DEVICE_USERNAME, - DEVICE_PASSWORD), - true); - objForTestDev.run(); - } - - @After - public void tearDown() { - provider.providerRegistry = null; - provider.cfgService = null; - } - - // To check if deviceCfgValue is empty or null - @Test - public void testActiveWithcomponentContextIsNull() { - - ComponentContext componentContext = EasyMock - .createMock(ComponentContext.class); - getDictionaryMockWithoutValues(componentContext); - replay(componentContext); - provider.activate(componentContext); - } - - // To check deviceEntry and device is null - @Test - public void testActiveWithDeviceEntryIsNull() { - - ComponentContext componentContext = EasyMock - .createMock(ComponentContext.class); - getDictionaryMockWithDeviceEntryNull(componentContext); - replay(componentContext); - provider.activate(componentContext); - } - - @Test - public void testActiveWithDeviceEntryWithoutUsernameAndPassword() { - - ComponentContext componentContext = EasyMock - .createMock(ComponentContext.class); - getDictionaryMockWithoutUsernameAndPassword(componentContext); - replay(componentContext); - provider.activate(componentContext); - } - - @Test - public void testActiveWithDeviceEntryWithNumberFomatEx() { - - ComponentContext componentContext = EasyMock - .createMock(ComponentContext.class); - getDictionaryMockDeviceEntryNumberFomatEx(componentContext); - replay(componentContext); - provider.activate(componentContext); - } - - @Test - public void testActiveWithDeviceEntryWithDifferentDeviceState() { - - ComponentContext componentContext = EasyMock - .createMock(ComponentContext.class); - getDictionaryMockWithDifferentDeviceState(componentContext); - replay(componentContext); - provider.activate(componentContext); - } - - @Test - public void testActiveWithDeviceEntryWithArrayOutOFBoundEx() { - - ComponentContext componentContext = EasyMock - .createMock(ComponentContext.class); - getDictionaryMockDeviceWithArrayOutOFBoundEx(componentContext); - replay(componentContext); - provider.activate(componentContext); - } - - @Test - public void isReachableWithInvalidDeviceId() { - assertFalse("Initially the Device ID Should not be reachable", - provider.isReachable(DID1)); - NetconfDevice device = new NetconfDevice(NULL, ZERO, NULL, NULL); - provider.netconfDeviceMap.put(DID1, device); - assertFalse("Particular Device ID cannot be Reachable", - provider.isReachable(DID1)); - } - - @Test - public void testDeactivate() { - - ComponentContext componentContext = EasyMock - .createMock(ComponentContext.class); - getDictionaryMockDeviceEntryForDeactivate(componentContext); - replay(componentContext); - testActiveWithDeviceEntryWithDifferentDeviceState(); - provider.deactivate(componentContext); - } - - private class TestDeviceCreator { - - private NetconfDevice device; - private boolean createFlag; - - public TestDeviceCreator(NetconfDevice device, boolean createFlag) { - this.device = device; - this.createFlag = createFlag; - } - - public void run() throws JNCException, IOException { - if (createFlag) { - log.info("Trying to create Device Info on ONOS core"); - advertiseDevices(); - } else { - log.info("Trying to remove Device Info on ONOS core"); - removeDevices(); - } - } - - /** - * For each Netconf Device, remove the entry from the device store. - */ - private void removeDevices() { - if (device == null) { - log.warn("The Request Netconf Device is null, cannot proceed further"); - return; - } - try { - DeviceId did = getDeviceId(); - if (!netconfDeviceMap.containsKey(did)) { - log.error("BAD Request: 'Currently device is not discovered, " - + "so cannot remove/disconnect the device: " - + device.deviceInfo() + "'"); - return; - } - providerService.deviceDisconnected(did); - device.disconnect(); - netconfDeviceMap.remove(did); - delay(EVENTINTERVAL); - } catch (URISyntaxException uriSyntaxExcpetion) { - log.error("Syntax Error while creating URI for the device: " - + device.deviceInfo() - + " couldn't remove the device from the store", - uriSyntaxExcpetion); - } - } - - /** - * Initialize Netconf Device object, and notify core saying device - * connected. - */ - private void advertiseDevices() throws JNCException, IOException { - try { - if (device == null) { - log.warn("The Request Netconf Device is null, cannot proceed further"); - return; - } - device.init(); - DeviceId did = getDeviceId(); - ChassisId cid = new ChassisId(); - DeviceDescription desc = new DefaultDeviceDescription( - did.uri(), - Device.Type.OTHER, - NULL, - NULL, - NULL, - NULL, cid); - log.info("Persisting Device" + did.uri().toString()); - - netconfDeviceMap.put(did, device); - providerService.deviceConnected(did, desc); - log.info("Done with Device Info Creation on ONOS core. Device Info: " - + device.deviceInfo() + " " + did.uri().toString()); - delay(EVENTINTERVAL); - } catch (URISyntaxException e) { - log.error("Syntax Error while creating URI for the device: " - + device.deviceInfo() - + " couldn't persist the device onto the store", e); - } catch (JNCException e) { - throw e; - } catch (IOException e) { - throw e; - } catch (Exception e) { - log.error("Error while initializing session for the device: " - + device.deviceInfo(), e); - } - } - - private DeviceId getDeviceId() throws URISyntaxException { - String additionalSSP = new StringBuilder(device.getUsername()) - .append(AT_THE_RATE).append(device.getSshHost()) - .append(COLON).append(device.getSshPort()).toString(); - DeviceId did = DeviceId.deviceId(new URI(SCHEME_NETCONF, - additionalSSP, null)); - return did; - } - } - - private class TestDeviceRegistry implements DeviceProviderRegistry { - - @Override - public DeviceProviderService register(DeviceProvider provider) { - return new TestProviderService(); - } - - @Override - public void unregister(DeviceProvider provider) { - } - - @Override - public Set<ProviderId> getProviders() { - return null; - } - - private class TestProviderService implements DeviceProviderService { - - @Override - public DeviceProvider provider() { - return null; - } - - @Override - public void deviceConnected(DeviceId deviceId, - DeviceDescription deviceDescription) { - } - - @Override - public void deviceDisconnected(DeviceId deviceId) { - - } - - @Override - public void updatePorts(DeviceId deviceId, - List<PortDescription> portDescriptions) { - - } - - @Override - public void portStatusChanged(DeviceId deviceId, - PortDescription portDescription) { - - } - - @Override - public void receivedRoleReply(DeviceId deviceId, - MastershipRole requested, - MastershipRole response) { - - } - - @Override - public void updatePortStatistics(DeviceId deviceId, - Collection<PortStatistics> portStatistics) { - - } - } - } -} diff --git a/framework/src/onos/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTestConstant.java b/framework/src/onos/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTestConstant.java deleted file mode 100644 index 1d848e26..00000000 --- a/framework/src/onos/providers/netconf/device/src/test/java/org/onosproject/provider/netconf/device/impl/NetconfDeviceProviderTestConstant.java +++ /dev/null @@ -1,46 +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.provider.netconf.device.impl; - -public final class NetconfDeviceProviderTestConstant { - - private NetconfDeviceProviderTestConstant() { - } - - public static final int ZERO = 0; - public static final int EVENTINTERVAL = 5; - public static final String DEV_CONFIG = "devConfigs"; - public static final String CONFIG_WITH_INVALID_ENTRY_NUMBER = "cisco:cisco" - + "@10.18.11.14:cisco:active"; - public static final String CONFIG_WITH_NULL_ENTRY = "null:null@null:0:active"; - public static final String CONFIG_WITH_DIFFERENT_DEVICE_STATE = "cisco:cisco@10.18.11.14:22:active," - + "cisco:cisco@10.18.11.18:22:inactive,cisco:cisco@10.18.11.14:22:invalid," - + "cisco:cisco@10.18.11.14:22:null"; - public static final String CONFIG_WITH_ARRAY_OUT_OF_BOUNDEX = "@10.18.11.14:22:active"; - public static final String CONFIG_ENTRY_FOR_DEACTIVATE = "netconf:cisco" - + "@10.18.11.14:22:active"; - public static final String DEVICE_IP = "10.18.14.19"; - public static final int DEVICE_PORT = 22; - public static final String DEVICE_USERNAME = "cisco"; - public static final String DEVICE_PASSWORD = "cisco"; - public static final String AT_THE_RATE = "@"; - public static final String COLON = ":"; - public static final String NULL = ""; - public static final String NULL_NULL = "null,null"; - public static final String SCHEME_NETCONF = "netconf"; - public static final String DEVICE_ID = "of:0000000000000001"; - -} diff --git a/framework/src/onos/providers/openflow/app/app.xml b/framework/src/onos/providers/openflow/app/app.xml deleted file mode 100644 index e54d1a8a..00000000 --- a/framework/src/onos/providers/openflow/app/app.xml +++ /dev/null @@ -1,33 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ 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. - --> -<app name="org.onosproject.openflow" origin="ON.Lab" version="${project.version}" - featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" - features="${project.artifactId}"> - <description>${project.description}</description> - - <artifact>mvn:${project.groupId}/onos-of-api/${project.version}</artifact> - <artifact>mvn:${project.groupId}/onos-of-ctl/${project.version}</artifact> - <artifact>mvn:${project.groupId}/onos-drivers/${project.version}</artifact> - - <artifact>mvn:${project.groupId}/onos-lldp-provider/${project.version}</artifact> - <artifact>mvn:${project.groupId}/onos-host-provider/${project.version}</artifact> - <artifact>mvn:${project.groupId}/onos-of-provider-device/${project.version}</artifact> - <artifact>mvn:${project.groupId}/onos-of-provider-packet/${project.version}</artifact> - <artifact>mvn:${project.groupId}/onos-of-provider-flow/${project.version}</artifact> - <artifact>mvn:${project.groupId}/onos-of-provider-group/${project.version}</artifact> - <artifact>mvn:${project.groupId}/onos-of-provider-meter/${project.version}</artifact> -</app> diff --git a/framework/src/onos/providers/openflow/app/features.xml b/framework/src/onos/providers/openflow/app/features.xml deleted file mode 100644 index 9dbae8af..00000000 --- a/framework/src/onos/providers/openflow/app/features.xml +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" standalone="yes"?> -<!-- - ~ 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. - --> -<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> - <repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository> - <feature name="${project.artifactId}" version="${project.version}" - description="${project.description}"> - <feature>onos-api</feature> - <bundle>mvn:io.netty/netty/3.9.2.Final</bundle> - <bundle>mvn:${project.groupId}/onos-of-api/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-of-ctl/${project.version}</bundle> - - <bundle>mvn:${project.groupId}/onos-lldp-provider/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-host-provider/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-of-provider-device/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-of-provider-packet/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-of-provider-flow/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-of-provider-group/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-of-provider-meter/${project.version}</bundle> - </feature> -</features> diff --git a/framework/src/onos/providers/openflow/app/pom.xml b/framework/src/onos/providers/openflow/app/pom.xml index cb55463b..ac5f6eee 100644 --- a/framework/src/onos/providers/openflow/app/pom.xml +++ b/framework/src/onos/providers/openflow/app/pom.xml @@ -27,55 +27,23 @@ </parent> <artifactId>onos-openflow</artifactId> - <packaging>pom</packaging> + <packaging>bundle</packaging> - <description>OpenFlow protocol southbound providers</description> + <properties> + <onos.app.name>org.onosproject.openflow</onos.app.name> + <onos.app.requires> + org.onosproject.openflow-base, + org.onosproject.hostprovider, + org.onosproject.lldpprovider + </onos.app.requires> + </properties> + + <description>OpenFlow southbound meta application</description> <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-of-api</artifactId> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-of-ctl</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-drivers</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-of-provider-device</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-of-provider-packet</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-of-provider-flow</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-of-provider-group</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-lldp-provider</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-host-provider</artifactId> - <version>${project.version}</version> - </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-of-api</artifactId> + </dependency> </dependencies> - </project> diff --git a/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java b/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java index 4d5b6b28..1354240f 100644 --- a/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java +++ b/framework/src/onos/providers/openflow/flow/src/main/java/org/onosproject/provider/of/flow/impl/FlowEntryBuilder.java @@ -50,6 +50,7 @@ import org.projectfloodlight.openflow.protocol.OFFlowRemoved; import org.projectfloodlight.openflow.protocol.OFFlowStatsEntry; import org.projectfloodlight.openflow.protocol.action.OFAction; import org.projectfloodlight.openflow.protocol.action.OFActionCircuit; +import org.projectfloodlight.openflow.protocol.action.OFActionEnqueue; import org.projectfloodlight.openflow.protocol.action.OFActionExperimenter; import org.projectfloodlight.openflow.protocol.action.OFActionGroup; import org.projectfloodlight.openflow.protocol.action.OFActionOutput; @@ -346,6 +347,10 @@ public class FlowEntryBuilder { OFActionSetQueue setQueue = (OFActionSetQueue) act; builder.setQueue(setQueue.getQueueId()); break; + case ENQUEUE: + OFActionEnqueue enqueue = (OFActionEnqueue) act; + builder.setQueue(enqueue.getQueueId(), PortNumber.portNumber(enqueue.getPort().getPortNumber())); + break; case STRIP_VLAN: case POP_VLAN: builder.popVlan(); @@ -364,7 +369,6 @@ public class FlowEntryBuilder { case SET_NW_TOS: case SET_NW_TTL: - case ENQUEUE: default: log.warn("Action type {} not yet implemented.", act.getType()); } @@ -703,10 +707,16 @@ public class FlowEntryBuilder { long tunnelId = match.get(MatchField.TUNNEL_ID).getValue(); builder.matchTunnelId(tunnelId); break; - case ARP_OP: case ARP_SHA: - case ARP_SPA: + mac = MacAddress.valueOf(match.get(MatchField.ARP_SHA).getLong()); + builder.matchArpSha(mac); + break; case ARP_THA: + mac = MacAddress.valueOf(match.get(MatchField.ARP_THA).getLong()); + builder.matchArpTha(mac); + break; + case ARP_OP: + case ARP_SPA: case ARP_TPA: case MPLS_TC: default: 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..c5de72a8 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 @@ -24,6 +24,7 @@ import org.onosproject.net.OchSignal; import org.onosproject.net.driver.DriverService; import org.onosproject.net.flow.FlowRule; import org.onosproject.net.flow.TrafficSelector; +import org.onosproject.net.flow.criteria.ArpHaCriterion; import org.onosproject.net.flow.criteria.Criterion; import org.onosproject.net.flow.criteria.EthCriterion; import org.onosproject.net.flow.criteria.EthTypeCriterion; @@ -105,6 +106,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 +129,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<Long> xid, @@ -176,6 +179,7 @@ public abstract class FlowModBuilder { UdpPortCriterion udpPortCriterion; SctpPortCriterion sctpPortCriterion; IPv6NDLinkLayerAddressCriterion llAddressCriterion; + ArpHaCriterion arpHaCriterion; for (Criterion c : selector.criteria()) { switch (c.type()) { @@ -413,10 +417,18 @@ public abstract class FlowModBuilder { mplsBos.mplsBos() ? OFBooleanValue.TRUE : OFBooleanValue.FALSE); break; - case ARP_OP: case ARP_SHA: - case ARP_SPA: + arpHaCriterion = (ArpHaCriterion) c; + mBuilder.setExact(MatchField.ARP_SHA, + MacAddress.of(arpHaCriterion.mac().toLong())); + break; case ARP_THA: + arpHaCriterion = (ArpHaCriterion) c; + mBuilder.setExact(MatchField.ARP_THA, + MacAddress.of(arpHaCriterion.mac().toLong())); + break; + case ARP_OP: + case ARP_SPA: case ARP_TPA: case MPLS_TC: case PBB_ISID: 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 c7898414..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 @@ -22,6 +22,7 @@ import org.onosproject.net.flow.FlowRule; import org.onosproject.net.flow.TrafficTreatment; import org.onosproject.net.flow.instructions.Instruction; import org.onosproject.net.flow.instructions.Instructions.OutputInstruction; +import org.onosproject.net.flow.instructions.Instructions.SetQueueInstruction; import org.onosproject.net.flow.instructions.L2ModificationInstruction; import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction; import org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction; @@ -35,6 +36,7 @@ import org.projectfloodlight.openflow.protocol.OFFlowMod; import org.projectfloodlight.openflow.protocol.OFFlowModFlags; import org.projectfloodlight.openflow.protocol.action.OFAction; import org.projectfloodlight.openflow.protocol.action.OFActionOutput; +import org.projectfloodlight.openflow.protocol.action.OFActionEnqueue; import org.projectfloodlight.openflow.protocol.match.Match; import org.projectfloodlight.openflow.types.IPv4Address; import org.projectfloodlight.openflow.types.MacAddress; @@ -67,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<Long> xid, @@ -167,6 +170,16 @@ public class FlowModBuilderVer10 extends FlowModBuilder { } acts.add(action.build()); break; + case QUEUE: + SetQueueInstruction queue = (SetQueueInstruction) i; + if (queue.port() == null) { + log.warn("Required argument 'port' undefined for OFActionEnqueue"); + } + OFActionEnqueue.Builder queueBuilder = factory().actions().buildEnqueue() + .setQueueId(queue.queueId()) + .setPort(OFPort.ofInt((int) queue.port().toLong())); + acts.add(queueBuilder.build()); + break; case L0MODIFICATION: case GROUP: case TABLE: 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<Long> xid, Optional<DriverService> driverService) { diff --git a/framework/src/onos/providers/openflow/group/src/main/java/org/onosproject/provider/of/group/impl/GroupModBuilder.java b/framework/src/onos/providers/openflow/group/src/main/java/org/onosproject/provider/of/group/impl/GroupModBuilder.java index d5804f44..c91616df 100644 --- a/framework/src/onos/providers/openflow/group/src/main/java/org/onosproject/provider/of/group/impl/GroupModBuilder.java +++ b/framework/src/onos/providers/openflow/group/src/main/java/org/onosproject/provider/of/group/impl/GroupModBuilder.java @@ -15,11 +15,25 @@ */ package org.onosproject.provider.of.group.impl; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; + import org.onlab.packet.Ip4Address; import org.onlab.packet.Ip6Address; import org.onosproject.core.GroupId; +import org.onosproject.net.DeviceId; import org.onosproject.net.PortNumber; +import org.onosproject.net.driver.DefaultDriverData; +import org.onosproject.net.driver.DefaultDriverHandler; +import org.onosproject.net.driver.Driver; +import org.onosproject.net.driver.DriverService; import org.onosproject.net.flow.TrafficTreatment; +import org.onosproject.net.flow.instructions.ExtensionInstruction; import org.onosproject.net.flow.instructions.Instruction; import org.onosproject.net.flow.instructions.Instructions; import org.onosproject.net.flow.instructions.L0ModificationInstruction; @@ -28,6 +42,7 @@ import org.onosproject.net.flow.instructions.L3ModificationInstruction; import org.onosproject.net.group.GroupBucket; import org.onosproject.net.group.GroupBuckets; import org.onosproject.net.group.GroupDescription; +import org.onosproject.openflow.controller.ExtensionInterpreter; import org.projectfloodlight.openflow.protocol.OFBucket; import org.projectfloodlight.openflow.protocol.OFFactory; import org.projectfloodlight.openflow.protocol.OFGroupAdd; @@ -52,14 +67,6 @@ import org.projectfloodlight.openflow.types.U32; import org.projectfloodlight.openflow.types.VlanPcp; import org.slf4j.Logger; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import java.util.Optional; - -import static org.slf4j.LoggerFactory.getLogger; - /* * Builder for GroupMod. */ @@ -70,6 +77,7 @@ public final class GroupModBuilder { private GroupDescription.Type type; private OFFactory factory; private Long xid; + private Optional<DriverService> driverService; private final Logger log = getLogger(getClass()); @@ -85,6 +93,16 @@ public final class GroupModBuilder { this.xid = xid.orElse((long) 0); } + private GroupModBuilder(GroupBuckets buckets, GroupId groupId, + GroupDescription.Type type, OFFactory factory, + Optional<Long> xid, Optional<DriverService> driverService) { + this.buckets = buckets; + this.groupId = groupId; + this.type = type; + this.factory = factory; + this.xid = xid.orElse((long) 0); + this.driverService = driverService; + } /** * Creates a builder for GroupMod. * @@ -103,6 +121,24 @@ public final class GroupModBuilder { } /** + * Creates a builder for GroupMod. + * + * @param buckets GroupBuckets object + * @param groupId Group Id to create + * @param type Group type + * @param factory OFFactory object + * @param xid transaction ID + * @param driverService driver Service + * @return GroupModBuilder object + */ + public static GroupModBuilder builder(GroupBuckets buckets, GroupId groupId, + GroupDescription.Type type, OFFactory factory, + Optional<Long> xid, Optional<DriverService> driverService) { + + return new GroupModBuilder(buckets, groupId, type, factory, xid, driverService); + } + + /** * Builds the GroupAdd OF message. * * @return GroupAdd OF message @@ -118,8 +154,17 @@ public final class GroupModBuilder { if (type == GroupDescription.Type.SELECT) { bucketBuilder.setWeight(1); } - bucketBuilder.setWatchGroup(OFGroup.ANY); - bucketBuilder.setWatchPort(OFPort.ANY); + + if (type == GroupDescription.Type.FAILOVER && bucket.watchPort() != null) { + bucketBuilder.setWatchPort(OFPort.of((int) bucket.watchPort().toLong())); + } else { + bucketBuilder.setWatchPort(OFPort.ANY); + } + if (type == GroupDescription.Type.FAILOVER && bucket.watchGroup() != null) { + bucketBuilder.setWatchGroup(OFGroup.of(bucket.watchGroup().id())); + } else { + bucketBuilder.setWatchGroup(OFGroup.ANY); + } OFBucket ofBucket = bucketBuilder.build(); ofBuckets.add(ofBucket); } @@ -218,6 +263,12 @@ public final class GroupModBuilder { .setGroup(OFGroup.of(grp.groupId().id())); actions.add(actgrp.build()); break; + case EXTENSION: + Instructions.ExtensionInstructionWrapper wrapper = + (Instructions.ExtensionInstructionWrapper) i; + actions.add(buildExtensionAction( + wrapper.extensionInstruction(), wrapper.deviceId())); + break; default: log.warn("Instruction type {} not yet implemented.", i.type()); } @@ -372,5 +423,21 @@ public final class GroupModBuilder { } return null; } + + private OFAction buildExtensionAction(ExtensionInstruction i, DeviceId deviceId) { + if (!driverService.isPresent()) { + log.error("No driver service present"); + return null; + } + Driver driver = driverService.get().getDriver(deviceId); + if (driver.hasBehaviour(ExtensionInterpreter.class)) { + DefaultDriverHandler handler = + new DefaultDriverHandler(new DefaultDriverData(driver, deviceId)); + ExtensionInterpreter interpreter = handler.behaviour(ExtensionInterpreter.class); + return interpreter.mapInstruction(factory, i); + } + + return null; + } } diff --git a/framework/src/onos/providers/openflow/group/src/main/java/org/onosproject/provider/of/group/impl/OpenFlowGroupProvider.java b/framework/src/onos/providers/openflow/group/src/main/java/org/onosproject/provider/of/group/impl/OpenFlowGroupProvider.java index 5783c842..e69fd6b9 100644 --- a/framework/src/onos/providers/openflow/group/src/main/java/org/onosproject/provider/of/group/impl/OpenFlowGroupProvider.java +++ b/framework/src/onos/providers/openflow/group/src/main/java/org/onosproject/provider/of/group/impl/OpenFlowGroupProvider.java @@ -16,7 +16,12 @@ package org.onosproject.provider.of.group.impl; -import com.google.common.collect.Maps; +import static org.slf4j.LoggerFactory.getLogger; + +import java.util.Collection; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.atomic.AtomicLong; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; @@ -26,6 +31,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; import org.onosproject.core.DefaultGroupId; import org.onosproject.core.GroupId; import org.onosproject.net.DeviceId; +import org.onosproject.net.driver.DriverService; import org.onosproject.net.group.DefaultGroup; import org.onosproject.net.group.Group; import org.onosproject.net.group.GroupBuckets; @@ -60,12 +66,7 @@ import org.projectfloodlight.openflow.protocol.OFStatsType; import org.projectfloodlight.openflow.protocol.OFVersion; import org.slf4j.Logger; -import java.util.Collection; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.atomic.AtomicLong; - -import static org.slf4j.LoggerFactory.getLogger; +import com.google.common.collect.Maps; /** * Provider which uses an OpenFlow controller to handle Group. @@ -81,6 +82,9 @@ public class OpenFlowGroupProvider extends AbstractProvider implements GroupProv @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) protected GroupProviderRegistry providerRegistry; + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) + protected DriverService driverService; + private GroupProviderService providerService; static final int POLL_INTERVAL = 10; @@ -139,12 +143,21 @@ public class OpenFlowGroupProvider extends AbstractProvider implements GroupProv return; } final Long groupModXid = XID_COUNTER.getAndIncrement(); - GroupModBuilder builder = - GroupModBuilder.builder(groupOperation.buckets(), - groupOperation.groupId(), - groupOperation.groupType(), - sw.factory(), - Optional.of(groupModXid)); + GroupModBuilder builder = null; + if (driverService == null) { + builder = GroupModBuilder.builder(groupOperation.buckets(), + groupOperation.groupId(), + groupOperation.groupType(), + sw.factory(), + Optional.of(groupModXid)); + } else { + builder = GroupModBuilder.builder(groupOperation.buckets(), + groupOperation.groupId(), + groupOperation.groupType(), + sw.factory(), + Optional.of(groupModXid), + Optional.of(driverService)); + } OFGroupMod groupMod = null; switch (groupOperation.opType()) { case ADD: @@ -158,6 +171,7 @@ public class OpenFlowGroupProvider extends AbstractProvider implements GroupProv break; default: log.error("Unsupported Group operation"); + return; } sw.sendMsg(groupMod); GroupId groudId = new DefaultGroupId(groupMod.getGroup().getGroupNumber()); diff --git a/framework/src/onos/providers/openflow/pom.xml b/framework/src/onos/providers/openflow/pom.xml index c098a609..1250af61 100644 --- a/framework/src/onos/providers/openflow/pom.xml +++ b/framework/src/onos/providers/openflow/pom.xml @@ -37,6 +37,7 @@ <module>flow</module> <module>group</module> <module>meter</module> + <module>base</module> <module>app</module> </modules> diff --git a/framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProvider.java b/framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProvider.java index 10e745e3..d573458e 100644 --- a/framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProvider.java +++ b/framework/src/onos/providers/ovsdb/device/src/main/java/org/onosproject/ovsdb/providers/device/OvsdbDeviceProvider.java @@ -27,6 +27,7 @@ import org.apache.felix.scr.annotations.Reference; import org.apache.felix.scr.annotations.ReferenceCardinality; import org.apache.felix.scr.annotations.Service; import org.onlab.packet.ChassisId; +import org.onlab.packet.IpAddress; import org.onosproject.net.DefaultAnnotations; import org.onosproject.net.Device; import org.onosproject.net.DeviceId; @@ -40,6 +41,7 @@ import org.onosproject.net.device.DeviceProviderService; import org.onosproject.net.device.DeviceService; import org.onosproject.net.provider.AbstractProvider; import org.onosproject.net.provider.ProviderId; +import org.onosproject.ovsdb.controller.OvsdbClientService; import org.onosproject.ovsdb.controller.OvsdbController; import org.onosproject.ovsdb.controller.OvsdbNodeId; import org.onosproject.ovsdb.controller.OvsdbNodeListener; @@ -87,8 +89,14 @@ public class OvsdbDeviceProvider extends AbstractProvider @Override public void triggerProbe(DeviceId deviceId) { - // TODO: This will be implemented later. log.info("Triggering probe on device {}", deviceId); + if (!isReachable(deviceId)) { + log.error("Failed to probe device {}", deviceId); + providerService.deviceDisconnected(deviceId); + return; + } else { + log.trace("Confirmed device {} connection", deviceId); + } } @Override @@ -98,7 +106,8 @@ public class OvsdbDeviceProvider extends AbstractProvider @Override public boolean isReachable(DeviceId deviceId) { - return true; + OvsdbClientService ovsdbClient = controller.getOvsdbClient(changeDeviceIdToNodeId(deviceId)); + return !(ovsdbClient == null || !ovsdbClient.isConnected()); } private class InnerOvsdbNodeListener implements OvsdbNodeListener { @@ -131,4 +140,12 @@ public class OvsdbDeviceProvider extends AbstractProvider } } + + private OvsdbNodeId changeDeviceIdToNodeId(DeviceId deviceId) { + String[] strings = deviceId.toString().split(":"); + if (strings.length < 1) { + return null; + } + return new OvsdbNodeId(IpAddress.valueOf(strings[1]), 0); + } } diff --git a/framework/src/onos/providers/pcep/app/features.xml b/framework/src/onos/providers/pcep/app/features.xml index ee205365..1cd92e44 100644 --- a/framework/src/onos/providers/pcep/app/features.xml +++ b/framework/src/onos/providers/pcep/app/features.xml @@ -20,8 +20,8 @@ description="${project.description}"> <feature>onos-api</feature> <bundle>mvn:${project.groupId}/onos-app-pcep-api/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-pcepio/${project.version}</bundle> - <bundle>mvn:${project.groupId}/onos-pcep-controller-api/${project.version}</bundle> + <bundle>mvn:${project.groupId}/onos-pcepio/${project.version}</bundle> + <bundle>mvn:${project.groupId}/onos-pcep-controller-api/${project.version}</bundle> <bundle>mvn:${project.groupId}/onos-pcep-controller-impl/${project.version}</bundle> <bundle>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</bundle> <bundle>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</bundle> diff --git a/framework/src/onos/providers/pcep/app/pom.xml b/framework/src/onos/providers/pcep/app/pom.xml index 96a04e88..35c1e9cf 100644 --- a/framework/src/onos/providers/pcep/app/pom.xml +++ b/framework/src/onos/providers/pcep/app/pom.xml @@ -14,49 +14,49 @@ ~ limitations under the License. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-providers</artifactId> - <version>1.4.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.onosproject</groupId> + <artifactId>onos-pcep-providers</artifactId> + <version>1.4.0-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> - <artifactId>onos-pcep</artifactId> - <packaging>pom</packaging> + <artifactId>onos-pcep</artifactId> + <packaging>pom</packaging> <description>PCEP protocol southbound providers</description> - + <dependencies> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-app-pcep-api</artifactId> - </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-app-pcep-api</artifactId> + </dependency> <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcepio</artifactId> - <version>${project.version}</version> - </dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-pcepio</artifactId> + <version>${project.version}</version> + </dependency> <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-controller-api</artifactId> - <version>${project.version}</version> - </dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-pcep-controller-api</artifactId> + <version>${project.version}</version> + </dependency> <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-controller-impl</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-provider-topology</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.onosproject</groupId> - <artifactId>onos-pcep-provider-tunnel</artifactId> - <version>${project.version}</version> - </dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-pcep-controller-impl</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-pcep-provider-topology</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onosproject</groupId> + <artifactId>onos-pcep-provider-tunnel</artifactId> + <version>${project.version}</version> + </dependency> - </dependencies> + </dependencies> </project> diff --git a/framework/src/onos/providers/pcep/pom.xml b/framework/src/onos/providers/pcep/pom.xml index 0f885e67..b6a425bb 100644 --- a/framework/src/onos/providers/pcep/pom.xml +++ b/framework/src/onos/providers/pcep/pom.xml @@ -25,8 +25,8 @@ <packaging>pom</packaging> <description>PCEP protocol providers root</description> <modules> - <module>topology</module> - <module>tunnel</module> - <module>app</module> + <module>topology</module> + <module>tunnel</module> + <module>app</module> </modules> </project>
\ No newline at end of file diff --git a/framework/src/onos/tools/build/conf/src/main/resources/onos/checkstyle.xml b/framework/src/onos/tools/build/conf/src/main/resources/onos/checkstyle.xml index e04479c5..fc6757a5 100644 --- a/framework/src/onos/tools/build/conf/src/main/resources/onos/checkstyle.xml +++ b/framework/src/onos/tools/build/conf/src/main/resources/onos/checkstyle.xml @@ -160,7 +160,9 @@ <module name="MemberName"/> <module name="MethodName"/> - <module name="PackageName"/> + <module name="PackageName"> + <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/> + </module> <module name="ParameterName"/> <module name="StaticVariableName"/> <module name="TypeName"/> diff --git a/framework/src/onos/tools/build/onos-build-docs b/framework/src/onos/tools/build/onos-build-docs index 93a73c14..f7d0a0b8 100755 --- a/framework/src/onos/tools/build/onos-build-docs +++ b/framework/src/onos/tools/build/onos-build-docs @@ -34,11 +34,11 @@ rm -fr $ONOS_ROOT/docs/target cd $ONOS_ROOT/docs processPom external.xml -mvn -f aux-external.xml javadoc:aggregate +mvn -f aux-external.xml javadoc:aggregate "$@" cd target && mv site/apidocs $apidocs tar zcf $apidocs.tar.gz $apidocs && cp $apidocs.tar.gz /tmp cd $ONOS_ROOT/docs processPom internal.xml -mvn -f aux-internal.xml javadoc:aggregate +mvn -f aux-internal.xml javadoc:aggregate "$@" diff --git a/framework/src/onos/tools/dev/bash_profile b/framework/src/onos/tools/dev/bash_profile index a0f040a5..b8244a77 100644 --- a/framework/src/onos/tools/dev/bash_profile +++ b/framework/src/onos/tools/dev/bash_profile @@ -67,7 +67,6 @@ alias pub='onos-push-update-bundle' # Short-hand for tailing and searching the ONOS (karaf) log alias tl='$ONOS_ROOT/tools/dev/bin/onos-local-log' -alias ll='less $KARAF_LOG' alias gl='grep $KARAF_LOG --colour=auto -E -e ' function filterLocalLog { diff --git a/framework/src/onos/tools/package/maven-plugin/pom.xml b/framework/src/onos/tools/package/maven-plugin/pom.xml index 54839b11..c2b5d8ae 100644 --- a/framework/src/onos/tools/package/maven-plugin/pom.xml +++ b/framework/src/onos/tools/package/maven-plugin/pom.xml @@ -85,6 +85,11 @@ <artifactId>jackson-annotations</artifactId> <version>2.4.2</version> </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.4</version> + </dependency> </dependencies> <build> diff --git a/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosAppMojo.java b/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosAppMojo.java index bfc6127a..09cf4dd9 100644 --- a/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosAppMojo.java +++ b/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosAppMojo.java @@ -62,6 +62,7 @@ public class OnosAppMojo extends AbstractMojo { private static final String ONOS_APP_NAME = "onos.app.name"; private static final String ONOS_APP_ORIGIN = "onos.app.origin"; + private static final String ONOS_APP_REQUIRES = "onos.app.requires"; private static final String JAR = "jar"; private static final String XML = "xml"; @@ -80,6 +81,7 @@ public class OnosAppMojo extends AbstractMojo { private String name; private String origin; + private String requiredApps; private String version = DEFAULT_VERSION; private String featuresRepo = DEFAULT_FEATURES_REPO; private List<String> artifacts; @@ -160,6 +162,9 @@ public class OnosAppMojo extends AbstractMojo { origin = (String) project.getProperties().get(ONOS_APP_ORIGIN); origin = origin != null ? origin : DEFAULT_ORIGIN; + requiredApps = (String) project.getProperties().get(ONOS_APP_REQUIRES); + requiredApps = requiredApps == null ? "" : requiredApps.replaceAll("[\\s]", ""); + if (appFile.exists()) { loadAppFile(appFile); } else { @@ -338,6 +343,7 @@ public class OnosAppMojo extends AbstractMojo { return string == null ? null : string.replaceAll("\\$\\{onos.app.name\\}", name) .replaceAll("\\$\\{onos.app.origin\\}", origin) + .replaceAll("\\$\\{onos.app.requires\\}", requiredApps) .replaceAll("\\$\\{project.groupId\\}", projectGroupId) .replaceAll("\\$\\{project.artifactId\\}", projectArtifactId) .replaceAll("\\$\\{project.version\\}", projectVersion) diff --git a/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosSwaggerMojo.java b/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosSwaggerMojo.java index ea847459..a75127a3 100644 --- a/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosSwaggerMojo.java +++ b/framework/src/onos/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosSwaggerMojo.java @@ -18,6 +18,7 @@ package org.onosproject.maven; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.common.base.Charsets; import com.google.common.io.ByteStreams; import com.google.common.io.Files; import com.thoughtworks.qdox.JavaProjectBuilder; @@ -124,11 +125,13 @@ public class OnosSwaggerMojo extends AbstractMojo { ObjectNode root = initializeRoot(); ArrayNode tags = mapper.createArrayNode(); ObjectNode paths = mapper.createObjectNode(); + ObjectNode definitions = mapper.createObjectNode(); root.set("tags", tags); root.set("paths", paths); + root.set("definitions", definitions); - builder.getClasses().forEach(jc -> processClass(jc, paths, tags)); + builder.getClasses().forEach(jc -> processClass(jc, paths, tags, definitions)); if (paths.size() > 0) { getLog().info("Generating ONOS REST API documentation..."); @@ -172,7 +175,7 @@ public class OnosSwaggerMojo extends AbstractMojo { // Checks whether javaClass has a path tag associated with it and if it does // processes its methods and creates a tag for the class on the root - void processClass(JavaClass javaClass, ObjectNode paths, ArrayNode tags) { + void processClass(JavaClass javaClass, ObjectNode paths, ArrayNode tags, ObjectNode definitions) { // If the class does not have a Path tag then ignore it JavaAnnotation annotation = getPathAnnotation(javaClass); if (annotation == null) { @@ -199,7 +202,7 @@ public class OnosSwaggerMojo extends AbstractMojo { ArrayNode tagArray = mapper.createArrayNode(); tagArray.add(tagPath); - processAllMethods(javaClass, resourcePath, paths, tagArray); + processAllMethods(javaClass, resourcePath, paths, tagArray, definitions); } private JavaAnnotation getPathAnnotation(JavaClass javaClass) { @@ -211,7 +214,7 @@ public class OnosSwaggerMojo extends AbstractMojo { // Checks whether a class's methods are REST methods and then places all the // methods under a specific path into the paths node private void processAllMethods(JavaClass javaClass, String resourcePath, - ObjectNode paths, ArrayNode tagArray) { + ObjectNode paths, ArrayNode tagArray, ObjectNode definitions) { // map of the path to its methods represented by an ObjectNode Map<String, ObjectNode> pathMap = new HashMap<>(); @@ -221,7 +224,7 @@ public class OnosSwaggerMojo extends AbstractMojo { if (name.equals(POST) || name.equals(GET) || name.equals(DELETE) || name.equals(PUT)) { // substring(12) removes "javax.ws.rs." String method = annotation.getType().toString().substring(12).toLowerCase(); - processRestMethod(javaMethod, method, pathMap, resourcePath, tagArray); + processRestMethod(javaMethod, method, pathMap, resourcePath, tagArray, definitions); } }); }); @@ -236,9 +239,10 @@ public class OnosSwaggerMojo extends AbstractMojo { private void processRestMethod(JavaMethod javaMethod, String method, Map<String, ObjectNode> pathMap, - String resourcePath, ArrayNode tagArray) { + String resourcePath, ArrayNode tagArray, ObjectNode definitions) { String fullPath = resourcePath, consumes = "", produces = "", comment = javaMethod.getComment(); + DocletTag tag = javaMethod.getTagByName("rsModel"); for (JavaAnnotation annotation : javaMethod.getAnnotations()) { String name = annotation.getType().getName(); if (name.equals(PATH)) { @@ -256,12 +260,19 @@ public class OnosSwaggerMojo extends AbstractMojo { methodNode.set("tags", tagArray); addSummaryDescriptions(methodNode, comment); - processParameters(javaMethod, methodNode); + addJsonSchemaDefinition(definitions, tag); + addJsonSchemaDefinition(definitions, tag); + + processParameters(javaMethod, methodNode, method, tag); processConsumesProduces(methodNode, "consumes", consumes); processConsumesProduces(methodNode, "produces", produces); - - addResponses(methodNode); + if (tag == null || ((method.toLowerCase().equals("post") || method.toLowerCase().equals("put")) + && !(tag.getParameters().size() > 1))) { + addResponses(methodNode, tag, false); + } else { + addResponses(methodNode, tag, true); + } ObjectNode operations = pathMap.get(fullPath); if (operations == null) { @@ -273,6 +284,24 @@ public class OnosSwaggerMojo extends AbstractMojo { } } + private void addJsonSchemaDefinition(ObjectNode definitions, DocletTag tag) { + File definitionsDirectory = new File(srcDirectory + "/src/main/resources/definitions"); + if (tag != null) { + tag.getParameters().stream().forEach(param -> { + try { + File config = new File(definitionsDirectory.getAbsolutePath() + "/" + + param + ".json"); + String lines = Files.readLines(config, Charsets.UTF_8).stream().reduce((t, u) -> t + u). + get(); + definitions.putPOJO(param, lines); + } catch (IOException e) { + e.printStackTrace(); + } + }); + + } + } + private void processConsumesProduces(ObjectNode methodNode, String type, String io) { if (!io.equals("")) { ArrayNode array = mapper.createArrayNode(); @@ -299,13 +328,19 @@ public class OnosSwaggerMojo extends AbstractMojo { // Temporary solution to add responses to a method // TODO Provide annotations in the web resources for responses and parse them - private void addResponses(ObjectNode methodNode) { + private void addResponses(ObjectNode methodNode, DocletTag tag, boolean responseJson) { ObjectNode responses = mapper.createObjectNode(); methodNode.set("responses", responses); ObjectNode success = mapper.createObjectNode(); success.put("description", "successful operation"); responses.set("200", success); + if (tag != null && responseJson) { + ObjectNode schema = mapper.createObjectNode(); + tag.getParameters().stream().forEach( + param -> schema.put("$ref", "#/definitions/" + param)); + success.set("schema", schema); + } ObjectNode defaultObj = mapper.createObjectNode(); defaultObj.put("description", "Unexpected error"); @@ -329,7 +364,7 @@ public class OnosSwaggerMojo extends AbstractMojo { } // Processes parameters of javaMethod and enters the proper key-values into the methodNode - private void processParameters(JavaMethod javaMethod, ObjectNode methodNode) { + private void processParameters(JavaMethod javaMethod, ObjectNode methodNode, String method, DocletTag tag) { ArrayNode parameters = mapper.createArrayNode(); methodNode.set("parameters", parameters); boolean required = true; @@ -346,7 +381,8 @@ public class OnosSwaggerMojo extends AbstractMojo { if (pathType != null) { //the parameter is a path or query parameter individualParameterNode.put("name", - pathType.getNamedParameter("value").toString().replace("\"", "")); + pathType.getNamedParameter("value") + .toString().replace("\"", "")); if (pathType.getType().getName().equals(PATH_PARAM)) { individualParameterNode.put("in", "path"); } else if (pathType.getType().getName().equals(QUERY_PARAM)) { @@ -357,10 +393,16 @@ public class OnosSwaggerMojo extends AbstractMojo { individualParameterNode.put("name", annotationName); individualParameterNode.put("in", "body"); - // TODO add actual hardcoded schemas and a type - // body parameters must have a schema associated with them - ArrayNode schema = mapper.createArrayNode(); - individualParameterNode.set("schema", schema); + // Adds the reference to the Json model for the input + // that goes in the post or put operation + if (tag != null && (method.toLowerCase().equals("post") || + method.toLowerCase().equals("put"))) { + ObjectNode schema = mapper.createObjectNode(); + tag.getParameters().stream().forEach(param -> { + schema.put("$ref", "#/definitions/" + param); + }); + individualParameterNode.set("schema", schema); + } } for (DocletTag p : javaMethod.getTagsByName("param")) { if (p.getValue().contains(annotationName)) { diff --git a/framework/src/onos/tools/package/maven-plugin/src/main/resources/org/onosproject/maven/app.xml b/framework/src/onos/tools/package/maven-plugin/src/main/resources/org/onosproject/maven/app.xml index 0f3133d3..84998807 100644 --- a/framework/src/onos/tools/package/maven-plugin/src/main/resources/org/onosproject/maven/app.xml +++ b/framework/src/onos/tools/package/maven-plugin/src/main/resources/org/onosproject/maven/app.xml @@ -16,7 +16,7 @@ --> <app name="${onos.app.name}" origin="${onos.app.origin}" version="${project.version}" featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" - features="${project.artifactId}"> + features="${project.artifactId}" apps="${onos.app.requires}"> <description>${project.description}</description> <artifact>mvn:${project.groupId}/${project.artifactId}/${project.version}</artifact> </app> diff --git a/framework/src/onos/tools/test/bin/onos-check-apps b/framework/src/onos/tools/test/bin/onos-check-apps index dfd6b4ef..5d83e416 100755 --- a/framework/src/onos/tools/test/bin/onos-check-apps +++ b/framework/src/onos/tools/test/bin/onos-check-apps @@ -24,7 +24,7 @@ for attempt in {1..3}; do # Check for differences case ${3:-equals} in equals) diff $aux.1 $aux.2;; - includes) [ $(egrep -c -f $aux.2 $aux.1) -eq $(wc -l $aux.2 | sed "s|$aux.2||g") ];; + includes) [ $(egrep -c -f $aux.2 $aux.1) -ge $(wc -l $aux.2 | sed "s|$aux.2||g") ];; excludes) ! egrep -f $aux.2 $aux.1;; esac diff --git a/framework/src/onos/tools/test/bin/onos-netcfg b/framework/src/onos/tools/test/bin/onos-netcfg new file mode 100755 index 00000000..23900ecb --- /dev/null +++ b/framework/src/onos/tools/test/bin/onos-netcfg @@ -0,0 +1,15 @@ +#!/bin/bash +# ----------------------------------------------------------------------------- +# ONOS network configuration uploader. +# ----------------------------------------------------------------------------- + +[ ! -d "$ONOS_ROOT" ] && echo "ONOS_ROOT is not defined" >&2 && exit 1 +. $ONOS_ROOT/tools/build/envDefaults + +node="${1:-$OCI}" +file="${2:-$ONOS_ROOT/tools/test/topos/oe-linear-3.json}" +url="${3}" + +curl -sS --fail -L --user $ONOS_WEB_USER:$ONOS_WEB_PASS \ + -X POST -H 'Content-Type:application/json' \ + http://$node:8181/onos/v1/network/configuration/${url} -d@$file diff --git a/framework/src/onos/tools/test/cells/aaron_local_cell b/framework/src/onos/tools/test/cells/aaron_local_cell new file mode 100644 index 00000000..e3b5f734 --- /dev/null +++ b/framework/src/onos/tools/test/cells/aaron_local_cell @@ -0,0 +1,10 @@ +# Local VirtualBox-based ONOS instances 1,2 & ONOS mininet box + +export ONOS_NIC=192.168.56.* +export OC1="192.168.56.101" +export OC2="192.168.56.102" +export OC3="192.168.56.103" +export OCN="192.168.56.100" + +export ONOS_USE_SSH=true +export ONOS_APPS="drivers,openflow,fwd,proxyarp,mobility" diff --git a/framework/src/onos/tools/test/scenarios/fast.xml b/framework/src/onos/tools/test/scenarios/fast.xml index 3cfe2c60..0d38c456 100644 --- a/framework/src/onos/tools/test/scenarios/fast.xml +++ b/framework/src/onos/tools/test/scenarios/fast.xml @@ -26,5 +26,5 @@ <dependency name="Archetypes" requires="Setup"/> <import file="${ONOS_SCENARIOS}/wrapup.xml"/> - <dependency name="Wrapup" requires="~Archetypes,~Setup,~Net-Fast"/> + <dependency name="Wrapup" requires="Prerequisites,~Archetypes,~Setup,~Net-Fast"/> </scenario> diff --git a/framework/src/onos/tools/test/scenarios/net-topo.xml b/framework/src/onos/tools/test/scenarios/net-topo.xml index abcf8642..cd720888 100644 --- a/framework/src/onos/tools/test/scenarios/net-topo.xml +++ b/framework/src/onos/tools/test/scenarios/net-topo.xml @@ -38,7 +38,7 @@ <step name="Net-Topo.Verify-Cluster0-LinkCount" requires="Net-Topo.Query-Cluster0" exec="test ${clusterTopo0LinkCount} == 140"/> <step name="Net-Topo.Verify-Cluster0-Root" requires="Net-Topo.Query-Cluster0" - exec="test '${clusterTopo0Root}' == 'of:000000000000000a'"/> + exec="test '${clusterTopo0Root}' == 'of:000000000000000a' -o '${clusterTopo0Root}' == 'of:000000000000000c'"/> <!-- Verify the list of devices for the cluster --> <step name="Net-Topo.Verify-Cluster0-Devices" diff --git a/framework/src/onos/tools/test/scenarios/setup.xml b/framework/src/onos/tools/test/scenarios/setup.xml index c26c0dea..071db8b9 100644 --- a/framework/src/onos/tools/test/scenarios/setup.xml +++ b/framework/src/onos/tools/test/scenarios/setup.xml @@ -40,7 +40,7 @@ <step name="Check-Components-${#}" exec="onos-check-components ${OC#}" requires="~Wait-for-Start-${#},"/> - <step name="Check-Apps-${#}" exec="onos-check-apps ${OC#}" + <step name="Check-Apps-${#}" exec="onos-check-apps ${OC#} ${ONOS_APPS} includes" requires="~Wait-for-Start-${#}"/> </parallel> </group> diff --git a/framework/src/onos/tools/test/topos/opticalUtils.py b/framework/src/onos/tools/test/topos/opticalUtils.py index 5d955e51..87903cc5 100644 --- a/framework/src/onos/tools/test/topos/opticalUtils.py +++ b/framework/src/onos/tools/test/topos/opticalUtils.py @@ -58,7 +58,7 @@ import os from time import sleep import urllib2 -from mininet.node import Switch, RemoteController +from mininet.node import Switch, OVSSwitch, RemoteController from mininet.topo import Topo from mininet.util import quietRun from mininet.net import Mininet @@ -356,8 +356,18 @@ class LINCSwitch(OpticalSwitch): return configDict @staticmethod - def bootOE(net): - "Start the LINC optical emulator within a mininet instance" + def bootOE(net, domain=None): + """ + Start the LINC optical emulator within a mininet instance + + This involves 1. converting the information stored in Linc* to configs + for both LINC and the network config system, 2. starting Linc, 3. connecting + cross-connects, and finally pushing the network configs to ONOS. + + Inevitably, there are times when we have OVS switches that should not be + under the control of the controller in charge of the Linc switches. We + hint at these by passing domain information. + """ LINCSwitch.opticalJSON = {} linkConfig = [] devices = [] @@ -365,9 +375,11 @@ class LINCSwitch(OpticalSwitch): LINCSwitch.controllers = net.controllers for switch in net.switches: + if domain and switch not in domain: + continue if isinstance(switch, OpticalSwitch): devices.append(switch.json()) - else: + elif isinstance(switch, OVSSwitch): devices.append(LINCSwitch.switchJSON(switch)) LINCSwitch.opticalJSON[ 'devices' ] = devices @@ -450,18 +462,21 @@ class LINCSwitch(OpticalSwitch): opener = urllib2.build_opener(handler) opener.open(url) urllib2.install_opener(opener) + # focus on just checking the state of devices we're interested in + devlist = map( lambda x: x['uri'], devices ) while True: response = json.load(urllib2.urlopen(url)) devs = response.get('devices') - # Wait for all devices to be registered - if (len(devices) != len(devs)): + # Wait for all devices to be registered. There is a chance that this is only a subgraph. + if (len(devices) > len(devs)): continue # Wait for all devices to available available = True for d in devs: - available &= d['available'] + if d['id'] in devlist: + available &= d['available'] if available: break @@ -615,9 +630,11 @@ class LINCSwitch(OpticalSwitch): if isinstance(link, LINCLink): if link.annotations[ 'optical.type' ] == 'cross-connect': tapCount += 1 - while True: - if str(tapCount) == quietRun('ip addr | grep tap | wc -l', shell=True).strip('\n'): + # tapCount can be less than the actual number of taps if the optical network + # is a subgraph of a larger multidomain network. + tapNum = int(quietRun('ip addr | grep tap | wc -l', shell=True).strip('\n')) + if tapCount <= tapNum: return True if timeout: if time >= TIMEOUT: diff --git a/framework/src/onos/utils/catalyst/pom.xml b/framework/src/onos/utils/catalyst/pom.xml new file mode 100644 index 00000000..bd1d52dd --- /dev/null +++ b/framework/src/onos/utils/catalyst/pom.xml @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>onlab-utils</artifactId> + <groupId>org.onosproject</groupId> + <version>1.4.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>utils.catalyst</artifactId> + <packaging>bundle</packaging> + + <description>ONLab catalyst dependency</description> + + <dependencies> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <configuration> + <createSourcesJar>true</createSourcesJar> + <artifactSet> + <includes> + <include>io.atomix.catalyst.*</include> + </includes> + </artifactSet> + </configuration> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + </execution> + </executions> + </plugin> + + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <configuration> + <instructions> + <Export-Package> + io.atomix.catalyst.* + </Export-Package> + </instructions> + </configuration> + </plugin> + + </plugins> + </build> +</project>
\ No newline at end of file diff --git a/framework/src/onos/utils/jdvue/src/main/java/org/onlab/jdvue/DependencyCycle.java b/framework/src/onos/utils/jdvue/src/main/java/org/onlab/jdvue/DependencyCycle.java index 444995bf..0fc761d4 100644 --- a/framework/src/onos/utils/jdvue/src/main/java/org/onlab/jdvue/DependencyCycle.java +++ b/framework/src/onos/utils/jdvue/src/main/java/org/onlab/jdvue/DependencyCycle.java @@ -110,7 +110,7 @@ public class DependencyCycle { @Override public int hashCode() { - return Objects.hash(cycle); + return cycle.hashCode(); } @Override 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 Binary files differnew file mode 100644 index 00000000..ba750519 --- /dev/null +++ b/framework/src/onos/utils/junit/src/main/resources/org/onosproject/openflow/controller/impl/ControllerTestKeystore.jks diff --git a/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/DisjointPathPair.java b/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/DisjointPathPair.java index 206a34c8..dfa150e3 100644 --- a/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/DisjointPathPair.java +++ b/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/DisjointPathPair.java @@ -30,8 +30,8 @@ import static com.google.common.base.MoreObjects.toStringHelper; */ public class DisjointPathPair<V extends Vertex, E extends Edge<V>> implements Path<V, E> { - private Path<V, E> primary, secondary; - boolean primaryActive = true; + private final Path<V, E> primary, secondary; + private boolean primaryActive = true; /** * Creates a disjoint path pair from two paths. @@ -88,7 +88,7 @@ public class DisjointPathPair<V extends Vertex, E extends Edge<V>> implements Pa * @return boolean representing whether it has backup */ public boolean hasBackup() { - return secondary != null && secondary.edges() != null; + return secondary != null; } @Override @@ -103,7 +103,9 @@ public class DisjointPathPair<V extends Vertex, E extends Edge<V>> implements Pa @Override public int hashCode() { - return hasBackup() ? Objects.hash(primary) + Objects.hash(secondary) : + // Note: DisjointPathPair with primary and secondary swapped + // must result in same hashCode + return hasBackup() ? primary.hashCode() + secondary.hashCode() : Objects.hash(primary); } diff --git a/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/DisjointPathPair.java.orig b/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/DisjointPathPair.java.orig deleted file mode 100644 index 1cf22b6a..00000000 --- a/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/DisjointPathPair.java.orig +++ /dev/null @@ -1,169 +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.onlab.graph; - -import java.util.List; -import java.util.Objects; -import java.util.Set; - -import static com.google.common.collect.ImmutableSet.of; -import static com.google.common.base.MoreObjects.toStringHelper; - - -public class DisjointPathPair<V extends Vertex, E extends Edge<V>> implements Path<V, E> { - public Path<V, E> path1, path2; - boolean usingPath1 = true; - -<<<<<<< HEAD - /** - * Creates a Disjoint Path Pair from two paths. - * - * @param p1 first path - * @param p2 second path - */ -======= ->>>>>>> Disjoint Path Pairs (Suurballe) utils - public DisjointPathPair(Path<V, E> p1, Path<V, E> p2) { - path1 = p1; - path2 = p2; - } -<<<<<<< HEAD - - @Override -======= ->>>>>>> Disjoint Path Pairs (Suurballe) utils - public V src() { - return path1.src(); - } - -<<<<<<< HEAD - @Override - public V dst() { - return path1.dst(); - } - - @Override -======= - public V dst() { - return path1.dst(); - } ->>>>>>> Disjoint Path Pairs (Suurballe) utils - public double cost() { - if (!hasBackup()) { - return path1.cost(); - } - return path1.cost() + path2.cost(); - } -<<<<<<< HEAD - - @Override -======= ->>>>>>> Disjoint Path Pairs (Suurballe) utils - public List<E> edges() { - if (usingPath1 || !hasBackup()) { - return path1.edges(); - } else { - return path2.edges(); - } - } -<<<<<<< HEAD - - /** - * Checks if this path pair contains a backup/secondary path. - * - * @return boolean representing whether it has backup - */ - public boolean hasBackup() { - return path2 != null && path2.edges() != null; - } - - /** - * Switches this disjoint path pair to using its backup path, instead of - * using its primary. - */ - public void useBackup() { - usingPath1 = !usingPath1; - } - - @Override -======= - public boolean hasBackup() { - return path2 != null && path2.edges() != null; - } - public void useBackup() { - usingPath1 = !usingPath1; - } ->>>>>>> Disjoint Path Pairs (Suurballe) utils - public String toString() { - return toStringHelper(this) - .add("src", src()) - .add("dst", dst()) - .add("cost", cost()) - .add("edges", edges()) - .toString(); - } -<<<<<<< HEAD - - @Override -======= ->>>>>>> Disjoint Path Pairs (Suurballe) utils - public int hashCode() { - Set<Path<V, E>> paths; - if (!hasBackup()) { - paths = of(path1); - } else { - paths = of(path1, path2); - } - return Objects.hash(paths); - } -<<<<<<< HEAD - - @Override -======= ->>>>>>> Disjoint Path Pairs (Suurballe) utils - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj instanceof DisjointPathPair) { - final DisjointPathPair other = (DisjointPathPair) obj; - return Objects.equals(this.src(), other.src()) && - Objects.equals(this.dst(), other.dst()) && - (Objects.equals(this.path1, other.path1) && - Objects.equals(this.path2, other.path2)) || - (Objects.equals(this.path1, other.path2) && - Objects.equals(this.path2, other.path1)); - } - return false; - } -<<<<<<< HEAD - - /** - * Returns number of paths inside this path pair object. - * - * @return number of paths - */ -======= ->>>>>>> Disjoint Path Pairs (Suurballe) utils - public int size() { - if (hasBackup()) { - return 2; - } - return 1; - } -} diff --git a/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/SRLGGraphSearch.java b/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/SrlgGraphSearch.java index 21f687a3..fa3d0ddf 100644 --- a/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/SRLGGraphSearch.java +++ b/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/SrlgGraphSearch.java @@ -31,7 +31,7 @@ import java.util.Random; * if one path goes through an edge in risk group 1, the other path will go * through no edges in risk group 1. */ -public class SRLGGraphSearch<V extends Vertex, E extends Edge<V>> +public class SrlgGraphSearch<V extends Vertex, E extends Edge<V>> extends AbstractGraphPathSearch<V, E> { static final int ITERATIONS = 100; @@ -55,7 +55,7 @@ public class SRLGGraphSearch<V extends Vertex, E extends Edge<V>> * @param groups the number of disjoint risk groups * @param grouping map linking edges to integral group assignments */ - public SRLGGraphSearch(int groups, Map<E, Integer> grouping) { + public SrlgGraphSearch(int groups, Map<E, Integer> grouping) { numGroups = groups; riskGrouping = grouping; } @@ -67,7 +67,7 @@ public class SRLGGraphSearch<V extends Vertex, E extends Edge<V>> * @param grouping map linking edges to object group assignments, * with same-group status linked to equality */ - public SRLGGraphSearch(Map<E, Object> grouping) { + public SrlgGraphSearch(Map<E, Object> grouping) { if (grouping == null) { useSuurballe = true; return; diff --git a/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/TarjanGraphSearch.java b/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/TarjanGraphSearch.java index 5bf305e6..1c436d94 100644 --- a/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/TarjanGraphSearch.java +++ b/framework/src/onos/utils/misc/src/main/java/org/onlab/graph/TarjanGraphSearch.java @@ -42,8 +42,8 @@ public class TarjanGraphSearch<V extends Vertex, E extends Edge<V>> * </p> */ @Override - public SCCResult<V, E> search(Graph<V, E> graph, EdgeWeight<V, E> weight) { - SCCResult<V, E> result = new SCCResult<>(graph); + public SccResult<V, E> search(Graph<V, E> graph, EdgeWeight<V, E> weight) { + SccResult<V, E> result = new SccResult<>(graph); for (V vertex : graph.getVertexes()) { VertexData data = result.data(vertex); if (data == null) { @@ -64,7 +64,7 @@ public class TarjanGraphSearch<V extends Vertex, E extends Edge<V>> */ private VertexData<V> connect(Graph<V, E> graph, V vertex, EdgeWeight<V, E> weight, - SCCResult<V, E> result) { + SccResult<V, E> result) { VertexData<V> data = result.addData(vertex); // Scan through all egress edges of the current vertex. @@ -99,7 +99,7 @@ public class TarjanGraphSearch<V extends Vertex, E extends Edge<V>> /** * Graph search result augmented with SCC vertexData. */ - public static final class SCCResult<V extends Vertex, E extends Edge<V>> + public static final class SccResult<V extends Vertex, E extends Edge<V>> implements Result { private final Graph<V, E> graph; @@ -110,7 +110,7 @@ public class TarjanGraphSearch<V extends Vertex, E extends Edge<V>> private final Map<V, VertexData<V>> vertexData = new HashMap<>(); private final List<VertexData<V>> visited = new ArrayList<>(); - private SCCResult(Graph<V, E> graph) { + private SccResult(Graph<V, E> graph) { this.graph = graph; } @@ -189,7 +189,7 @@ public class TarjanGraphSearch<V extends Vertex, E extends Edge<V>> return Collections.unmodifiableSet(edges); } - public SCCResult<V, E> build() { + public SccResult<V, E> build() { clusterVertexes = Collections.unmodifiableList(clusterVertexes); clusterEdges = Collections.unmodifiableList(clusterEdges); return this; diff --git a/framework/src/onos/utils/misc/src/main/java/org/onlab/util/DefaultHashMap.java b/framework/src/onos/utils/misc/src/main/java/org/onlab/util/DefaultHashMap.java new file mode 100644 index 00000000..d6ddbd56 --- /dev/null +++ b/framework/src/onos/utils/misc/src/main/java/org/onlab/util/DefaultHashMap.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.onlab.util; + +import java.util.HashMap; + +/** + * HashMap that returns a default value for unmapped keys. + */ +public final class DefaultHashMap<K, V> extends HashMap<K, V> { + + /** Default value to return when no key binding exists. */ + protected final V defaultValue; + + /** + * Constructs an empty map with the given default value. + * + * @param defaultValue the default value + */ + public DefaultHashMap(V defaultValue) { + this.defaultValue = defaultValue; + } + + @Override + public V get(Object k) { + return containsKey(k) ? super.get(k) : defaultValue; + } +}
\ No newline at end of file diff --git a/framework/src/onos/utils/misc/src/main/java/org/onlab/util/Frequency.java b/framework/src/onos/utils/misc/src/main/java/org/onlab/util/Frequency.java index 5669abdc..1ef71130 100644 --- a/framework/src/onos/utils/misc/src/main/java/org/onlab/util/Frequency.java +++ b/framework/src/onos/utils/misc/src/main/java/org/onlab/util/Frequency.java @@ -18,8 +18,6 @@ package org.onlab.util; import com.google.common.base.MoreObjects; import com.google.common.collect.ComparisonChain; -import java.util.Objects; - /** * Class representing frequency. This class is intended to be used for a value whose unit is Hz * and its family (KHz, MHz, etc.). @@ -157,7 +155,7 @@ public final class Frequency implements RichComparable<Frequency> { @Override public int hashCode() { - return Objects.hash(frequency); + return Long.hashCode(frequency); } @Override diff --git a/framework/src/onos/utils/misc/src/main/java/org/onlab/util/Tools.java b/framework/src/onos/utils/misc/src/main/java/org/onlab/util/Tools.java index 1b788145..ffefbfd4 100644 --- a/framework/src/onos/utils/misc/src/main/java/org/onlab/util/Tools.java +++ b/framework/src/onos/utils/misc/src/main/java/org/onlab/util/Tools.java @@ -40,6 +40,7 @@ import java.util.Collection; import java.util.Dictionary; import java.util.List; import java.util.Random; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -144,6 +145,23 @@ public abstract class Tools { } /** + * Returns the specified set if the set is not null and not empty; + * otherwise throws a not found exception. + * + * @param item set to check + * @param message not found message + * @param <T> Set item type + * @return item if not null and not empty + * @throws org.onlab.util.ItemNotFoundException if set is null or empty + */ + public static <T> Set<T> emptyIsNotFound(Set<T> item, String message) { + if (item == null || item.isEmpty()) { + throw new ItemNotFoundException(message); + } + return item; + } + + /** * Returns the specified item if that item is not null; otherwise throws * bad argument exception. * diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/DisjointPathPairTest.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/DisjointPathPairTest.java new file mode 100644 index 00000000..ca6c56c4 --- /dev/null +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/DisjointPathPairTest.java @@ -0,0 +1,43 @@ +package org.onlab.graph; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.testing.EqualsTester; + +/** + * Test of DisjointPathPair. + */ +public class DisjointPathPairTest { + + private static final TestVertex A = new TestVertex("A"); + private static final TestVertex B = new TestVertex("B"); + private static final TestVertex C = new TestVertex("C"); + private static final TestVertex D = new TestVertex("D"); + + private static final TestEdge AB = new TestEdge(A, B, 1.0); + private static final TestEdge BC = new TestEdge(B, C, 1.0); + private static final TestEdge AD = new TestEdge(A, D, 1.0); + private static final TestEdge DC = new TestEdge(D, C, 1.0); + + private static final Path<TestVertex, TestEdge> ABC + = new DefaultPath<>(ImmutableList.of(AB, BC), 1.0); + private static final Path<TestVertex, TestEdge> ADC + = new DefaultPath<>(ImmutableList.of(AD, DC), 1.0); + + @Test + public void testSwappingPrimarySecondaryDoesntImpactHashCode() { + assertEquals(new DisjointPathPair<>(ABC, ADC).hashCode(), + new DisjointPathPair<>(ADC, ABC).hashCode()); + } + + @Test + public void testSwappingPrimarySecondaryDoesntImpactEquality() { + new EqualsTester() + .addEqualityGroup(new DisjointPathPair<>(ABC, ADC), + new DisjointPathPair<>(ADC, ABC)); + } + +} diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SRLGGraphSearchTest.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SrlgGraphSearchTest.java index 8bfd270c..26d50364 100644 --- a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SRLGGraphSearchTest.java +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/SrlgGraphSearchTest.java @@ -31,11 +31,11 @@ import static org.onlab.graph.GraphPathSearch.ALL_PATHS; /** * Test of the Suurballe backup path algorithm. */ -public class SRLGGraphSearchTest extends BreadthFirstSearchTest { +public class SrlgGraphSearchTest extends BreadthFirstSearchTest { @Override protected AbstractGraphPathSearch<TestVertex, TestEdge> graphSearch() { - return new SRLGGraphSearch<>(null); + return new SrlgGraphSearch<>(null); } public void setDefaultWeights() { @@ -64,7 +64,7 @@ public class SRLGGraphSearchTest extends BreadthFirstSearchTest { riskProfile.put(bC, 0); riskProfile.put(aD, 1); riskProfile.put(dC, 1); - SRLGGraphSearch<TestVertex, TestEdge> search = new SRLGGraphSearch<>(2, riskProfile); + SrlgGraphSearch<TestVertex, TestEdge> search = new SrlgGraphSearch<>(2, riskProfile); Set<Path<TestVertex, TestEdge>> paths = search.search(graph, A, C, weight, ALL_PATHS).paths(); System.out.println("\n\n\n" + paths + "\n\n\n"); assertEquals("one disjoint path pair found", 1, paths.size()); @@ -105,7 +105,7 @@ public class SRLGGraphSearchTest extends BreadthFirstSearchTest { riskProfile.put(dC, 1); riskProfile.put(cE, 2); riskProfile.put(bE, 3); - SRLGGraphSearch<TestVertex, TestEdge> search = new SRLGGraphSearch<>(4, riskProfile); + SrlgGraphSearch<TestVertex, TestEdge> search = new SrlgGraphSearch<>(4, riskProfile); search.search(graph, A, E, weight, ALL_PATHS).paths(); } @@ -127,7 +127,7 @@ public class SRLGGraphSearchTest extends BreadthFirstSearchTest { riskProfile.put(dE, 3); riskProfile.put(aC, 4); riskProfile.put(cE, 5); - SRLGGraphSearch<TestVertex, TestEdge> search = new SRLGGraphSearch<>(6, riskProfile); + SrlgGraphSearch<TestVertex, TestEdge> search = new SrlgGraphSearch<>(6, riskProfile); Set<Path<TestVertex, TestEdge>> paths = search.search(graph, A, E, weight, ALL_PATHS).paths(); assertTrue("> one disjoint path pair found", paths.size() >= 1); checkIsDisjoint(paths.iterator().next(), riskProfile); @@ -147,7 +147,7 @@ public class SRLGGraphSearchTest extends BreadthFirstSearchTest { riskProfile.put(bC, 0); riskProfile.put(aD, 1); riskProfile.put(dC, 0); - SRLGGraphSearch<TestVertex, TestEdge> search = new SRLGGraphSearch<>(2, riskProfile); + SrlgGraphSearch<TestVertex, TestEdge> search = new SrlgGraphSearch<>(2, riskProfile); Set<Path<TestVertex, TestEdge>> paths = search.search(graph, A, C, weight, ALL_PATHS).paths(); System.out.println(paths); assertTrue("no disjoint path pairs found", paths.size() == 0); @@ -167,7 +167,7 @@ public class SRLGGraphSearchTest extends BreadthFirstSearchTest { riskProfile.put(bC, 0); riskProfile.put(aD, 1); riskProfile.put(dC, 0); - SRLGGraphSearch<TestVertex, TestEdge> search = new SRLGGraphSearch<>(2, riskProfile); + SrlgGraphSearch<TestVertex, TestEdge> search = new SrlgGraphSearch<>(2, riskProfile); Set<Path<TestVertex, TestEdge>> paths = search.search(graph, A, E, weight, ALL_PATHS).paths(); assertTrue("no disjoint path pairs found", paths.size() == 0); } diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/TarjanGraphSearchTest.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/TarjanGraphSearchTest.java index 624c5781..40f90513 100644 --- a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/TarjanGraphSearchTest.java +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/TarjanGraphSearchTest.java @@ -19,20 +19,20 @@ import org.junit.Test; import static com.google.common.collect.ImmutableSet.of; import static org.junit.Assert.assertEquals; -import static org.onlab.graph.TarjanGraphSearch.SCCResult; +import static org.onlab.graph.TarjanGraphSearch.SccResult; /** * Tarjan graph search tests. */ public class TarjanGraphSearchTest extends GraphTest { - private void validate(SCCResult<TestVertex, TestEdge> result, int cc) { + private void validate(SccResult<TestVertex, TestEdge> result, int cc) { System.out.println("Cluster count: " + result.clusterVertexes().size()); System.out.println("Clusters: " + result.clusterVertexes()); assertEquals("incorrect cluster count", cc, result.clusterCount()); } - private void validate(SCCResult<TestVertex, TestEdge> result, + private void validate(SccResult<TestVertex, TestEdge> result, int i, int vc, int ec) { assertEquals("incorrect cluster count", vc, result.clusterVertexes().get(i).size()); assertEquals("incorrect edge count", ec, result.clusterEdges().get(i).size()); @@ -42,7 +42,7 @@ public class TarjanGraphSearchTest extends GraphTest { public void basic() { graph = new AdjacencyListsGraph<>(vertexes(), edges()); TarjanGraphSearch<TestVertex, TestEdge> gs = new TarjanGraphSearch<>(); - SCCResult<TestVertex, TestEdge> result = gs.search(graph, null); + SccResult<TestVertex, TestEdge> result = gs.search(graph, null); validate(result, 6); } @@ -59,7 +59,7 @@ public class TarjanGraphSearchTest extends GraphTest { new TestEdge(H, A, 1))); TarjanGraphSearch<TestVertex, TestEdge> gs = new TarjanGraphSearch<>(); - SCCResult<TestVertex, TestEdge> result = gs.search(graph, null); + SccResult<TestVertex, TestEdge> result = gs.search(graph, null); validate(result, 1); validate(result, 0, 8, 8); } @@ -76,7 +76,7 @@ public class TarjanGraphSearchTest extends GraphTest { new TestEdge(G, H, 1), new TestEdge(H, E, 1))); TarjanGraphSearch<TestVertex, TestEdge> gs = new TarjanGraphSearch<>(); - SCCResult<TestVertex, TestEdge> result = gs.search(graph, null); + SccResult<TestVertex, TestEdge> result = gs.search(graph, null); validate(result, 2); validate(result, 0, 4, 4); validate(result, 1, 4, 4); @@ -95,7 +95,7 @@ public class TarjanGraphSearchTest extends GraphTest { new TestEdge(H, E, 1), new TestEdge(B, E, 1))); TarjanGraphSearch<TestVertex, TestEdge> gs = new TarjanGraphSearch<>(); - SCCResult<TestVertex, TestEdge> result = gs.search(graph, null); + SccResult<TestVertex, TestEdge> result = gs.search(graph, null); validate(result, 2); validate(result, 0, 4, 4); validate(result, 1, 4, 4); @@ -116,7 +116,7 @@ public class TarjanGraphSearchTest extends GraphTest { new TestEdge(E, B, -1))); TarjanGraphSearch<TestVertex, TestEdge> gs = new TarjanGraphSearch<>(); - SCCResult<TestVertex, TestEdge> result = gs.search(graph, weight); + SccResult<TestVertex, TestEdge> result = gs.search(graph, weight); validate(result, 2); validate(result, 0, 4, 4); validate(result, 1, 4, 4); diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/TestVertex.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/TestVertex.java index be92bd27..b0b92a4a 100644 --- a/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/TestVertex.java +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/graph/TestVertex.java @@ -30,7 +30,7 @@ public class TestVertex implements Vertex { @Override public int hashCode() { - return Objects.hash(name); + return name.hashCode(); } @Override diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/util/DefaultHashMapTest.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/DefaultHashMapTest.java new file mode 100644 index 00000000..db6b5fb7 --- /dev/null +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/DefaultHashMapTest.java @@ -0,0 +1,81 @@ +/* + * 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.onlab.util; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Unit tests for {@link DefaultHashMap}. + */ +public class DefaultHashMapTest { + + private static final String ONE = "one"; + private static final String TWO = "two"; + private static final String THREE = "three"; + private static final String FOUR = "four"; + + private static final String ALPHA = "Alpha"; + private static final String BETA = "Beta"; + private static final String OMEGA = "Omega"; + + private DefaultHashMap<String, Integer> map; + private DefaultHashMap<String, String> chartis; + + private void loadMap() { + map.put(ONE, 1); + map.put(TWO, 2); + } + + private void fortioCharti() { + chartis.put(ONE, ALPHA); + chartis.put(TWO, BETA); + } + + @Test + public void nullDefaultIsAllowed() { + // but makes this class behave no different than HashMap + map = new DefaultHashMap<>(null); + loadMap(); + assertEquals("missing 1", 1, (int) map.get(ONE)); + assertEquals("missing 2", 2, (int) map.get(TWO)); + assertEquals("three?", null, map.get(THREE)); + assertEquals("four?", null, map.get(FOUR)); + } + + @Test + public void defaultToFive() { + map = new DefaultHashMap<>(5); + loadMap(); + assertEquals("missing 1", 1, (int) map.get(ONE)); + assertEquals("missing 2", 2, (int) map.get(TWO)); + assertEquals("three?", 5, (int) map.get(THREE)); + assertEquals("four?", 5, (int) map.get(FOUR)); + } + + @Test + public void defaultToOmega() { + chartis = new DefaultHashMap<>(OMEGA); + fortioCharti(); + assertEquals("missing 1", ALPHA, chartis.get(ONE)); + assertEquals("missing 2", BETA, chartis.get(TWO)); + assertEquals("three?", OMEGA, chartis.get(THREE)); + assertEquals("four?", OMEGA, chartis.get(FOUR)); + } + +} diff --git a/framework/src/onos/utils/misc/src/test/java/org/onlab/util/HexStringTest.java b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/HexStringTest.java index e04e29a2..f4aadd15 100644 --- a/framework/src/onos/utils/misc/src/test/java/org/onlab/util/HexStringTest.java +++ b/framework/src/onos/utils/misc/src/test/java/org/onlab/util/HexStringTest.java @@ -47,7 +47,7 @@ public class HexStringTest { } @Test - public void testToLongMSB() { + public void testToLongMsb() { String dpidStr = "ca:7c:5e:d1:64:7a:95:9b"; long valid = -3856102927509056101L; long testLong = HexString.toLong(dpidStr); diff --git a/framework/src/onos/utils/netty/src/main/java/org/onlab/netty/NettyMessaging.java b/framework/src/onos/utils/netty/src/main/java/org/onlab/netty/NettyMessaging.java index 8c759d14..1cd7ca7b 100644 --- a/framework/src/onos/utils/netty/src/main/java/org/onlab/netty/NettyMessaging.java +++ b/framework/src/onos/utils/netty/src/main/java/org/onlab/netty/NettyMessaging.java @@ -15,6 +15,10 @@ */ package org.onlab.netty; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.RemovalListener; +import com.google.common.cache.RemovalNotification; import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.PooledByteBufAllocator; @@ -34,11 +38,20 @@ import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; +import org.apache.commons.pool.KeyedPoolableObjectFactory; +import org.apache.commons.pool.impl.GenericKeyedObjectPool; +import org.onosproject.store.cluster.messaging.Endpoint; +import org.onosproject.store.cluster.messaging.MessagingService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.TrustManagerFactory; import java.io.FileInputStream; import java.io.IOException; import java.security.KeyStore; - import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; @@ -51,23 +64,6 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.function.Consumer; import java.util.function.Function; -import org.apache.commons.pool.KeyedPoolableObjectFactory; -import org.apache.commons.pool.impl.GenericKeyedObjectPool; -import org.onosproject.store.cluster.messaging.Endpoint; -import org.onosproject.store.cluster.messaging.MessagingService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import com.google.common.cache.RemovalListener; -import com.google.common.cache.RemovalNotification; - -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLEngine; -import javax.net.ssl.TrustManagerFactory; - /** * Implementation of MessagingService based on <a href="http://netty.io/">Netty</a> framework. */ @@ -102,7 +98,7 @@ public class NettyMessaging implements MessagingService { private Class<? extends Channel> clientChannelClass; protected static final boolean TLS_DISABLED = false; - protected boolean enableNettyTLS = TLS_DISABLED; + protected boolean enableNettyTls = TLS_DISABLED; protected String ksLocation; protected String tsLocation; @@ -259,8 +255,8 @@ public class NettyMessaging implements MessagingService { b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); b.group(serverGroup, clientGroup); b.channel(serverChannelClass); - if (enableNettyTLS) { - b.childHandler(new SSLServerCommunicationChannelInitializer()); + if (enableNettyTls) { + b.childHandler(new SslServerCommunicationChannelInitializer()); } else { b.childHandler(new OnosCommunicationChannelInitializer()); } @@ -303,8 +299,8 @@ public class NettyMessaging implements MessagingService { // http://normanmaurer.me/presentations/2014-facebook-eng-netty/slides.html#37.0 bootstrap.channel(clientChannelClass); bootstrap.option(ChannelOption.SO_KEEPALIVE, true); - if (enableNettyTLS) { - bootstrap.handler(new SSLClientCommunicationChannelInitializer()); + if (enableNettyTls) { + bootstrap.handler(new SslClientCommunicationChannelInitializer()); } else { bootstrap.handler(new OnosCommunicationChannelInitializer()); } @@ -325,7 +321,7 @@ public class NettyMessaging implements MessagingService { } } - private class SSLServerCommunicationChannelInitializer extends ChannelInitializer<SocketChannel> { + private class SslServerCommunicationChannelInitializer extends ChannelInitializer<SocketChannel> { private final ChannelHandler dispatcher = new InboundMessageDispatcher(); private final ChannelHandler encoder = new MessageEncoder(); @@ -345,15 +341,15 @@ public class NettyMessaging implements MessagingService { SSLContext serverContext = SSLContext.getInstance("TLS"); serverContext.init(kmf.getKeyManagers(), tmFactory.getTrustManagers(), null); - SSLEngine serverSSLEngine = serverContext.createSSLEngine(); + SSLEngine serverSslEngine = serverContext.createSSLEngine(); - serverSSLEngine.setNeedClientAuth(true); - serverSSLEngine.setUseClientMode(false); - serverSSLEngine.setEnabledProtocols(serverSSLEngine.getSupportedProtocols()); - serverSSLEngine.setEnabledCipherSuites(serverSSLEngine.getSupportedCipherSuites()); - serverSSLEngine.setEnableSessionCreation(true); + serverSslEngine.setNeedClientAuth(true); + serverSslEngine.setUseClientMode(false); + serverSslEngine.setEnabledProtocols(serverSslEngine.getSupportedProtocols()); + serverSslEngine.setEnabledCipherSuites(serverSslEngine.getSupportedCipherSuites()); + serverSslEngine.setEnableSessionCreation(true); - channel.pipeline().addLast("ssl", new io.netty.handler.ssl.SslHandler(serverSSLEngine)) + channel.pipeline().addLast("ssl", new io.netty.handler.ssl.SslHandler(serverSslEngine)) .addLast("encoder", encoder) .addLast("decoder", new MessageDecoder()) .addLast("handler", dispatcher); @@ -361,7 +357,7 @@ public class NettyMessaging implements MessagingService { } - private class SSLClientCommunicationChannelInitializer extends ChannelInitializer<SocketChannel> { + private class SslClientCommunicationChannelInitializer extends ChannelInitializer<SocketChannel> { private final ChannelHandler dispatcher = new InboundMessageDispatcher(); private final ChannelHandler encoder = new MessageEncoder(); @@ -381,14 +377,14 @@ public class NettyMessaging implements MessagingService { SSLContext clientContext = SSLContext.getInstance("TLS"); clientContext.init(kmf.getKeyManagers(), tmFactory.getTrustManagers(), null); - SSLEngine clientSSLEngine = clientContext.createSSLEngine(); + SSLEngine clientSslEngine = clientContext.createSSLEngine(); - clientSSLEngine.setUseClientMode(true); - clientSSLEngine.setEnabledProtocols(clientSSLEngine.getSupportedProtocols()); - clientSSLEngine.setEnabledCipherSuites(clientSSLEngine.getSupportedCipherSuites()); - clientSSLEngine.setEnableSessionCreation(true); + clientSslEngine.setUseClientMode(true); + clientSslEngine.setEnabledProtocols(clientSslEngine.getSupportedProtocols()); + clientSslEngine.setEnabledCipherSuites(clientSslEngine.getSupportedCipherSuites()); + clientSslEngine.setEnableSessionCreation(true); - channel.pipeline().addLast("ssl", new io.netty.handler.ssl.SslHandler(clientSSLEngine)) + channel.pipeline().addLast("ssl", new io.netty.handler.ssl.SslHandler(clientSslEngine)) .addLast("encoder", encoder) .addLast("decoder", new MessageDecoder()) .addLast("handler", dispatcher); diff --git a/framework/src/onos/utils/pom.xml b/framework/src/onos/utils/pom.xml index c2fa5dc6..2129c85d 100644 --- a/framework/src/onos/utils/pom.xml +++ b/framework/src/onos/utils/pom.xml @@ -41,7 +41,8 @@ <module>thirdparty</module> <module>stc</module> <module>jdvue</module> - <module>jnc</module> <!-- FIXME publish and remove before release --> + <module>jnc</module> + <module>catalyst</module> <!-- FIXME publish and remove before release --> </modules> <dependencies> diff --git a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Coordinator.java b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Coordinator.java index ef1c31f3..228e7834 100644 --- a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Coordinator.java +++ b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Coordinator.java @@ -25,6 +25,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -41,7 +42,7 @@ import static org.onlab.stc.Coordinator.Status.*; */ public class Coordinator { - private static final int MAX_THREADS = 16; + private static final int MAX_THREADS = 64; private final ExecutorService executor = newFixedThreadPool(MAX_THREADS); @@ -143,13 +144,15 @@ public class Coordinator { } /** - * Wants for completion of the entire process flow. + * Waits for completion of the entire process flow. * * @return exit code to use * @throws InterruptedException if interrupted while waiting for completion */ public int waitFor() throws InterruptedException { - latch.await(); + while (!store.isComplete()) { + latch.await(1, TimeUnit.SECONDS); + } return store.hasFailures() ? 1 : 0; } @@ -234,15 +237,26 @@ public class Coordinator { substitute(step.command()))); } } else if (directive == SKIP) { - if (step instanceof Group) { - Group group = (Group) step; - group.children().forEach(child -> delegate.onCompletion(child, SKIPPED)); - } - delegate.onCompletion(step, SKIPPED); + skipStep(step); } } /** + * Recursively skips the specified step or group and any steps/groups within. + * + * @param step step or group + */ + private void skipStep(Step step) { + if (step instanceof Group) { + Group group = (Group) step; + store.markComplete(step, SKIPPED); + group.children().forEach(this::skipStep); + } + delegate.onCompletion(step, SKIPPED); + + } + + /** * Determines the state of the specified step. * * @param step test step @@ -258,8 +272,8 @@ public class Coordinator { Status depStatus = store.getStatus(dependency.dst()); if (depStatus == WAITING || depStatus == IN_PROGRESS) { return NOOP; - } else if ((depStatus == FAILED || depStatus == SKIPPED) && - !dependency.isSoft()) { + } else if (((depStatus == FAILED || depStatus == SKIPPED) && !dependency.isSoft()) || + (step.group() != null && store.getStatus(step.group()) == SKIPPED)) { return SKIP; } } diff --git a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Step.java b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Step.java index 3d8ea983..e14addb5 100644 --- a/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Step.java +++ b/framework/src/onos/utils/stc/src/main/java/org/onlab/stc/Step.java @@ -101,7 +101,7 @@ public class Step implements Vertex { @Override public int hashCode() { - return Objects.hash(name); + return name.hashCode(); } @Override diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/AbstractMapper.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/AbstractMapper.java index f49202dd..0d9d94d3 100644 --- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/AbstractMapper.java +++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/AbstractMapper.java @@ -29,6 +29,11 @@ import static com.google.common.base.Strings.isNullOrEmpty; public abstract class AbstractMapper<E extends Throwable> implements ExceptionMapper<E> { /** + * Holds the current exception for use in subclasses. + */ + protected Throwable error; + + /** * Returns the response status to be given when the exception occurs. * * @return response status @@ -37,6 +42,7 @@ public abstract class AbstractMapper<E extends Throwable> implements ExceptionMa @Override public Response toResponse(E exception) { + error = exception; return response(responseStatus(), exception).build(); } @@ -50,6 +56,7 @@ public abstract class AbstractMapper<E extends Throwable> implements ExceptionMa */ protected Response.ResponseBuilder response(Response.Status status, Throwable exception) { + error = exception; ObjectMapper mapper = new ObjectMapper(); String message = messageFrom(exception); ObjectNode result = mapper.createObjectNode() diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java index 5a9050d0..778750e6 100644 --- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java +++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/exceptions/ServerErrorMapper.java @@ -18,13 +18,19 @@ package org.onosproject.rest.exceptions; import javax.ws.rs.core.Response; import javax.ws.rs.ext.Provider; +import org.slf4j.Logger; + +import static org.slf4j.LoggerFactory.getLogger; + /** * Mapper for service not found exceptions to the INTERNAL_SERVER_ERROR response code. */ @Provider public class ServerErrorMapper extends AbstractMapper<RuntimeException> { + private static final Logger log = getLogger(ServerErrorMapper.class); @Override protected Response.Status responseStatus() { + log.warn("Unhandled REST exception", error); return Response.Status.INTERNAL_SERVER_ERROR; } } diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java index 636fc333..b38633bf 100644 --- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java +++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java @@ -44,6 +44,7 @@ public class ApplicationsWebResource extends AbstractWebResource { * Get all installed applications. * Returns array of all installed applications. * + * @rsModel Applications * @return 200 OK */ @GET @@ -56,7 +57,7 @@ public class ApplicationsWebResource extends AbstractWebResource { /** * Get application details. * Returns details of the specified application. - * + * @rsModel Application * @param name application name * @return 200 OK; 404; 401 */ diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ClusterWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ClusterWebResource.java index 312f6e35..16a4dc7f 100644 --- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ClusterWebResource.java +++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ClusterWebResource.java @@ -49,6 +49,7 @@ public class ClusterWebResource extends AbstractWebResource { * Returns array of all cluster nodes. * * @return 200 OK + * @rsModel Cluster */ @GET public Response getClusterNodes() { @@ -62,6 +63,7 @@ public class ClusterWebResource extends AbstractWebResource { * * @param id cluster node identifier * @return 200 OK + * @rsModel ClusterNode */ @GET @Path("{id}") @@ -78,6 +80,7 @@ public class ClusterWebResource extends AbstractWebResource { * @param config cluster definition * @return 200 OK * @throws IOException to signify bad request + * @rsModel ClusterPost */ @POST @Path("configuration") diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ConfigProvider.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ConfigProvider.java index dbd80cca..06c73d39 100644 --- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ConfigProvider.java +++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/ConfigProvider.java @@ -327,7 +327,7 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider { String value = annotations.value("optical.waves").trim(); try { int numChls = Integer.parseInt(value); - updateOMSPorts(numChls, src, dst); + updateOmsPorts(numChls, src, dst); } catch (NumberFormatException e) { log.warn("Invalid channel ({}), can't configure port(s)", value); return; @@ -373,7 +373,7 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider { } } - private void updateOMSPorts(int numChls, ConnectPoint srcCp, ConnectPoint dstCp) { + private void updateOmsPorts(int numChls, ConnectPoint srcCp, ConnectPoint dstCp) { // round down to largest slot that allows numChl channels to fit into C band range ChannelSpacing chl = null; Frequency perChl = TOTAL.floorDivision(numChls); diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/DevicesWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/DevicesWebResource.java index 05756e5a..23ca46e7 100644 --- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/DevicesWebResource.java +++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/DevicesWebResource.java @@ -46,6 +46,7 @@ public class DevicesWebResource extends AbstractWebResource { * Returns array of all discovered infrastructure devices. * * @return 200 OK + * @rsModel DevicesGet */ @GET public Response getDevices() { @@ -59,6 +60,7 @@ public class DevicesWebResource extends AbstractWebResource { * * @param id device identifier * @return 200 OK + * @rsModel DeviceGet */ @GET @Path("{id}") @@ -89,6 +91,7 @@ public class DevicesWebResource extends AbstractWebResource { * Get ports of infrastructure device. * Returns details of the specified infrastructure device. * + * @rsModel DeviceGetPorts * @param id device identifier * @return 200 OK */ diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java index 0e88e34e..252a3ba7 100644 --- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java +++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/FlowsWebResource.java @@ -58,7 +58,7 @@ public class FlowsWebResource extends AbstractWebResource { /** * Get all flow entries. Returns array of all flow rules in the system. - * + * @rsModel Flows * @return array of all the intents in the system */ @GET @@ -80,7 +80,7 @@ public class FlowsWebResource extends AbstractWebResource { /** * Get flow entries of a device. Returns array of all flow rules for the * specified device. - * + * @rsModel Flows * @param deviceId device identifier * @return flow data as an array */ @@ -103,7 +103,7 @@ public class FlowsWebResource extends AbstractWebResource { /** * Get flow rule. Returns the flow entry specified by the device id and * flow rule id. - * + * @rsModel Flows * @param deviceId device identifier * @param flowId flow rule identifier * @return flow data as an array @@ -130,7 +130,7 @@ public class FlowsWebResource extends AbstractWebResource { /** * Create new flow rule. Creates and installs a new flow rule for the * specified device. - * + * @rsModel FlowsPost * @param deviceId device identifier * @param stream flow rule JSON * @return status of the request - CREATED if the JSON is correct, diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java index b89f5add..455e4929 100644 --- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java +++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/HostsWebResource.java @@ -70,6 +70,7 @@ public class HostsWebResource extends AbstractWebResource { * Returns array of all known end-station hosts. * * @return 200 OK + * @rsModel Hosts */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -85,6 +86,7 @@ public class HostsWebResource extends AbstractWebResource { * * @param id host identifier * @return 200 OK + * @rsModel Host */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -103,6 +105,7 @@ public class HostsWebResource extends AbstractWebResource { * @param mac host MAC address * @param vlan host VLAN identifier * @return 200 OK + * @rsModel Host */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -122,6 +125,7 @@ public class HostsWebResource extends AbstractWebResource { * @param stream input JSON * @return status of the request - CREATED if the JSON is correct, * BAD_REQUEST if the JSON is invalid + * @rsModel HostPut */ @POST @Consumes(MediaType.APPLICATION_JSON) @@ -195,6 +199,7 @@ public class HostsWebResource extends AbstractWebResource { while (ipStrings.hasNext()) { ips.add(IpAddress.valueOf(ipStrings.next().asText())); } + //TODO remove elements from json node after reading them SparseAnnotations annotations = annotations(node); // Update host inventory diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java index c6270199..e36ea8af 100644 --- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java +++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/LinksWebResource.java @@ -44,7 +44,7 @@ public class LinksWebResource extends AbstractWebResource { /** * Get infrastructure links. * Returns array of all links, or links for the specified device or port. - * + * @rsModel LinksGet * @param deviceId (optional) device identifier * @param port (optional) port number * @param direction (optional) direction qualifier diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java index 808fcc16..69c0b6a3 100644 --- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java +++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/NetworkConfigWebResource.java @@ -15,10 +15,9 @@ */ package org.onosproject.rest.resources; -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.onosproject.net.config.NetworkConfigService; -import org.onosproject.net.config.SubjectFactory; -import org.onosproject.rest.AbstractWebResource; +import java.io.IOException; +import java.io.InputStream; +import java.util.Set; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -29,8 +28,16 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.io.IOException; -import java.io.InputStream; + +import org.onosproject.net.config.Config; +import org.onosproject.net.config.NetworkConfigService; +import org.onosproject.net.config.SubjectFactory; +import org.onosproject.rest.AbstractWebResource; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +import static org.onlab.util.Tools.emptyIsNotFound; +import static org.onlab.util.Tools.nullIsNotFound; /** * Manage network configurations. @@ -38,9 +45,30 @@ import java.io.InputStream; @Path("network/configuration") public class NetworkConfigWebResource extends AbstractWebResource { + + private String subjectClassNotFoundErrorString(String subjectClassKey) { + return "Config for '" + subjectClassKey + "' not found"; + } + + private String subjectNotFoundErrorString(String subjectClassKey, + String subjectKey) { + return "Config for '" + + subjectClassKey + "/" + subjectKey + + "' not found"; + } + + private String configKeyNotFoundErrorString(String subjectClassKey, + String subjectKey, + String configKey) { + return "Config for '" + + subjectClassKey + "/" + subjectKey + "/" + configKey + + "' not found"; + } + /** * Get entire network configuration base. * + * @rsModel NetCfgGet * @return network configuration JSON */ @GET @@ -70,7 +98,9 @@ public class NetworkConfigWebResource extends AbstractWebResource { public Response download(@PathParam("subjectClassKey") String subjectClassKey) { NetworkConfigService service = get(NetworkConfigService.class); ObjectNode root = mapper().createObjectNode(); - SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey); + SubjectFactory subjectFactory = + nullIsNotFound(service.getSubjectFactory(subjectClassKey), + subjectClassNotFoundErrorString(subjectClassKey)); produceJson(service, root, subjectFactory, subjectFactory.subjectClass()); return ok(root).build(); } @@ -90,8 +120,12 @@ public class NetworkConfigWebResource extends AbstractWebResource { @PathParam("subjectKey") String subjectKey) { NetworkConfigService service = get(NetworkConfigService.class); ObjectNode root = mapper().createObjectNode(); - SubjectFactory subjectFactory = service.getSubjectFactory(subjectClassKey); - produceSubjectJson(service, root, subjectFactory.createSubject(subjectKey)); + SubjectFactory subjectFactory = + nullIsNotFound(service.getSubjectFactory(subjectClassKey), + subjectClassNotFoundErrorString(subjectClassKey)); + produceSubjectJson(service, root, subjectFactory.createSubject(subjectKey), + true, + subjectNotFoundErrorString(subjectClassKey, subjectKey)); return ok(root).build(); } @@ -111,26 +145,47 @@ public class NetworkConfigWebResource extends AbstractWebResource { @PathParam("subjectKey") String subjectKey, @PathParam("configKey") String configKey) { NetworkConfigService service = get(NetworkConfigService.class); - return ok(service.getConfig(service.getSubjectFactory(subjectClassKey).createSubject(subjectKey), - service.getConfigClass(subjectClassKey, configKey)).node()).build(); + + Object subject = + nullIsNotFound(service.getSubjectFactory(subjectClassKey) + .createSubject(subjectKey), + subjectNotFoundErrorString(subjectClassKey, subjectKey)); + + Class configClass = + nullIsNotFound(service.getConfigClass(subjectClassKey, configKey), + configKeyNotFoundErrorString(subjectClassKey, subjectKey, configKey)); + Config config = + nullIsNotFound(service.getConfig(subject, configClass), + configKeyNotFoundErrorString(subjectClassKey, + subjectKey, + configKey)); + return ok(config.node()).build(); } @SuppressWarnings("unchecked") private void produceJson(NetworkConfigService service, ObjectNode node, SubjectFactory subjectFactory, Class subjectClass) { service.getSubjects(subjectClass).forEach(s -> - produceSubjectJson(service, newObject(node, subjectFactory.subjectKey(s)), s)); + produceSubjectJson(service, newObject(node, subjectFactory.subjectKey(s)), s, false, "")); } private void produceSubjectJson(NetworkConfigService service, ObjectNode node, - Object subject) { - service.getConfigs(subject).forEach(c -> node.set(c.key(), c.node())); + Object subject, + boolean emptyIsError, + String emptyErrorMessage) { + Set<? extends Config<Object>> configs = service.getConfigs(subject); + if (emptyIsError) { + // caller wants an empty set to be a 404 + configs = emptyIsNotFound(configs, emptyErrorMessage); + } + configs.forEach(c -> node.set(c.key(), c.node())); } /** * Upload bulk network configuration. * + * @rsModel NetCfgGet * @param request network configuration JSON rooted at the top node * @return empty response * @throws IOException if unable to parse the request @@ -253,17 +308,15 @@ public class NetworkConfigWebResource extends AbstractWebResource { * Clear all network configurations for a subject class. * * @param subjectClassKey subject class key - * @return empty response */ @DELETE @Path("{subjectClassKey}") @SuppressWarnings("unchecked") - public Response delete(@PathParam("subjectClassKey") String subjectClassKey) { + public void delete(@PathParam("subjectClassKey") String subjectClassKey) { NetworkConfigService service = get(NetworkConfigService.class); - service.getSubjects(service.getSubjectFactory(subjectClassKey).getClass()) + service.getSubjects(service.getSubjectFactory(subjectClassKey).subjectClass()) .forEach(subject -> service.getConfigs(subject) .forEach(config -> service.removeConfig(subject, config.getClass()))); - return Response.ok().build(); } /** @@ -271,17 +324,15 @@ public class NetworkConfigWebResource extends AbstractWebResource { * * @param subjectClassKey subjectKey class key * @param subjectKey subjectKey key - * @return empty response */ @DELETE @Path("{subjectClassKey}/{subjectKey}") @SuppressWarnings("unchecked") - public Response delete(@PathParam("subjectClassKey") String subjectClassKey, + public void delete(@PathParam("subjectClassKey") String subjectClassKey, @PathParam("subjectKey") String subjectKey) { NetworkConfigService service = get(NetworkConfigService.class); Object s = service.getSubjectFactory(subjectClassKey).createSubject(subjectKey); service.getConfigs(s).forEach(c -> service.removeConfig(s, c.getClass())); - return Response.ok().build(); } /** @@ -290,18 +341,16 @@ public class NetworkConfigWebResource extends AbstractWebResource { * @param subjectClassKey subjectKey class key * @param subjectKey subjectKey key * @param configKey configuration class key - * @return empty response */ @DELETE @Path("{subjectClassKey}/{subjectKey}/{configKey}") @SuppressWarnings("unchecked") - public Response delete(@PathParam("subjectClassKey") String subjectClassKey, + public void delete(@PathParam("subjectClassKey") String subjectClassKey, @PathParam("subjectKey") String subjectKey, @PathParam("configKey") String configKey) { NetworkConfigService service = get(NetworkConfigService.class); service.removeConfig(service.getSubjectFactory(subjectClassKey).createSubject(subjectKey), service.getConfigClass(subjectClassKey, configKey)); - return Response.ok().build(); } } diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/PathsWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/PathsWebResource.java index 9714690c..c14b4ec2 100644 --- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/PathsWebResource.java +++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/PathsWebResource.java @@ -60,7 +60,7 @@ public class PathsWebResource extends AbstractWebResource { /** * Get all shortest paths between any two hosts or devices. * Returns array of all shortest paths between any two elements. - * + * @rsModel Paths * @param src source identifier * @param dst destination identifier * @return path data @@ -79,7 +79,7 @@ public class PathsWebResource extends AbstractWebResource { /** * Get all shortest disjoint paths between any two hosts or devices. * Returns array of all shortest disjoint paths between any two elements. - * + * @rsModel Paths * @param src source identifier * @param dst destination identifier * @return path data diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java index c91cb6d0..7a452044 100644 --- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java +++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/StatisticsWebResource.java @@ -59,7 +59,7 @@ public class StatisticsWebResource extends AbstractWebResource { /** * Get load statistics for all links or for a specific link. - * + * @rsModel StatisticsFlowsLink * @param deviceId (optional) device ID for a specific link * @param port (optional) port number for a specified link * @return JSON encoded array lof Load objects @@ -101,7 +101,7 @@ public class StatisticsWebResource extends AbstractWebResource { /** * Get table statistics for all tables of all devices. - * + * @rsModel StatisticsFlowsTables * @return JSON encoded array of table statistics */ @GET @@ -111,11 +111,11 @@ public class StatisticsWebResource extends AbstractWebResource { final FlowRuleService service = get(FlowRuleService.class); final Iterable<Device> devices = get(DeviceService.class).getDevices(); final ObjectNode root = mapper().createObjectNode(); - final ArrayNode rootArrayNode = root.putArray("device-table-statistics"); + final ArrayNode rootArrayNode = root.putArray("statistics"); for (final Device device : devices) { final ObjectNode deviceStatsNode = mapper().createObjectNode(); deviceStatsNode.put("device", device.id().toString()); - final ArrayNode statisticsNode = deviceStatsNode.putArray("table-statistics"); + final ArrayNode statisticsNode = deviceStatsNode.putArray("table"); final Iterable<TableStatisticsEntry> tableStatsEntries = service.getFlowTableStatistics(device.id()); if (tableStatsEntries != null) { for (final TableStatisticsEntry entry : tableStatsEntries) { @@ -130,7 +130,7 @@ public class StatisticsWebResource extends AbstractWebResource { /** * Get table statistics for all tables of a specified device. - * + * @rsModel StatisticsFlowsTables * @param deviceId device ID * @return JSON encoded array of table statistics */ @@ -142,11 +142,11 @@ public class StatisticsWebResource extends AbstractWebResource { final Iterable<TableStatisticsEntry> tableStatisticsEntries = service.getFlowTableStatistics(DeviceId.deviceId(deviceId)); final ObjectNode root = mapper().createObjectNode(); - final ArrayNode rootArrayNode = root.putArray("table-statistics"); + final ArrayNode rootArrayNode = root.putArray("statistics"); final ObjectNode deviceStatsNode = mapper().createObjectNode(); deviceStatsNode.put("device", deviceId); - final ArrayNode statisticsNode = deviceStatsNode.putArray("table-statistics"); + final ArrayNode statisticsNode = deviceStatsNode.putArray("table"); for (final TableStatisticsEntry entry : tableStatisticsEntries) { statisticsNode.add(codec(TableStatisticsEntry.class).encode(entry, this)); } diff --git a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/TopologyWebResource.java b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/TopologyWebResource.java index f6ae8253..d51bd5a0 100644 --- a/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/TopologyWebResource.java +++ b/framework/src/onos/web/api/src/main/java/org/onosproject/rest/resources/TopologyWebResource.java @@ -50,6 +50,7 @@ public class TopologyWebResource extends AbstractWebResource { * Get overview of current topology. * * @return topology overview + * @rsModel Topology */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -63,6 +64,7 @@ public class TopologyWebResource extends AbstractWebResource { * Get overview of topology SCCs. * * @return topology clusters overview + * @rsModel TopologyClusters */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -80,6 +82,7 @@ public class TopologyWebResource extends AbstractWebResource { * * @param clusterId id of the cluster to query * @return topology cluster details + * @rsModel TopologyCluster */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -103,6 +106,7 @@ public class TopologyWebResource extends AbstractWebResource { * * @param clusterId id of the cluster to query * @return topology cluster devices + * @rsModel TopologyClustersDevices */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -126,6 +130,7 @@ public class TopologyWebResource extends AbstractWebResource { * * @param clusterId id of the cluster to query * @return topology cluster links + * @rsModel LinksGet */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -136,7 +141,7 @@ public class TopologyWebResource extends AbstractWebResource { List<Link> links = Lists.newArrayList(get(TopologyService.class) - .getClusterLinks(topology, cluster)); + .getClusterLinks(topology, cluster)); return ok(encodeArray(Link.class, "links", links)).build(); } @@ -174,7 +179,8 @@ public class TopologyWebResource extends AbstractWebResource { * * @param connectPointString deviceid:portnumber * @return JSON representation of true if the connect point is broadcast, - * false otherwise + * false otherwise + * @rsModel TopologyBroadcast */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -188,8 +194,8 @@ public class TopologyWebResource extends AbstractWebResource { boolean isBroadcast = get(TopologyService.class).isBroadcastPoint(topology, connectPoint); return ok(mapper() - .createObjectNode() - .put("broadcast", isBroadcast)) + .createObjectNode() + .put("broadcast", isBroadcast)) .build(); } @@ -198,7 +204,8 @@ public class TopologyWebResource extends AbstractWebResource { * * @param connectPointString deviceid:portnumber * @return JSON representation of true if the connect point is broadcast, - * false otherwise + * false otherwise + * @rsModel TopologyInfrastructure */ @GET @Produces(MediaType.APPLICATION_JSON) @@ -212,8 +219,8 @@ public class TopologyWebResource extends AbstractWebResource { boolean isInfrastructure = get(TopologyService.class).isInfrastructure(topology, connectPoint); return ok(mapper() - .createObjectNode() - .put("infrastructure", isInfrastructure)) + .createObjectNode() + .put("infrastructure", isInfrastructure)) .build(); } diff --git a/framework/src/onos/web/api/src/test/java/org/onosproject/rest/ApplicationsResourceTest.java b/framework/src/onos/web/api/src/test/java/org/onosproject/rest/ApplicationsResourceTest.java index 6fee43ed..3e72f18d 100644 --- a/framework/src/onos/web/api/src/test/java/org/onosproject/rest/ApplicationsResourceTest.java +++ b/framework/src/onos/web/api/src/test/java/org/onosproject/rest/ApplicationsResourceTest.java @@ -85,19 +85,19 @@ public class ApplicationsResourceTest extends ResourceTest { private Application app1 = new DefaultApplication(id1, VER, "app1", "origin1", ApplicationRole.ADMIN, ImmutableSet.of(), Optional.of(FURL), - ImmutableList.of("My Feature")); + ImmutableList.of("My Feature"), ImmutableList.of()); private Application app2 = new DefaultApplication(id2, VER, "app2", "origin2", ApplicationRole.ADMIN, ImmutableSet.of(), Optional.of(FURL), - ImmutableList.of("My Feature")); + ImmutableList.of("My Feature"), ImmutableList.of()); private Application app3 = new DefaultApplication(id3, VER, "app3", "origin3", ApplicationRole.ADMIN, ImmutableSet.of(), Optional.of(FURL), - ImmutableList.of("My Feature")); + ImmutableList.of("My Feature"), ImmutableList.of()); private Application app4 = new DefaultApplication(id4, VER, "app4", "origin4", ApplicationRole.ADMIN, ImmutableSet.of(), Optional.of(FURL), - ImmutableList.of("My Feature")); + ImmutableList.of("My Feature"), ImmutableList.of()); /** * Hamcrest matcher to check that an application representation in JSON matches diff --git a/framework/src/onos/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java b/framework/src/onos/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java index 4fb58215..8910e733 100644 --- a/framework/src/onos/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java +++ b/framework/src/onos/web/api/src/test/java/org/onosproject/rest/FlowsResourceTest.java @@ -585,7 +585,7 @@ public class FlowsResourceTest extends ResourceTest { replay(mockFlowService); WebResource rs = resource(); - InputStream jsonStream = IntentsResourceTest.class + InputStream jsonStream = FlowsResourceTest.class .getResourceAsStream("post-flow.json"); ClientResponse response = rs.path("flows/of:0000000000000001") diff --git a/framework/src/onos/web/api/src/test/java/org/onosproject/rest/HostResourceTest.java b/framework/src/onos/web/api/src/test/java/org/onosproject/rest/HostResourceTest.java index 8c765402..5ac483d8 100644 --- a/framework/src/onos/web/api/src/test/java/org/onosproject/rest/HostResourceTest.java +++ b/framework/src/onos/web/api/src/test/java/org/onosproject/rest/HostResourceTest.java @@ -375,7 +375,7 @@ public class HostResourceTest extends ResourceTest { replay(mockHostService); - InputStream jsonStream = IntentsResourceTest.class + InputStream jsonStream = HostResourceTest.class .getResourceAsStream("post-host.json"); WebResource rs = resource(); diff --git a/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java b/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java index 82b7a782..700e57e3 100644 --- a/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java +++ b/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandler.java @@ -289,6 +289,7 @@ public class TopologyViewMessageHandler extends TopologyViewMessageHandlerBase { @Override public void process(long sid, ObjectNode payload) { + removeListeners(); stopSummaryMonitoring(); traffic.stopMonitoring(); } diff --git a/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java b/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java index 840e89f3..f35b6c03 100644 --- a/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java +++ b/framework/src/onos/web/gui/src/main/java/org/onosproject/ui/impl/TopologyViewMessageHandlerBase.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import org.onlab.osgi.ServiceDirectory; import org.onlab.packet.IpAddress; +import org.onlab.util.DefaultHashMap; import org.onosproject.cluster.ClusterEvent; import org.onosproject.cluster.ClusterService; import org.onosproject.cluster.ControllerNode; @@ -80,17 +81,9 @@ import java.util.concurrent.ConcurrentHashMap; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Strings.isNullOrEmpty; -import static org.onosproject.cluster.ClusterEvent.Type.INSTANCE_ADDED; -import static org.onosproject.cluster.ClusterEvent.Type.INSTANCE_REMOVED; import static org.onosproject.cluster.ControllerNode.State.ACTIVE; import static org.onosproject.net.DefaultEdgeLink.createEdgeLink; import static org.onosproject.net.PortNumber.portNumber; -import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED; -import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_REMOVED; -import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED; -import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED; -import static org.onosproject.net.link.LinkEvent.Type.LINK_ADDED; -import static org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED; import static org.onosproject.ui.topo.TopoConstants.CoreButtons; import static org.onosproject.ui.topo.TopoConstants.Properties; import static org.onosproject.ui.topo.TopoUtils.compactLinkString; @@ -100,6 +93,33 @@ import static org.onosproject.ui.topo.TopoUtils.compactLinkString; */ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { + // default to an "add" event... + private static final DefaultHashMap<ClusterEvent.Type, String> CLUSTER_EVENT = + new DefaultHashMap<>("addInstance"); + + // default to an "update" event... + private static final DefaultHashMap<DeviceEvent.Type, String> DEVICE_EVENT = + new DefaultHashMap<>("updateDevice"); + private static final DefaultHashMap<LinkEvent.Type, String> LINK_EVENT = + new DefaultHashMap<>("updateLink"); + private static final DefaultHashMap<HostEvent.Type, String> HOST_EVENT = + new DefaultHashMap<>("updateHost"); + + // but call out specific events that we care to differentiate... + static { + CLUSTER_EVENT.put(ClusterEvent.Type.INSTANCE_REMOVED, "removeInstance"); + + DEVICE_EVENT.put(DeviceEvent.Type.DEVICE_ADDED, "addDevice"); + DEVICE_EVENT.put(DeviceEvent.Type.DEVICE_REMOVED, "removeDevice"); + + LINK_EVENT.put(LinkEvent.Type.LINK_ADDED, "addLink"); + LINK_EVENT.put(LinkEvent.Type.LINK_REMOVED, "removeLink"); + + HOST_EVENT.put(HostEvent.Type.HOST_ADDED, "addHost"); + HOST_EVENT.put(HostEvent.Type.HOST_REMOVED, "removeHost"); + HOST_EVENT.put(HostEvent.Type.HOST_MOVED, "moveHost"); + } + protected static final Logger log = LoggerFactory.getLogger(TopologyViewMessageHandlerBase.class); @@ -204,7 +224,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { } // Produces a cluster instance message to the client. - protected ObjectNode instanceMessage(ClusterEvent event, String messageType) { + protected ObjectNode instanceMessage(ClusterEvent event, String msgType) { ControllerNode node = event.subject(); int switchCount = mastershipService.getDevicesOf(node.id()).size(); ObjectNode payload = objectNode() @@ -222,10 +242,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { payload.set("labels", labels); addMetaUi(node.id().toString(), payload); - String type = messageType != null ? messageType : - ((event.type() == INSTANCE_ADDED) ? "addInstance" : - ((event.type() == INSTANCE_REMOVED ? "removeInstance" : - "addInstance"))); + String type = msgType != null ? msgType : CLUSTER_EVENT.get(event.type()); return JsonUtils.envelope(type, 0, payload); } @@ -251,8 +268,7 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { addGeoLocation(device, payload); addMetaUi(device.id().toString(), payload); - String type = (event.type() == DEVICE_ADDED) ? "addDevice" : - ((event.type() == DEVICE_REMOVED) ? "removeDevice" : "updateDevice"); + String type = DEVICE_EVENT.get(event.type()); return JsonUtils.envelope(type, 0, payload); } @@ -268,29 +284,32 @@ public abstract class TopologyViewMessageHandlerBase extends UiMessageHandler { .put("srcPort", link.src().port().toString()) .put("dst", link.dst().deviceId().toString()) .put("dstPort", link.dst().port().toString()); - String type = (event.type() == LINK_ADDED) ? "addLink" : - ((event.type() == LINK_REMOVED) ? "removeLink" : "updateLink"); + String type = LINK_EVENT.get(event.type()); return JsonUtils.envelope(type, 0, payload); } // Produces a host event message to the client. protected ObjectNode hostMessage(HostEvent event) { Host host = event.subject(); + Host prevHost = event.prevSubject(); String hostType = host.annotations().value(AnnotationKeys.TYPE); + ObjectNode payload = objectNode() .put("id", host.id().toString()) .put("type", isNullOrEmpty(hostType) ? "endstation" : hostType) .put("ingress", compactLinkString(edgeLink(host, true))) .put("egress", compactLinkString(edgeLink(host, false))); payload.set("cp", hostConnect(host.location())); + if (prevHost != null && prevHost.location() != null) { + payload.set("prevCp", hostConnect(prevHost.location())); + } payload.set("labels", labels(ip(host.ipAddresses()), host.mac().toString())); payload.set("props", props(host.annotations())); addGeoLocation(host, payload); addMetaUi(host.id().toString(), payload); - String type = (event.type() == HOST_ADDED) ? "addHost" : - ((event.type() == HOST_REMOVED) ? "removeHost" : "updateHost"); + String type = HOST_EVENT.get(event.type()); return JsonUtils.envelope(type, 0, payload); } diff --git a/framework/src/onos/web/gui/src/main/webapp/app/fw/svg/icon.js b/framework/src/onos/web/gui/src/main/webapp/app/fw/svg/icon.js index 12536361..cc26360f 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/fw/svg/icon.js +++ b/framework/src/onos/web/gui/src/main/webapp/app/fw/svg/icon.js @@ -51,6 +51,7 @@ devIcon_SWITCH: 'switch', devIcon_ROADM: 'roadm', + deviceTable: 'switch', flowTable: 'flowTable', portTable: 'portTable', groupTable: 'groupTable', diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/device/device.css b/framework/src/onos/web/gui/src/main/webapp/app/view/device/device.css index e0e9cf57..8d8a582b 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/device/device.css +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/device/device.css @@ -23,7 +23,20 @@ } #ov-device div.ctrl-btns { - width: 240px; +} + +.light #ov-device .current-view use { + fill: white; +} +.dark #ov-device .current-view use { + fill: #304860; +} + +.light #ov-device .current-view rect { + fill: deepskyblue; +} +.dark #ov-device .current-view rect { + fill: #eee; } /* More in generic panel.css */ diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/device/device.html b/framework/src/onos/web/gui/src/main/webapp/app/view/device/device.html index 63a04db8..6f1813a0 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/device/device.html +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/device/device.html @@ -9,6 +9,9 @@ ng-click="toggleRefresh()"></div> <div class="separator"></div> + <div ng-class="{'current-view': !!selId}" + icon icon-id="deviceTable" icon-size="36"></div> + <div ng-class="{active: !!selId}" icon icon-id="flowTable" icon-size="36" tooltip tt-msg="flowTip" diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/flow/flow.css b/framework/src/onos/web/gui/src/main/webapp/app/view/flow/flow.css index 4aa96210..30226222 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/flow/flow.css +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/flow/flow.css @@ -23,7 +23,6 @@ } #ov-flow div.ctrl-btns { - width: 240px; } .light #ov-flow .current-view use { diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/flow/flow.html b/framework/src/onos/web/gui/src/main/webapp/app/view/flow/flow.html index 5fce98cf..8fc1839e 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/flow/flow.html +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/flow/flow.html @@ -13,6 +13,11 @@ <div class="separator"></div> + <div class="active" + icon icon-id="deviceTable" icon-size="36" + tooltip tt-msg="deviceTip" + ng-click="nav('device')"></div> + <div class="current-view" icon icon-id="flowTable" icon-size="36"></div> diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/flow/flow.js b/framework/src/onos/web/gui/src/main/webapp/app/view/flow/flow.js index 15678d5e..7bb988a2 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/flow/flow.js +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/flow/flow.js @@ -37,6 +37,7 @@ fs = _fs_; tbs = _tbs_; ns = _ns_; + $scope.deviceTip = 'Show device table'; $scope.portTip = 'Show port view for this device'; $scope.groupTip = 'Show group view for this device'; diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/group/group.css b/framework/src/onos/web/gui/src/main/webapp/app/view/group/group.css index 42f1c31d..6773aa83 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/group/group.css +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/group/group.css @@ -23,7 +23,6 @@ } #ov-group div.ctrl-btns { - width: 240px; } .light #ov-group .current-view use { diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/group/group.html b/framework/src/onos/web/gui/src/main/webapp/app/view/group/group.html index b963f469..93484dc8 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/group/group.html +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/group/group.html @@ -30,6 +30,11 @@ <div class="separator"></div> <div class="active" + icon icon-id="deviceTable" icon-size="36" + tooltip tt-msg="deviceTip" + ng-click="nav('device')"></div> + + <div class="active" icon icon-id="flowTable" icon-size="36" tooltip tt-msg="flowTip" ng-click="nav('flow')"></div> diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/group/group.js b/framework/src/onos/web/gui/src/main/webapp/app/view/group/group.js index 2510190b..2cb1f0c4 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/group/group.js +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/group/group.js @@ -37,6 +37,7 @@ fs = _fs_; tbs = _tbs_; ns = _ns_; + $scope.deviceTip = 'Show device table'; $scope.flowTip = 'Show flow view for this device'; $scope.portTip = 'Show port view for this device'; diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/port/port.css b/framework/src/onos/web/gui/src/main/webapp/app/view/port/port.css index 7fcfee3f..2aaacfce 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/port/port.css +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/port/port.css @@ -23,7 +23,6 @@ } #ov-port div.ctrl-btns { - width: 240px; } .light #ov-port .current-view use { diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/port/port.html b/framework/src/onos/web/gui/src/main/webapp/app/view/port/port.html index 8eecb9d6..fa79e5ea 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/port/port.html +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/port/port.html @@ -30,6 +30,11 @@ <div class="separator"></div> <div class="active" + icon icon-id="deviceTable" icon-size="36" + tooltip tt-msg="deviceTip" + ng-click="nav('device')"></div> + + <div class="active" icon icon-id="flowTable" icon-size="36" tooltip tt-msg="flowTip" ng-click="nav('flow')"></div> diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/port/port.js b/framework/src/onos/web/gui/src/main/webapp/app/view/port/port.js index a157c5be..1e8585dd 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/port/port.js +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/port/port.js @@ -37,6 +37,7 @@ fs = _fs_; tbs = _tbs_; ns = _ns_; + $scope.deviceTip = 'Show device table'; $scope.flowTip = 'Show flow view for this device'; $scope.groupTip = 'Show group view for this device'; diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topo.js b/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topo.js index 7ddfd136..702584af 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topo.js +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topo.js @@ -30,7 +30,7 @@ // references to injected services etc. var $scope, $log, $cookies, fs, ks, zs, gs, ms, sus, flash, wss, ps, - tes, tfs, tps, tis, tss, tls, tts, tos, fltr, ttbs, ttip, tov; + tds, tes, tfs, tps, tis, tss, tls, tts, tos, fltr, ttbs, ttip, tov; // DOM elements var ovtopo, svg, defs, zoomLayer, mapG, spriteG, forceG, noDevsLayer; @@ -425,7 +425,7 @@ .controller('OvTopoCtrl', ['$scope', '$log', '$location', '$timeout', '$cookies', 'FnService', 'MastService', 'KeyService', 'ZoomService', 'GlyphService', 'MapService', 'SvgUtilService', 'FlashService', - 'WebSocketService', 'PrefsService', + 'WebSocketService', 'PrefsService', 'TopoDialogService', 'TopoEventService', 'TopoForceService', 'TopoPanelService', 'TopoInstService', 'TopoSelectService', 'TopoLinkService', 'TopoTrafficService', 'TopoObliqueService', 'TopoFilterService', @@ -433,9 +433,9 @@ 'TopoOverlayService', function (_$scope_, _$log_, $loc, $timeout, _$cookies_, _fs_, mast, _ks_, - _zs_, _gs_, _ms_, _sus_, _flash_, _wss_, _ps_, _tes_, _tfs_, - _tps_, _tis_, _tss_, _tls_, _tts_, _tos_, _fltr_, _ttbs_, tspr, - _ttip_, _tov_) { + _zs_, _gs_, _ms_, _sus_, _flash_, _wss_, _ps_, _tds_, _tes_, + _tfs_, _tps_, _tis_, _tss_, _tls_, _tts_, _tos_, _fltr_, + _ttbs_, tspr, _ttip_, _tov_) { var params = $loc.search(), projection, dim, @@ -461,6 +461,7 @@ flash = _flash_; wss = _wss_; ps = _ps_; + tds = _tds_; tes = _tes_; tfs = _tfs_; // TODO: consider funnelling actions through TopoForceService... @@ -495,6 +496,7 @@ tes.stop(); ks.unbindKeys(); tps.destroyPanels(); + tds.closeDialog(); tis.destroyInst(); tfs.destroyForce(); ttbs.destroyToolbar(); diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoDialog.js b/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoDialog.js index 93079183..0c47511b 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoDialog.js +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoDialog.js @@ -106,6 +106,13 @@ .on('click', invoke); } + function setTitle(title) { + if (pApi) { + pApi.appendHeader('h2').text(title); + } + return dApi; + } + function addContent(content) { if (pApi) { pApi.appendBody(content); @@ -127,11 +134,11 @@ pApi = createDialog(); } pApi.reset(); - pApi.appendHeader('h2').text('=dialog='); panel.show(); // return the dialog object API dApi = { + setTitle: setTitle, addContent: addContent, addButton: addButton }; diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoEvent.js b/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoEvent.js index 2957629a..9b07f878 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoEvent.js +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoEvent.js @@ -55,6 +55,7 @@ removeDevice: tfs, addHost: tfs, updateHost: tfs, + moveHost: tfs, removeHost: tfs, addLink: tfs, updateLink: tfs, diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoForce.js b/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoForce.js index 844d7dc9..175ee796 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoForce.js +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoForce.js @@ -187,6 +187,35 @@ } } + function moveHost(data) { + var id = data.id, + d = lu[id], + lnk; + if (d) { + // first remove the old host link + removeLinkElement(d.linkData); + + // merge new data + angular.extend(d, data); + if (tms.positionNode(d, true)) { + sendUpdateMeta(d); + } + + // now create a new host link + lnk = tms.createHostLink(data); + if (lnk) { + d.linkData = lnk; + network.links.push(lnk); + lu[d.ingress] = lnk; + lu[d.egress] = lnk; + } + + updateNodes(); + updateLinks(); + fResume(); + } + } + function removeHost(data) { var id = data.id, d = lu[id]; @@ -1142,6 +1171,7 @@ removeDevice: removeDevice, addHost: addHost, updateHost: updateHost, + moveHost: moveHost, removeHost: removeHost, addLink: addLink, updateLink: updateLink, diff --git a/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoToolbar.js b/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoToolbar.js index 06285442..804e2a3c 100644 --- a/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoToolbar.js +++ b/framework/src/onos/web/gui/src/main/webapp/app/view/topo/topoToolbar.js @@ -23,7 +23,7 @@ 'use strict'; // injected references - var $log, fs, tbs, ps, tov, api; + var $log, fs, tbs, ps, tov, tds, api; // API: // getActionEntry @@ -192,6 +192,8 @@ }); } + // ensure dialog has closed (if opened by outgoing overlay) + tds.closeDialog(); thirdRow.clear(); if (!order.length) { @@ -271,14 +273,15 @@ angular.module('ovTopo') .factory('TopoToolbarService', ['$log', 'FnService', 'ToolbarService', 'PrefsService', - 'TopoOverlayService', + 'TopoOverlayService', 'TopoDialogService', - function (_$log_, _fs_, _tbs_, _ps_, _tov_) { + function (_$log_, _fs_, _tbs_, _ps_, _tov_, _tds_) { $log = _$log_; fs = _fs_; tbs = _tbs_; ps = _ps_; tov = _tov_; + tds = _tds_; return { init: init, |