blob: 633a356a83598abf9b80c55f91a3e096a6c97712 [file] [log] [blame]
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -08001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 Open Networking Laboratory
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;
Brian O'Connorabafb502014-12-02 22:26:20 -080026import org.onosproject.codec.CodecService;
27import org.onosproject.codec.JsonCodec;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080028import org.onosproject.core.Application;
Brian O'Connorabafb502014-12-02 22:26:20 -080029import org.onosproject.net.Annotations;
30import org.onosproject.net.ConnectPoint;
31import org.onosproject.net.Device;
Ray Milkey1f95bd32014-12-10 11:11:00 -080032import org.onosproject.net.Host;
33import org.onosproject.net.HostLocation;
Brian O'Connorabafb502014-12-02 22:26:20 -080034import org.onosproject.net.Link;
Ray Milkey19ffea32015-01-28 10:03:06 -080035import org.onosproject.net.Path;
Brian O'Connorabafb502014-12-02 22:26:20 -080036import org.onosproject.net.Port;
Jian Liecb3c0f2015-12-15 10:07:49 -080037import org.onosproject.net.device.PortStatistics;
Ray Milkey39616f32015-05-14 15:43:00 -070038import org.onosproject.net.driver.Driver;
Ray Milkey4f5de002014-12-17 19:26:11 -080039import org.onosproject.net.flow.FlowEntry;
Ray Milkeyd43fe452015-05-29 09:35:12 -070040import org.onosproject.net.flow.FlowRule;
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -070041import org.onosproject.net.flow.TableStatisticsEntry;
Ray Milkey4f5de002014-12-17 19:26:11 -080042import org.onosproject.net.flow.TrafficSelector;
43import org.onosproject.net.flow.TrafficTreatment;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080044import org.onosproject.net.flow.criteria.Criterion;
45import org.onosproject.net.flow.instructions.Instruction;
Ray Milkey39616f32015-05-14 15:43:00 -070046import org.onosproject.net.group.Group;
47import org.onosproject.net.group.GroupBucket;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080048import org.onosproject.net.intent.ConnectivityIntent;
Ray Milkeyb9a8a182015-01-20 14:15:35 -080049import org.onosproject.net.intent.Constraint;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080050import org.onosproject.net.intent.HostToHostIntent;
Ray Milkey2b217142014-12-15 09:24:24 -080051import org.onosproject.net.intent.Intent;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080052import org.onosproject.net.intent.PointToPointIntent;
Jian Li5c411232015-12-16 15:29:16 -080053import org.onosproject.net.meter.Band;
54import org.onosproject.net.meter.Meter;
Ray Milkeyb9af9462015-07-17 11:12:09 -070055import org.onosproject.net.statistic.Load;
Ray Milkey82e50312015-01-22 17:01:42 -080056import org.onosproject.net.topology.Topology;
57import org.onosproject.net.topology.TopologyCluster;
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080058import org.slf4j.Logger;
59import org.slf4j.LoggerFactory;
60
Thomas Vachuskade563cf2015-04-01 00:28:50 -070061import java.util.Map;
62import java.util.Set;
63import java.util.concurrent.ConcurrentHashMap;
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080064
65/**
66 * Implementation of the JSON codec brokering service.
67 */
68@Component(immediate = true)
69@Service
70public class CodecManager implements CodecService {
71
72 private static Logger log = LoggerFactory.getLogger(CodecManager.class);
73
74 private final Map<Class<?>, JsonCodec> codecs = new ConcurrentHashMap<>();
75
76 @Activate
77 public void activate() {
78 codecs.clear();
Thomas Vachuska02aeb032015-01-06 22:36:30 -080079 registerCodec(Application.class, new ApplicationCodec());
Thomas Vachuskade563cf2015-04-01 00:28:50 -070080 registerCodec(ControllerNode.class, new ControllerNodeCodec());
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080081 registerCodec(Annotations.class, new AnnotationsCodec());
82 registerCodec(Device.class, new DeviceCodec());
83 registerCodec(Port.class, new PortCodec());
84 registerCodec(ConnectPoint.class, new ConnectPointCodec());
85 registerCodec(Link.class, new LinkCodec());
Ray Milkey1f95bd32014-12-10 11:11:00 -080086 registerCodec(Host.class, new HostCodec());
87 registerCodec(HostLocation.class, new HostLocationCodec());
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080088 registerCodec(HostToHostIntent.class, new HostToHostIntentCodec());
89 registerCodec(PointToPointIntent.class, new PointToPointIntentCodec());
Ray Milkey2b217142014-12-15 09:24:24 -080090 registerCodec(Intent.class, new IntentCodec());
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080091 registerCodec(ConnectivityIntent.class, new ConnectivityIntentCodec());
Ray Milkey4f5de002014-12-17 19:26:11 -080092 registerCodec(FlowEntry.class, new FlowEntryCodec());
Ray Milkeyd43fe452015-05-29 09:35:12 -070093 registerCodec(FlowRule.class, new FlowRuleCodec());
Ray Milkey4f5de002014-12-17 19:26:11 -080094 registerCodec(TrafficTreatment.class, new TrafficTreatmentCodec());
95 registerCodec(TrafficSelector.class, new TrafficSelectorCodec());
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080096 registerCodec(Instruction.class, new InstructionCodec());
97 registerCodec(Criterion.class, new CriterionCodec());
98 registerCodec(Ethernet.class, new EthernetCodec());
Ray Milkeyb9a8a182015-01-20 14:15:35 -080099 registerCodec(Constraint.class, new ConstraintCodec());
Ray Milkey82e50312015-01-22 17:01:42 -0800100 registerCodec(Topology.class, new TopologyCodec());
101 registerCodec(TopologyCluster.class, new TopologyClusterCodec());
Ray Milkey19ffea32015-01-28 10:03:06 -0800102 registerCodec(Path.class, new PathCodec());
Ray Milkey39616f32015-05-14 15:43:00 -0700103 registerCodec(Group.class, new GroupCodec());
104 registerCodec(Driver.class, new DriverCodec());
105 registerCodec(GroupBucket.class, new GroupBucketCodec());
Ray Milkeyb9af9462015-07-17 11:12:09 -0700106 registerCodec(Load.class, new LoadCodec());
Jian Li5c411232015-12-16 15:29:16 -0800107 registerCodec(Meter.class, new MeterCodec());
108 registerCodec(Band.class, new MeterBandCodec());
Srikanth Vavilapalli95810f52015-09-14 15:49:56 -0700109 registerCodec(TableStatisticsEntry.class, new TableStatisticsEntryCodec());
Srikanth Vavilapallid120f5c2015-11-24 14:15:01 -0800110 registerCodec(PortStatistics.class, new PortStatisticsCodec());
Jian Li72315152015-12-10 17:20:43 -0800111 registerCodec(Metric.class, new MetricCodec());
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -0800112 log.info("Started");
113 }
114
115 @Deactivate
Ray Milkey1f95bd32014-12-10 11:11:00 -0800116 public void deactivate() {
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -0800117 codecs.clear();
118 log.info("Stopped");
119 }
120
121 @Override
122 public Set<Class<?>> getCodecs() {
123 return ImmutableSet.copyOf(codecs.keySet());
124 }
125
126 @Override
127 @SuppressWarnings("unchecked")
128 public <T> JsonCodec<T> getCodec(Class<T> entityClass) {
129 return codecs.get(entityClass);
130 }
131
132 @Override
133 public <T> void registerCodec(Class<T> entityClass, JsonCodec<T> codec) {
134 codecs.putIfAbsent(entityClass, codec);
135 }
136
137 @Override
138 public void unregisterCodec(Class<?> entityClass) {
139 codecs.remove(entityClass);
140 }
141
142}