Merge "Tests for neutron-ovsdb"
[groupbasedpolicy.git] / renderers / ofoverlay / src / main / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / sfcutils / SfcNshHeader.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others. 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
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.sfcutils;
10
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address;
12 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
13
14 import com.google.common.net.InetAddresses;
15
16
17 public class SfcNshHeader {
18     private final Ipv4Address nshTunIpDst;
19     private final PortNumber nshTunUdpPort;
20     private final Long nshNspToChain;
21     private final Short nshNsiToChain;
22     private final Long nshNspFromChain;
23     private final Short nshNsiFromChain;
24     private final Long nshMetaC1;
25     private final Long nshMetaC2;
26
27     private static final int TYPE = 1;
28
29     private SfcNshHeader(SfcNshHeaderBuilder builder) {
30         this.nshMetaC1 = builder.nshMetaC1;
31         this.nshMetaC2 = builder.nshMetaC2;
32         this.nshTunIpDst = builder.nshTunIpDst;
33         this.nshTunUdpPort = builder.nshTunUdpPort;
34         this.nshNspToChain = builder.nshNspToChain;
35         this.nshNspFromChain = builder.nshNspFromChain;
36         this.nshNsiToChain = builder.nshNsiToChain;
37         this.nshNsiFromChain = builder.nshNsiFromChain;
38
39     }
40
41     public boolean isValid(SfcNshHeader sfcNshHeader) {
42         if (sfcNshHeader.nshTunIpDst == null) return false;
43         if (sfcNshHeader.nshNspToChain == null) return false;
44         if (sfcNshHeader.nshNspFromChain == null) return false;
45         if (sfcNshHeader.nshNsiToChain == null) return false;
46         if (sfcNshHeader.nshNsiFromChain == null) return false;
47         if (sfcNshHeader.nshMetaC1 == null) return false;
48         if (sfcNshHeader.nshMetaC2 == null) return false;
49         return true;
50     }
51
52     public Ipv4Address getNshTunIpDst() {
53         return nshTunIpDst;
54     }
55
56
57     public PortNumber getNshTunUdpPort() {
58         return nshTunUdpPort;
59     }
60
61
62     public Long getNshNspToChain() {
63         return nshNspToChain;
64     }
65
66     public Short getNshNsiToChain() {
67         return nshNsiToChain;
68     }
69
70     public Long getNshNspFromChain() {
71         return nshNspFromChain;
72     }
73
74
75
76     public Short getNshNsiFromChain() {
77         return nshNsiFromChain;
78     }
79
80
81     public Long getNshMetaC1() {
82         return nshMetaC1;
83     }
84
85     public Long getNshMetaC2() {
86         return nshMetaC2;
87     }
88
89     public static Long convertIpAddressToLong(Ipv4Address ipv4Address) {
90         return (InetAddresses.coerceToInteger(InetAddresses.forString(ipv4Address.getValue()))) & 0xFFFFFFFFL;
91     }
92
93     public static int getType() {
94         return TYPE;
95     }
96
97     public static class SfcNshHeaderBuilder {
98         private Ipv4Address nshTunIpDst;
99         private PortNumber nshTunUdpPort;
100         private Long nshNspToChain;
101         private  Short nshNsiToChain;
102         private Long nshNspFromChain;
103         private Short nshNsiFromChain;
104         private Long nshMetaC1;
105         private Long nshMetaC2;
106
107         public SfcNshHeader build() {
108             SfcNshHeader sfcNshHeader = new SfcNshHeader(this);
109             return sfcNshHeader;
110         }
111
112         /**
113          * SfcNshHeaderBuilder requires following in constructor:
114          */
115         public SfcNshHeaderBuilder() {
116
117         }
118
119         public SfcNshHeaderBuilder(SfcNshHeader sfcNshHeader) {
120
121             this.nshTunIpDst = sfcNshHeader.nshTunIpDst;
122             this.nshTunUdpPort = sfcNshHeader.nshTunUdpPort;
123             this.nshNspToChain = sfcNshHeader.nshNspToChain;
124             this.nshNsiToChain = sfcNshHeader.nshNsiToChain;
125             this.nshNspFromChain = sfcNshHeader.nshNspFromChain;
126             this.nshNsiFromChain = sfcNshHeader.nshNsiFromChain;
127             this.nshMetaC1 = sfcNshHeader.nshMetaC1;
128             this.nshMetaC2 = sfcNshHeader.nshMetaC2;
129         }
130
131         public SfcNshHeaderBuilder setNshTunIpDst(Ipv4Address nshTunIpDst) {
132             this.nshTunIpDst = nshTunIpDst;
133             return this;
134         }
135
136         public SfcNshHeaderBuilder setNshTunUdpPort(PortNumber nshTunUdpPort) {
137             this.nshTunUdpPort = nshTunUdpPort;
138             return this;
139         }
140
141         public SfcNshHeaderBuilder setNshNspToChain(Long nshNspToChain) {
142             this.nshNspToChain = nshNspToChain;
143             return this;
144         }
145
146         public SfcNshHeaderBuilder setNshNsiToChain(Short nshNsiToChain) {
147             this.nshNsiToChain = nshNsiToChain;
148             return this;
149         }
150
151         public SfcNshHeaderBuilder setNshNspFromChain(Long nshNspFromChain) {
152             this.nshNspFromChain = nshNspFromChain;
153             return this;
154         }
155
156         public SfcNshHeaderBuilder setNshNsiFromChain(Short nshNsiFromChain) {
157             this.nshNsiFromChain = nshNsiFromChain;
158             return this;
159         }
160
161         public SfcNshHeaderBuilder setNshMetaC1(Long nshMetaC1) {
162             this.nshMetaC1 = nshMetaC1;
163             return this;
164         }
165
166         public SfcNshHeaderBuilder setNshMetaC2(Long nshMetaC2) {
167             this.nshMetaC2 = nshMetaC2;
168             return this;
169         }
170
171     }
172
173
174
175 }