bdfb2021048e28227d5925abe3ae988ad243a0bf
[neutron.git] / neutron-spi / src / main / java / org / opendaylight / neutron / spi / NeutronSecurityRule.java
1 /*
2  * Copyright (C) 2014 Red Hat, 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
9 package org.opendaylight.neutron.spi;
10
11 import java.io.Serializable;
12 import javax.xml.bind.annotation.XmlAccessType;
13 import javax.xml.bind.annotation.XmlAccessorType;
14 import javax.xml.bind.annotation.XmlElement;
15 import javax.xml.bind.annotation.XmlRootElement;
16
17 /**
18  * See OpenStack Network API v2.0 Reference for description of
19  * annotated attributes. The current fields are as follows:
20  *
21  * <p>
22  * id                uuid (String) UUID for the security group rule.
23  * direction         String Direction the VM traffic  (ingress/egress).
24  * security_group_id The security group to associate rule with.
25  * protocol          String IP Protocol (icmp, tcp, udp, etc) or uint8.
26  * port_range_min    Integer Port at start of range
27  * port_range_max    Integer Port at end of range
28  * ethertype         String ethertype in L2 packet (IPv4, IPv6, etc)
29  * remote_ip_prefix  String (IP cidr) CIDR for address range.
30  * remote_group_id   uuid-str Source security group to apply to rule.
31  * tenant_id         uuid-str Owner of security rule. Admin only outside tenant.
32  */
33
34 @XmlRootElement
35 @XmlAccessorType(XmlAccessType.NONE)
36 public final class NeutronSecurityRule extends NeutronObject<NeutronSecurityRule>
37         implements Serializable, INeutronObject<NeutronSecurityRule> {
38     private static final long serialVersionUID = 1L;
39
40     @XmlElement(name = "direction")
41     String securityRuleDirection;
42
43     @XmlElement(name = "protocol")
44     String securityRuleProtocol;
45
46     @XmlElement(name = "port_range_min")
47     Integer securityRulePortMin;
48
49     @XmlElement(name = "port_range_max")
50     Integer securityRulePortMax;
51
52     @XmlElement(name = "ethertype")
53     String securityRuleEthertype;
54
55     @XmlElement(name = "remote_ip_prefix")
56     String securityRuleRemoteIpPrefix;
57
58     @XmlElement(name = "remote_group_id")
59     String securityRemoteGroupID;
60
61     @XmlElement(name = "security_group_id")
62     String securityRuleGroupID;
63
64     public NeutronSecurityRule() {
65     }
66
67     public String getSecurityRuleDirection() {
68         return securityRuleDirection;
69     }
70
71     public void setSecurityRuleDirection(String securityRuleDirection) {
72         this.securityRuleDirection = securityRuleDirection;
73     }
74
75     public String getSecurityRuleProtocol() {
76         return securityRuleProtocol;
77     }
78
79     public void setSecurityRuleProtocol(String securityRuleProtocol) {
80         this.securityRuleProtocol = securityRuleProtocol;
81     }
82
83     public Integer getSecurityRulePortMin() {
84         return securityRulePortMin;
85     }
86
87     public void setSecurityRulePortMin(Integer securityRulePortMin) {
88         this.securityRulePortMin = securityRulePortMin;
89     }
90
91     public Integer getSecurityRulePortMax() {
92         return securityRulePortMax;
93     }
94
95     public void setSecurityRulePortMax(Integer securityRulePortMax) {
96         this.securityRulePortMax = securityRulePortMax;
97     }
98
99     public String getSecurityRuleEthertype() {
100         return securityRuleEthertype;
101     }
102
103     public void setSecurityRuleEthertype(String securityRuleEthertype) {
104         this.securityRuleEthertype = securityRuleEthertype;
105     }
106
107     public String getSecurityRuleRemoteIpPrefix() {
108         return securityRuleRemoteIpPrefix;
109     }
110
111     public void setSecurityRuleRemoteIpPrefix(String securityRuleRemoteIpPrefix) {
112         this.securityRuleRemoteIpPrefix = securityRuleRemoteIpPrefix;
113     }
114
115     public String getSecurityRemoteGroupID() {
116         return securityRemoteGroupID;
117     }
118
119     public void setSecurityRemoteGroupID(String securityRemoteGroupID) {
120         this.securityRemoteGroupID = securityRemoteGroupID;
121     }
122
123     public String getSecurityRuleGroupID() {
124         return securityRuleGroupID;
125     }
126
127     public void setSecurityRuleGroupID(String securityRuleGroupID) {
128         this.securityRuleGroupID = securityRuleGroupID;
129     }
130
131     @Override
132     protected boolean extractField(String field, NeutronSecurityRule ans) {
133         switch (field) {
134             case "direction":
135                 ans.setSecurityRuleDirection(this.getSecurityRuleDirection());
136                 break;
137             case "protocol":
138                 ans.setSecurityRuleProtocol(this.getSecurityRuleProtocol());
139                 break;
140             case "port_range_min":
141                 ans.setSecurityRulePortMin(this.getSecurityRulePortMin());
142                 break;
143             case "port_range_max":
144                 ans.setSecurityRulePortMax(this.getSecurityRulePortMax());
145                 break;
146             case "ethertype":
147                 ans.setSecurityRuleEthertype(this.getSecurityRuleEthertype());
148                 break;
149             case "remote_ip_prefix":
150                 ans.setSecurityRuleRemoteIpPrefix(this.getSecurityRuleRemoteIpPrefix());
151                 break;
152             case "remote_group_id":
153                 ans.setSecurityRemoteGroupID(this.getSecurityRemoteGroupID());
154                 break;
155             case "security_group_id":
156                 ans.setSecurityRuleGroupID(this.getSecurityRuleGroupID());
157                 break;
158             default:
159                 return super.extractField(field, ans);
160         }
161         return true;
162     }
163
164     @Override
165     public String toString() {
166         return "NeutronSecurityRule{" + "securityRuleUUID='" + uuid + '\'' + ", securityRuleDirection='"
167                 + securityRuleDirection + '\'' + ", securityRuleProtocol='" + securityRuleProtocol + '\''
168                 + ", securityRulePortMin=" + securityRulePortMin + ", securityRulePortMax=" + securityRulePortMax
169                 + ", securityRuleEthertype='" + securityRuleEthertype + '\'' + ", securityRuleRemoteIpPrefix='"
170                 + securityRuleRemoteIpPrefix + '\'' + ", securityRemoteGroupID=" + securityRemoteGroupID
171                 + ", securityRuleGroupID='" + securityRuleGroupID + '\'' + ", securityRuleTenantID='" + tenantID + '\''
172                 + '}';
173     }
174 }