6dbdef09b37381c6824ecf9239ab0a0695b054d3
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / yang / gen / v1 / urn / opendaylight / params / xml / ns / yang / openflow / _switch / connection / provider / impl / rev140328 / SwitchConnectionProviderModule.java
1 /**
2 * Generated file
3
4 * Generated from: yang module name: openflow-switch-connection-provider-impl  yang module local name: openflow-switch-connection-provider-impl
5 * Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
6 * Generated at: Fri Mar 28 17:50:58 PDT 2014
7 *
8 * Do not modify this file unless it is present under src/main directory
9 */
10 package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328;
11
12 import java.net.InetAddress;
13 import java.net.UnknownHostException;
14
15 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
16 import org.opendaylight.openflowjava.protocol.impl.connection.SwitchConnectionProviderImpl;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22 *
23 */
24 public final class SwitchConnectionProviderModule extends org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow._switch.connection.provider.impl.rev140328.AbstractSwitchConnectionProviderModule
25  {
26     
27     private static Logger LOG = LoggerFactory
28             .getLogger(SwitchConnectionProviderModule.class);
29
30     /**
31      * @param identifier
32      * @param dependencyResolver
33      */
34     public SwitchConnectionProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
35         super(identifier, dependencyResolver);
36     }
37
38     /**
39      * @param identifier
40      * @param dependencyResolver
41      * @param oldModule
42      * @param oldInstance
43      */
44     public SwitchConnectionProviderModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier, org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
45             SwitchConnectionProviderModule oldModule, java.lang.AutoCloseable oldInstance) {
46         super(identifier, dependencyResolver, oldModule, oldInstance);
47     }
48
49     @Override
50     protected void customValidation(){
51         // Add custom validation for module attributes here.
52     }
53
54     @Override
55     public java.lang.AutoCloseable createInstance() {
56         LOG.info("SwitchConnectionProvider started.");
57         SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
58         try {
59             ConnectionConfiguration connConfiguration = createConnectionConfiguration();
60             switchConnectionProviderImpl.setConfiguration(connConfiguration);
61         } catch (UnknownHostException e) {
62             throw new IllegalArgumentException(e.getMessage(), e);
63         }
64         return switchConnectionProviderImpl;
65     }
66
67     /**
68      * @return
69      * @throws UnknownHostException 
70      */
71     private ConnectionConfiguration createConnectionConfiguration() throws UnknownHostException {
72         final InetAddress address = extractIpAddressBin(getAddress());
73         final Integer port = getPort();
74         final long switchIdleTimeout = getSwitchIdleTimeout();
75         
76         return new ConnectionConfiguration() {
77             @Override
78             public InetAddress getAddress() {
79                 return address;
80             }
81             @Override
82             public int getPort() {
83                 return port;
84             }
85             @Override
86             public Object getTransferProtocol() {
87                 // TODO Auto-generated method stub
88                 return null;
89             }
90             @Override
91             public FEATURE_SUPPORT getTlsSupport() {
92                 // TODO Auto-generated method stub
93                 return null;
94             }
95             @Override
96             public long getSwitchIdleTimeout() {
97                 return switchIdleTimeout;
98             }
99             @Override
100             public Object getSslContext() {
101                 // TODO Auto-generated method stub
102                 return null;
103             }
104         };
105     }
106
107     /**
108      * @param address
109      * @return
110      * @throws UnknownHostException 
111      */
112     private static InetAddress extractIpAddressBin(IpAddress address) throws UnknownHostException {
113         byte[] addressBin = null;
114         if (address != null) {
115             if (address.getIpv4Address() != null) {
116                 addressBin = address2bin(address.getIpv4Address().getValue());
117             } else if (address.getIpv6Address() != null) {
118                 addressBin = address2bin(address.getIpv6Address().getValue());
119             }
120         }
121         
122         if (addressBin == null) {
123             return null;
124         } else {
125             return InetAddress.getByAddress(addressBin);
126         }
127     }
128
129     /**
130      * @param value
131      * @return
132      */
133     private static byte[] address2bin(String value) {
134         //TODO: translate ipv4 or ipv6 into byte[]
135         return null;
136     }
137 }