wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 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 | */ |
Thomas Vachuska | bf916ea | 2015-05-20 18:24:34 -0700 | [diff] [blame^] | 16 | |
| 17 | package org.onosproject.incubator.net.tunnel; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 18 | |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | import org.onosproject.core.DefaultGroupId; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 21 | import org.onosproject.net.AbstractDescription; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 22 | import org.onosproject.net.SparseAnnotations; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 23 | import org.onosproject.net.provider.ProviderId; |
| 24 | |
| 25 | import com.google.common.base.MoreObjects; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * Default implementation of immutable tunnel description entity. |
| 29 | */ |
| 30 | public class DefaultTunnelDescription extends AbstractDescription |
| 31 | implements TunnelDescription { |
| 32 | |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 33 | private final TunnelId tunnelId; |
| 34 | private final TunnelEndPoint src; |
| 35 | private final TunnelEndPoint dst; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 36 | private final Tunnel.Type type; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 37 | private final DefaultGroupId groupId; // represent for a group flow table |
| 38 | // which a tunnel match up |
| 39 | // tunnel producer |
| 40 | private final ProviderId producerName; // tunnel producer name |
| 41 | private final TunnelName tunnelName; // name of a tunnel |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 42 | |
| 43 | /** |
| 44 | * Creates a tunnel description using the supplied information. |
| 45 | * |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 46 | * @param id TunnelId |
| 47 | * @param src TunnelPoint source |
| 48 | * @param dst TunnelPoint destination |
| 49 | * @param type tunnel type |
| 50 | * @param groupId groupId |
| 51 | * @param producerName tunnel producer |
| 52 | * @param tunnelName tunnel name |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 53 | * @param annotations optional key/value annotations |
| 54 | */ |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 55 | public DefaultTunnelDescription(TunnelId id, TunnelEndPoint src, |
| 56 | TunnelEndPoint dst, Tunnel.Type type, |
| 57 | DefaultGroupId groupId, |
| 58 | ProviderId producerName, |
| 59 | TunnelName tunnelName, |
| 60 | SparseAnnotations... annotations) { |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 61 | super(annotations); |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 62 | checkNotNull(producerName, "producerName cannot be null"); |
| 63 | checkNotNull(src, "src cannot be null"); |
| 64 | checkNotNull(dst, "dst cannot be null"); |
| 65 | checkNotNull(type, "type cannot be null"); |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 66 | this.tunnelId = id; |
| 67 | this.src = src; |
| 68 | this.dst = dst; |
| 69 | this.type = type; |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 70 | this.groupId = groupId; |
| 71 | this.producerName = producerName; |
| 72 | this.tunnelName = tunnelName; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public TunnelId id() { |
| 77 | return tunnelId; |
| 78 | } |
| 79 | |
| 80 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 81 | public TunnelEndPoint src() { |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 82 | return src; |
| 83 | } |
| 84 | |
| 85 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 86 | public TunnelEndPoint dst() { |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 87 | return dst; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public Tunnel.Type type() { |
| 92 | return type; |
| 93 | } |
| 94 | |
| 95 | @Override |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 96 | public DefaultGroupId groupId() { |
| 97 | return groupId; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public ProviderId producerName() { |
| 102 | return producerName; |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public TunnelName tunnelName() { |
| 107 | return tunnelName; |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public String toString() { |
| 112 | return MoreObjects.toStringHelper(this) |
| 113 | .add("tunnelId", id()) |
| 114 | .add("src", src()) |
| 115 | .add("dst", dst()) |
| 116 | .add("type", type()) |
jcc | 4a20a5f | 2015-04-30 15:43:39 +0800 | [diff] [blame] | 117 | .add("tunnelName", tunnelName()) |
| 118 | .add("producerName", producerName()) |
| 119 | .add("groupId", groupId()) |
wei wei | 89ddc32 | 2015-03-22 16:29:04 -0500 | [diff] [blame] | 120 | .toString(); |
| 121 | } |
| 122 | |
| 123 | } |