ELAN: skip remote unicast MACs
[netvirt.git] / neutronvpn / api / src / main / java / org / opendaylight / netvirt / neutronvpn / api / enums / IpVersionChoice.java
1 /*
2  * Copyright (c) 2017 6WIND, Inc. 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.netvirt.neutronvpn.api.enums;
9
10 /**this enum is used to make a choice between IPv4 or IPv6 or both.
11  */
12 public enum IpVersionChoice {
13     UNDEFINED(0),
14     IPV4(4),
15     IPV6(6),
16     IPV4AND6(10);
17     public final int choice;
18
19     IpVersionChoice(int value) {
20         choice = value;
21     }
22
23     public boolean isIpVersionChosen(IpVersionChoice arg) {
24         if (this.choice == IpVersionChoice.IPV4AND6.choice || this.choice == arg.choice) {
25             return true;
26         }
27         return false;
28     }
29
30     /**used to get an association of ipv4 and/or ipv6 choice if it is possible.
31      * @param ipVers the IP version to combine with this
32      * @return the new IpVersionChoice
33      */
34     public IpVersionChoice addVersion(IpVersionChoice ipVers) {
35         if (ipVers == null) {
36             return this;
37         }
38         if (this.choice == UNDEFINED.choice) {
39             return ipVers;
40         }
41         if (this.choice == IPV4AND6.choice || ipVers.choice == IPV4AND6.choice) {
42             return IPV4AND6;
43         }
44         int newChoice = this.choice + ipVers.choice;
45         switch (newChoice) {
46             case 4:  return IpVersionChoice.IPV4;
47             case 8:  return IpVersionChoice.IPV4;
48
49             case 6:  return IpVersionChoice.IPV6;
50             case 12:  return IpVersionChoice.IPV6;
51
52             case 10:  return IpVersionChoice.IPV4AND6;
53
54             default:  return IpVersionChoice.UNDEFINED;
55         }
56     }
57 }