YANG revision dates mass-update
[bgpcep.git] / pcep / topology / topology-provider / src / test / java / org / opendaylight / bgpcep / pcep / topology / provider / PCEPTriggeredReSynchronizationProcedureTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.bgpcep.pcep.topology.provider;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createLsp;
15 import static org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil.createPath;
16 import static org.opendaylight.protocol.util.CheckTestUtil.readDataOperational;
17
18 import java.util.Collections;
19 import java.util.List;
20 import java.util.Optional;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.protocol.pcep.PCEPSession;
24 import org.opendaylight.protocol.pcep.pcc.mock.spi.MsgBuilderUtil;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.Tlvs3;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.Tlvs3Builder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.lsp.db.version.tlv.LspDbVersion;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.lsp.db.version.tlv.LspDbVersionBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev181109.Stateful1;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.crabbe.initiated.rev181109.Stateful1Builder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.OperationalStatus;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.Pcrpt;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.PlspId;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.SrpIdNumber;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.SymbolicPathName;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.Tlvs1;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.Tlvs1Builder;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.identifiers.tlv.LspIdentifiersBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp.object.LspBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.srp.object.SrpBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.stateful.capability.tlv.StatefulBuilder;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.symbolic.path.name.tlv.SymbolicPathNameBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.Open;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.open.TlvsBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.LspId;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.PccSyncState;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.TriggerSyncInputBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.pcep.rev200120.pcep.client.attributes.path.computation.client.ReportedLsp;
50 import org.opendaylight.yangtools.yang.common.Uint32;
51 import org.opendaylight.yangtools.yang.common.Uint64;
52
53 public class PCEPTriggeredReSynchronizationProcedureTest
54         extends AbstractPCEPSessionTest<Stateful07TopologySessionListenerFactory> {
55     private Stateful07TopologySessionListener listener;
56
57     private PCEPSession session;
58     private final LspDbVersion lspDbVersion = new LspDbVersionBuilder().setLspDbVersionValue(Uint64.ONE).build();
59
60     @Override
61     @Before
62     public void setUp() throws Exception {
63         super.setUp();
64         this.listener = (Stateful07TopologySessionListener) getSessionListener();
65     }
66
67     @Test
68     public void testTriggeredResynchronization() throws Exception {
69         //session up - sync skipped (LSP-DBs match)
70         this.session = getPCEPSession(getOpen(), getOpen());
71         this.listener.onSessionUp(this.session);
72
73         //report LSP + LSP-DB version number
74         final Pcrpt pcRpt = getPcrt();
75         this.listener.onMessage(this.session, pcRpt);
76
77         readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
78             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
79             assertFalse(pcc.getReportedLsp().isEmpty());
80             return pcc;
81         });
82
83         //PCEP Trigger Full Resync
84         this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).build());
85         readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
86             assertEquals(PccSyncState.PcepTriggeredResync, pcc.getStateSync());
87             return pcc;
88         });
89
90         //end of sync
91         final Pcrpt syncMsg = getSyncMsg();
92         this.listener.onMessage(this.session, syncMsg);
93         readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
94             //check node - synchronized
95             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
96             return pcc;
97         });
98
99         this.listener.onMessage(this.session, pcRpt);
100         readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
101             final List<?> lsp = pcc.getReportedLsp();
102             assertNotNull(lsp);
103             assertEquals(1, lsp.size());
104             return pcc;
105         });
106
107         //Trigger Full Resync
108         this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).build());
109         this.listener.onMessage(this.session, pcRpt);
110         //end of sync
111         this.listener.onMessage(this.session, syncMsg);
112         readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
113             //check node - synchronized
114             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
115             //check reported LSP is not empty, Stale LSP state were purged
116             assertEquals(1, pcc.getReportedLsp().size());
117             return pcc;
118         });
119     }
120
121     @Test
122     public void testTriggeredResynchronizationLsp() throws Exception {
123         //session up - sync skipped (LSP-DBs match)
124
125         this.session = getPCEPSession(getOpen(), getOpen());
126         this.listener.onSessionUp(this.session);
127
128         //report LSP + LSP-DB version number
129         final Pcrpt pcRpt = getPcrt();
130         this.listener.onMessage(this.session, pcRpt);
131         readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
132             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
133             final List<ReportedLsp> reportedLspPcc = pcc.getReportedLsp();
134             assertFalse(reportedLspPcc.isEmpty());
135             return pcc;
136         });
137
138         //Trigger Full Resync
139         this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).setName("test").build());
140         readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
141             assertEquals(PccSyncState.PcepTriggeredResync, pcc.getStateSync());
142             assertFalse(pcc.getReportedLsp().isEmpty());
143             return pcc;
144         });
145
146         this.listener.onMessage(this.session, pcRpt);
147         readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
148             assertFalse(pcc.getReportedLsp().isEmpty());
149             return pcc;
150         });
151
152         //sync rpt + LSP-DB
153         final Pcrpt syncMsg = getSyncMsg();
154         this.listener.onMessage(this.session, syncMsg);
155         readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
156             //check node - synchronized
157             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
158             //check reported LSP
159             assertEquals(1, pcc.getReportedLsp().size());
160             return pcc;
161         });
162
163         //Trigger Full Resync
164         this.listener.triggerSync(new TriggerSyncInputBuilder().setNode(this.nodeId).setName("test").build());
165         this.listener.onMessage(this.session, syncMsg);
166         readDataOperational(getDataBroker(), this.pathComputationClientIId, pcc -> {
167             //check node - synchronized
168             assertEquals(PccSyncState.Synchronized, pcc.getStateSync());
169             //check reported LSP
170             assertNull(pcc.getReportedLsp());
171             return pcc;
172         });
173     }
174
175     private Open getOpen() {
176         return new OpenBuilder(super.getLocalPref()).setTlvs(new TlvsBuilder().addAugmentation(Tlvs1.class,
177             new Tlvs1Builder().setStateful(new StatefulBuilder().addAugmentation(Stateful1.class, new Stateful1Builder()
178                 .setInitiation(Boolean.TRUE).build()).addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight
179                     .params.xml.ns.yang.controller.pcep.sync.optimizations.rev181109.Stateful1.class,
180                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync.optimizations
181                     .rev181109.Stateful1Builder().setIncludeDbVersion(Boolean.TRUE).setTriggeredResync(Boolean.TRUE)
182                     .build()).build()).build()).addAugmentation(Tlvs3.class, new Tlvs3Builder()
183             .setLspDbVersion(this.lspDbVersion).build()).build()).build();
184     }
185
186     private static Pcrpt getSyncMsg() {
187         final SrpBuilder srpBuilder = new SrpBuilder();
188         // not sue whether use 0 instead of nextRequest() or do not insert srp == SRP-ID-number = 0
189         srpBuilder.setOperationId(new SrpIdNumber(Uint32.ONE));
190         return MsgBuilderUtil.createPcRtpMessage(createLsp(Uint32.ZERO, false, Optional.of(
191                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp
192                         .object.lsp.TlvsBuilder().addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params
193                                 .xml.ns.yang.controller.pcep.sync.optimizations.rev181109.Tlvs1.class,
194                     new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync
195                             .optimizations.rev181109.Tlvs1Builder()
196                         .setLspDbVersion(new LspDbVersionBuilder().setLspDbVersionValue(Uint64.valueOf(3L))
197                                 .build()).build()).build()), true, false),
198                             Optional.of(srpBuilder.build()), createPath(Collections.emptyList()));
199     }
200
201     private static Pcrpt getPcrt() {
202         return MsgBuilderUtil.createPcRtpMessage(new LspBuilder().setPlspId(new PlspId(Uint32.ONE)).setTlvs(
203                 new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev181109.lsp
204                         .object.lsp.TlvsBuilder().setLspIdentifiers(new LspIdentifiersBuilder()
205                         .setLspId(new LspId(Uint32.ONE)).build()).setSymbolicPathName(
206                     new SymbolicPathNameBuilder().setPathName(new SymbolicPathName("test".getBytes())).build())
207                     .addAugmentation(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep
208                                     .sync.optimizations.rev181109.Tlvs1.class,
209                         new org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.sync
210                                 .optimizations.rev181109.Tlvs1Builder().setLspDbVersion(new LspDbVersionBuilder()
211                                 .setLspDbVersionValue(Uint64.ONE).build()).build()).build())
212                 .setPlspId(new PlspId(Uint32.ONE)).setSync(true).setRemove(false)
213                         .setOperational(OperationalStatus.Active).build(), Optional.empty(),
214             createPath(Collections.emptyList()));
215     }
216 }