2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.protocol.pcep.segment.routing;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.opendaylight.protocol.util.CheckTestUtil.readDataOperational;
14 import com.google.common.collect.Lists;
15 import java.nio.charset.StandardCharsets;
16 import java.util.List;
18 import java.util.concurrent.ExecutionException;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.opendaylight.bgpcep.pcep.topology.provider.AbstractPCEPSessionTest;
22 import org.opendaylight.bgpcep.pcep.topology.provider.AbstractTopologySessionListener;
23 import org.opendaylight.bgpcep.pcep.topology.provider.Stateful07TopologySessionListenerFactory;
24 import org.opendaylight.protocol.pcep.PCEPSession;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressNoZone;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4AddressNoZone;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.Path1;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.Pcrpt;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.PcrptBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.PlspId;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.SrpIdNumber;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.SymbolicPathName;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.LspIdentifiersBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.object.LspBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.object.lsp.TlvsBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.pcrpt.message.PcrptMessageBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.pcrpt.message.pcrpt.message.ReportsBuilder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.pcrpt.message.pcrpt.message.reports.PathBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.srp.object.SrpBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.symbolic.path.name.tlv.SymbolicPathNameBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.SidType;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.network.topology.topology.node.path.computation.client.reported.lsp.path.ero.subobject.subobject.type.SrEroType;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.pcrpt.pcrpt.message.reports.path.ero.subobject.subobject.type.SrEroTypeBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.subobject.nai.IpNodeId;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.segment.routing.rev181109.sr.subobject.nai.IpNodeIdBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.EroBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.Subobject;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.path.setup.type.tlv.PathSetupTypeBuilder;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLspKey;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.reported.lsp.Path;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.reported.lsp.PathKey;
56 import org.opendaylight.yangtools.yang.common.Uint32;
57 import org.opendaylight.yangtools.yang.common.Uint8;
59 public class TopologyProviderTest extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
61 private AbstractTopologySessionListener<SrpIdNumber, PlspId> listener;
62 private PCEPSession session;
65 @SuppressWarnings("unchecked")
67 public void setUp() throws Exception {
69 this.listener = (AbstractTopologySessionListener<SrpIdNumber, PlspId>) getSessionListener();
70 this.session = getPCEPSession(getLocalPref(), getRemotePref());
74 public void testOnReportMessage() throws ExecutionException, InterruptedException {
75 this.listener.onSessionUp(this.session);
77 Pcrpt pcRptMsg = createSrPcRpt("1.1.1.1", "sr-path1", Uint32.ONE, true);
78 this.listener.onMessage(this.session, pcRptMsg);
79 readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
81 final Map<ReportedLspKey, ReportedLsp> reportedLsps = pcc.getReportedLsp();
82 assertNotNull(reportedLsps);
83 assertEquals(1, reportedLsps.size());
84 final ReportedLsp lsp = reportedLsps.values().iterator().next();
85 assertEquals("sr-path1", lsp.getName());
87 final Map<PathKey, Path> paths = lsp.getPath();
89 final Path path = paths.values().iterator().next();
91 assertEquals(1, path.augmentation(Path1.class).getPathSetupType().getPst().intValue());
92 final List<Subobject> subobjects = path.getEro().nonnullSubobject();
93 assertEquals(1, subobjects.size());
94 assertEquals("1.1.1.1", ((IpNodeId)((SrEroType)subobjects.get(0).getSubobjectType())
95 .getNai()).getIpAddress().getIpv4AddressNoZone().getValue());
99 pcRptMsg = createSrPcRpt("1.1.1.3", "sr-path2", Uint32.TWO, false);
100 this.listener.onMessage(this.session, pcRptMsg);
101 readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
102 //check second lsp sr-path
103 final Map<ReportedLspKey, ReportedLsp> reportedLsps = pcc.getReportedLsp();
104 assertNotNull(reportedLsps);
105 assertEquals(2, reportedLsps.size());
110 pcRptMsg = createSrPcRpt("1.1.1.2", "sr-path1", Uint32.ONE, true);
111 this.listener.onMessage(this.session, pcRptMsg);
112 readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
113 //check updated sr-path
114 final Map<ReportedLspKey, ReportedLsp> reportedLsps = pcc.getReportedLsp();
115 assertNotNull(reportedLsps);
116 assertEquals(2, reportedLsps.size());
117 for (final ReportedLsp rlsp : reportedLsps.values()) {
118 if (rlsp.getName().equals("sr-path1")) {
119 final List<Subobject> subobjects = rlsp.nonnullPath().values().iterator().next()
120 .getEro().nonnullSubobject();
121 assertEquals(1, subobjects.size());
122 assertEquals("1.1.1.2", ((IpNodeId)((SrEroType)subobjects.get(0)
123 .getSubobjectType()).getNai()).getIpAddress().getIpv4AddressNoZone().getValue());
130 private static Pcrpt createSrPcRpt(final String nai, final String pathName, final Uint32 plspId,
131 final boolean hasLspIdTlv) {
132 final TlvsBuilder lspTlvBuilder = new TlvsBuilder();
134 lspTlvBuilder.setLspIdentifiers(new LspIdentifiersBuilder().setLspId(new LspId(plspId)).build());
136 return new PcrptBuilder().setPcrptMessage(new PcrptMessageBuilder().setReports(Lists.newArrayList(
137 new ReportsBuilder().setLsp(new LspBuilder().setPlspId(new PlspId(plspId)).setRemove(false).setSync(true)
138 .setAdministrative(true).setDelegate(true)
139 .setTlvs(lspTlvBuilder.setSymbolicPathName(new SymbolicPathNameBuilder()
140 .setPathName(new SymbolicPathName(pathName.getBytes(StandardCharsets.UTF_8))).build()).build())
142 .setSrp(new SrpBuilder().setOperationId(new SrpIdNumber(Uint32.ZERO)).setTlvs(
143 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109
144 .srp.object.srp.TlvsBuilder()
145 .setPathSetupType(new PathSetupTypeBuilder().setPst(Uint8.ONE).build()).build()).build())
146 .setPath(new PathBuilder().setEro(createSrEroObject(nai)).build())
147 .build())).build()).build();
150 private static Ero createSrEroObject(final String nai) {
151 final SrEroTypeBuilder srEroBuilder = new SrEroTypeBuilder()
154 .setSidType(SidType.Ipv4NodeId)
155 .setSid(Uint32.valueOf(123456))
156 .setNai(new IpNodeIdBuilder().setIpAddress(new IpAddressNoZone(new Ipv4AddressNoZone(nai)))
158 final SubobjectBuilder subobjBuilder = new SubobjectBuilder().setSubobjectType(srEroBuilder.build())
161 final List<Subobject> subobjects = Lists.newArrayList(subobjBuilder.build());
162 return new EroBuilder().setProcessingRule(false).setIgnore(false).setSubobject(subobjects).build();