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