This patch revises yang model of neutron fwaas and related codes.
- fix tcp/udp port
- introduce identity and identityref for protocol/action
- drop descr for consistency
- drop backpointers. firewall-rules
If openstack provider wants a list of rules associated with
a given firewall policy, walk through rules and find rules whose
policy is the uuid of the policy.
- drop status in firewall policy which isn't defined in neutron API
- eliminated deprecated methods in neutron-spi
Change-Id: Ie6fac4202fadcff718d0d4960230eefe06852bc6
Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
Signed-off-by: Ritu Sood <ritu.sood@intel.com>
public String singleton_fw_rule_create_test() {
String url = base + "/fw/firewall_rules";
String content = "{ \"firewall_rule\": { \"action\": \"allow\"," +
- "\"description\": \"\", \"destination_ip_address\": null," +
- "\"destination_port\": \"80\", \"enabled\": true," +
+ "\"destination_ip_address\": null," +
+ "\"destination_port_min\": \"80\", \"destination_port_max\": \"80\"," +
+ "\"enabled\": true," +
"\"firewall_policy_id\": null," +
"\"id\": \"8722e0e0-9cc9-4490-9660-8c9a5732fbb0\"," +
"\"ip_version\": 4, \"name\": \"ALLOW_HTTP\"," +
"\"position\": null, \"protocol\": \"tcp\"," +
"\"shared\": false, \"source_ip_address\": null," +
- "\"source_port\": null," +
+ "\"source_port_min\": null, \"source_port_max\": null," +
"\"tenant_id\": \"45977fa2dbd7482098dd68d0d8970117\" } }";
ITNeutronE2E.test_create(url, content, "Firewall Rule Singleton Post Failed");
return content;
public void fw_rule_modify_test() {
String url = base + "/fw/firewall_rules/8722e0e0-9cc9-4490-9660-8c9a5732fbb0";
String content = "{ \"firewall_rule\": { \"action\": \"allow\"," +
- "\"description\": \"\", \"destination_ip_address\": null," +
- "\"destination_port\": \"80\", \"enabled\": true," +
+ "\"destination_ip_address\": null," +
+ "\"destination_port_min\": \"80\", \"destination_port_max\": \"80\"," +
+ "\"enabled\": true," +
"\"firewall_policy_id\": null," +
"\"id\": \"8722e0e0-9cc9-4490-9660-8c9a5732fbb0\"," +
"\"ip_version\": 4, \"name\": \"ALLOW_HTTP\"," +
"\"position\": null, \"protocol\": \"tcp\"," +
"\"shared\": true, \"source_ip_address\": null," +
- "\"source_port\": null," +
+ "\"source_port_min\": null, \"source_port_max\": null," +
"\"tenant_id\": \"45977fa2dbd7482098dd68d0d8970117\" } }";
- ITNeutronE2E.test_modify(url, content, "Firewall Rule Singleton Post Failed");
+ ITNeutronE2E.test_modify(url, content, "Firewall Rule Singleton Put Failed");
}
public void fw_rule_element_get_test() {
public void fw_rule_element_get_with_query_test() {
String url = base + "/fw/firewall_rules/8722e0e0-9cc9-4490-9660-8c9a5732fbb0" +
- "?fields=id&fields=tenant_id&fields=name&fields=description&fields=status" +
+ "?fields=id&fields=tenant_id&fields=name" +
"&fields=shared&fields=firewall_policy_id&fields=protocol&fields=enabled" +
"&fields=source_ip_address&fields=destination_ip_address" +
- "&fields=destination_port&fields=position&fields=action&fields=source_port" +
+ "&fields=destination_port_min&fields=destination_port_max&fields=position" +
+ "&fields=action&fields=source_port_min&fields=source_port_max" +
"&fields=limit&fields=marker&fields=page_reverse";
ITNeutronE2E.test_fetch(url, true, "Firewall Rule Element Get With Query Failed");
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Intel corporation and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712;
+
+import com.google.common.collect.ImmutableBiMap;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.FwProtocolBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.FwProtocolIcmp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.FwProtocolTcp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.FwProtocolUdp;
+
+
+public final class NeutronUtils {
+ private NeutronUtils() {
+ throw new UnsupportedOperationException("Utility class should not be instantiated.");
+ }
+
+ // For FWaaS
+ public static class FwProtocolMapper {
+ private FwProtocolMapper() {
+ throw new UnsupportedOperationException("Utility class should not be instantiated.");
+ }
+
+ private static final ImmutableBiMap<String, Class<? extends FwProtocolBase>> MAPPER
+ = new ImmutableBiMap.Builder<String, Class<? extends FwProtocolBase>>()
+ .put("tcp", FwProtocolTcp.class)
+ .put("udp", FwProtocolUdp.class)
+ .put("icmp", FwProtocolIcmp.class)
+ .build();
+
+ public static Class<? extends FwProtocolBase> get(String key) {
+ return MAPPER.get(key);
+ }
+
+ public static String getName(Class<? extends FwProtocolBase> key) {
+ ImmutableBiMap<Class<? extends FwProtocolBase>, String> inverseMapper = MAPPER.inverse();
+ return inverseMapper.get(key);
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2016 Intel corporation and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.fwaas.rev150712;
+
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.FwProtocolBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.NeutronUtils;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.fwaas.rev150712.FirewallRuleAttributes.Protocol;
+
+/**
+ * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
+ * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
+ *
+ * The reason behind putting it under src/main/java is:
+ * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
+ * loss of user code.
+ *
+ */
+public class FirewallRuleAttributesProtocolBuilder {
+ public static Protocol getDefaultInstance(final java.lang.String defaultValue) {
+ Class<? extends FwProtocolBase> fwProtocol =
+ NeutronUtils.FwProtocolMapper.get(defaultValue);
+ if (fwProtocol != null) {
+ return new Protocol(fwProtocol);
+ }
+ Short protocol = Short.parseShort(defaultValue);
+ return new Protocol(protocol);
+ }
+}
base probe-base;
}
+ // FWaaS v1
+ identity fw-protocol-base {
+ description "Base identity for firewall protocol";
+ }
+
+ identity fw-protocol-tcp {
+ description "TCP protocol.";
+ base fw-protocol-base;
+ }
+
+ identity fw-protocol-udp {
+ description "UDP protocol.";
+ base fw-protocol-base;
+ }
+
+ identity fw-protocol-icmp {
+ description "ICMP protocol.";
+ base fw-protocol-base;
+ }
+
// DIRECTION
identity direction-base {
description "Base identity for direction";
prefix neutron-fwaas;
import ietf-yang-types { prefix "yang"; }
- // It requires rfc6991 (revision 2013-07-15), but odl don't have it, so this patch verify build will fail.
- import ietf-inet-types { prefix "inet"; revision-date 2010-09-24; }
import neutron-attrs { prefix "attrs"; }
+ import neutron-constants { prefix "constants"; }
+ import neutron-types { prefix "types"; }
organization "OpenDaylight Neutron Group";
revision "2015-07-12" {
description
- "OpenDaylight Beryllium release";
+ "OpenDaylight Beryllium release";
}
grouping firewall-attributes {
- leaf descr {
- type string;
- description "Detailed description of the firewall.";
- }
leaf shared {
description "whether the firewall is shared or not";
type boolean;
}
grouping firewall-policy-attributes {
- leaf descr {
- type string;
- description "Detailed description of the firewall policy.";
- }
leaf shared {
description "whether the firewall policy is shared or not";
type boolean;
description "whether the firewall policy is audited or not";
type boolean;
}
- leaf-list firewall-rules {
- description "whether the firewall policy is audited or not";
- type yang:uuid;
- }
+ }
+
+ identity action-base {
+ description "firewall rule action";
+ }
+
+ identity action-allow {
+ description "firewall rule allow";
+ base action-base;
+ }
+
+ identity action-deny {
+ description "firewall rule deny";
+ base action-base;
}
grouping firewall-rule-attributes {
- leaf descr {
- type string;
- description "Detailed description of the firewall rule.";
- }
- leaf status {
- type string;
- description "Status of the firewall rule.";
- }
leaf shared {
description "whether the firewall rule is shared or not";
type boolean;
}
leaf protocol {
description "the protocol this rule applies to";
- type string;
+ type union {
+ type uint8;
+ type identityref {
+ base "constants:fw-protocol-base";
+ }
+ }
}
leaf ip-version {
description "the ip version this rule applies to";
- type int16;
+ type identityref {
+ base "constants:ip-version-base";
+ }
}
leaf source-ip-addr {
- type inet:ip-address;
+ type types:ip-prefix-or-address;
description "the source ip address for this rule";
}
leaf destination-ip-addr {
- type inet:ip-address;
+ type types:ip-prefix-or-address;
description "the destination ip address for this rule";
}
- leaf source-port {
- description "the source port for this rule";
- type int16;
+ leaf source-port-range-min {
+ description "the source port range min for this rule";
+ type uint16;
}
- leaf destination-port {
- description "the destination port for this rule";
- type int16;
+ leaf source-port-range-max {
+ description "the source port range max for this rule";
+ type uint16;
+ }
+ leaf destination-port-range-min {
+ description "the destination port range min for this rule";
+ type uint16;
+ }
+ leaf destination-port-range-max {
+ description "the destination port range max for this rule";
+ type uint16;
}
leaf position {
description "the priority position this rule occupies";
}
leaf action {
description "the action fot this rule";
- type string;
+ type identityref {
+ base "action-base";
+ }
}
}
* id uuid-str
* tenant_id uuid-str
* name String
- * description String
* admin_state_up Bool
- * status String
* shared Bool
* firewall_policy_id uuid-str
* http://docs.openstack.org/api/openstack-network/2.0/openstack-network.pdf
@XmlElement (name = "name")
String firewallName;
- @XmlElement (name = "description")
- String firewallDescription;
-
@XmlElement (defaultValue = "true", name = "admin_state_up")
Boolean firewallAdminStateIsUp;
- @XmlElement (name = "status")
- String firewallStatus;
-
@XmlElement (defaultValue = "false", name = "shared")
Boolean firewallIsShared;
@XmlElement (name = "firewall_policy_id")
String neutronFirewallPolicyID;
- // @deprecated use getID()
- public String getFirewallUUID() {
- return getID();
- }
-
- // @deprecated use setID()
- public void setFirewallUUID(String uuid) {
- setID(uuid);
- }
-
- @Deprecated
- public String getFirewallTenantID() {
- return getTenantID();
- }
-
- @Deprecated
- public void setFirewallTenantID(String tenantID) {
- setTenantID(tenantID);
- }
-
public String getFirewallName() {
return firewallName;
}
this.firewallName = firewallName;
}
- public String getFirewallDescription() {
- return firewallDescription;
- }
-
- public void setFirewallDescription(String firewallDescription) {
- this.firewallDescription = firewallDescription;
- }
-
public Boolean getFirewallAdminStateIsUp() {
return firewallAdminStateIsUp;
}
this.firewallAdminStateIsUp = firewallAdminStateIsUp;
}
- public String getFirewallStatus() {
- return firewallStatus;
- }
-
- public void setFirewallStatus(String firewallStatus) {
- this.firewallStatus = firewallStatus;
- }
-
public Boolean getFirewallIsShared() {
return firewallIsShared;
}
if (s.equals("name")) {
ans.setFirewallName(this.getFirewallName());
}
- if(s.equals("description")) {
- ans.setFirewallDescription(this.getFirewallDescription());
- }
if (s.equals("admin_state_up")) {
ans.setFirewallAdminStateIsUp(firewallAdminStateIsUp);
}
- if (s.equals("status")) {
- ans.setFirewallStatus(this.getFirewallStatus());
- }
if (s.equals("shared")) {
ans.setFirewallIsShared(firewallIsShared);
}
"firewallUUID='" + uuid + '\'' +
", firewallTenantID='" + tenantID + '\'' +
", firewallName='" + firewallName + '\'' +
- ", firewallDescription='" + firewallDescription + '\'' +
", firewallAdminStateIsUp=" + firewallAdminStateIsUp +
- ", firewallStatus='" + firewallStatus + '\'' +
", firewallIsShared=" + firewallIsShared +
", firewallRulePolicyID=" + neutronFirewallPolicyID +
'}';
* id uuid-str
* tenant_id uuid-str
* name String
- * description String
* shared Boolean
- * firewall_rules List
* audited Boolean
* http://docs.openstack.org/api/openstack-network/2.0/openstack-network.pdf
*
@XmlElement (name = "name")
String firewallPolicyName;
- @XmlElement (name = "description")
- String firewallPolicyDescription;
-
@XmlElement (defaultValue = "false", name = "shared")
Boolean firewallPolicyIsShared;
- @XmlElement (name = "firewall_rules")
- List<String> firewallPolicyRules;
-
@XmlElement (defaultValue = "false", name = "audited")
Boolean firewallPolicyIsAudited;
this.firewallPolicyIsAudited = firewallPolicyIsAudited;
}
- public void setFirewallPolicyRules(List<String> firewallPolicyRules) {
- this.firewallPolicyRules = firewallPolicyRules;
- }
-
- public List<String> getFirewallPolicyRules() {
- return firewallPolicyRules;
- }
-
public Boolean getFirewallPolicyIsShared() {
return firewallPolicyIsShared;
}
this.firewallPolicyIsShared = firewallPolicyIsShared;
}
- public String getFirewallPolicyDescription() {
- return firewallPolicyDescription;
- }
-
- public void setFirewallPolicyDescription(String firewallPolicyDescription) {
- this.firewallPolicyDescription = firewallPolicyDescription;
- }
-
public String getFirewallPolicyName() {
return firewallPolicyName;
}
this.firewallPolicyName = firewallPolicyName;
}
- @Deprecated
- public String getFirewallPolicyTenantID() {
- return getTenantID();
- }
-
- @Deprecated
- public void setFirewallPolicyTenantID(String tenantID) {
- setTenantID(tenantID);
- }
-
- // @deprecated use getID()
- public String getFirewallPolicyUUID() {
- return getID();
- }
-
- // @deprecated use setID()
- public void setFirewallPolicyUUID(String uuid) {
- setID(uuid);
- }
-
public NeutronFirewallPolicy extractFields(List<String> fields) {
NeutronFirewallPolicy ans = new NeutronFirewallPolicy();
Iterator<String> i = fields.iterator();
if (s.equals("name")) {
ans.setFirewallPolicyName(this.getFirewallPolicyName());
}
- if(s.equals("description")) {
- ans.setFirewallPolicyDescription(this.getFirewallPolicyDescription());
- }
if (s.equals("shared")) {
ans.setFirewallPolicyIsShared(firewallPolicyIsShared);
}
- if (s.equals("firewall_rules")) {
- List<String> firewallRuleList = new ArrayList<String>();
- firewallRuleList.addAll(this.getFirewallPolicyRules());
- ans.setFirewallPolicyRules(firewallRuleList);
- }
if (s.equals("audited")) {
ans.setFirewallPolicyIsAudited(firewallPolicyIsAudited);
}
"firewallPolicyUUID='" + uuid + '\'' +
", firewallPolicyTenantID='" + tenantID + '\'' +
", firewallPolicyName='" + firewallPolicyName + '\'' +
- ", firewallPolicyDescription='" + firewallPolicyDescription + '\'' +
", firewallPolicyIsShared=" + firewallPolicyIsShared +
- ", firewallPolicyRules=" + firewallPolicyRules +
", firewallPolicyIsAudited='" + firewallPolicyIsAudited + '\'' +
'}';
}
*
* tenant_id uuid-str
* name String
- * description String
* admin_state_up Bool
- * status String
* shared Bool
* firewall_policy_id uuid-str
* protocol String
* ip_version Integer
* source_ip_address String (IP addr or CIDR)
* destination_ip_address String (IP addr or CIDR)
- * source_port Integer
- * destination_port Integer
+ * source_port_range_min Integer
+ * source_port_range_max Integer
+ * destination_port_range_min Integer
+ * destination_port_range_max Integer
* position Integer
* action String
* enabled Bool
@XmlElement(name = "name")
String firewallRuleName;
- @XmlElement(name = "description")
- String firewallRuleDescription;
-
- @XmlElement(name = "status")
- String firewallRuleStatus;
-
@XmlElement(defaultValue = "false", name = "shared")
Boolean firewallRuleIsShared;
@XmlElement(name = "destination_ip_address")
String firewallRuleDstIpAddr;
- @XmlElement(name = "source_port")
- Integer firewallRuleSrcPort;
+ @XmlElement(name = "source_port_range_min")
+ Integer firewallRuleSrcPortRangeMin;
+
+ @XmlElement(name = "source_port_range_max")
+ Integer firewallRuleSrcPortRangeMax;
+
+ @XmlElement(name = "destination_port_range_min")
+ Integer firewallRuleDstPortRangeMin;
- @XmlElement(name = "destination_port")
- Integer firewallRuleDstPort;
+ @XmlElement(name = "destination_port_range_max")
+ Integer firewallRuleDstPortRangeMax;
@XmlElement(name = "position")
Integer firewallRulePosition;
this.firewallRulePosition = firewallRulePosition;
}
- public Integer getFirewallRuleDstPort() {
- return firewallRuleDstPort;
+ public Integer getFirewallRuleDstPortRangeMin() {
+ return firewallRuleDstPortRangeMin;
+ }
+
+ public void setFirewallRuleDstPortRangeMin(Integer firewallRuleDstPortRangeMin) {
+ this.firewallRuleDstPortRangeMin = firewallRuleDstPortRangeMin;
+ }
+
+ public Integer getFirewallRuleDstPortRangeMax() {
+ return firewallRuleDstPortRangeMax;
}
- public void setFirewallRuleDstPort(Integer firewallRuleDstPort) {
- this.firewallRuleDstPort = firewallRuleDstPort;
+ public void setFirewallRuleDstPortRangeMax(Integer firewallRuleDstPortRangeMax) {
+ this.firewallRuleDstPortRangeMax = firewallRuleDstPortRangeMax;
}
- public Integer getFirewallRuleSrcPort() {
- return firewallRuleSrcPort;
+ public Integer getFirewallRuleSrcPortRangeMin() {
+ return firewallRuleSrcPortRangeMin;
}
- public void setFirewallRuleSrcPort(Integer firewallRuleSrcPort) {
- this.firewallRuleSrcPort = firewallRuleSrcPort;
+ public void setFirewallRuleSrcPortRangeMin(Integer firewallRuleSrcPortRangeMin) {
+ this.firewallRuleSrcPortRangeMin = firewallRuleSrcPortRangeMin;
+ }
+
+ public Integer getFirewallRuleSrcPortRangeMax() {
+ return firewallRuleSrcPortRangeMax;
+ }
+
+ public void setFirewallRuleSrcPortRangeMax(Integer firewallRuleSrcPortRangeMax) {
+ this.firewallRuleSrcPortRangeMax = firewallRuleSrcPortRangeMax;
}
public String getFirewallRuleDstIpAddr() {
this.firewallRuleIsShared = firewallRuleIsShared;
}
- public String getFirewallRuleStatus() {
- return firewallRuleStatus;
- }
-
- public void setFirewallRuleStatus(String firewallRuleStatus) {
- this.firewallRuleStatus = firewallRuleStatus;
- }
-
- public String getFirewallRuleDescription() {
- return firewallRuleDescription;
- }
-
- public void setFirewallRuleDescription(String firewallRuleDescription) {
- this.firewallRuleDescription = firewallRuleDescription;
- }
-
public String getFirewallRuleName() {
return firewallRuleName;
}
this.firewallRuleName = firewallRuleName;
}
- @Deprecated
- public String getFirewallRuleTenantID() {
- return getTenantID();
- }
-
- @Deprecated
- public void setFirewallRuleTenantID(String tenantID) {
- setTenantID(tenantID);
- }
-
- // @deprecated use getID()
- public String getFirewallRuleUUID() {
- return getID();
- }
-
- // @deprecated use setID()
- public void setFireWallRuleID(String uuid) {
- setID(uuid);
- }
-
public NeutronFirewallRule extractFields(List<String> fields) {
NeutronFirewallRule ans = new NeutronFirewallRule();
Iterator<String> i = fields.iterator();
if (s.equals("name")) {
ans.setFirewallRuleName(this.getFirewallRuleName());
}
- if (s.equals("description")) {
- ans.setFirewallRuleDescription(this.getFirewallRuleDescription());
- }
- if (s.equals("status")) {
- ans.setFirewallRuleStatus(this.getFirewallRuleStatus());
- }
if (s.equals("shared")) {
ans.setFirewallRuleIsShared(firewallRuleIsShared);
}
if (s.equals("destination_ip_address")) {
ans.setFirewallRuleDstIpAddr(this.getFirewallRuleDstIpAddr());
}
- if (s.equals("source_port")) {
- ans.setFirewallRuleSrcPort(this.getFirewallRuleSrcPort());
+ if (s.equals("source_port_range_min")) {
+ ans.setFirewallRuleSrcPortRangeMin(this.getFirewallRuleSrcPortRangeMin());
+ }
+ if (s.equals("source_port_range_max")) {
+ ans.setFirewallRuleSrcPortRangeMax(this.getFirewallRuleSrcPortRangeMax());
+ }
+ if (s.equals("destination_port_range_min")) {
+ ans.setFirewallRuleDstPortRangeMin(this.getFirewallRuleDstPortRangeMin());
}
- if (s.equals("destination_port")) {
- ans.setFirewallRuleDstPort(this.getFirewallRuleDstPort());
+ if (s.equals("destination_port_range_max")) {
+ ans.setFirewallRuleDstPortRangeMax(this.getFirewallRuleDstPortRangeMax());
}
if (s.equals("position")) {
ans.setFirewallRulePosition(this.getFirewallRulePosition());
"firewallRuleUUID='" + uuid + '\'' +
", firewallRuleTenantID='" + tenantID + '\'' +
", firewallRuleName='" + firewallRuleName + '\'' +
- ", firewallRuleDescription='" + firewallRuleDescription + '\'' +
- ", firewallRuleStatus='" + firewallRuleStatus + '\'' +
", firewallRuleIsShared=" + firewallRuleIsShared +
", firewallRulePolicyID=" + firewallRulePolicyID +
", firewallRuleProtocol='" + firewallRuleProtocol + '\'' +
", firewallRuleIpVer=" + firewallRuleIpVer +
", firewallRuleSrcIpAddr='" + firewallRuleSrcIpAddr + '\'' +
", firewallRuleDstIpAddr='" + firewallRuleDstIpAddr + '\'' +
- ", firewallRuleSrcPort=" + firewallRuleSrcPort +
- ", firewallRuleDstPort=" + firewallRuleDstPort +
+ ", firewallRuleSrcPort=" + firewallRuleSrcPortRangeMin + ':' + firewallRuleSrcPortRangeMax +
+ ", firewallRuleDstPort=" + firewallRuleDstPortRangeMin + ':' + firewallRuleDstPortRangeMax +
", firewallRulePosition=" + firewallRulePosition +
", firewallRuleAction='" + firewallRuleAction + '\'' +
", firewallRuleIsEnabled=" + firewallRuleIsEnabled +
Assert.assertEquals("NeutronFirewall JAXB Test 3: Testing name failed",
"jaxb-test", testObject.getFirewallName());
- Assert.assertEquals("NeutronFirewall JAXB Test 4: Testing description failed",
- "Test of NeutronFirewall JAXB", testObject.getFirewallDescription());
-
Assert.assertFalse("NeutronFirewall JAXB Test 5: Testing admin_state_up failed",
testObject.getFirewallAdminStateIsUp());
- Assert.assertEquals("NeutronFirewall JAXB Test 6: Testing status failed",
- "DOWN", testObject.getFirewallStatus());
-
Assert.assertTrue("NeutronFirewall JAXB Test 7: Testing shared failed",
testObject.getFirewallIsShared());
Assert.assertEquals("NeutronFirewallPolicy JAXB Test 3: Testing name failed",
"jaxb-test", testObject.getFirewallPolicyName());
- Assert.assertEquals("NeutronFirewallPolicy JAXB Test 4: Testing description failed",
- "Test of NeutronFirewallPolicy JAXB", testObject.getFirewallPolicyDescription());
-
Assert.assertTrue("NeutronFirewallPolicy JAXB Test 5: Testing shared failed",
testObject.getFirewallPolicyIsShared());
Assert.assertTrue("NeutronFirewallPolicy JAXB Test 6: Testing audited failed",
testObject.getFirewallPolicyIsAudited());
-
- List<String> policyRules = testObject.getFirewallPolicyRules();
- Assert.assertEquals("NeutronFirewallPolicy JAXB Test 7.1: Testing firewall policy rules length failed",
- 1, policyRules.size());
- Assert.assertEquals("NeutronFirewallPolicy JAXB Test 7.2: Testing firewall policy rules content failed",
- "83ca694a-eeff-48e5-b2d8-fe5198cf2e86", policyRules.get(0));
} catch (Exception e) {
Assert.assertTrue("Tests failed", false);
}
}
- private static final String NeutronFirewallRule_sourceJson="{ \"action\": \"allow\", \"description\": \"Test of NeutronFirewallRule JAXB\", \"destination_ip_address\": \"10.10.10.10\", \"destination_port\": \"80\", \"enabled\": true, \"firewall_policy_id\": \"83ca694a-eeff-48e5-b2d8-fe5198cf2e86\", \"id\": \"8722e0e0-9cc9-4490-9660-8c9a5732fbb0\", \"ip_version\": 4, \"name\": \"ALLOW_HTTP\", \"position\": 1, \"protocol\": \"tcp\", \"shared\": false, \"source_ip_address\": \"10.10.10.8\", \"source_port\": null, \"tenant_id\": \"45977fa2dbd7482098dd68d0d8970117\" }";
+ private static final String NeutronFirewallRule_sourceJson="{ \"action\": \"allow\", \"description\": \"Test of NeutronFirewallRule JAXB\", \"destination_ip_address\": \"10.10.10.10\", \"destination_port_range_min\": \"80\", \"destination_port_range_max\": \"81\", \"enabled\": true, \"firewall_policy_id\": \"83ca694a-eeff-48e5-b2d8-fe5198cf2e86\", \"id\": \"8722e0e0-9cc9-4490-9660-8c9a5732fbb0\", \"ip_version\": 4, \"name\": \"ALLOW_HTTP\", \"position\": 1, \"protocol\": \"tcp\", \"shared\": false, \"source_ip_address\": \"10.10.10.8\", \"source_port\": null, \"tenant_id\": \"45977fa2dbd7482098dd68d0d8970117\" }";
@Test
public void test_NeutronFirewallRule_JAXB() {
Assert.assertEquals("NeutronFirewallRule JAXB Test 3: Testing name failed",
"ALLOW_HTTP", testObject.getFirewallRuleName());
- Assert.assertEquals("NeutronFirewallRule JAXB Test 4: Testing description failed",
- "Test of NeutronFirewallRule JAXB", testObject.getFirewallRuleDescription());
-
Assert.assertEquals("NeutronFirewallRule JAXB Test 5: Testing firewaulPolicyRuleID failed",
"83ca694a-eeff-48e5-b2d8-fe5198cf2e86", testObject.getFirewallRulePolicyID());
Assert.assertEquals("NeutronFirewallRule JAXB Test 10: Testing destination IP address failed",
"10.10.10.10", testObject.getFirewallRuleDstIpAddr());
- Assert.assertEquals("NeutronFirewallRule JAXB Test 11: Testing source port failed",
- null, testObject.getFirewallRuleSrcPort());
+ Assert.assertEquals("NeutronFirewallRule JAXB Test 11.1: Testing source port min failed",
+ null, testObject.getFirewallRuleSrcPortRangeMin());
+
+ Assert.assertEquals("NeutronFirewallRule JAXB Test 11.2: Testing source port failed",
+ null, testObject.getFirewallRuleSrcPortRangeMax());
+
+ Assert.assertEquals("NeutronFirewallRule JAXB Test 12.1: Testing destination port min failed",
+ new Integer(80), testObject.getFirewallRuleDstPortRangeMin());
- Assert.assertEquals("NeutronFirewallRule JAXB Test 12: Testing destination port failed",
- new Integer(80), testObject.getFirewallRuleDstPort());
+ Assert.assertEquals("NeutronFirewallRule JAXB Test 12.2: Testing destination port max failed",
+ new Integer(81), testObject.getFirewallRuleDstPortRangeMax());
Assert.assertEquals("NeutronFirewallRule JAXB Test 13: Testing position failed",
new Integer(1), testObject.getFirewallRulePosition());
@QueryParam("id") String queryFirewallUUID,
@QueryParam("tenant_id") String queryFirewallTenantID,
@QueryParam("name") String queryFirewallName,
- @QueryParam("description") String queryFirewallDescription,
@QueryParam("admin_state_up") Boolean queryFirewallAdminStateIsUp,
- @QueryParam("status") String queryFirewallStatus,
@QueryParam("shared") Boolean queryFirewallIsShared,
@QueryParam("firewall_policy_id") String queryFirewallPolicyID,
// pagination
queryFirewallTenantID.equals(nsg.getTenantID())) &&
(queryFirewallName == null ||
queryFirewallName.equals(nsg.getFirewallName())) &&
- (queryFirewallDescription == null ||
- queryFirewallDescription.equals(nsg.getFirewallDescription())) &&
(queryFirewallAdminStateIsUp == null ||
queryFirewallAdminStateIsUp.equals(nsg.getFirewallAdminStateIsUp())) &&
- (queryFirewallStatus == null ||
- queryFirewallStatus.equals(nsg.getFirewallStatus())) &&
(queryFirewallIsShared == null ||
queryFirewallIsShared.equals(nsg.getFirewallIsShared())) &&
(queryFirewallPolicyID == null ||
@QueryParam("id") String queryFirewallPolicyUUID,
@QueryParam("tenant_id") String queryFirewallPolicyTenantID,
@QueryParam("name") String queryFirewallPolicyName,
- @QueryParam("description") String querySecurityPolicyDescription,
@QueryParam("shared") Boolean querySecurityPolicyIsShared,
- @QueryParam("firewall_rules") List<String> querySecurityPolicyFirewallRules,
@QueryParam("audited") Boolean querySecurityPolicyIsAudited,
// pagination
@QueryParam("limit") String limit,
queryFirewallPolicyTenantID.equals(nsg.getTenantID())) &&
(queryFirewallPolicyName == null ||
queryFirewallPolicyName.equals(nsg.getFirewallPolicyName())) &&
- (querySecurityPolicyDescription == null ||
- querySecurityPolicyDescription.equals(nsg.getFirewallPolicyDescription())) &&
(querySecurityPolicyIsShared == null ||
querySecurityPolicyIsShared.equals(nsg.getFirewallPolicyIsShared())) &&
- (querySecurityPolicyFirewallRules.size() == 0 ||
- querySecurityPolicyFirewallRules.equals(nsg.getFirewallPolicyRules())) &&
(querySecurityPolicyIsAudited == null ||
querySecurityPolicyIsAudited.equals(nsg.getFirewallPolicyIsAudited()))) {
if (fields.size() > 0) {
@QueryParam("id") String queryFirewallRuleUUID,
@QueryParam("tenant_id") String queryFirewallRuleTenantID,
@QueryParam("name") String queryFirewallRuleName,
- @QueryParam("description") String queryFirewallRuleDescription,
- @QueryParam("status") String queryFirewallRuleStatus,
@QueryParam("shared") Boolean queryFirewallRuleIsShared,
@QueryParam("firewall_policy_id") String queryFirewallRulePolicyID,
@QueryParam("protocol") String queryFirewallRuleProtocol,
@QueryParam("ip_version") Integer queryFirewallRuleIpVer,
@QueryParam("source_ip_address") String queryFirewallRuleSrcIpAddr,
@QueryParam("destination_ip_address") String queryFirewallRuleDstIpAddr,
- @QueryParam("source_port") Integer queryFirewallRuleSrcPort,
- @QueryParam("destination_port") Integer queryFirewallRuleDstPort,
+ @QueryParam("source_port_range_min") Integer queryFirewallRuleSrcPortRangeMin,
+ @QueryParam("source_port_range_max") Integer queryFirewallRuleSrcPortRangeMax,
+ @QueryParam("destination_port_range_min") Integer queryFirewallRuleDstPortRangeMin,
+ @QueryParam("destination_port_range_max") Integer queryFirewallRuleDstPortRangeMax,
@QueryParam("position") Integer queryFirewallRulePosition,
@QueryParam("action") String queryFirewallRuleAction,
@QueryParam("enabled") Boolean queryFirewallRuleIsEnabled,
queryFirewallRuleTenantID.equals(nsr.getTenantID())) &&
(queryFirewallRuleName == null ||
queryFirewallRuleName.equals(nsr.getFirewallRuleName())) &&
- (queryFirewallRuleDescription == null ||
- queryFirewallRuleDescription.equals(nsr.getFirewallRuleDescription())) &&
- (queryFirewallRuleStatus == null ||
- queryFirewallRuleStatus.equals(nsr.getFirewallRuleStatus())) &&
(queryFirewallRuleIsShared == null ||
queryFirewallRuleIsShared.equals(nsr.getFirewallRuleIsShared())) &&
(queryFirewallRulePolicyID == null ||
queryFirewallRuleSrcIpAddr.equals(nsr.getFirewallRuleSrcIpAddr())) &&
(queryFirewallRuleDstIpAddr == null ||
queryFirewallRuleDstIpAddr.equals(nsr.getFirewallRuleDstIpAddr())) &&
- (queryFirewallRuleSrcPort == null ||
- queryFirewallRuleSrcPort.equals(nsr.getFirewallRuleSrcPort())) &&
- (queryFirewallRuleDstPort == null ||
- queryFirewallRuleDstPort.equals(nsr.getFirewallRuleDstPort())) &&
+ (queryFirewallRuleSrcPortRangeMin == null ||
+ queryFirewallRuleSrcPortRangeMin.equals(nsr.getFirewallRuleSrcPortRangeMin())) &&
+ (queryFirewallRuleSrcPortRangeMax == null ||
+ queryFirewallRuleSrcPortRangeMax.equals(nsr.getFirewallRuleSrcPortRangeMax())) &&
+ (queryFirewallRuleDstPortRangeMin == null ||
+ queryFirewallRuleDstPortRangeMin.equals(nsr.getFirewallRuleDstPortRangeMin())) &&
+ (queryFirewallRuleDstPortRangeMax == null ||
+ queryFirewallRuleDstPortRangeMax.equals(nsr.getFirewallRuleDstPortRangeMax())) &&
(queryFirewallRulePosition == null ||
queryFirewallRulePosition.equals(nsr.getFirewallRulePosition())) &&
(queryFirewallRuleAction == null ||
answer.setTenantID(firewall.getTenantId());
}
answer.setFirewallAdminStateIsUp(firewall.isAdminStateUp());
- if (firewall.getStatus() != null) {
- answer.setFirewallStatus(firewall.getStatus());
- }
- if (firewall.getDescr() != null) {
- answer.setFirewallDescription(firewall.getDescr());
- }
if (firewall.isShared() != null) {
answer.setFirewallIsShared(firewall.isShared());
}
if (firewall.getFirewallAdminStateIsUp() != null) {
firewallBuilder.setAdminStateUp(firewall.getFirewallAdminStateIsUp());
}
- if (firewall.getFirewallStatus() != null) {
- firewallBuilder.setStatus(firewall.getFirewallStatus());
- }
- if (firewall.getFirewallDescription() != null) {
- firewallBuilder.setDescr(firewall.getFirewallDescription());
- }
if (firewall.getFirewallIsShared() != null) {
firewallBuilder.setShared(firewall.getFirewallIsShared());
}
package org.opendaylight.neutron.transcriber;
-import java.util.ArrayList;
import java.util.List;
import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
import org.opendaylight.neutron.spi.INeutronFirewallPolicyCRUD;
import org.opendaylight.neutron.spi.NeutronFirewallPolicy;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.fwaas.rev150712.policies.attributes.FirewallPolicies;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.fwaas.rev150712.policies.attributes.firewall.policies.FirewallPolicy;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.fwaas.rev150712.policies.attributes.firewall.policies.FirewallPolicyBuilder;
if (policy.getTenantId() != null) {
answer.setTenantID(policy.getTenantId());
}
- if (policy.getDescr() != null) {
- answer.setFirewallPolicyDescription(policy.getDescr());
- }
if (policy.isShared() != null) {
answer.setFirewallPolicyIsShared(policy.isShared());
}
if (policy.isAudited() != null) {
answer.setFirewallPolicyIsAudited(policy.isAudited());
}
- if (policy.getFirewallRules() != null) {
- final List<String> rules = new ArrayList<String>();
- for (final Uuid rule: policy.getFirewallRules()) {
- rules.add(rule.getValue());
- }
- answer.setFirewallPolicyRules(rules);
- }
return answer;
}
if (policy.getTenantID() != null) {
policyBuilder.setTenantId(toUuid(policy.getTenantID()));
}
- if (policy.getFirewallPolicyDescription() != null) {
- policyBuilder.setDescr(policy.getFirewallPolicyDescription());
- }
if (policy.getFirewallPolicyIsShared() != null) {
policyBuilder.setShared(policy.getFirewallPolicyIsShared());
}
if (policy.getFirewallPolicyIsAudited() != null) {
policyBuilder.setAudited(policy.getFirewallPolicyIsAudited());
}
- if (policy.getFirewallPolicyRules() != null) {
- final List<Uuid> rules = new ArrayList<Uuid>();
- for (final String rule: policy.getFirewallPolicyRules()) {
- rules.add(toUuid(rule));
- }
- policyBuilder.setFirewallRules(rules);
- }
return policyBuilder.build();
}
import org.opendaylight.neutron.spi.INeutronFirewallRuleCRUD;
import org.opendaylight.neutron.spi.NeutronFirewallRule;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.IpVersionBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.IpVersionV4;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.IpVersionV6;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.NeutronUtils.FwProtocolMapper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.fwaas.rev150712.ActionAllow;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.fwaas.rev150712.ActionBase;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.fwaas.rev150712.ActionDeny;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.fwaas.rev150712.FirewallRuleAttributes.Protocol;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.fwaas.rev150712.rules.attributes.FirewallRules;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.fwaas.rev150712.rules.attributes.firewall.rules.FirewallRule;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.fwaas.rev150712.rules.attributes.firewall.rules.FirewallRuleBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
-
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.types.rev160517.IpPrefixOrAddress;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+
+import com.google.common.collect.ImmutableBiMap;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
public class NeutronFirewallRuleInterface extends AbstractNeutronInterface<FirewallRule, FirewallRules, NeutronFirewallRule> implements INeutronFirewallRuleCRUD {
private static final Logger LOGGER = LoggerFactory.getLogger(NeutronFirewallRuleInterface.class);
+ private static final ImmutableBiMap<Class<? extends ActionBase>, String> ACTION_MAP
+ = new ImmutableBiMap.Builder<Class<? extends ActionBase>, String>()
+ .put(ActionAllow.class, "allow")
+ .put(ActionDeny.class, "deny")
+ .build();
+
+ private static final ImmutableBiMap<Class<? extends IpVersionBase>, Integer> IP_VERSION_MAP
+ = new ImmutableBiMap.Builder<Class<? extends IpVersionBase>, Integer>()
+ .put(IpVersionV4.class, Integer.valueOf(4))
+ .put(IpVersionV6.class, Integer.valueOf(6))
+ .build();
+
NeutronFirewallRuleInterface(ProviderContext providerContext) {
super(providerContext);
}
if (rule.getTenantId() != null) {
answer.setTenantID(rule.getTenantId());
}
- if (rule.getDescr() != null) {
- answer.setFirewallRuleDescription(rule.getDescr());
- }
- if (rule.getStatus() != null) {
- answer.setFirewallRuleStatus(rule.getStatus());
- }
if (rule.isShared() != null) {
answer.setFirewallRuleIsShared(rule.isShared());
}
answer.setFirewallRulePolicyID(rule.getFirewallPolicyId().getValue());
}
if (rule.getProtocol() != null) {
- answer.setFirewallRuleProtocol(rule.getProtocol());
+ final Protocol protocol = rule.getProtocol();
+ if (protocol.getUint8() != null) {
+ // uint8
+ answer.setFirewallRuleProtocol(protocol.getUint8().toString());
+ } else {
+ // symbolic protocol name
+ answer.setFirewallRuleProtocol(FwProtocolMapper.getName(protocol.getIdentityref()));
+ }
}
if (rule.getIpVersion() != null) {
- answer.setFirewallRuleIpVer(rule.getIpVersion().intValue());
+ answer.setFirewallRuleIpVer(IP_VERSION_MAP.get(rule.getIpVersion()));
}
if (rule.getSourceIpAddr() != null) {
answer.setFirewallRuleSrcIpAddr(String.valueOf(rule.getSourceIpAddr().getValue()));
if (rule.getDestinationIpAddr() != null) {
answer.setFirewallRuleDstIpAddr(String.valueOf(rule.getDestinationIpAddr().getValue()));
}
- if (rule.getSourcePort() != null) {
- answer.setFirewallRuleSrcPort(rule.getSourcePort().intValue());
+ if (rule.getSourcePortRangeMin() != null) {
+ answer.setFirewallRuleSrcPortRangeMin(rule.getSourcePortRangeMin());
}
- if (rule.getDestinationPort() != null) {
- answer.setFirewallRuleDstPort(rule.getDestinationPort().intValue());
+ if (rule.getSourcePortRangeMax() != null) {
+ answer.setFirewallRuleSrcPortRangeMax(rule.getSourcePortRangeMax());
+ }
+ if (rule.getDestinationPortRangeMin() != null) {
+ answer.setFirewallRuleDstPortRangeMin(rule.getDestinationPortRangeMin());
+ }
+ if (rule.getDestinationPortRangeMax() != null) {
+ answer.setFirewallRuleDstPortRangeMax(rule.getDestinationPortRangeMax());
}
if (rule.getPosition() != null) {
- answer.setFirewallRulePosition(rule.getPosition().intValue());
+ answer.setFirewallRulePosition(Integer.valueOf(rule.getPosition().intValue()));
}
if (rule.getAction() != null) {
- answer.setFirewallRuleAction(rule.getAction());
+ answer.setFirewallRuleAction(ACTION_MAP.get(rule.getAction()));
}
return answer;
}
if (rule.getTenantID() != null) {
ruleBuilder.setTenantId(toUuid(rule.getTenantID()));
}
- if (rule.getFirewallRuleDescription() != null) {
- ruleBuilder.setDescr(rule.getFirewallRuleDescription());
- }
- if (rule.getFirewallRuleStatus() != null) {
- ruleBuilder.setStatus(rule.getFirewallRuleStatus());
- }
if (rule.getFirewallRuleIsShared() != null) {
ruleBuilder.setShared(rule.getFirewallRuleIsShared());
}
ruleBuilder.setFirewallPolicyId(toUuid(rule.getFirewallRulePolicyID()));
}
if (rule.getFirewallRuleProtocol() != null) {
- ruleBuilder.setProtocol(rule.getFirewallRuleProtocol());
+ final String protocolString = rule.getFirewallRuleProtocol();
+ final Protocol protocol = new Protocol(protocolString.toCharArray());
+ ruleBuilder.setProtocol(protocol);
}
if (rule.getFirewallRuleIpVer() != null) {
- ruleBuilder.setIpVersion(rule.getFirewallRuleIpVer().shortValue());
+ final ImmutableBiMap<Integer, Class<? extends IpVersionBase>> mapper = IP_VERSION_MAP.inverse();
+ ruleBuilder.setIpVersion(mapper.get(rule.getFirewallRuleIpVer()));
}
if (rule.getFirewallRuleSrcIpAddr() != null) {
- final IpAddress ipAddress = new IpAddress(rule.getFirewallRuleSrcIpAddr().toCharArray());
+ final IpPrefixOrAddress ipAddress = new IpPrefixOrAddress(rule.getFirewallRuleSrcIpAddr().toCharArray());
ruleBuilder.setSourceIpAddr(ipAddress);
}
if (rule.getFirewallRuleDstIpAddr() != null) {
- final IpAddress ipAddress = new IpAddress(rule.getFirewallRuleDstIpAddr().toCharArray());
+ final IpPrefixOrAddress ipAddress = new IpPrefixOrAddress(rule.getFirewallRuleDstIpAddr().toCharArray());
ruleBuilder.setDestinationIpAddr(ipAddress);
}
- if (rule.getFirewallRuleSrcPort() != null) {
- ruleBuilder.setSourcePort(rule.getFirewallRuleSrcPort().shortValue());
+ if (rule.getFirewallRuleSrcPortRangeMin() != null) {
+ ruleBuilder.setSourcePortRangeMin(rule.getFirewallRuleSrcPortRangeMin());
+ }
+ if (rule.getFirewallRuleSrcPortRangeMax() != null) {
+ ruleBuilder.setSourcePortRangeMax(rule.getFirewallRuleSrcPortRangeMax());
+ }
+ if (rule.getFirewallRuleDstPortRangeMin() != null) {
+ ruleBuilder.setDestinationPortRangeMin(rule.getFirewallRuleDstPortRangeMin());
}
- if (rule.getFirewallRuleDstPort() != null) {
- ruleBuilder.setDestinationPort(rule.getFirewallRuleDstPort().shortValue());
+ if (rule.getFirewallRuleDstPortRangeMax() != null) {
+ ruleBuilder.setDestinationPortRangeMax(rule.getFirewallRuleDstPortRangeMax());
}
if (rule.getFirewallRulePosition() != null) {
ruleBuilder.setPosition(rule.getFirewallRulePosition().shortValue());
}
if (rule.getFirewallRuleAction() != null) {
- ruleBuilder.setAction(rule.getFirewallRuleAction());
+ final ImmutableBiMap<String, Class<? extends ActionBase>> mapper = ACTION_MAP.inverse();
+ ruleBuilder.setAction(mapper.get(rule.getFirewallRuleAction()));
}
return ruleBuilder.build();
}