sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 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 | */ |
sangho | 93447f1 | 2016-02-24 00:33:22 +0900 | [diff] [blame] | 16 | package org.onosproject.openstackinterface; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 17 | |
sanghoshin | f4ffb94 | 2015-12-10 11:28:24 +0900 | [diff] [blame] | 18 | import java.util.Collection; |
| 19 | |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 20 | import static com.google.common.base.Preconditions.checkNotNull; |
| 21 | |
| 22 | |
| 23 | /** |
| 24 | * Represents the network information given by Neutron. |
| 25 | */ |
| 26 | public final class OpenstackNetwork { |
| 27 | |
| 28 | private String name; |
| 29 | private String tenantId; |
| 30 | private String segmentId; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 31 | private String id; |
daniel | bb83ebc | 2015-10-29 15:13:06 +0900 | [diff] [blame] | 32 | private NetworkType networkType; |
sanghoshin | f4ffb94 | 2015-12-10 11:28:24 +0900 | [diff] [blame] | 33 | private Collection<OpenstackSubnet> subnets; |
daniel | bb83ebc | 2015-10-29 15:13:06 +0900 | [diff] [blame] | 34 | |
| 35 | public enum NetworkType { |
| 36 | /** |
| 37 | * Currently only VXLAN moded is supported. |
| 38 | */ |
Hyunsun Moon | f789520 | 2016-01-12 12:21:48 -0800 | [diff] [blame] | 39 | VXLAN |
daniel | bb83ebc | 2015-10-29 15:13:06 +0900 | [diff] [blame] | 40 | } |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Returns the builder object of the OpenstackNetwork class. |
| 44 | * |
| 45 | * @return OpenstackNetwork builder object |
| 46 | */ |
| 47 | public static OpenstackNetwork.Builder builder() { |
| 48 | return new Builder(); |
| 49 | } |
| 50 | |
| 51 | private OpenstackNetwork(String name, String tenantId, String id, String sid, |
sanghoshin | f4ffb94 | 2015-12-10 11:28:24 +0900 | [diff] [blame] | 52 | NetworkType type, Collection<OpenstackSubnet> subnets) { |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 53 | this.name = checkNotNull(name); |
| 54 | this.tenantId = checkNotNull(tenantId); |
| 55 | this.segmentId = checkNotNull(sid); |
| 56 | this.id = checkNotNull(id); |
daniel | bb83ebc | 2015-10-29 15:13:06 +0900 | [diff] [blame] | 57 | this.networkType = type; |
sanghoshin | f4ffb94 | 2015-12-10 11:28:24 +0900 | [diff] [blame] | 58 | this.subnets = subnets; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | public String name() { |
| 62 | return this.name; |
| 63 | } |
| 64 | |
| 65 | public String tenantId() { |
| 66 | return this.tenantId; |
| 67 | } |
| 68 | |
| 69 | public String id() { |
| 70 | return this.id; |
| 71 | } |
| 72 | |
| 73 | public String segmentId() { |
| 74 | return this.segmentId; |
| 75 | } |
| 76 | |
daniel | bb83ebc | 2015-10-29 15:13:06 +0900 | [diff] [blame] | 77 | public NetworkType networkType() { |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 78 | return this.networkType; |
| 79 | } |
| 80 | |
sanghoshin | f4ffb94 | 2015-12-10 11:28:24 +0900 | [diff] [blame] | 81 | public Collection<OpenstackSubnet> subnets() { |
| 82 | return this.subnets; |
| 83 | } |
| 84 | |
sanghoshin | 46297d2 | 2015-11-03 17:51:24 +0900 | [diff] [blame] | 85 | @Override |
| 86 | protected Object clone() throws CloneNotSupportedException { |
| 87 | return super.clone(); |
| 88 | } |
| 89 | |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 90 | public static final class Builder { |
| 91 | private String name; |
| 92 | private String tenantId; |
| 93 | private String id; |
| 94 | private String sid; |
daniel | bb83ebc | 2015-10-29 15:13:06 +0900 | [diff] [blame] | 95 | private NetworkType networkType; |
sanghoshin | f4ffb94 | 2015-12-10 11:28:24 +0900 | [diff] [blame] | 96 | private Collection<OpenstackSubnet> subnets; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 97 | |
| 98 | public Builder name(String name) { |
| 99 | this.name = name; |
| 100 | |
| 101 | return this; |
| 102 | } |
| 103 | |
| 104 | public Builder tenantId(String tenantId) { |
| 105 | this.tenantId = tenantId; |
| 106 | |
| 107 | return this; |
| 108 | } |
| 109 | |
| 110 | public Builder id(String id) { |
| 111 | this.id = id; |
| 112 | |
| 113 | return this; |
| 114 | } |
| 115 | |
| 116 | public Builder segmentId(String sid) { |
| 117 | this.sid = sid; |
| 118 | |
| 119 | return this; |
| 120 | } |
| 121 | |
daniel | bb83ebc | 2015-10-29 15:13:06 +0900 | [diff] [blame] | 122 | public Builder networkType(NetworkType type) { |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 123 | this.networkType = type; |
| 124 | |
| 125 | return this; |
| 126 | } |
| 127 | |
sanghoshin | f4ffb94 | 2015-12-10 11:28:24 +0900 | [diff] [blame] | 128 | public Builder subnets(Collection<OpenstackSubnet> subnets) { |
| 129 | this.subnets = subnets; |
| 130 | |
| 131 | return this; |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 132 | } |
| 133 | |
sanghoshin | f4ffb94 | 2015-12-10 11:28:24 +0900 | [diff] [blame] | 134 | public OpenstackNetwork build() { |
| 135 | return new OpenstackNetwork(name, tenantId, id, sid, networkType, subnets); |
| 136 | } |
sanghoshin | 94872a1 | 2015-10-16 18:04:34 +0900 | [diff] [blame] | 137 | } |
| 138 | } |