@XmlElement (name = "extra_dhcp_opts")
List<NeutronPort_ExtraDHCPOption> extraDHCPOptions;
+ //Port security is enabled by default for backward compatibility.
+ @XmlElement (defaultValue = "true", name = "port_security_enabled")
+ Boolean portSecurityEnabled;
+
public NeutronPort() {
}
public Boolean getAdminStateUp() { return adminStateUp; }
public void setAdminStateUp(Boolean newValue) {
- adminStateUp = newValue;
+ adminStateUp = newValue;
}
public String getStatus() {
}
public String getBindinghostID() {
- return bindinghostID;
+ return bindinghostID;
}
public void setBindinghostID(String bindinghostID) {
- this.bindinghostID = bindinghostID;
+ this.bindinghostID = bindinghostID;
+ }
+
+ public String getBindingvnicType() {
+ return bindingvnicType;
}
- public String getBindingvnicType() {
- return bindingvnicType;
- }
+ public void setBindingvnicType(String bindingvnicType) {
+ this.bindingvnicType = bindingvnicType;
+ }
+
+ public String getBindingvifType() {
+ return bindingvifType;
+ }
- public void setBindingvnicType(String bindingvnicType) {
- this.bindingvnicType = bindingvnicType;
- }
+ public void setBindingvifType(String bindingvifType) {
+ this.bindingvifType = bindingvifType;
+ }
- public String getBindingvifType() {
- return bindingvifType;
- }
+ public Boolean getPortSecurityEnabled() {
+ if (portSecurityEnabled == null) {
+ return true;
+ }
+ return portSecurityEnabled;
+ }
- public void setBindingvifType(String bindingvifType) {
- this.bindingvifType = bindingvifType;
- }
+ public void setPortSecurityEnabled(Boolean newValue) {
+ portSecurityEnabled = newValue;
+ }
/**
* This method copies selected fields from the object and returns them
if ("security_groups".equals(field)) {
ans.setSecurityGroups(new ArrayList<NeutronSecurityGroup>(this.getSecurityGroups()));
}
+ if ("port_security_enabled".equals(field)) {
+ ans.setPortSecurityEnabled(this.getPortSecurityEnabled());
+ }
}
return ans;
}
@Override
public void initDefaults() {
adminStateUp = true;
+ portSecurityEnabled = true;
if (status == null) {
status = "ACTIVE";
}
+ ", fixedIPs=" + fixedIPs + ", deviceID=" + deviceID + ", deviceOwner=" + deviceOwner + ", tenantID="
+ tenantID + ", securityGroups=" + securityGroups
+ ", bindinghostID=" + bindinghostID + ", bindingvnicType=" + bindingvnicType
- + ", bindingvnicType=" + bindingvnicType + "]";
+ + ", bindingvnicType=" + bindingvnicType + ", portSecurityEnabled=" + portSecurityEnabled +"]";
}
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Intel Corporation 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.neutron.spi;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.List;
+
+public class NeutronPortSecurityJAXBTest {
+
+ // JSON with PortSecurityEnabled set true
+ private static final String portSecurityEnabled_sourceJson = "{ "
+ + "\"status\": \"ACTIVE\", "
+ + "\"name\": \"net1\", "
+ + "\"admin_state_up\": true, "
+ + "\"tenant_id\": \"9bacb3c5d39d41a79512987f338cf177\", "
+ + "\"fixed_ips\": [ { \"ip_address\":\"192.168.111.3\" , \"subnet_id\": \"22b44fc2-4ffb-4de4-b0f9-69d58b37ae27\" } ],"
+ + "\"binding:vif_details\": [{\"port_filter\": true , \"ovs_hybrid_plug\": true } ], "
+ + "\"extra_dhcp_opts\": [\"\"], " + "\"security_groups\": [\"\"], " + "\"allowed_address_pairs\": [\"\"], "
+ + "\"device_id\": \"257614cc-e178-4c92-9c61-3b28d40eca44\", " + "\"device_owner\": \"\", "
+ + "\"binding:host_id\": \"\", " + "\"binding:vif_type\": \"unbound\", "
+ + "\"binding:vnic_type\": \"normal\", " + "\"mac_address\": \"fa:16:3e:c9:cb:f0\", "
+ + "\"network_id\": \"e9330b1f-a2ef-4160-a991-169e56ab17f5\", "
+ + "\"id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\", "
+ + "\"port_security_enabled\": true }";
+
+
+ // JSON with PortSecurityEnabled set false
+ private static final String portSecurityDisabled_sourceJson = "{ "
+ + "\"status\": \"ACTIVE\", "
+ + "\"name\": \"net1\", "
+ + "\"admin_state_up\": true, "
+ + "\"tenant_id\": \"9bacb3c5d39d41a79512987f338cf177\", "
+ + "\"fixed_ips\": [ { \"ip_address\":\"192.168.111.3\" , \"subnet_id\": \"22b44fc2-4ffb-4de4-b0f9-69d58b37ae27\" } ],"
+ + "\"binding:vif_details\": [{\"port_filter\": true , \"ovs_hybrid_plug\": true } ], "
+ + "\"extra_dhcp_opts\": [\"\"], " + "\"security_groups\": [\"\"], " + "\"allowed_address_pairs\": [\"\"], "
+ + "\"device_id\": \"257614cc-e178-4c92-9c61-3b28d40eca44\", " + "\"device_owner\": \"\", "
+ + "\"binding:host_id\": \"\", " + "\"binding:vif_type\": \"unbound\", "
+ + "\"binding:vnic_type\": \"normal\", " + "\"mac_address\": \"fa:16:3e:c9:cb:f0\", "
+ + "\"network_id\": \"e9330b1f-a2ef-4160-a991-169e56ab17f5\", "
+ + "\"id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\", "
+ + "\"port_security_enabled\": false }";
+
+ // JSON with PortSecurityEnabled not set for compatibility test
+ private static final String portSecurityDefault_sourceJson = "{ "
+ + "\"status\": \"ACTIVE\", "
+ + "\"name\": \"net1\", "
+ + "\"admin_state_up\": true, "
+ + "\"tenant_id\": \"9bacb3c5d39d41a79512987f338cf177\", "
+ + "\"fixed_ips\": [ { \"ip_address\":\"192.168.111.3\" , \"subnet_id\": \"22b44fc2-4ffb-4de4-b0f9-69d58b37ae27\" } ],"
+ + "\"binding:vif_details\": [{\"port_filter\": true , \"ovs_hybrid_plug\": true } ], "
+ + "\"extra_dhcp_opts\": [\"\"], " + "\"security_groups\": [\"\"], " + "\"allowed_address_pairs\": [\"\"], "
+ + "\"device_id\": \"257614cc-e178-4c92-9c61-3b28d40eca44\", " + "\"device_owner\": \"\", "
+ + "\"binding:host_id\": \"\", " + "\"binding:vif_type\": \"unbound\", "
+ + "\"binding:vnic_type\": \"normal\", " + "\"mac_address\": \"fa:16:3e:c9:cb:f0\", "
+ + "\"network_id\": \"e9330b1f-a2ef-4160-a991-169e56ab17f5\", "
+ + "\"id\": \"4e8e5957-649f-477b-9e5b-f1f75b21c03c\" }";
+
+ @Test
+ public void test_NeutronPortSecurityEnabled_JAXB() {
+ test_PortSecurityEnabled_JAXB(portSecurityEnabled_sourceJson, true);
+ }
+
+ @Test
+ public void test_NeutronPortSecurityDisabled_JAXB() {
+ test_PortSecurityEnabled_JAXB(portSecurityDisabled_sourceJson, false);
+ }
+
+ /*
+ By Default PortSecurity is enabled for backward compatibility.
+ This test checks the case when the parameter is not available.
+ */
+ @Test
+ public void test_NeutronPortSecurityDefault_JAXB() {
+ test_PortSecurityEnabled_JAXB(portSecurityDefault_sourceJson, true);
+ }
+
+ private void test_PortSecurityEnabled_JAXB(String sourceJson, Boolean portSecurityEnabled) {
+ NeutronPort testObject = new NeutronPort();
+ try {
+ NeutronPort neutronObject = (NeutronPort) JaxbTestHelper.jaxbUnmarshall(testObject, sourceJson);
+ Assert.assertEquals("NeutronPort JAXB Test 1: Testing id failed", "4e8e5957-649f-477b-9e5b-f1f75b21c03c",
+ neutronObject.getID());
+
+ Assert.assertEquals("NeutronPort JAXB Test 2: Testing tenant_id failed",
+ "9bacb3c5d39d41a79512987f338cf177", neutronObject.getTenantID());
+
+ Assert.assertEquals("NeutronPort JAXB Test 3: Testing network_id failed",
+ "e9330b1f-a2ef-4160-a991-169e56ab17f5", neutronObject.getNetworkUUID());
+
+ Assert.assertEquals("NeutronPort JAXB Test 4: Testing status failed", "ACTIVE", neutronObject.getStatus());
+
+ List<Neutron_IPs> fixedIPs = neutronObject.getFixedIPs();
+ Assert.assertEquals(" NeutronPort JAXB Test 5.1: Testing fixed_ips list length failed", 1, fixedIPs.size());
+
+ Assert.assertEquals(" NeutronPort JAXB Test 5.2: Testing ip_address value failed", "192.168.111.3",
+ fixedIPs.get(0).ipAddress);
+
+ Assert.assertEquals(" NeutronPort JAXB Test 5.3: Testing subnet_id value failed",
+ "22b44fc2-4ffb-4de4-b0f9-69d58b37ae27", fixedIPs.get(0).subnetUUID);
+
+ List<NeutronPort_ExtraDHCPOption> extraDHCPOptions = neutronObject.getExtraDHCPOptions();
+
+ Assert.assertEquals("NeutronPort JAXB Test 6: Testing extra_dhcp_opts list length failed", 1,
+ extraDHCPOptions.size());
+
+ List<NeutronSecurityGroup> securityGroups = neutronObject.getSecurityGroups();
+ Assert.assertEquals("NeutronPort JAXB Test 7: Testing security_groups list length failed", 1,
+ securityGroups.size());
+
+ List<NeutronPort_AllowedAddressPairs> allowedAddressPairs = neutronObject.getAllowedAddressPairs();
+ Assert.assertEquals("NeutronPort JAXB Test 8: Testing allowed_address_pairs list length failed", 1,
+ allowedAddressPairs.size());
+
+ List<NeutronPort_VIFDetail> vifDetails = neutronObject.getVIFDetail();
+
+ Assert.assertEquals("NeutronPort JAXB Test 9.1: Testing vif_details list length failed", 1,
+ vifDetails.size());
+
+ Assert.assertEquals("NeutronPort JAXB Test 9.2: Testing port_filter value failed", true,
+ vifDetails.get(0).portFilter);
+
+ Assert.assertEquals("NeutronNetwork JAXB Test 9.3: Testing ovs_hybrid_plug value failed", true,
+ vifDetails.get(0).ovsHybridPlug);
+
+ Assert.assertEquals("NeutronPort JAXB Test 10: Testing name failed", "net1", neutronObject.getName());
+
+ Assert.assertEquals("NeutronPort JAXB Test 11: Testing admin_state_up failed", true,
+ neutronObject.getAdminStateUp());
+
+ Assert.assertEquals("NeutronPort JAXB Test 12: Testing binding:vif_type failed", "unbound",
+ neutronObject.getBindingvifType());
+
+ Assert.assertEquals("NeutronPort JAXB Test 13: Testing binding:vnic_type failed", "normal",
+ neutronObject.getBindingvnicType());
+
+ Assert.assertEquals("NeutronPort JAXB Test 14: Testing mac_address failed", "fa:16:3e:c9:cb:f0",
+ neutronObject.getMacAddress());
+
+ Assert.assertEquals("NeutronPort JAXB Test 15: Testing device_id failed",
+ "257614cc-e178-4c92-9c61-3b28d40eca44", neutronObject.getDeviceID());
+
+ Assert.assertEquals("NeutronPort JAXB Test 16: Testing device_owner failed", "",
+ neutronObject.getDeviceOwner());
+
+ Assert.assertEquals("NeutronPort JAXB Test 17: Testing binding:host_id failed", "",
+ neutronObject.getBindinghostID());
+
+ Assert.assertEquals("NeutronPort JAXB Test 18: Testing port_security_enabled failed", portSecurityEnabled,
+ neutronObject.getPortSecurityEnabled());
+
+ } catch (Exception e) {
+ Assert.assertFalse("Tests Failed", true);
+ }
+ }
+}
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.PortBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.portsecurity.rev150712.PortSecurityExtension;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.portsecurity.rev150712.PortSecurityExtensionBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.osgi.framework.BundleContext;
result.setBindingvnicType(binding.getVnicType());
}
+ private void portSecurityExtension(Port port, NeutronPort result) {
+ PortSecurityExtension portSecurity = port.getAugmentation(PortSecurityExtension.class);
+ if(portSecurity != null && portSecurity.isPortSecurityEnabled() != null) {
+ result.setPortSecurityEnabled(portSecurity.isPortSecurityEnabled());
+ }
+ }
+
protected NeutronPort fromMd(Port port) {
NeutronPort result = new NeutronPort();
result.setAdminStateUp(port.isAdminStateUp());
}
result.setID(port.getUuid().getValue());
addExtensions(port, result);
+ portSecurityExtension(port, result);
return result;
}
bindingBuilder.setVnicType(neutronPort.getBindingvnicType());
}
+ PortSecurityExtensionBuilder portSecurityBuilder = new PortSecurityExtensionBuilder();
+ if (neutronPort.getPortSecurityEnabled() != null) {
+ portSecurityBuilder.setPortSecurityEnabled(neutronPort.getPortSecurityEnabled());
+ }
+
PortBuilder portBuilder = new PortBuilder();
portBuilder.addAugmentation(PortBindingExtension.class,
bindingBuilder.build());
+ portBuilder.addAugmentation(PortSecurityExtension.class, portSecurityBuilder.build());
portBuilder.setAdminStateUp(neutronPort.isAdminStateUp());
if(neutronPort.getAllowedAddressPairs() != null) {
List<AllowedAddressPairs> listAllowedAddressPairs = new ArrayList<AllowedAddressPairs>();