2 * Copyright (c) 2013 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.impl;
10 import org.opendaylight.protocol.concepts.HandlerRegistry;
11 import org.opendaylight.protocol.pcep.impl.object.PCEPBandwidthObjectParser;
12 import org.opendaylight.protocol.pcep.impl.object.PCEPClassTypeObjectParser;
13 import org.opendaylight.protocol.pcep.impl.object.PCEPCloseObjectParser;
14 import org.opendaylight.protocol.pcep.impl.object.PCEPEndPointsObjectParser;
15 import org.opendaylight.protocol.pcep.impl.object.PCEPErrorObjectParser;
16 import org.opendaylight.protocol.pcep.impl.object.PCEPExplicitRouteObjectParser;
17 import org.opendaylight.protocol.pcep.impl.object.PCEPGlobalConstraintsObjectParser;
18 import org.opendaylight.protocol.pcep.impl.object.PCEPIncludeRouteObjectParser;
19 import org.opendaylight.protocol.pcep.impl.object.PCEPLoadBalancingObjectParser;
20 import org.opendaylight.protocol.pcep.impl.object.PCEPLspObjectParser;
21 import org.opendaylight.protocol.pcep.impl.object.PCEPLspaObjectParser;
22 import org.opendaylight.protocol.pcep.impl.object.PCEPMetricObjectParser;
23 import org.opendaylight.protocol.pcep.impl.object.PCEPNoPathObjectParser;
24 import org.opendaylight.protocol.pcep.impl.object.PCEPNotificationObjectParser;
25 import org.opendaylight.protocol.pcep.impl.object.PCEPObjectiveFunctionObjectParser;
26 import org.opendaylight.protocol.pcep.impl.object.PCEPOpenObjectParser;
27 import org.opendaylight.protocol.pcep.impl.object.PCEPPathKeyObjectParser;
28 import org.opendaylight.protocol.pcep.impl.object.PCEPReportedRouteObjectParser;
29 import org.opendaylight.protocol.pcep.impl.object.PCEPRequestParameterObjectParser;
30 import org.opendaylight.protocol.pcep.impl.object.PCEPSrpObjectParser;
31 import org.opendaylight.protocol.pcep.impl.object.PCEPSvecObjectParser;
32 import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
33 import org.opendaylight.protocol.pcep.spi.ObjectParser;
34 import org.opendaylight.protocol.pcep.spi.ObjectSerializer;
35 import org.opendaylight.protocol.pcep.spi.SubobjectHandlerRegistry;
36 import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.BandwidthObject;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClasstypeObject;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseObject;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.EndpointsObject;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExplicitRouteObject;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.GcObject;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.IncludeRouteObject;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LoadBalancingObject;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspObject;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.LspaObject;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.MetricObject;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NoPathObject;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.NotificationObject;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfObject;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PathKeyObject;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.PcepErrorObject;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ReportedRouteObject;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RpObject;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpObject;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SvecObject;
59 import org.opendaylight.yangtools.yang.binding.DataContainer;
61 import com.google.common.base.Preconditions;
66 public final class SimpleObjectHandlerRegistry implements ObjectHandlerRegistry {
67 public static final ObjectHandlerRegistry INSTANCE;
70 final ObjectHandlerRegistry reg = new SimpleObjectHandlerRegistry();
72 final SubobjectHandlerRegistry subobjReg = SimpleSubobjectHandlerFactory.INSTANCE;
73 final TlvHandlerRegistry tlvReg = SimpleTlvHandlerRegistry.INSTANCE;
75 reg.registerObjectParser(PCEPOpenObjectParser.CLASS, PCEPOpenObjectParser.TYPE, new PCEPOpenObjectParser(subobjReg, tlvReg));
76 reg.registerObjectParser(PCEPRequestParameterObjectParser.CLASS, PCEPRequestParameterObjectParser.TYPE,
77 new PCEPRequestParameterObjectParser(subobjReg, tlvReg));
78 reg.registerObjectParser(PCEPNoPathObjectParser.CLASS, PCEPNoPathObjectParser.TYPE, new PCEPNoPathObjectParser(subobjReg, tlvReg));
79 reg.registerObjectParser(PCEPEndPointsObjectParser.CLASS, PCEPEndPointsObjectParser.TYPE, new PCEPEndPointsObjectParser(subobjReg, tlvReg));
80 reg.registerObjectParser(PCEPEndPointsObjectParser.CLASS_6, PCEPEndPointsObjectParser.TYPE_6, new PCEPEndPointsObjectParser(subobjReg, tlvReg));
81 reg.registerObjectParser(PCEPBandwidthObjectParser.CLASS, PCEPBandwidthObjectParser.TYPE, new PCEPBandwidthObjectParser(subobjReg, tlvReg));
82 reg.registerObjectParser(PCEPBandwidthObjectParser.E_CLASS, PCEPBandwidthObjectParser.E_TYPE, new PCEPBandwidthObjectParser(subobjReg, tlvReg));
83 reg.registerObjectParser(PCEPMetricObjectParser.CLASS, PCEPMetricObjectParser.TYPE, new PCEPMetricObjectParser(subobjReg, tlvReg));
84 reg.registerObjectParser(PCEPExplicitRouteObjectParser.CLASS, PCEPExplicitRouteObjectParser.TYPE,
85 new PCEPExplicitRouteObjectParser(subobjReg, tlvReg));
86 reg.registerObjectParser(PCEPReportedRouteObjectParser.CLASS, PCEPReportedRouteObjectParser.TYPE,
87 new PCEPReportedRouteObjectParser(subobjReg, tlvReg));
88 reg.registerObjectParser(PCEPLspaObjectParser.CLASS, PCEPLspaObjectParser.TYPE, new PCEPLspaObjectParser(subobjReg, tlvReg));
89 reg.registerObjectParser(PCEPIncludeRouteObjectParser.CLASS, PCEPIncludeRouteObjectParser.TYPE,
90 new PCEPIncludeRouteObjectParser(subobjReg, tlvReg));
91 reg.registerObjectParser(PCEPSvecObjectParser.CLASS, PCEPSvecObjectParser.TYPE, new PCEPSvecObjectParser(subobjReg, tlvReg));
92 reg.registerObjectParser(PCEPNotificationObjectParser.CLASS, PCEPNotificationObjectParser.TYPE,
93 new PCEPNotificationObjectParser(subobjReg, tlvReg));
94 reg.registerObjectParser(PCEPErrorObjectParser.CLASS, PCEPErrorObjectParser.TYPE, new PCEPErrorObjectParser(subobjReg, tlvReg));
95 reg.registerObjectParser(PCEPLoadBalancingObjectParser.CLASS, PCEPLoadBalancingObjectParser.TYPE,
96 new PCEPLoadBalancingObjectParser(subobjReg, tlvReg));
97 reg.registerObjectParser(PCEPCloseObjectParser.CLASS, PCEPCloseObjectParser.TYPE, new PCEPCloseObjectParser(subobjReg, tlvReg));
98 reg.registerObjectParser(PCEPPathKeyObjectParser.CLASS, PCEPPathKeyObjectParser.TYPE, new PCEPPathKeyObjectParser(subobjReg, tlvReg));
99 reg.registerObjectParser(PCEPObjectiveFunctionObjectParser.CLASS, PCEPObjectiveFunctionObjectParser.TYPE,
100 new PCEPObjectiveFunctionObjectParser(subobjReg, tlvReg));
101 reg.registerObjectParser(PCEPClassTypeObjectParser.CLASS, PCEPClassTypeObjectParser.TYPE, new PCEPClassTypeObjectParser(subobjReg, tlvReg));
102 reg.registerObjectParser(PCEPGlobalConstraintsObjectParser.CLASS, PCEPGlobalConstraintsObjectParser.TYPE,
103 new PCEPGlobalConstraintsObjectParser(subobjReg, tlvReg));
104 reg.registerObjectParser(PCEPLspObjectParser.CLASS, PCEPLspObjectParser.TYPE, new PCEPLspObjectParser(subobjReg, tlvReg));
105 reg.registerObjectParser(PCEPSrpObjectParser.CLASS, PCEPSrpObjectParser.TYPE, new PCEPSrpObjectParser(subobjReg, tlvReg));
106 // reg.registerObjectParser(PCEPExcludeRouteObjectParser.CLASS, PCEPExcludeRouteObjectParser.TYPE, new
107 // PCEPExcludeRouteObjectParser(reg));
109 reg.registerObjectSerializer(OpenObject.class, new PCEPOpenObjectParser(subobjReg, tlvReg));
110 reg.registerObjectSerializer(RpObject.class, new PCEPRequestParameterObjectParser(subobjReg, tlvReg));
111 reg.registerObjectSerializer(NoPathObject.class, new PCEPNoPathObjectParser(subobjReg, tlvReg));
112 reg.registerObjectSerializer(EndpointsObject.class, new PCEPEndPointsObjectParser(subobjReg, tlvReg));
113 reg.registerObjectSerializer(BandwidthObject.class, new PCEPBandwidthObjectParser(subobjReg, tlvReg));
114 reg.registerObjectSerializer(MetricObject.class, new PCEPMetricObjectParser(subobjReg, tlvReg));
115 reg.registerObjectSerializer(ExplicitRouteObject.class, new PCEPExplicitRouteObjectParser(subobjReg, tlvReg));
116 reg.registerObjectSerializer(ReportedRouteObject.class, new PCEPReportedRouteObjectParser(subobjReg, tlvReg));
117 reg.registerObjectSerializer(LspaObject.class, new PCEPLspaObjectParser(subobjReg, tlvReg));
118 reg.registerObjectSerializer(IncludeRouteObject.class, new PCEPIncludeRouteObjectParser(subobjReg, tlvReg));
119 reg.registerObjectSerializer(SvecObject.class, new PCEPSvecObjectParser(subobjReg, tlvReg));
120 reg.registerObjectSerializer(NotificationObject.class, new PCEPNotificationObjectParser(subobjReg, tlvReg));
121 reg.registerObjectSerializer(PcepErrorObject.class, new PCEPErrorObjectParser(subobjReg, tlvReg));
122 reg.registerObjectSerializer(LoadBalancingObject.class, new PCEPLoadBalancingObjectParser(subobjReg, tlvReg));
123 reg.registerObjectSerializer(CloseObject.class, new PCEPCloseObjectParser(subobjReg, tlvReg));
124 reg.registerObjectSerializer(PathKeyObject.class, new PCEPPathKeyObjectParser(subobjReg, tlvReg));
125 reg.registerObjectSerializer(OfObject.class, new PCEPObjectiveFunctionObjectParser(subobjReg, tlvReg));
126 reg.registerObjectSerializer(ClasstypeObject.class, new PCEPClassTypeObjectParser(subobjReg, tlvReg));
127 reg.registerObjectSerializer(GcObject.class, new PCEPGlobalConstraintsObjectParser(subobjReg, tlvReg));
128 reg.registerObjectSerializer(LspObject.class, new PCEPLspObjectParser(subobjReg, tlvReg));
129 reg.registerObjectSerializer(SrpObject.class, new PCEPSrpObjectParser(subobjReg, tlvReg));
130 // reg.registerObjectSerializer(ExcludeRouteObject.class, new PCEPExcludeRouteObjectParser(reg));
135 private final HandlerRegistry<DataContainer, ObjectParser, ObjectSerializer> handlers = new HandlerRegistry<>();
137 private static final int createKey(final int objectClass, final int objectType) {
138 Preconditions.checkArgument(objectClass >= 0 && objectClass <= 255);
139 Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
140 return (objectClass << 4) | objectType;
144 public AutoCloseable registerObjectParser(final int objectClass, final int objectType, final ObjectParser parser) {
145 Preconditions.checkArgument(objectClass >= 0 && objectClass <= 255);
146 Preconditions.checkArgument(objectType >= 0 && objectType <= 15);
147 return handlers.registerParser(createKey(objectClass, objectType), parser);
151 public AutoCloseable registerObjectSerializer(final Class<? extends Object> objClass, final ObjectSerializer serializer) {
152 return handlers.registerSerializer(objClass, serializer);
156 public ObjectParser getObjectParser(final int objectClass, final int objectType) {
157 return handlers.getParser(createKey(objectClass, objectType));
161 public ObjectSerializer getObjectSerializer(final Object object) {
162 return handlers.getSerializer(object.getImplementedInterface());