Update Nicira Api to support L3 functionality

This commit is contained in:
Hugo Trippaers 2012-09-25 15:51:48 -07:00
parent 5c4cf11860
commit bfc8da1082
11 changed files with 630 additions and 5 deletions

View File

@ -0,0 +1,53 @@
package com.cloud.network.nicira;
public class DestinationNatRule extends NatRule {
private Match match;
private String to_destination_ip_address_min;
private String to_destination_ip_address_max;
private Integer to_destination_port;
private String uuid;
private String type = "DestinationNatRule";
public Match getMatch() {
return match;
}
public void setMatch(Match match) {
this.match = match;
}
public String getToDestinationIpAddressMin() {
return to_destination_ip_address_min;
}
public void setToDestinationIpAddressMin(
String to_destination_ip_address_min) {
this.to_destination_ip_address_min = to_destination_ip_address_min;
}
public String getToDestinationIpAddressMax() {
return to_destination_ip_address_max;
}
public void setToDestinationIpAddressMax(
String to_destination_ip_address_max) {
this.to_destination_ip_address_max = to_destination_ip_address_max;
}
public Integer getToDestinationPort() {
return to_destination_port;
}
public void setToDestinationPort(Integer to_destination_port) {
this.to_destination_port = to_destination_port;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}

View File

@ -0,0 +1,54 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.nicira;
/**
*
*/
public class L3GatewayAttachment extends Attachment {
private String l3_gateway_service_uuid;
private String type = "L3GatewayAttachment";
private int vlan_id;
public L3GatewayAttachment(String l3_gateway_service_uuid) {
this.l3_gateway_service_uuid = l3_gateway_service_uuid;
// VLAN 0 is untagged, set explicitly of no vlan is given in the constructor
this.vlan_id = 0;
}
public L3GatewayAttachment(String l3_gateway_service_uuid, int vlan_id) {
this.l3_gateway_service_uuid = l3_gateway_service_uuid;
this.vlan_id = vlan_id;
}
public String getL3GatewayServiceUuid() {
return l3_gateway_service_uuid;
}
public void setL3GatewayServiceUuid(String l3_gateway_service_uuid) {
this.l3_gateway_service_uuid = l3_gateway_service_uuid;
}
public int getVlanId() {
return vlan_id;
}
public void setVlanId(int vlan_id) {
this.vlan_id = vlan_id;
}
}

View File

@ -0,0 +1,64 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.nicira;
import java.util.List;
/**
*
*/
public class LogicalRouterConfig {
private String display_name;
private RoutingConfig routing_config;
private String type = "LogicalRouterConfig";
private String uuid;
private List<NiciraNvpTag> tags;
public RoutingConfig getRoutingConfig() {
return routing_config;
}
public void setRoutingConfig(RoutingConfig routing_config) {
this.routing_config = routing_config;
}
public String getDisplayName() {
return display_name;
}
public void setDisplayName(String display_name) {
this.display_name = display_name;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public List<NiciraNvpTag> getTags() {
return tags;
}
public void setTags(List<NiciraNvpTag> tags) {
this.tags = tags;
}
}

View File

@ -0,0 +1,90 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.nicira;
import java.util.List;
/**
*
*/
public class LogicalRouterPort {
private String display_name;
private List<NiciraNvpTag> tags;
private Integer portno;
private boolean admin_status_enabled;
private List<String> ip_addresses;
private String mac_address;
private String type = "LogicalRouterPortConfig";
private String uuid;
public int getPortno() {
return portno;
}
public void setPortno(int portno) {
this.portno = portno;
}
public boolean isAdminStatusEnabled() {
return admin_status_enabled;
}
public void setAdminStatusEnabled(boolean admin_status_enabled) {
this.admin_status_enabled = admin_status_enabled;
}
public List<String> getIpAddresses() {
return ip_addresses;
}
public void setIpAddresses(List<String> ip_addresses) {
this.ip_addresses = ip_addresses;
}
public String getMacAddress() {
return mac_address;
}
public void setMacAddress(String mac_address) {
this.mac_address = mac_address;
}
public String getDisplayName() {
return display_name;
}
public void setDisplayName(String display_name) {
this.display_name = display_name;
}
public List<NiciraNvpTag> getTags() {
return tags;
}
public void setTags(List<NiciraNvpTag> tags) {
this.tags = tags;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}

View File

@ -0,0 +1,133 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.nicira;
/**
*
*/
public class Match {
private Integer protocol;
private String source_ip_addresses;
private boolean source_ip_addresses_not;
private String destination_ip_addresses;
private boolean destination_ip_addresses_not;
private Integer source_port_min;
private Integer source_port_max;
private boolean source_port_not;
private Integer destination_port_min;
private Integer destination_port_max;
private boolean destination_port_not;
private String ethertype = "IPv4";
public Integer getProtocol() {
return protocol;
}
public void setProtocol(Integer protocol) {
this.protocol = protocol;
}
public Integer getSource_port_min() {
return source_port_min;
}
public void setSourcePortMin(Integer source_port_min) {
this.source_port_min = source_port_min;
}
public Integer getSourcePortMax() {
return source_port_max;
}
public void setSourcePortMax(Integer source_port_max) {
this.source_port_max = source_port_max;
}
public boolean isSourcePortNot() {
return source_port_not;
}
public void setSourcePortNot(boolean source_port_not) {
this.source_port_not = source_port_not;
}
public Integer getDestinationPortMin() {
return destination_port_min;
}
public void setDestinationPortMin(Integer destination_port_min) {
this.destination_port_min = destination_port_min;
}
public Integer getDestinationPortMax() {
return destination_port_max;
}
public void setDestinationPortMax(Integer destination_port_max) {
this.destination_port_max = destination_port_max;
}
public boolean isDestinationPortNot() {
return destination_port_not;
}
public void setDestinationPortNot(boolean destination_port_not) {
this.destination_port_not = destination_port_not;
}
public String getEthertype() {
return ethertype;
}
public void setEthertype(String ethertype) {
this.ethertype = ethertype;
}
public String getSourceIpAddresses() {
return source_ip_addresses;
}
public void setSourceIpAddresses(String source_ip_addresses) {
this.source_ip_addresses = source_ip_addresses;
}
public boolean isSourceIpAddressesNot() {
return source_ip_addresses_not;
}
public void setSourceIpAddresses_not(boolean source_ip_addresses_not) {
this.source_ip_addresses_not = source_ip_addresses_not;
}
public String getDestinationIpAddresses() {
return destination_ip_addresses;
}
public void setDestinationIpAddresses(String destination_ip_addresses) {
this.destination_ip_addresses = destination_ip_addresses;
}
public boolean isDestinationIpAddressesNot() {
return destination_ip_addresses_not;
}
public void setDestinationIpAddressesNot(boolean destination_ip_addresses_not) {
this.destination_ip_addresses_not = destination_ip_addresses_not;
}
}

View File

@ -0,0 +1,24 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.nicira;
/**
*
*/
public abstract class NatRule {
}

View File

@ -78,6 +78,7 @@ import com.google.gson.reflect.TypeToken;
public class NiciraNvpApi {
private static final Logger s_logger = Logger.getLogger(NiciraNvpApi.class);
private final static String _protocol = "https";
private String _name;
private String _host;
@ -117,7 +118,7 @@ public class NiciraNvpApi {
String url;
try {
url = new URL("https", _host, "/ws.v1/login").toString();
url = new URL(_protocol, _host, "/ws.v1/login").toString();
} catch (MalformedURLException e) {
s_logger.error("Unable to build Nicira API URL", e);
throw new NiciraNvpApiException("Unable to build Nicira API URL", e);
@ -210,11 +211,61 @@ public class NiciraNvpApi {
return lspl;
}
public LogicalRouterConfig createLogicalRouter(LogicalRouterConfig logicalRouterConfig) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter";
LogicalRouterConfig lrc = executeCreateObject(logicalRouterConfig, new TypeToken<LogicalRouterConfig>(){}.getType(), uri, Collections.<String,String>emptyMap());
return lrc;
}
public void deleteLogicalRouter(String logicalRouterUuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid;
executeDeleteObject(uri);
}
public LogicalRouterPort createLogicalRouterPort(String logicalRouterUuid, LogicalRouterPort logicalRouterPort) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport";
LogicalRouterPort lrp = executeCreateObject(logicalRouterPort, new TypeToken<LogicalRouterPort>(){}.getType(), uri, Collections.<String,String>emptyMap());
return lrp;
}
public void deleteLogicalRouterPort(String logicalRouterUuid, String logicalRouterPortUuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport/" + logicalRouterPortUuid;
executeDeleteObject(uri);
}
public void modifyLogicalRouterPortAttachment(String logicalRouterUuid, String logicalRouterPortUuid, Attachment attachment) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/lport/" + logicalRouterPortUuid + "/attachment";
executeUpdateObject(attachment, uri, Collections.<String,String>emptyMap());
}
public NatRule createLogicalRouterNatRule(String logicalRouterUuid, NatRule natRule) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/nat";
if (natRule instanceof SourceNatRule) {
return executeCreateObject(natRule, new TypeToken<SourceNatRule>(){}.getType(), uri, Collections.<String,String>emptyMap());
}
else if (natRule instanceof DestinationNatRule) {
return executeCreateObject(natRule, new TypeToken<DestinationNatRule>(){}.getType(), uri, Collections.<String,String>emptyMap());
}
throw new NiciraNvpApiException("Unknown NatRule type");
}
public void deleteLogicalRouterNatRule(String logicalRouterUuid, String natRuleUuid) throws NiciraNvpApiException {
String uri = "/ws.v1/lrouter/" + logicalRouterUuid + "/nat/" + natRuleUuid;
executeDeleteObject(uri);
}
private <T> void executeUpdateObject(T newObject, String uri, Map<String,String> parameters) throws NiciraNvpApiException {
String url;
try {
url = new URL("https", _host, uri).toString();
url = new URL(_protocol, _host, uri).toString();
} catch (MalformedURLException e) {
s_logger.error("Unable to build Nicira API URL", e);
throw new NiciraNvpApiException("Connection to NVP Failed");
@ -244,7 +295,7 @@ public class NiciraNvpApi {
private <T> T executeCreateObject(T newObject, Type returnObjectType, String uri, Map<String,String> parameters) throws NiciraNvpApiException {
String url;
try {
url = new URL("https", _host, uri).toString();
url = new URL(_protocol, _host, uri).toString();
} catch (MalformedURLException e) {
s_logger.error("Unable to build Nicira API URL", e);
throw new NiciraNvpApiException("Unable to build Nicira API URL", e);
@ -282,7 +333,7 @@ public class NiciraNvpApi {
private void executeDeleteObject(String uri) throws NiciraNvpApiException {
String url;
try {
url = new URL("https", _host, uri).toString();
url = new URL(_protocol, _host, uri).toString();
} catch (MalformedURLException e) {
s_logger.error("Unable to build Nicira API URL", e);
throw new NiciraNvpApiException("Unable to build Nicira API URL", e);
@ -303,7 +354,7 @@ public class NiciraNvpApi {
private <T> T executeRetrieveObject(Type returnObjectType, String uri, Map<String,String> parameters) throws NiciraNvpApiException {
String url;
try {
url = new URL("https", _host, uri).toString();
url = new URL(_protocol, _host, uri).toString();
} catch (MalformedURLException e) {
s_logger.error("Unable to build Nicira API URL", e);
throw new NiciraNvpApiException("Unable to build Nicira API URL", e);

View File

@ -0,0 +1,34 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.nicira;
/**
*
*/
public class RouterNextHop {
private String gateway_ip_address;
private String type = "RouterNextHop";
public String getGatewayIpAddress() {
return gateway_ip_address;
}
public void setGatewayIpAddress(String gateway_ip_address) {
this.gateway_ip_address = gateway_ip_address;
}
}

View File

@ -0,0 +1,5 @@
package com.cloud.network.nicira;
public class RoutingConfig {
}

View File

@ -0,0 +1,38 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.nicira;
/**
*
*/
public class SingleDefaultRouteImplictRoutingConfig extends RoutingConfig {
public RouterNextHop default_route_next_hop;
public String type = "SingleDefaultRouteImplicitRoutingConfig";
public SingleDefaultRouteImplictRoutingConfig(RouterNextHop routerNextHop) {
default_route_next_hop = routerNextHop;
}
public RouterNextHop getDefaultRouteNextHop() {
return default_route_next_hop;
}
public void setDefaultRouteNextHop(RouterNextHop default_route_next_hop) {
this.default_route_next_hop = default_route_next_hop;
}
}

View File

@ -0,0 +1,79 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.nicira;
/**
*
*/
public class SourceNatRule extends NatRule {
private Match match;
private String to_source_ip_address_min;
private String to_source_ip_address_max;
private Integer to_source_port_min;
private Integer to_source_port_max;
private String uuid;
private String type = "SourceNatRule";
public Match getMatch() {
return match;
}
public void setMatch(Match match) {
this.match = match;
}
public String getToSourceIpAddressMin() {
return to_source_ip_address_min;
}
public void setToSourceIpAddressMin(String to_source_ip_address_min) {
this.to_source_ip_address_min = to_source_ip_address_min;
}
public String getToSourceIpAddressMax() {
return to_source_ip_address_max;
}
public void setToSourceIpAddressMax(String to_source_ip_address_max) {
this.to_source_ip_address_max = to_source_ip_address_max;
}
public Integer getToSourcePortMin() {
return to_source_port_min;
}
public void setToSourcePortMin(Integer to_source_port_min) {
this.to_source_port_min = to_source_port_min;
}
public Integer getToSourcePortMax() {
return to_source_port_max;
}
public void setToSourcePortMax(Integer to_source_port_max) {
this.to_source_port_max = to_source_port_max;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}