Merge "Bug 1029: Remove dead code: samples/clustersession"
[controller.git] / opendaylight / adsal / hosttracker / api / src / main / java / org / opendaylight / controller / hosttracker / HostIdFactory.java
1 /*
2  * Copyright IBM Corporation, 2013.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.hosttracker;
9
10 import java.net.InetAddress;
11
12 import org.opendaylight.controller.sal.packet.address.DataLinkAddress;
13
14 /*
15  * Class used to generate a key based on the scheme choosen for hostsdb storage in hosttracker.
16  * @author Deepak Udapudi
17  */
18 public class HostIdFactory {
19     public static final String DEFAULT_IP_KEY_SCHEME = "IP";
20     public static final String IP_MAC_KEY_SCHEME = "IP+MAC";
21     private static String scheme = null;
22     static {
23         scheme = System.getProperty("hosttracker.keyscheme");
24     }
25
26     public static String getScheme() {
27         return scheme;
28     }
29
30     public static IHostId create(InetAddress ip, DataLinkAddress mac) {
31         IHostId ipHostId = new IPHostId(ip);
32         if (scheme != null) {
33             switch (scheme) {
34
35             case DEFAULT_IP_KEY_SCHEME:
36                 return ipHostId;
37             case IP_MAC_KEY_SCHEME:
38                 IHostId ipMacHostId = new IPMacHostId(ip, mac);
39                 return ipMacHostId;
40             default:
41                 return ipHostId;
42
43             }
44         }
45         return ipHostId;
46     }
47
48 }