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.spi;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.ArgumentMatchers.anyBoolean;
12 import static org.mockito.ArgumentMatchers.anyList;
13 import static org.mockito.Mockito.doNothing;
14 import static org.mockito.Mockito.doReturn;
16 import io.netty.buffer.ByteBuf;
17 import io.netty.buffer.Unpooled;
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.Mock;
25 import org.mockito.junit.MockitoJUnitRunner;
26 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
27 import org.opendaylight.protocol.pcep.spi.pojo.SimplePCEPExtensionProviderContext;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.iana.rev130816.EnterpriseNumber;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.Keepalive;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev181109.KeepaliveBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Message;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.ObjectHeader;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Tlv;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.Subobject;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.exclude.route.object.xro.SubobjectBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.list.tlv.OfList;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.list.tlv.OfListBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.open.object.OpenBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.rp.object.Rp;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.EnterpriseSpecificInformation;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.tlvs.VendorInformationTlv;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route.subobjects.subobject.type.IpPrefixCaseBuilder;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820._record.route.subobjects.subobject.type.LabelCase;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCase;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.AsNumberCaseBuilder;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.basic.explicit.route.subobjects.subobject.type.IpPrefixCase;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.LabelType;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCase;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCaseBuilder;
52 import org.opendaylight.yangtools.concepts.Registration;
53 import org.opendaylight.yangtools.yang.common.Uint32;
55 @RunWith(MockitoJUnitRunner.StrictStubs.class)
56 public class RegistryTest {
59 XROSubobjectParser xroParser;
61 XROSubobjectSerializer xroSerializer;
64 RROSubobjectParser rroParser;
66 RROSubobjectSerializer rroSerializer;
69 EROSubobjectParser eroParser;
71 EROSubobjectSerializer eroSerializer;
76 TlvSerializer tlvSerializer;
79 ObjectParser objectParser;
82 ObjectSerializer objectSerializer;
85 MessageParser msgParser;
87 MessageSerializer msgSerializer;
90 LabelParser labelParser;
92 LabelSerializer labelSerializer;
95 VendorInformationObject esi;
98 EnterpriseSpecificInformation es;
101 VendorInformationTlv viTlv;
103 public final List<Registration> regs = new ArrayList<>();
105 final PCEPExtensionProviderContext ctx = new SimplePCEPExtensionProviderContext();
107 @SuppressWarnings("unchecked")
109 public void setUp() throws PCEPDeserializerException {
110 doReturn(null).when(this.xroParser).parseSubobject(any(ByteBuf.class), anyBoolean());
111 doNothing().when(this.xroSerializer).serializeSubobject(any(Subobject.class), any(ByteBuf.class));
113 doReturn(this.viTlv).when(this.tlvParser).parseTlv(any(ByteBuf.class));
114 doNothing().when(this.tlvSerializer).serializeTlv(any(Tlv.class), any(ByteBuf.class));
116 doReturn(5).when(this.objectParser).getObjectClass();
117 doReturn(1).when(this.objectParser).getObjectType();
118 doReturn(new OpenBuilder().build()).when(this.objectParser).parseObject(any(ObjectHeader.class),
120 doNothing().when(this.objectSerializer).serializeObject(any(Object.class), any(ByteBuf.class));
122 doReturn(null).when(this.msgParser).parseMessage(any(ByteBuf.class), anyList());
123 doNothing().when(this.msgSerializer).serializeMessage(any(Message.class), any(ByteBuf.class));
125 doNothing().when(this.labelSerializer).serializeLabel(anyBoolean(), anyBoolean(), any(LabelType.class),
128 doReturn(this.es).when(this.esi).getEnterpriseSpecificInformation();
130 doReturn(this.es).when(this.viTlv).getEnterpriseSpecificInformation();
132 doReturn(EnterpriseSpecificInformation.class).when(this.es).implementedInterface();
136 public void testRegistry() throws PCEPDeserializerException {
137 this.regs.add(this.ctx.registerXROSubobjectParser(2, this.xroParser));
138 this.regs.add(this.ctx.registerXROSubobjectSerializer(AsNumberCase.class, this.xroSerializer));
140 this.regs.add(this.ctx.registerRROSubobjectParser(3, this.rroParser));
141 this.regs.add(this.ctx.registerRROSubobjectSerializer(LabelCase.class, this.rroSerializer));
143 this.regs.add(this.ctx.registerEROSubobjectParser(4, this.eroParser));
144 this.regs.add(this.ctx.registerEROSubobjectSerializer(IpPrefixCase.class, this.eroSerializer));
146 this.regs.add(this.ctx.registerTlvParser(1, this.tlvParser));
147 this.regs.add(this.ctx.registerTlvSerializer(OfList.class, this.tlvSerializer));
149 this.regs.add(this.ctx.registerObjectParser(this.objectParser));
150 this.regs.add(this.ctx.registerObjectSerializer(Rp.class, this.objectSerializer));
152 this.regs.add(this.ctx.registerMessageParser(6, this.msgParser));
153 this.regs.add(this.ctx.registerMessageSerializer(Keepalive.class, this.msgSerializer));
155 this.regs.add(this.ctx.registerLabelParser(7, this.labelParser));
156 this.regs.add(this.ctx.registerLabelSerializer(Type1LabelCase.class, this.labelSerializer));
158 this.regs.add(this.ctx.registerVendorInformationObjectParser(new EnterpriseNumber(Uint32.TEN),
160 this.regs.add(this.ctx.registerVendorInformationObjectSerializer(EnterpriseSpecificInformation.class,
161 this.objectSerializer));
163 this.regs.add(this.ctx.registerVendorInformationTlvParser(new EnterpriseNumber(Uint32.valueOf(12)),
165 this.regs.add(this.ctx.registerVendorInformationTlvSerializer(EnterpriseSpecificInformation.class,
166 this.tlvSerializer));
168 final ByteBuf buffer = Unpooled.buffer();
169 this.ctx.getXROSubobjectHandlerRegistry().parseSubobject(2, buffer, false);
170 this.ctx.getXROSubobjectHandlerRegistry().serializeSubobject(new SubobjectBuilder()
171 .setSubobjectType(new AsNumberCaseBuilder().build()).build(), buffer);
173 this.ctx.getEROSubobjectHandlerRegistry().parseSubobject(3, buffer, true);
174 this.ctx.getEROSubobjectHandlerRegistry().serializeSubobject(new org.opendaylight.yang.gen.v1.urn.opendaylight
175 .params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.ero.SubobjectBuilder()
176 .setSubobjectType(new AsNumberCaseBuilder().build()).build(), buffer);
178 this.ctx.getRROSubobjectHandlerRegistry().parseSubobject(4, buffer);
179 this.ctx.getRROSubobjectHandlerRegistry().serializeSubobject(new org.opendaylight.yang.gen.v1.urn.opendaylight
180 .params.xml.ns.yang.pcep.types.rev181109.reported.route.object.rro.SubobjectBuilder()
181 .setSubobjectType(new IpPrefixCaseBuilder().build()).build(), buffer);
183 this.ctx.getLabelHandlerRegistry().parseLabel(1, buffer);
184 this.ctx.getLabelHandlerRegistry().serializeLabel(true, false, new Type1LabelCaseBuilder().build(), buffer);
186 this.ctx.getTlvHandlerRegistry().parseTlv(2, buffer);
187 this.ctx.getTlvHandlerRegistry().serializeTlv(new OfListBuilder().build(), buffer);
189 this.ctx.getObjectHandlerRegistry().parseObject(4, 1, new ObjectHeaderImpl(true, false), buffer);
190 this.ctx.getObjectHandlerRegistry().serializeObject(new OpenBuilder().build(), buffer);
192 this.ctx.getMessageHandlerRegistry().parseMessage(6, buffer, Collections.emptyList());
193 this.ctx.getMessageHandlerRegistry().serializeMessage(new KeepaliveBuilder().build(), buffer);
195 this.ctx.getVendorInformationObjectRegistry().parseVendorInformationObject(
196 new EnterpriseNumber(Uint32.TEN), new ObjectHeaderImpl(true, false), buffer);
197 this.ctx.getVendorInformationObjectRegistry().serializeVendorInformationObject(this.esi, buffer);
199 this.ctx.getVendorInformationTlvRegistry().parseVendorInformationTlv(
200 new EnterpriseNumber(Uint32.valueOf(12)), buffer);
201 this.ctx.getVendorInformationTlvRegistry().serializeVendorInformationTlv(this.viTlv, buffer);