blob: 50a35c3927f608b798684318ac85f023dc67822f [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
Thomas Vachuskade563cf2015-04-01 00:28:50 -070018import com.google.common.collect.ImmutableSet;
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080019import org.apache.felix.scr.annotations.Activate;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Deactivate;
22import org.apache.felix.scr.annotations.Service;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080023import org.onlab.packet.Ethernet;
Thomas Vachuskade563cf2015-04-01 00:28:50 -070024import org.onosproject.cluster.ControllerNode;
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.codec.CodecService;
26import org.onosproject.codec.JsonCodec;
Thomas Vachuska02aeb032015-01-06 22:36:30 -080027import org.onosproject.core.Application;
Brian O'Connorabafb502014-12-02 22:26:20 -080028import org.onosproject.net.Annotations;
29import org.onosproject.net.ConnectPoint;
30import org.onosproject.net.Device;
Ray Milkey1f95bd32014-12-10 11:11:00 -080031import org.onosproject.net.Host;
32import org.onosproject.net.HostLocation;
Brian O'Connorabafb502014-12-02 22:26:20 -080033import org.onosproject.net.Link;
Ray Milkey19ffea32015-01-28 10:03:06 -080034import org.onosproject.net.Path;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import org.onosproject.net.Port;
Ray Milkey39616f32015-05-14 15:43:00 -070036import org.onosproject.net.driver.Driver;
Ray Milkey4f5de002014-12-17 19:26:11 -080037import org.onosproject.net.flow.FlowEntry;
38import org.onosproject.net.flow.TrafficSelector;
39import org.onosproject.net.flow.TrafficTreatment;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080040import org.onosproject.net.flow.criteria.Criterion;
41import org.onosproject.net.flow.instructions.Instruction;
Ray Milkey39616f32015-05-14 15:43:00 -070042import org.onosproject.net.group.Group;
43import org.onosproject.net.group.GroupBucket;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080044import org.onosproject.net.intent.ConnectivityIntent;
Ray Milkeyb9a8a182015-01-20 14:15:35 -080045import org.onosproject.net.intent.Constraint;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080046import org.onosproject.net.intent.HostToHostIntent;
Ray Milkey2b217142014-12-15 09:24:24 -080047import org.onosproject.net.intent.Intent;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080048import org.onosproject.net.intent.PointToPointIntent;
Ray Milkey82e50312015-01-22 17:01:42 -080049import org.onosproject.net.topology.Topology;
50import org.onosproject.net.topology.TopologyCluster;
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080051import org.slf4j.Logger;
52import org.slf4j.LoggerFactory;
53
Thomas Vachuskade563cf2015-04-01 00:28:50 -070054import java.util.Map;
55import java.util.Set;
56import java.util.concurrent.ConcurrentHashMap;
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080057
58/**
59 * Implementation of the JSON codec brokering service.
60 */
61@Component(immediate = true)
62@Service
63public class CodecManager implements CodecService {
64
65 private static Logger log = LoggerFactory.getLogger(CodecManager.class);
66
67 private final Map<Class<?>, JsonCodec> codecs = new ConcurrentHashMap<>();
68
69 @Activate
70 public void activate() {
71 codecs.clear();
Thomas Vachuska02aeb032015-01-06 22:36:30 -080072 registerCodec(Application.class, new ApplicationCodec());
Thomas Vachuskade563cf2015-04-01 00:28:50 -070073 registerCodec(ControllerNode.class, new ControllerNodeCodec());
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080074 registerCodec(Annotations.class, new AnnotationsCodec());
75 registerCodec(Device.class, new DeviceCodec());
76 registerCodec(Port.class, new PortCodec());
77 registerCodec(ConnectPoint.class, new ConnectPointCodec());
78 registerCodec(Link.class, new LinkCodec());
Ray Milkey1f95bd32014-12-10 11:11:00 -080079 registerCodec(Host.class, new HostCodec());
80 registerCodec(HostLocation.class, new HostLocationCodec());
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080081 registerCodec(HostToHostIntent.class, new HostToHostIntentCodec());
82 registerCodec(PointToPointIntent.class, new PointToPointIntentCodec());
Ray Milkey2b217142014-12-15 09:24:24 -080083 registerCodec(Intent.class, new IntentCodec());
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080084 registerCodec(ConnectivityIntent.class, new ConnectivityIntentCodec());
Ray Milkey4f5de002014-12-17 19:26:11 -080085 registerCodec(FlowEntry.class, new FlowEntryCodec());
86 registerCodec(TrafficTreatment.class, new TrafficTreatmentCodec());
87 registerCodec(TrafficSelector.class, new TrafficSelectorCodec());
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080088 registerCodec(Instruction.class, new InstructionCodec());
89 registerCodec(Criterion.class, new CriterionCodec());
90 registerCodec(Ethernet.class, new EthernetCodec());
Ray Milkeyb9a8a182015-01-20 14:15:35 -080091 registerCodec(Constraint.class, new ConstraintCodec());
Ray Milkey82e50312015-01-22 17:01:42 -080092 registerCodec(Topology.class, new TopologyCodec());
93 registerCodec(TopologyCluster.class, new TopologyClusterCodec());
Ray Milkey19ffea32015-01-28 10:03:06 -080094 registerCodec(Path.class, new PathCodec());
Ray Milkey39616f32015-05-14 15:43:00 -070095 registerCodec(Group.class, new GroupCodec());
96 registerCodec(Driver.class, new DriverCodec());
97 registerCodec(GroupBucket.class, new GroupBucketCodec());
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080098 log.info("Started");
99 }
100
101 @Deactivate
Ray Milkey1f95bd32014-12-10 11:11:00 -0800102 public void deactivate() {
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -0800103 codecs.clear();
104 log.info("Stopped");
105 }
106
107 @Override
108 public Set<Class<?>> getCodecs() {
109 return ImmutableSet.copyOf(codecs.keySet());
110 }
111
112 @Override
113 @SuppressWarnings("unchecked")
114 public <T> JsonCodec<T> getCodec(Class<T> entityClass) {
115 return codecs.get(entityClass);
116 }
117
118 @Override
119 public <T> void registerCodec(Class<T> entityClass, JsonCodec<T> codec) {
120 codecs.putIfAbsent(entityClass, codec);
121 }
122
123 @Override
124 public void unregisterCodec(Class<?> entityClass) {
125 codecs.remove(entityClass);
126 }
127
128}