blob: 88fb8ddca490583e415d718e9c43f62880387356 [file] [log] [blame]
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
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
Ray Milkeyb9a8a182015-01-20 14:15:35 -080018import java.util.Map;
19import java.util.Set;
20import java.util.concurrent.ConcurrentHashMap;
21
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080022import org.apache.felix.scr.annotations.Activate;
23import org.apache.felix.scr.annotations.Component;
24import org.apache.felix.scr.annotations.Deactivate;
25import org.apache.felix.scr.annotations.Service;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080026import org.onlab.packet.Ethernet;
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;
Brian O'Connorabafb502014-12-02 22:26:20 -080030import org.onosproject.net.Annotations;
31import org.onosproject.net.ConnectPoint;
32import org.onosproject.net.Device;
Ray Milkey1f95bd32014-12-10 11:11:00 -080033import org.onosproject.net.Host;
34import org.onosproject.net.HostLocation;
Brian O'Connorabafb502014-12-02 22:26:20 -080035import org.onosproject.net.Link;
36import org.onosproject.net.Port;
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;
42import org.onosproject.net.intent.ConnectivityIntent;
Ray Milkeyb9a8a182015-01-20 14:15:35 -080043import org.onosproject.net.intent.Constraint;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080044import org.onosproject.net.intent.HostToHostIntent;
Ray Milkey2b217142014-12-15 09:24:24 -080045import org.onosproject.net.intent.Intent;
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080046import org.onosproject.net.intent.PointToPointIntent;
Ray Milkey82e50312015-01-22 17:01:42 -080047import org.onosproject.net.topology.Topology;
48import org.onosproject.net.topology.TopologyCluster;
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080049import org.slf4j.Logger;
50import org.slf4j.LoggerFactory;
51
Ray Milkeyb9a8a182015-01-20 14:15:35 -080052import com.google.common.collect.ImmutableSet;
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080053
54/**
55 * Implementation of the JSON codec brokering service.
56 */
57@Component(immediate = true)
58@Service
59public class CodecManager implements CodecService {
60
61 private static Logger log = LoggerFactory.getLogger(CodecManager.class);
62
63 private final Map<Class<?>, JsonCodec> codecs = new ConcurrentHashMap<>();
64
65 @Activate
66 public void activate() {
67 codecs.clear();
Thomas Vachuska02aeb032015-01-06 22:36:30 -080068 registerCodec(Application.class, new ApplicationCodec());
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080069 registerCodec(Annotations.class, new AnnotationsCodec());
70 registerCodec(Device.class, new DeviceCodec());
71 registerCodec(Port.class, new PortCodec());
72 registerCodec(ConnectPoint.class, new ConnectPointCodec());
73 registerCodec(Link.class, new LinkCodec());
Ray Milkey1f95bd32014-12-10 11:11:00 -080074 registerCodec(Host.class, new HostCodec());
75 registerCodec(HostLocation.class, new HostLocationCodec());
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080076 registerCodec(HostToHostIntent.class, new HostToHostIntentCodec());
77 registerCodec(PointToPointIntent.class, new PointToPointIntentCodec());
Ray Milkey2b217142014-12-15 09:24:24 -080078 registerCodec(Intent.class, new IntentCodec());
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080079 registerCodec(ConnectivityIntent.class, new ConnectivityIntentCodec());
Ray Milkey4f5de002014-12-17 19:26:11 -080080 registerCodec(FlowEntry.class, new FlowEntryCodec());
81 registerCodec(TrafficTreatment.class, new TrafficTreatmentCodec());
82 registerCodec(TrafficSelector.class, new TrafficSelectorCodec());
Ray Milkeyc95bb9d2015-01-06 10:28:24 -080083 registerCodec(Instruction.class, new InstructionCodec());
84 registerCodec(Criterion.class, new CriterionCodec());
85 registerCodec(Ethernet.class, new EthernetCodec());
Ray Milkeyb9a8a182015-01-20 14:15:35 -080086 registerCodec(Constraint.class, new ConstraintCodec());
Ray Milkey82e50312015-01-22 17:01:42 -080087 registerCodec(Topology.class, new TopologyCodec());
88 registerCodec(TopologyCluster.class, new TopologyClusterCodec());
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080089 log.info("Started");
90 }
91
92 @Deactivate
Ray Milkey1f95bd32014-12-10 11:11:00 -080093 public void deactivate() {
Thomas Vachuskaca60f2b2014-11-06 01:34:28 -080094 codecs.clear();
95 log.info("Stopped");
96 }
97
98 @Override
99 public Set<Class<?>> getCodecs() {
100 return ImmutableSet.copyOf(codecs.keySet());
101 }
102
103 @Override
104 @SuppressWarnings("unchecked")
105 public <T> JsonCodec<T> getCodec(Class<T> entityClass) {
106 return codecs.get(entityClass);
107 }
108
109 @Override
110 public <T> void registerCodec(Class<T> entityClass, JsonCodec<T> codec) {
111 codecs.putIfAbsent(entityClass, codec);
112 }
113
114 @Override
115 public void unregisterCodec(Class<?> entityClass) {
116 codecs.remove(entityClass);
117 }
118
119}