blob: cd39d4766f42b11522a9239d2796fa68d341c194 [file] [log] [blame]
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -08003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.codec.impl;
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080017
Jian Li72315152015-12-10 17:20:43 -080018import com.codahale.metrics.Metric;
Thomas Vachuskade563cf2015-04-01 00:28:50 -070019import com.google.common.collect.ImmutableSet;
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080020import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
23import org.apache.felix.scr.annotations.Service;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080024import org.onlab.packet.Ethernet;
Thomas Vachuskade563cf2015-04-01 00:28:50 -070025import org.onosproject.cluster.ControllerNode;
Jian Lib68a2b02016-05-02 11:23:32 -070026import org.onosproject.cluster.RoleInfo;
Brian O'Connorabafb502014-12-02 22:26:20 -080027import org.onosproject.codec.CodecService;
28import org.onosproject.codec.JsonCodec;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080029import org.onosproject.core.Application;
Jian Lie1c1c8d2016-05-09 16:24:40 -070030import org.onosproject.core.ApplicationId;
Sangsik Yoonf0b3ad82016-08-19 18:47:59 +090031import org.onosproject.incubator.net.dpi.DpiStatInfo;
32import org.onosproject.incubator.net.dpi.DpiStatInfoCodec;
33import org.onosproject.incubator.net.dpi.DpiStatistics;
34import org.onosproject.incubator.net.dpi.DpiStatisticsCodec;
35import org.onosproject.incubator.net.dpi.FlowStatInfo;
36import org.onosproject.incubator.net.dpi.FlowStatInfoCodec;
37import org.onosproject.incubator.net.dpi.ProtocolStatInfo;
38import org.onosproject.incubator.net.dpi.ProtocolStatInfoCodec;
39import org.onosproject.incubator.net.dpi.TrafficStatInfo;
40import org.onosproject.incubator.net.dpi.TrafficStatInfoCodec;
Claudine Chiufb8b8162016-04-01 23:50:51 +000041import org.onosproject.incubator.net.virtual.TenantId;
42import org.onosproject.incubator.net.virtual.VirtualDevice;
Claudine Chiu25f07be2016-06-27 16:21:21 +000043import org.onosproject.incubator.net.virtual.VirtualHost;
Claudine Chiuf6bf8d52016-04-08 01:31:54 +000044import org.onosproject.incubator.net.virtual.VirtualLink;
Claudine Chiufb8b8162016-04-01 23:50:51 +000045import org.onosproject.incubator.net.virtual.VirtualNetwork;
46import org.onosproject.incubator.net.virtual.VirtualPort;
Jian Lib68a2b02016-05-02 11:23:32 -070047import org.onosproject.mastership.MastershipTerm;
Brian O'Connorabafb502014-12-02 22:26:20 -080048import org.onosproject.net.Annotations;
49import org.onosproject.net.ConnectPoint;
50import org.onosproject.net.Device;
Jonathan Hart8338b8d2017-08-15 15:46:14 -070051import org.onosproject.net.DisjointPath;
52import org.onosproject.net.FilteredConnectPoint;
Ray Milkey1f95bd32014-12-10 11:11:00 -080053import org.onosproject.net.Host;
54import org.onosproject.net.HostLocation;
Brian O'Connorabafb502014-12-02 22:26:20 -080055import org.onosproject.net.Link;
Jian Lib68a2b02016-05-02 11:23:32 -070056import org.onosproject.net.MastershipRole;
Ray Milkey19ffea32015-01-28 10:03:06 -080057import org.onosproject.net.Path;
Brian O'Connorabafb502014-12-02 22:26:20 -080058import org.onosproject.net.Port;
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -070059import org.onosproject.net.behaviour.protection.TransportEndpointDescription;
Jian Liecb3c0f2015-12-15 10:07:49 -080060import org.onosproject.net.device.PortStatistics;
Ray Milkey39616f32015-05-14 15:43:00 -070061import org.onosproject.net.driver.Driver;
Ray Milkey4f5de002014-12-17 19:26:11 -080062import org.onosproject.net.flow.FlowEntry;
Ray Milkeyd43fe452015-05-29 09:35:12 -070063import org.onosproject.net.flow.FlowRule;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070064import org.onosproject.net.flow.TableStatisticsEntry;
Ray Milkey4f5de002014-12-17 19:26:11 -080065import org.onosproject.net.flow.TrafficSelector;
66import org.onosproject.net.flow.TrafficTreatment;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080067import org.onosproject.net.flow.criteria.Criterion;
68import org.onosproject.net.flow.instructions.Instruction;
Jian Li8bcef8b2016-01-06 11:35:53 -080069import org.onosproject.net.flowobjective.FilteringObjective;
70import org.onosproject.net.flowobjective.ForwardingObjective;
71import org.onosproject.net.flowobjective.NextObjective;
Ray Milkey39616f32015-05-14 15:43:00 -070072import org.onosproject.net.group.Group;
73import org.onosproject.net.group.GroupBucket;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080074import org.onosproject.net.intent.ConnectivityIntent;
Ray Milkeyb9a8a182015-01-20 14:15:35 -080075import org.onosproject.net.intent.Constraint;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080076import org.onosproject.net.intent.HostToHostIntent;
Ray Milkey2b217142014-12-15 09:24:24 -080077import org.onosproject.net.intent.Intent;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080078import org.onosproject.net.intent.PointToPointIntent;
Chiara Contolia8f69ff2016-07-28 01:06:07 +090079import org.onosproject.net.intent.SinglePointToMultiPointIntent;
dvaddire95c84ed2017-06-14 15:42:24 +053080import org.onosproject.net.intent.util.IntentMiniSummary;
nassima toumi95761312017-05-23 14:00:33 +030081import org.onosproject.net.intent.MultiPointToSinglePointIntent;
Brian Stankeb9170d92016-02-19 14:18:42 -050082import org.onosproject.net.key.DeviceKey;
Jonathan Hart07eb0412016-02-08 16:42:29 -080083import org.onosproject.net.mcast.McastRoute;
Jian Li5c411232015-12-16 15:29:16 -080084import org.onosproject.net.meter.Band;
85import org.onosproject.net.meter.Meter;
Jian Li95678962016-01-26 17:17:52 -080086import org.onosproject.net.meter.MeterRequest;
Claudine Chiu1f036b82017-03-09 16:45:56 -050087import org.onosproject.net.packet.PacketRequest;
Jian Lib68b9a82016-02-23 10:25:54 +090088import org.onosproject.net.region.Region;
Ray Milkeyb9af9462015-07-17 11:12:09 -070089import org.onosproject.net.statistic.Load;
Ray Milkey82e50312015-01-22 17:01:42 -080090import org.onosproject.net.topology.Topology;
91import org.onosproject.net.topology.TopologyCluster;
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080092import org.slf4j.Logger;
93import org.slf4j.LoggerFactory;
94
Thomas Vachuskade563cf2015-04-01 00:28:50 -070095import java.util.Map;
96import java.util.Set;
97import java.util.concurrent.ConcurrentHashMap;
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080098
Heedo Kang4a47a302016-02-29 17:40:23 +090099import static org.onosproject.security.AppGuard.checkPermission;
Jonathan Hart8338b8d2017-08-15 15:46:14 -0700100import static org.onosproject.security.AppPermission.Type.CODEC_READ;
101import static org.onosproject.security.AppPermission.Type.CODEC_WRITE;
Heedo Kang4a47a302016-02-29 17:40:23 +0900102
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -0800103/**
104 * Implementation of the JSON codec brokering service.
105 */
106@Component(immediate = true)
107@Service
108public class CodecManager implements CodecService {
109
110 private static Logger log = LoggerFactory.getLogger(CodecManager.class);
111
112 private final Map<Class<?>, JsonCodec> codecs = new ConcurrentHashMap<>();
113
114 @Activate
115 public void activate() {
116 codecs.clear();
Thomas Vachuska02aeb032015-01-06 22:36:30 -0800117 registerCodec(Application.class, new ApplicationCodec());
Jian Lie1c1c8d2016-05-09 16:24:40 -0700118 registerCodec(ApplicationId.class, new ApplicationIdCodec());
Thomas Vachuskade563cf2015-04-01 00:28:50 -0700119 registerCodec(ControllerNode.class, new ControllerNodeCodec());
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -0800120 registerCodec(Annotations.class, new AnnotationsCodec());
121 registerCodec(Device.class, new DeviceCodec());
122 registerCodec(Port.class, new PortCodec());
123 registerCodec(ConnectPoint.class, new ConnectPointCodec());
124 registerCodec(Link.class, new LinkCodec());
Ray Milkey1f95bd32014-12-10 11:11:00 -0800125 registerCodec(Host.class, new HostCodec());
126 registerCodec(HostLocation.class, new HostLocationCodec());
Ray Milkeyc95bb9d2015-01-06 10:28:24 -0800127 registerCodec(HostToHostIntent.class, new HostToHostIntentCodec());
dvaddire95c84ed2017-06-14 15:42:24 +0530128 registerCodec(IntentMiniSummary.class, new IntentMiniSummaryCodec());
Ray Milkeyc95bb9d2015-01-06 10:28:24 -0800129 registerCodec(PointToPointIntent.class, new PointToPointIntentCodec());
Chiara Contolia8f69ff2016-07-28 01:06:07 +0900130 registerCodec(SinglePointToMultiPointIntent.class, new SinglePointToMultiPointIntentCodec());
nassima toumi95761312017-05-23 14:00:33 +0300131 registerCodec(MultiPointToSinglePointIntent.class, new MultiPointToSinglePointIntentCodec());
Ray Milkey2b217142014-12-15 09:24:24 -0800132 registerCodec(Intent.class, new IntentCodec());
Ray Milkeyc95bb9d2015-01-06 10:28:24 -0800133 registerCodec(ConnectivityIntent.class, new ConnectivityIntentCodec());
Ray Milkey4f5de002014-12-17 19:26:11 -0800134 registerCodec(FlowEntry.class, new FlowEntryCodec());
Ray Milkeyd43fe452015-05-29 09:35:12 -0700135 registerCodec(FlowRule.class, new FlowRuleCodec());
Ray Milkey4f5de002014-12-17 19:26:11 -0800136 registerCodec(TrafficTreatment.class, new TrafficTreatmentCodec());
137 registerCodec(TrafficSelector.class, new TrafficSelectorCodec());
Ray Milkeyc95bb9d2015-01-06 10:28:24 -0800138 registerCodec(Instruction.class, new InstructionCodec());
139 registerCodec(Criterion.class, new CriterionCodec());
140 registerCodec(Ethernet.class, new EthernetCodec());
Ray Milkeyb9a8a182015-01-20 14:15:35 -0800141 registerCodec(Constraint.class, new ConstraintCodec());
Ray Milkey82e50312015-01-22 17:01:42 -0800142 registerCodec(Topology.class, new TopologyCodec());
143 registerCodec(TopologyCluster.class, new TopologyClusterCodec());
Ray Milkey19ffea32015-01-28 10:03:06 -0800144 registerCodec(Path.class, new PathCodec());
Jayasree Ghoshd3ff5402016-08-17 18:41:19 +0530145 registerCodec(DisjointPath.class, new DisjointPathCodec());
Ray Milkey39616f32015-05-14 15:43:00 -0700146 registerCodec(Group.class, new GroupCodec());
147 registerCodec(Driver.class, new DriverCodec());
148 registerCodec(GroupBucket.class, new GroupBucketCodec());
Ray Milkeyb9af9462015-07-17 11:12:09 -0700149 registerCodec(Load.class, new LoadCodec());
Jian Li95678962016-01-26 17:17:52 -0800150 registerCodec(MeterRequest.class, new MeterRequestCodec());
Jian Li5c411232015-12-16 15:29:16 -0800151 registerCodec(Meter.class, new MeterCodec());
152 registerCodec(Band.class, new MeterBandCodec());
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700153 registerCodec(TableStatisticsEntry.class, new TableStatisticsEntryCodec());
Srikanth Vavilapallid120f5c2015-11-24 14:15:01 -0800154 registerCodec(PortStatistics.class, new PortStatisticsCodec());
Jian Li72315152015-12-10 17:20:43 -0800155 registerCodec(Metric.class, new MetricCodec());
Jian Li8bcef8b2016-01-06 11:35:53 -0800156 registerCodec(FilteringObjective.class, new FilteringObjectiveCodec());
157 registerCodec(ForwardingObjective.class, new ForwardingObjectiveCodec());
158 registerCodec(NextObjective.class, new NextObjectiveCodec());
Jonathan Hart07eb0412016-02-08 16:42:29 -0800159 registerCodec(McastRoute.class, new McastRouteCodec());
Brian Stankeb9170d92016-02-19 14:18:42 -0500160 registerCodec(DeviceKey.class, new DeviceKeyCodec());
Jian Lib68b9a82016-02-23 10:25:54 +0900161 registerCodec(Region.class, new RegionCodec());
Claudine Chiufb8b8162016-04-01 23:50:51 +0000162 registerCodec(TenantId.class, new TenantIdCodec());
163 registerCodec(VirtualNetwork.class, new VirtualNetworkCodec());
164 registerCodec(VirtualDevice.class, new VirtualDeviceCodec());
165 registerCodec(VirtualPort.class, new VirtualPortCodec());
Claudine Chiuf6bf8d52016-04-08 01:31:54 +0000166 registerCodec(VirtualLink.class, new VirtualLinkCodec());
Claudine Chiu25f07be2016-06-27 16:21:21 +0000167 registerCodec(VirtualHost.class, new VirtualHostCodec());
Jian Lib68a2b02016-05-02 11:23:32 -0700168 registerCodec(MastershipTerm.class, new MastershipTermCodec());
169 registerCodec(MastershipRole.class, new MastershipRoleCodec());
170 registerCodec(RoleInfo.class, new RoleInfoCodec());
Sangsik Yoonf0b3ad82016-08-19 18:47:59 +0900171 registerCodec(DpiStatistics.class, new DpiStatisticsCodec());
172 registerCodec(DpiStatInfo.class, new DpiStatInfoCodec());
173 registerCodec(TrafficStatInfo.class, new TrafficStatInfoCodec());
174 registerCodec(ProtocolStatInfo.class, new ProtocolStatInfoCodec());
175 registerCodec(FlowStatInfo.class, new FlowStatInfoCodec());
Yuta HIGUCHI776f0742016-11-03 15:51:14 -0700176 registerCodec(FilteredConnectPoint.class, new FilteredConnectPointCodec());
Yuta HIGUCHIa255bb42016-11-03 16:04:08 -0700177 registerCodec(TransportEndpointDescription.class, new TransportEndpointDescriptionCodec());
Claudine Chiu1f036b82017-03-09 16:45:56 -0500178 registerCodec(PacketRequest.class, new PacketRequestCodec());
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -0800179 log.info("Started");
180 }
181
182 @Deactivate
Ray Milkey1f95bd32014-12-10 11:11:00 -0800183 public void deactivate() {
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -0800184 codecs.clear();
185 log.info("Stopped");
186 }
187
188 @Override
189 public Set<Class<?>> getCodecs() {
Heedo Kang4a47a302016-02-29 17:40:23 +0900190 checkPermission(CODEC_READ);
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -0800191 return ImmutableSet.copyOf(codecs.keySet());
192 }
193
194 @Override
195 @SuppressWarnings("unchecked")
196 public <T> JsonCodec<T> getCodec(Class<T> entityClass) {
Heedo Kang4a47a302016-02-29 17:40:23 +0900197 checkPermission(CODEC_READ);
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -0800198 return codecs.get(entityClass);
199 }
200
201 @Override
202 public <T> void registerCodec(Class<T> entityClass, JsonCodec<T> codec) {
Heedo Kang4a47a302016-02-29 17:40:23 +0900203 checkPermission(CODEC_WRITE);
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -0800204 codecs.putIfAbsent(entityClass, codec);
205 }
206
207 @Override
208 public void unregisterCodec(Class<?> entityClass) {
Heedo Kang4a47a302016-02-29 17:40:23 +0900209 checkPermission(CODEC_WRITE);
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -0800210 codecs.remove(entityClass);
211 }
212
213}