4baf6d2dc1cb2840c276ad3793309b5bc5b1e3a9
[openflowjava.git] / openflow-nx-resubmit-action / src / main / java / org / opendaylight / openflowjava / protocol / nx / NxResubmitActionRegistrator.java
1 /*\r
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.openflowjava.protocol.nx;\r
10 \r
11 import java.util.List;\r
12 \r
13 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterActionDeserializerKey;\r
14 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterActionSerializerKey;\r
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
16 import org.opendaylight.openflowjava.protocol.nx.deserialization.NxActionResubmitDeserializer;\r
17 import org.opendaylight.openflowjava.protocol.nx.serialization.NxActionResubmitSerializer;\r
18 import org.opendaylight.openflowjava.protocol.spi.connection.SwitchConnectionProvider;\r
19 \r
20 /**\r
21  * @author michal.polkorab\r
22  *\r
23  */\r
24 public class NxResubmitActionRegistrator implements AutoCloseable {\r
25 \r
26     /** Nicira experimenter ID */\r
27     public static final Long NICIRA_EXPERIMENTER_ID = 0x00002320L;\r
28     private List<SwitchConnectionProvider> providers;\r
29 \r
30     /**\r
31      * @param providers providers that shall be filled with serializers\r
32      */\r
33     public void registerNxResubmitSerializer(List<SwitchConnectionProvider> providers) {\r
34         if (providers != null) {\r
35             this.providers = providers;\r
36             for (SwitchConnectionProvider provider : providers) {\r
37                 /* In case of handling multiple actions, instructions and other structures which\r
38                  * are differentiated by vendor / experimenter subtype, vendor has to\r
39                  * switch / choose between these subtypes.\r
40                  * \r
41                  * This has to be done in this way because of experimenter headers, which\r
42                  * provide only vendor / experimenter ID. Subtype position may be different\r
43                  * for different vendors (or not present at all) - that's why vendor has to\r
44                  * handle it in his own implementations.\r
45                  */\r
46                 provider.registerActionSerializer(new ExperimenterActionSerializerKey(\r
47                         EncodeConstants.OF13_VERSION_ID, NICIRA_EXPERIMENTER_ID),\r
48                         new NxActionResubmitSerializer());\r
49             }\r
50         }\r
51     }\r
52 \r
53     /**\r
54      * @param providers providers that shall be filled with deserializers\r
55      */\r
56     public void registerNxResubmitDeserializer(List<SwitchConnectionProvider> providers) {\r
57         if (providers != null) {\r
58             this.providers = providers;\r
59             for (SwitchConnectionProvider provider : providers) {\r
60                 /* In case of handling multiple actions, instructions and other structures which\r
61                  * are differentiated by vendor / experimenter subtype, vendor has to\r
62                  * switch / choose between these subtypes.\r
63                  * \r
64                  * This has to be done in this way because of experimenter headers, which\r
65                  * provide only vendor / experimenter ID. Subtype position may be different\r
66                  * for different vendors (or not present at all) - that's why vendor has to\r
67                  * handle it in his own implementations.\r
68                  */\r
69                 provider.registerActionDeserializer(new ExperimenterActionDeserializerKey(\r
70                         EncodeConstants.OF13_VERSION_ID, NICIRA_EXPERIMENTER_ID),\r
71                         new NxActionResubmitDeserializer());\r
72             }\r
73         }\r
74     }\r
75 \r
76     @Override\r
77     public void close() throws Exception {\r
78         for (SwitchConnectionProvider provider : providers) {\r
79             // unregister serializer\r
80             provider.unregisterSerializer(new ExperimenterActionSerializerKey(\r
81                     EncodeConstants.OF13_VERSION_ID, NICIRA_EXPERIMENTER_ID));\r
82             // unregister deserializer\r
83             provider.unregisterDeserializer(new ExperimenterActionDeserializerKey(\r
84                     EncodeConstants.OF13_VERSION_ID, NICIRA_EXPERIMENTER_ID));\r
85         }\r
86     }\r
87 }