<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
- <scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools.model</groupId>
</plugin>
</plugins>
</build>
-</project>
\ No newline at end of file
+</project>
package org.opendaylight.protocol.pcep.pcc.mock;
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.LoggerContext;
import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
import com.google.common.net.InetAddresses;
import io.netty.util.concurrent.DefaultPromise;
import io.netty.util.concurrent.GlobalEventExecutor;
public static void main(String[] args) throws InterruptedException, ExecutionException, UnknownHostException {
if (args.length < 2) {
- LOG.info("Insufficient number of arguments {}.", args.length);
+ LOG.error("Insufficient number of arguments {}.", args.length);
return;
}
int pccCount = 1;
int lsps = 1;
boolean pcError = false;
+ final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+ getRootLogger(lc).setLevel(ch.qos.logback.classic.Level.INFO);
int argIdx = 0;
while (argIdx < args.length) {
if (args[argIdx].equals("--local-address")) {
- localAddress = InetAddress.getByName(args[argIdx + 1]);
- argIdx++;
+ localAddress = InetAddress.getByName(args[++argIdx]);
} else if (args[argIdx].equals("--remote-address")) {
- remoteAddress = InetAddress.getByName(args[argIdx + 1]);
- argIdx++;
+ remoteAddress = InetAddress.getByName(args[++argIdx]);
} else if (args[argIdx].equals("--pcc")) {
- pccCount = Integer.valueOf(args[argIdx + 1]);
- argIdx++;
+ pccCount = Integer.valueOf(args[++argIdx]);
} else if (args[argIdx].equals("--lsp")) {
- lsps = Integer.valueOf(args[argIdx + 1]);
- argIdx++;
+ lsps = Integer.valueOf(args[++argIdx]);
} else if (args[argIdx].equals("--pcerr")) {
pcError = true;
- argIdx++;
+ } else if (args[argIdx].equals("--log-level")) {
+ getRootLogger(lc).setLevel(Level.toLevel(args[++argIdx], ch.qos.logback.classic.Level.INFO));
} else {
LOG.warn("WARNING: Unrecognized argument: {}", args[argIdx]);
}
InetAddress currentAddress = localAddress;
int i = 0;
while (i < pccCount) {
- final int pccNumber = i + 1;
final InetAddress pccAddress = currentAddress;
pcc.createClient(new InetSocketAddress(pccAddress, 0), new InetSocketAddress(pceAddress, DEFAULT_PORT),
new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, RECONNECT_STRATEGY_TIMEOUT),
@Override
public PCEPSessionListener getSessionListener() {
- return new SimpleSessionListener(lspsPerPcc, pcerr, pccNumber, pccAddress);
+ return new SimpleSessionListener(lspsPerPcc, pcerr, pccAddress);
}
}).get();
i++;
}
}
+ private static ch.qos.logback.classic.Logger getRootLogger(final LoggerContext lc) {
+ return Iterables.find(lc.getLoggerList(), new Predicate<Logger>() {
+ @Override
+ public boolean apply(Logger input) {
+ return input.getName().equals(Logger.ROOT_LOGGER_NAME);
+ }
+ });
+ }
+
}
new Ipv4ExtendedTunnelId(extendedTunnelAddress.getHostAddress()))
.build()).build()).setTunnelId(new TunnelId((int) lspId)).build());
if (symbolicPathName) {
+ final String pathName = "pcc_" + tunnelSender.getHostAddress() + "_tunnel_" + lspId;
tlvs.setSymbolicPathName(new SymbolicPathNameBuilder().setPathName(
- new SymbolicPathName(Charsets.UTF_8.encode("tunnel" + lspId).array())).build());
+ new SymbolicPathName(pathName.getBytes(Charsets.UTF_8))).build());
}
return tlvs.build();
}
private static final Logger LOG = LoggerFactory.getLogger(SimpleSessionListener.class);
- private final int pccNumber;
private final int lspsCount;
private final boolean pcError;
private final InetAddress address;
- public SimpleSessionListener(final int lspsCount, final boolean pcError, final int pccNumber,
- final InetAddress address) {
+ public SimpleSessionListener(final int lspsCount, final boolean pcError, final InetAddress address) {
Preconditions.checkArgument(lspsCount > 0);
this.lspsCount = lspsCount;
this.pcError = pcError;
- this.pccNumber = pccNumber;
this.address = address;
}
@Override
public void onMessage(final PCEPSession session, final Message message) {
- LOG.debug("Received message: {}", message);
+ LOG.trace("Received message: {}", message);
if (message instanceof Pcupd) {
final Pcupd updMsg = (Pcupd) message;
final Updates updates = updMsg.getPcupdMessage().getUpdates().get(0);
public void onSessionUp(final PCEPSession session) {
LOG.debug("Session up.");
for (int i = 1; i <= this.lspsCount; i++) {
- final Tlvs tlvs = MsgBuilderUtil.createLspTlvs(i * this.pccNumber, true, this.address, this.address,
+ final Tlvs tlvs = MsgBuilderUtil.createLspTlvs(i, true, this.address, this.address,
this.address);
session.sendMessage(createPcRtpMessage(
- createLsp(i * this.pccNumber, true, Optional.<Tlvs> fromNullable(tlvs)), Optional.<Srp> absent(),
+ createLsp(i, true, Optional.<Tlvs> fromNullable(tlvs)), Optional.<Srp> absent(),
createPath(Collections.<Subobject> emptyList())));
}
// end-of-sync marker
@Override
public void onSessionDown(final PCEPSession session, final Exception e) {
- LOG.debug("Session down with cause : {} or exception: {}", e.getCause(), e, e);
+ LOG.info("Session down with cause : {} or exception: {}", e.getCause(), e, e);
session.close();
}
@Override
public void onSessionTerminated(final PCEPSession session, final PCEPTerminationReason cause) {
- LOG.debug("Session terminated. Cause : {}", cause.toString());
+ LOG.info("Session terminated. Cause : {}", cause.toString());
}
private InetAddress getDestinationAddress(final List<Subobject> subobjects) {
try {
return InetAddress.getByName(prefix.substring(0, prefix.indexOf('/')));
} catch (UnknownHostException e) {
- LOG.debug("Unknown host name {}", prefix);
+ LOG.warn("Unknown host name {}", prefix);
}
}
return this.address;
public void testSessionEstablishment() {
try {
org.opendaylight.protocol.pcep.testtool.Main.main(new String[]{"-a", "127.0.1.0:4189", "-ka", "10", "-d", "0", "--stateful", "--active"});
- Main.main(new String[] {"--local-address", "127.0.0.1", "--remote-address", "127.0.1.0", "--pcc", "2", "--lsp", "1"});
+ Main.main(new String[] {"--local-address", "127.0.0.1", "--remote-address", "127.0.1.0", "--pcc", "2", "--lsp", "1", "--log-level", "DEBUG"});
} catch (Exception e) {
- Assert.fail();
+ Assert.fail(e.getMessage());
}
}
@Test
public void testSessionListenerPcRpt() throws UnknownHostException {
- final SimpleSessionListener sessionListser = new SimpleSessionListener(1, false, 1,
- InetAddress.getByName(IP_ADDRESS));
+ final SimpleSessionListener sessionListser = new SimpleSessionListener(1, false, InetAddress.getByName(IP_ADDRESS));
sessionListser.onSessionUp(this.mockedSession);
// one lsp + end-of-sync marker
@Test
public void testSessionListenerPcErr() throws UnknownHostException {
- final SimpleSessionListener sessionListser = new SimpleSessionListener(1, true, 1,
- InetAddress.getByName(IP_ADDRESS));
+ final SimpleSessionListener sessionListser = new SimpleSessionListener(1, true, InetAddress.getByName(IP_ADDRESS));
sessionListser.onMessage(this.mockedSession, createUpdMsg());
// send PcErr as a response to PcUpd
public class Stateful07TopologySessionListenerTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
+ private static final String TUNNEL_NAME = "pcc_" + TEST_ADDRESS + "_tunnel_0";
+
private Stateful07TopologySessionListener listener;
@Before
pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
assertEquals(1, pcc.getReportedLsp().size());
ReportedLsp reportedLsp = pcc.getReportedLsp().get(0);
- assertEquals(TEST_LSP_NAME, reportedLsp.getName());
+ assertEquals(TUNNEL_NAME, reportedLsp.getName());
assertEquals(1, reportedLsp.getPath().size());
Path path = reportedLsp.getPath().get(0);
assertEquals(1, path.getEro().getSubobject().size());
org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder updArgsBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.update.lsp.args.ArgumentsBuilder();
updArgsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(ERO_IP_PREFIX, DST_IP_PREFIX)));
updArgsBuilder.addAugmentation(Arguments3.class, new Arguments3Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
- final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TEST_LSP_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
+ final UpdateLspInput update = new UpdateLspInputBuilder().setArguments(updArgsBuilder.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
this.topologyRpcs.updateLsp(update);
assertEquals(2, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(1) instanceof Pcupd);
pcc = topology.getNode().get(0).getAugmentation(Node1.class).getPathComputationClient();
assertEquals(1, pcc.getReportedLsp().size());
reportedLsp = pcc.getReportedLsp().get(0);
- assertEquals(TEST_LSP_NAME, reportedLsp.getName());
+ assertEquals(TUNNEL_NAME, reportedLsp.getName());
assertEquals(1, reportedLsp.getPath().size());
path = reportedLsp.getPath().get(0);
assertEquals(2, path.getEro().getSubobject().size());
// ensure-operational
final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.ensure.lsp.operational.args.ArgumentsBuilder ensureArgs = new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev131024.ensure.lsp.operational.args.ArgumentsBuilder();
ensureArgs.addAugmentation(Arguments1.class, new Arguments1Builder().setOperational(OperationalStatus.Active).build());
- final EnsureLspOperationalInput ensure = new EnsureLspOperationalInputBuilder().setArguments(ensureArgs.build()).setName(TEST_LSP_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
+ final EnsureLspOperationalInput ensure = new EnsureLspOperationalInputBuilder().setArguments(ensureArgs.build()).setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
final OperationResult result = this.topologyRpcs.ensureLspOperational(ensure).get().getResult();
//check result
assertNull(result.getFailure());
// remove-lsp
- final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TEST_LSP_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
+ final RemoveLspInput remove = new RemoveLspInputBuilder().setName(TUNNEL_NAME).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
this.topologyRpcs.removeLsp(remove);
assertEquals(3, this.receivedMsgs.size());
assertTrue(this.receivedMsgs.get(2) instanceof Pcinitiate);
argsBuilder.setEndpointsObj(new EndpointsObjBuilder().setAddressFamily(ipv4Builder.build()).build());
argsBuilder.setEro(createEroWithIpPrefixes(Lists.newArrayList(ERO_IP_PREFIX)));
argsBuilder.addAugmentation(Arguments2.class, new Arguments2Builder().setLsp(new LspBuilder().setDelegate(true).setAdministrative(true).build()).build());
- return new AddLspInputBuilder().setName(TEST_LSP_NAME).setArguments(argsBuilder.build()).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
+ return new AddLspInputBuilder().setName(TUNNEL_NAME).setArguments(argsBuilder.build()).setNetworkTopologyRef(new NetworkTopologyRef(TOPO_IID)).setNode(NODE_ID).build();
}
}