import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
-
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
-
import java.util.List;
-
import org.opendaylight.protocol.pcep.spi.AbstractMessageParser;
import org.opendaylight.protocol.pcep.spi.MessageUtil;
import org.opendaylight.protocol.pcep.spi.ObjectRegistry;
public void serializeMessage(final Message message, final ByteBuf out) {
Preconditions.checkArgument(message instanceof Pcinitiate, "Wrong instance of Message. Passed instance of %s. Need Pcinitiate.", message.getClass());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.pcinitiate.message.PcinitiateMessage init = ((Pcinitiate) message).getPcinitiateMessage();
- ByteBuf buffer = Unpooled.buffer();
+ final ByteBuf buffer = Unpooled.buffer();
for (final Requests req : init.getRequests()) {
serializeObject(req.getEndpointsObj(), buffer);
serializeObject(req.getLspa(), buffer);
}
final PcinitiateMessageBuilder builder = new PcinitiateMessageBuilder();
final List<Requests> reqs = Lists.newArrayList();
- Requests req = null;
while (!objects.isEmpty()) {
- req = this.getValidRequest(objects);
- if (req == null) {
- break;
- }
- reqs.add(req);
+ reqs.add(this.getValidRequest(objects));
}
builder.setRequests(reqs);
return new PcinitiateBuilder().setPcinitiateMessage(builder.build()).build();
import org.opendaylight.protocol.pcep.spi.PCEPDeserializerException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.Pcinitiate;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.PcinitiateBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.PcinitiateMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.pcinitiate.message.PcinitiateMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.pcinitiate.message.pcinitiate.message.Requests;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.pcinitiate.message.pcinitiate.message.RequestsBuilder;
@Override
public void serializeMessage(final Message message, final ByteBuf out) {
- Preconditions.checkArgument(message instanceof PcinitiateMessage, "Wrong instance of Message. Passed instance of %s. Need PcinitiateMessage.", message.getClass());
+ Preconditions.checkArgument(message instanceof Pcinitiate, "Wrong instance of Message. Passed instance of %s. Need PcinitiateMessage.", message.getClass());
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev131126.pcinitiate.message.PcinitiateMessage init = ((Pcinitiate) message).getPcinitiateMessage();
- ByteBuf buffer = Unpooled.buffer();
+ final ByteBuf buffer = Unpooled.buffer();
for (final Requests req : init.getRequests()) {
serializeRequest(req, buffer);
}
}
final PcinitiateMessageBuilder builder = new PcinitiateMessageBuilder();
final List<Requests> reqs = Lists.newArrayList();
- Requests req = null;
while (!objects.isEmpty()) {
- req = this.getValidRequest(objects);
- if (req == null) {
- break;
- }
- reqs.add(req);
+ reqs.add(this.getValidRequest(objects));
}
builder.setRequests(reqs);
return new PcinitiateBuilder().setPcinitiateMessage(builder.build()).build();
package org.opendaylight.protocol.pcep.impl;
import com.google.common.base.Preconditions;
-
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.util.concurrent.Promise;
-
import java.net.InetSocketAddress;
-
import org.opendaylight.protocol.framework.AbstractDispatcher;
import org.opendaylight.protocol.framework.SessionListenerFactory;
import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
/**
* Implementation of PCEPDispatcher.
*/
-public class PCEPDispatcherImpl extends AbstractDispatcher<PCEPSessionImpl, PCEPSessionListener> implements PCEPDispatcher, AutoCloseable {
+public class PCEPDispatcherImpl extends AbstractDispatcher<PCEPSessionImpl, PCEPSessionListener> implements PCEPDispatcher {
private static final Logger LOG = LoggerFactory.getLogger(PCEPDispatcherImpl.class);
private final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> snf;
private final MD5ServerChannelFactory<?> scf;
* Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
*/
public PCEPDispatcherImpl(final MessageRegistry registry,
- final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory,
- final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
+ final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory,
+ final EventLoopGroup bossGroup, final EventLoopGroup workerGroup) {
this(registry, negotiatorFactory, bossGroup, workerGroup, null, null);
}
* Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
*/
public PCEPDispatcherImpl(final MessageRegistry registry,
- final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory,
- final EventLoopGroup bossGroup, final EventLoopGroup workerGroup, final MD5ChannelFactory<?> cf,
- final MD5ServerChannelFactory<?> scf) {
+ final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> negotiatorFactory,
+ final EventLoopGroup bossGroup, final EventLoopGroup workerGroup, final MD5ChannelFactory<?> cf,
+ final MD5ServerChannelFactory<?> scf) {
super(bossGroup, workerGroup);
this.cf = cf;
this.scf = scf;
@Override
public synchronized ChannelFuture createServer(final InetSocketAddress address,
- final SessionListenerFactory<PCEPSessionListener> listenerFactory) {
+ final SessionListenerFactory<PCEPSessionListener> listenerFactory) {
return createServer(address, null, listenerFactory);
}
@Override
protected void customizeBootstrap(final Bootstrap b) {
- if (keys != null && !keys.isEmpty()) {
- if (cf == null) {
+ if (this.keys != null && !this.keys.isEmpty()) {
+ if (this.cf == null) {
throw new UnsupportedOperationException("No key access instance available, cannot use key mapping");
}
- LOG.debug("Adding MD5 keys {} to boostrap {}", keys, b);
- b.channelFactory(cf);
- b.option(MD5ChannelOption.TCP_MD5SIG, keys);
+ LOG.debug("Adding MD5 keys {} to boostrap {}", this.keys, b);
+ b.channelFactory(this.cf);
+ b.option(MD5ChannelOption.TCP_MD5SIG, this.keys);
}
}
@Override
protected void customizeBootstrap(final ServerBootstrap b) {
- if (keys != null && !keys.isEmpty()) {
- if (scf == null) {
+ if (this.keys != null && !this.keys.isEmpty()) {
+ if (this.scf == null) {
throw new UnsupportedOperationException("No key access instance available, cannot use key mapping");
}
- LOG.debug("Adding MD5 keys {} to boostrap {}", keys, b);
- b.channelFactory(scf);
- b.option(MD5ChannelOption.TCP_MD5SIG, keys);
+ LOG.debug("Adding MD5 keys {} to boostrap {}", this.keys, b);
+ b.channelFactory(this.scf);
+ b.option(MD5ChannelOption.TCP_MD5SIG, this.keys);
}
// Make sure we are doing round-robin processing
@Override
public synchronized ChannelFuture createServer(final InetSocketAddress address, final KeyMapping keys,
- final SessionListenerFactory<PCEPSessionListener> listenerFactory) {
+ final SessionListenerFactory<PCEPSessionListener> listenerFactory) {
this.keys = keys;
- ChannelFuture ret = super.createServer(address, new PipelineInitializer<PCEPSessionImpl>() {
+ final ChannelFuture ret = super.createServer(address, new PipelineInitializer<PCEPSessionImpl>() {
@Override
public void initializeChannel(final SocketChannel ch, final Promise<PCEPSessionImpl> promise) {
ch.pipeline().addLast(PCEPDispatcherImpl.this.hf.getDecoders());
import com.google.common.base.Objects;
import com.google.common.base.Objects.ToStringHelper;
import com.google.common.base.Preconditions;
-
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.util.concurrent.Future;
-
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.TimeUnit;
-
import org.opendaylight.protocol.framework.AbstractProtocolSession;
import org.opendaylight.protocol.pcep.PCEPCloseTermination;
import org.opendaylight.protocol.pcep.PCEPSession;
private final Keepalive kaMessage = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build();
PCEPSessionImpl(final PCEPSessionListener listener, final int maxUnknownMessages, final Channel channel,
- final Open localOpen, final Open remoteOpen) {
+ final Open localOpen, final Open remoteOpen) {
this.listener = Preconditions.checkNotNull(listener);
this.channel = Preconditions.checkNotNull(channel);
this.localOpen = Preconditions.checkNotNull(localOpen);
}
LOG.info("Session {}[{}] <-> {}[{}] started", channel.localAddress(), localOpen.getSessionId(), channel.remoteAddress(),
- remoteOpen.getSessionId());
+ remoteOpen.getSessionId());
}
/**
LOG.info("Closing PCEP session: {}", this);
this.closed = true;
this.sendMessage(new CloseBuilder().setCCloseMessage(
- new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason(reason.getShortValue()).build()).build()).build());
+ new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason(reason.getShortValue()).build()).build()).build());
this.channel.close();
}
this.listener.onSessionTerminated(this, new PCEPCloseTermination(reason));
this.closed = true;
this.sendMessage(new CloseBuilder().setCCloseMessage(
- new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason(reason.getShortValue()).build()).build()).build());
+ new CCloseMessageBuilder().setCClose(new CCloseBuilder().setReason(reason.getShortValue()).build()).build()).build());
this.close();
}
* @param msg incoming message
*/
@Override
- public void handleMessage(final Message msg) {
+ public synchronized void handleMessage(final Message msg) {
// Update last reception time
this.lastMessageReceivedAt = System.nanoTime();
this.receivedMsgCount++;
if (err.getErrors() == null || err.getErrors().isEmpty()) {
throw new IllegalArgumentException("Errors should not be empty.");
}
- ByteBuf buffer = Unpooled.buffer();
+ final ByteBuf buffer = Unpooled.buffer();
if (err.getErrorType() instanceof RequestCase) {
final List<Rps> rps = ((RequestCase) err.getErrorType()).getRequest().getRps();
for (final Rps r : rps) {
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
- if (requestParameters != null && !requestParameters.isEmpty()) {
+ if (!requestParameters.isEmpty()) {
b.setErrorType(new RequestCaseBuilder().setRequest(new RequestBuilder().setRps(requestParameters).build()).build());
}
public final class TlvUtil {
- protected static final int HEADER_SIZE = 4;
+ public static final int HEADER_SIZE = 4;
public static final int PADDED_TO = 4;
private static final Logger LOG = LoggerFactory.getLogger(Main.class);
public static final String USAGE = "DESCRIPTION:\n"
- + "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
- + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
- + "\t\tFormat: x.x.x.x:y where y is port number.\n\n" +
+ + "\tCreates a server with given parameters. As long as it runs, it accepts connections " + "from PCCs.\n" + "USAGE:\n"
+ + "\t-a, --address\n" + "\t\tthe ip address to which is this server bound.\n"
+ + "\t\tFormat: x.x.x.x:y where y is port number.\n\n" +
"\t-d, --deadtimer\n" + "\t\tin seconds, value of the desired deadtimer\n"
+ "\t\tAccording to RFC5440, recommended value for deadtimer is 4 times the value\n"
while (i < args.length) {
if (args[i].equalsIgnoreCase("-a") || args[i].equalsIgnoreCase("--address")) {
final String[] ip = args[i + 1].split(":");
- address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.valueOf(ip[1]));
+ address = new InetSocketAddress(InetAddress.getByName(ip[0]), Integer.parseInt(ip[1]));
i++;
} else if (args[i].equalsIgnoreCase("-d") || args[i].equalsIgnoreCase("--deadtimer")) {
deadTimerValue = Integer.valueOf(args[i + 1]);
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
-
import io.netty.util.concurrent.FutureListener;
-
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException;
-
import javax.annotation.concurrent.GuardedBy;
-
import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
}
void resolveRequest(final PCEPRequest req) {
- requests.add(req);
+ this.requests.add(req);
}
private void notifyRequests() {
- for (PCEPRequest r : requests) {
+ for (final PCEPRequest r : this.requests) {
r.done(OperationResults.SUCCESS);
}
}
// FIXME: Futures.transform...
try {
- Optional<Topology> topoMaybe = trans.read(LogicalDatastoreType.OPERATIONAL, this.serverSessionManager.getTopology()).get();
+ final Optional<Topology> topoMaybe = trans.read(LogicalDatastoreType.OPERATIONAL, this.serverSessionManager.getTopology()).get();
Preconditions.checkState(topoMaybe.isPresent(), "Failed to find topology.");
final Topology topo = topoMaybe.get();
for (final Node n : topo.getNode()) {
final Node1 ta = new Node1Builder().setPathComputationClient(pccBuilder.build()).build();
this.topologyAugment = this.topologyNode.augmentation(Node1.class);
- this.pccIdentifier = topologyAugment.child(PathComputationClient.class);
+ this.pccIdentifier = this.topologyAugment.child(PathComputationClient.class);
trans.put(LogicalDatastoreType.OPERATIONAL, this.topologyAugment, ta);
LOG.trace("Peer data {} set to {}", this.topologyAugment, ta);
}
protected final synchronized ListenableFuture<OperationResult> sendMessage(final Message message, final S requestId,
- final Metadata metadata) {
+ final Metadata metadata) {
final io.netty.util.concurrent.Future<Void> f = this.session.sendMessage(message);
final PCEPRequest req = new PCEPRequest(metadata);
this.requests.put(requestId, req);
public void operationComplete(final io.netty.util.concurrent.Future<Void> future) {
if (!future.isSuccess()) {
synchronized (AbstractTopologySessionListener.this) {
- requests.remove(requestId);
+ AbstractTopologySessionListener.this.requests.remove(requestId);
}
req.done(OperationResults.UNSENT);
LOG.info("Failed to send request {}, instruction cancelled", requestId, future.cause());
* @param remove True if this is an LSP path removal
*/
protected final synchronized void updateLsp(final MessageContext ctx, final L id, final String lspName,
- final ReportedLspBuilder rlb, final boolean solicited, final boolean remove) {
+ final ReportedLspBuilder rlb, final boolean solicited, final boolean remove) {
final String name;
if (lspName == null) {
// just one path should be reported
Preconditions.checkState(rlb.getPath().size() == 1);
- LspId reportedLspId = rlb.getPath().get(0).getLspId();
+ final LspId reportedLspId = rlb.getPath().get(0).getLspId();
// check previous report for existing paths
- ReportedLsp previous = this.lspData.get(name);
+ final ReportedLsp previous = this.lspData.get(name);
// if no previous report about the lsp exist, just proceed
if (previous != null) {
- List<Path> updatedPaths = new ArrayList<>(previous.getPath());
+ final List<Path> updatedPaths = new ArrayList<>(previous.getPath());
LOG.debug("Found previous paths {} to this lsp name {}", updatedPaths, name);
- for (Path path : previous.getPath()) {
+ for (final Path path : previous.getPath()) {
//we found reported path in previous reports
if (path.getLspId().getValue() == 0 || path.getLspId().equals(reportedLspId)) {
LOG.debug("Match on lsp-id {}", path.getLspId().getValue() );
}
protected final InstanceIdentifier<ReportedLsp> lspIdentifier(final String name) {
- return pccIdentifier.child(ReportedLsp.class, new ReportedLspKey(name));
+ return this.pccIdentifier.child(ReportedLsp.class, new ReportedLspKey(name));
}
/**
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.util.Collections;
-import javax.annotation.concurrent.GuardedBy;
-
import org.opendaylight.protocol.pcep.PCEPSession;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.PcinitiateBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.pcinitiate.message.PcinitiateMessageBuilder;
super(serverSessionManager);
}
- @GuardedBy("this")
- private long requestId = 1;
-
@Override
protected void onSessionUp(final PCEPSession session, final PathComputationClientBuilder pccBuilder) {
final InetAddress peerAddress = session.getRemoteAddress();
return false;
}
- @GuardedBy("this")
- private PlspId nextRequest() {
- return new PlspId(this.requestId++);
- }
-
@Override
public synchronized ListenableFuture<OperationResult> addLsp(final AddLspArgs input) {
Preconditions.checkArgument(input != null && input.getName() != null && input.getNode() != null && input.getArguments() != null, "Mandatory XML tags are missing.");
final RequestsBuilder rb = new RequestsBuilder();
rb.fieldsFrom(input.getArguments());
rb.setLspa(new LspaBuilder().setTlvs(
- new TlvsBuilder().addAugmentation(
- org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs2.class,
- new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs2Builder().setSymbolicPathName(
- name.build()).build()).build()).build());
+ new TlvsBuilder().addAugmentation(
+ org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs2.class,
+ new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated._00.rev140113.Tlvs2Builder().setSymbolicPathName(
+ name.build()).build()).build()).build());
final PcinitiateMessageBuilder ib = new PcinitiateMessageBuilder(MESSAGE_HEADER);
ib.setRequests(Collections.singletonList(rb.build()));
// Send the message
return sendMessage(new PcinitiateBuilder().setPcinitiateMessage(ib.build()).build(), input.getName(),
- input.getArguments().getMetadata());
+ input.getArguments().getMetadata());
}
});
}