re-factor gre controller

Signed-off-by: tuna <ng.tuna@gmail.com>
This commit is contained in:
Tuna 2013-07-25 15:46:31 +07:00 committed by tuna
parent 96188a3730
commit 4e914b7087
32 changed files with 859 additions and 1287 deletions

View File

@ -126,6 +126,8 @@ public interface Network extends ControlledEntity, StateObject<Network.State>, I
public static final Provider NiciraNvp = new Provider("NiciraNvp", false);
public static final Provider InternalLbVm = new Provider("InternalLbVm", false);
public static final Provider CiscoVnmc = new Provider("CiscoVnmc", true);
// Ovs
public static final Provider Ovs = new Provider("Ovs", false);
private final String name;
private final boolean isExternal;

View File

@ -266,7 +266,6 @@
<bean id="objectInDataStoreDaoImpl" class="org.apache.cloudstack.storage.db.ObjectInDataStoreDaoImpl" />
<bean id="ovsTunnelInterfaceDaoImpl" class="com.cloud.network.ovs.dao.OvsTunnelInterfaceDaoImpl" />
<bean id="ovsTunnelNetworkDaoImpl" class="com.cloud.network.ovs.dao.OvsTunnelNetworkDaoImpl" />
<bean id="ovsDeviceDaoImpl" class="com.cloud.network.ovs.dao.OvsDeviceDaoImpl" />
<bean id="ovsNicMappingDaoImpl" class="com.cloud.network.ovs.dao.OvsNicMappingDaoImpl" />
<bean id="physicalNetworkDaoImpl" class="com.cloud.network.dao.PhysicalNetworkDaoImpl" />
<bean id="physicalNetworkIsolationMethodDaoImpl" class="com.cloud.network.dao.PhysicalNetworkIsolationMethodDaoImpl" />

View File

@ -264,18 +264,6 @@ import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.Networks.IsolationType;
import com.cloud.network.Networks.TrafficType;
import com.cloud.network.PhysicalNetworkSetupInfo;
import com.cloud.network.ovs.OvsCreateGreTunnelAnswer;
import com.cloud.network.ovs.OvsCreateGreTunnelCommand;
import com.cloud.network.ovs.OvsCreateTunnelAnswer;
import com.cloud.network.ovs.OvsCreateTunnelCommand;
import com.cloud.network.ovs.OvsDeleteFlowCommand;
import com.cloud.network.ovs.OvsDestroyBridgeCommand;
import com.cloud.network.ovs.OvsDestroyTunnelCommand;
import com.cloud.network.ovs.OvsFetchInterfaceAnswer;
import com.cloud.network.ovs.OvsFetchInterfaceCommand;
import com.cloud.network.ovs.OvsSetTagAndFlowAnswer;
import com.cloud.network.ovs.OvsSetTagAndFlowCommand;
import com.cloud.network.ovs.OvsSetupBridgeCommand;
import com.cloud.network.rules.FirewallRule;
import com.cloud.resource.ServerResource;
import com.cloud.resource.hypervisor.HypervisorResource;

View File

@ -0,0 +1,81 @@
// 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.agent.api;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
public class OvsCreateGreTunnelAnswer extends Answer {
String hostIp;
String remoteIp;
String bridge;
String key;
long from;
long to;
int port;
public OvsCreateGreTunnelAnswer(Command cmd, boolean success, String details) {
super(cmd, success, details);
}
public OvsCreateGreTunnelAnswer(Command cmd, boolean success,
String details, String hostIp, String bridge) {
super(cmd, success, details);
OvsCreateGreTunnelCommand c = (OvsCreateGreTunnelCommand) cmd;
this.hostIp = hostIp;
this.bridge = bridge;
this.remoteIp = c.getRemoteIp();
this.key = c.getKey();
this.port = -1;
this.from = c.getFrom();
this.to = c.getTo();
}
public OvsCreateGreTunnelAnswer(Command cmd, boolean success,
String details, String hostIp, String bridge, int port) {
this(cmd, success, details, hostIp, bridge);
this.port = port;
}
public String getHostIp() {
return hostIp;
}
public String getRemoteIp() {
return remoteIp;
}
public String getBridge() {
return bridge;
}
public String getKey() {
return key;
}
public long getFrom() {
return from;
}
public long getTo() {
return to;
}
public int getPort() {
return port;
}
}

View File

@ -14,41 +14,42 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.ovs;
package com.cloud.agent.api;
import com.cloud.agent.api.Command;
public class OvsCreateGreTunnelCommand extends Command {
String remoteIp;
String key;
long from;
long to;
String remoteIp;
String key;
long from;
long to;
@Override
public boolean executeInSequence() {
return true;
}
@Override
public boolean executeInSequence() {
return true;
}
public OvsCreateGreTunnelCommand(String remoteIp, String key, long from, long to) {
this.remoteIp = remoteIp;
this.key = key;
this.from = from;
this.to = to;
}
public OvsCreateGreTunnelCommand(String remoteIp, String key, long from,
long to) {
this.remoteIp = remoteIp;
this.key = key;
this.from = from;
this.to = to;
}
public String getRemoteIp() {
return remoteIp;
}
public String getRemoteIp() {
return remoteIp;
}
public String getKey() {
return key;
}
public String getKey() {
return key;
}
public long getFrom() {
return from;
}
public long getFrom() {
return from;
}
public long getTo() {
return to;
}
public long getTo() {
return to;
}
}

View File

@ -0,0 +1,85 @@
// 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.agent.api;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
public class OvsCreateTunnelAnswer extends Answer {
Long from;
Long to;
long networkId;
String inPortName;
// for debug info
String fromIp;
String toIp;
int key;
String bridge;
public OvsCreateTunnelAnswer(Command cmd, boolean success, String details,
String bridge) {
super(cmd, success, details);
OvsCreateTunnelCommand c = (OvsCreateTunnelCommand) cmd;
from = c.getFrom();
to = c.getTo();
networkId = c.getNetworkId();
inPortName = "[]";
fromIp = c.getFromIp();
toIp = c.getRemoteIp();
key = c.getKey();
this.bridge = bridge;
}
public OvsCreateTunnelAnswer(Command cmd, boolean success, String details,
String inPortName, String bridge) {
this(cmd, success, details, bridge);
this.inPortName = inPortName;
}
public Long getFrom() {
return from;
}
public Long getTo() {
return to;
}
public long getNetworkId() {
return networkId;
}
public String getInPortName() {
return inPortName;
}
public String getFromIp() {
return fromIp;
}
public String getToIp() {
return toIp;
}
public int getKey() {
return key;
}
public String getBridge() {
return bridge;
}
}

View File

@ -14,47 +14,57 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.ovs;
package com.cloud.agent.api;
import com.cloud.agent.api.Command;
public class OvsSetTagAndFlowCommand extends Command {
String vlans;
String vmName;
String seqno;
String tag;
Long vmId;
public class OvsCreateTunnelCommand extends Command {
Integer key;
String remoteIp;
Long from;
Long to;
long networkId;
@Override
public boolean executeInSequence() {
return true;
}
// for debug info
String fromIp;
public String getSeqNo() {
return seqno;
}
@Override
public boolean executeInSequence() {
return true;
}
public String getVlans() {
return vlans;
}
public OvsCreateTunnelCommand(String remoteIp, Integer key, Long from,
Long to, long networkId, String fromIp) {
this.remoteIp = remoteIp;
this.key = key;
this.from = from;
this.to = to;
this.networkId = networkId;
this.fromIp = fromIp;
}
public String getVmName() {
return vmName;
}
public Integer getKey() {
return key;
}
public Long getVmId() {
return vmId;
}
public String getRemoteIp() {
return remoteIp;
}
public String getTag() {
return tag;
}
public Long getFrom() {
return from;
}
public Long getTo() {
return to;
}
public long getNetworkId() {
return networkId;
}
public String getFromIp() {
return fromIp;
}
public OvsSetTagAndFlowCommand(String vmName, String tag, String vlans, String seqno, Long vmId) {
this.vmName = vmName;
this.tag = tag;
this.vlans = vlans;
this.seqno = seqno;
this.vmId = vmId;
}
}

View File

@ -14,23 +14,23 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.ovs;
package com.cloud.agent.api;
import com.cloud.agent.api.Command;
public class OvsDeleteFlowCommand extends Command {
String vmName;
String vmName;
@Override
public boolean executeInSequence() {
return true;
}
@Override
public boolean executeInSequence() {
return true;
}
public String getVmName() {
return vmName;
}
public String getVmName() {
return vmName;
}
public OvsDeleteFlowCommand(String vmName) {
this.vmName = vmName;
}
public OvsDeleteFlowCommand(String vmName) {
this.vmName = vmName;
}
}

View File

@ -15,31 +15,30 @@
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.ovs;
package com.cloud.agent.api;
import com.cloud.agent.api.Command;
public class OvsDestroyBridgeCommand extends Command {
Long networkId;
Integer key;
Long networkId;
Integer key;
public OvsDestroyBridgeCommand(Long networkId, Integer key) {
this.networkId = networkId;
this.key = key;
}
public OvsDestroyBridgeCommand(Long networkId, Integer key) {
this.networkId = networkId;
this.key = key;
}
public Long getNetworkId() {
return networkId;
}
public Long getNetworkId() {
return networkId;
}
public Integer getKey() {
return key;
}
@Override
public boolean executeInSequence() {
return true;
}
public Integer getKey() {
return key;
}
@Override
public boolean executeInSequence() {
return true;
}
}

View File

@ -14,37 +14,37 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.ovs;
package com.cloud.agent.api;
import com.cloud.agent.api.Command;
public class OvsDestroyTunnelCommand extends Command {
Long networkId;
Integer key;
String inPortName;
Long networkId;
Integer key;
String inPortName;
public OvsDestroyTunnelCommand(Long networkId, Integer key, String inPortName) {
this.networkId = networkId;
this.inPortName = inPortName;
this.key = key;
}
public OvsDestroyTunnelCommand(Long networkId, Integer key,
String inPortName) {
this.networkId = networkId;
this.inPortName = inPortName;
this.key = key;
}
public Long getNetworkId() {
return networkId;
}
public Long getNetworkId() {
return networkId;
}
public String getInPortName() {
return inPortName;
}
public String getInPortName() {
return inPortName;
}
public Integer getKey() {
return key;
}
@Override
public boolean executeInSequence() {
return true;
}
public Integer getKey() {
return key;
}
@Override
public boolean executeInSequence() {
return true;
}
}

View File

@ -15,43 +15,44 @@
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.ovs;
package com.cloud.agent.api;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
public class OvsFetchInterfaceAnswer extends Answer {
String ip;
String netmask;
String mac;
String label;
String ip;
String netmask;
String mac;
String label;
public OvsFetchInterfaceAnswer(Command cmd, boolean success, String details) {
super(cmd, success, details);
this.label = ((OvsFetchInterfaceCommand)cmd).getLabel();
}
public OvsFetchInterfaceAnswer(Command cmd, boolean success, String details) {
super(cmd, success, details);
this.label = ((OvsFetchInterfaceCommand) cmd).getLabel();
}
public OvsFetchInterfaceAnswer(Command cmd, boolean success, String details, String ip, String netmask, String mac) {
super(cmd, success, details);
this.ip = ip;
this.netmask = netmask;
this.mac = mac;
this.label = ((OvsFetchInterfaceCommand)cmd).getLabel();
}
public OvsFetchInterfaceAnswer(Command cmd, boolean success,
String details, String ip, String netmask, String mac) {
super(cmd, success, details);
this.ip = ip;
this.netmask = netmask;
this.mac = mac;
this.label = ((OvsFetchInterfaceCommand) cmd).getLabel();
}
public String getIp() {
return ip;
}
public String getIp() {
return ip;
}
public String getNetmask() {
return netmask;
}
public String getNetmask() {
return netmask;
}
public String getMac() {
return mac;
}
public String getMac() {
return mac;
}
public String getLabel() {
return label;
}
public String getLabel() {
return label;
}
}

View File

@ -15,24 +15,24 @@
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.ovs;
package com.cloud.agent.api;
import com.cloud.agent.api.Command;
public class OvsFetchInterfaceCommand extends Command {
String label;
String label;
@Override
public boolean executeInSequence() {
return true;
}
@Override
public boolean executeInSequence() {
return true;
}
public OvsFetchInterfaceCommand(String label) {
this.label = label;
}
public OvsFetchInterfaceCommand(String label) {
this.label = label;
}
public String getLabel() {
return label;
}
public String getLabel() {
return label;
}
}

View File

@ -14,27 +14,27 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.ovs;
package com.cloud.agent.api;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
public class OvsSetTagAndFlowAnswer extends Answer {
Long vmId;
Long seqno;
Long vmId;
Long seqno;
public OvsSetTagAndFlowAnswer(Command cmd, boolean success, String details) {
super(cmd, success, details);
OvsSetTagAndFlowCommand c = (OvsSetTagAndFlowCommand)cmd;
this.vmId = c.getVmId();
this.seqno = Long.parseLong(c.getSeqNo());
}
public OvsSetTagAndFlowAnswer(Command cmd, boolean success, String details) {
super(cmd, success, details);
OvsSetTagAndFlowCommand c = (OvsSetTagAndFlowCommand) cmd;
this.vmId = c.getVmId();
this.seqno = Long.parseLong(c.getSeqNo());
}
public Long getVmId() {
return vmId;
}
public Long getVmId() {
return vmId;
}
public Long getSeqNo() {
return seqno;
}
public Long getSeqNo() {
return seqno;
}
}

View File

@ -0,0 +1,61 @@
// 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.agent.api;
import com.cloud.agent.api.Command;
public class OvsSetTagAndFlowCommand extends Command {
String vlans;
String vmName;
String seqno;
String tag;
Long vmId;
@Override
public boolean executeInSequence() {
return true;
}
public String getSeqNo() {
return seqno;
}
public String getVlans() {
return vlans;
}
public String getVmName() {
return vmName;
}
public Long getVmId() {
return vmId;
}
public String getTag() {
return tag;
}
public OvsSetTagAndFlowCommand(String vmName, String tag, String vlans,
String seqno, Long vmId) {
this.vmName = vmName;
this.tag = tag;
this.vlans = vlans;
this.seqno = seqno;
this.vmId = vmId;
}
}

View File

@ -15,36 +15,35 @@
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.ovs;
package com.cloud.agent.api;
import com.cloud.agent.api.Command;
public class OvsSetupBridgeCommand extends Command {
Integer key;
Long hostId;
Long networkId;
Integer key;
Long hostId;
Long networkId;
@Override
public boolean executeInSequence() {
return true;
}
@Override
public boolean executeInSequence() {
return true;
}
public OvsSetupBridgeCommand(Integer key, Long hostId, Long networkId) {
this.key = key;
this.hostId = hostId;
this.networkId = networkId;
}
public OvsSetupBridgeCommand(Integer key, Long hostId, Long networkId) {
this.key = key;
this.hostId = hostId;
this.networkId = networkId;
}
public Integer getKey() {
return key;
}
public Integer getKey() {
return key;
}
public Long getHostId() {
return hostId;
}
public Long getNetworkId() {
return networkId;
}
public Long getHostId() {
return hostId;
}
public Long getNetworkId() {
return networkId;
}
}

View File

@ -14,7 +14,7 @@
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.network.ovs;
package com.cloud.agent.api;
import com.cloud.agent.api.StartupCommand;
import com.cloud.host.Host;

View File

@ -1,65 +0,0 @@
// 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.api.response;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseResponse;
import org.apache.cloudstack.api.EntityReference;
import com.cloud.network.ovs.dao.OvsDeviceVO;
import com.cloud.serializer.Param;
import com.google.gson.annotations.SerializedName;
@EntityReference(value = OvsDeviceVO.class)
public class OvsDeviceResponse extends BaseResponse {
@SerializedName(ApiConstants.OVS_DEVICE_ID)
@Param(description = "device id of the Ovs")
private String id;
@SerializedName(ApiConstants.PHYSICAL_NETWORK_ID)
@Param(description = "the physical network to which this device belongs to")
private String physicalNetworkId;
@SerializedName(ApiConstants.OVS_DEVICE_NAME)
@Param(description = "device name")
private String deviceName;
@SerializedName(ApiConstants.HOST_NAME)
@Param(description = "the controller Ip address")
private String hostName;
public String getId() {
return this.id;
}
public void setId(String vnsDeviceId) {
this.id = vnsDeviceId;
}
public void setPhysicalNetworkId(String physicalNetworkId) {
this.physicalNetworkId = physicalNetworkId;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
}

View File

@ -1,116 +0,0 @@
// 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.commands;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
import com.cloud.api.response.OvsDeviceResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.element.OvsElementService;
import com.cloud.network.ovs.dao.OvsDeviceVO;
import com.cloud.user.UserContext;
import com.cloud.utils.exception.CloudRuntimeException;
@APICommand(name = "addDevice", responseObject = OvsDeviceResponse.class, description = "Adds a Ovs controller device")
public class AddOvsDeviceCmd extends BaseAsyncCmd {
private static final String s_name = "adddeviceresponse";
@Inject
OvsElementService _ovsElementService;
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@Parameter(name = ApiConstants.PHYSICAL_NETWORK_ID, type = CommandType.UUID, entityType = PhysicalNetworkResponse.class, required = true, description = "the Physical Network ID")
private Long physicalNetworkId;
@Parameter(name = ApiConstants.HOST_NAME, type = CommandType.STRING, required = true, description = "Hostname of ip address of the BigSwitch VNS Controller.")
private String host;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getPhysicalNetworkId() {
return physicalNetworkId;
}
public String getHost() {
return host;
}
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException,
InsufficientCapacityException, ServerApiException,
ConcurrentOperationException, ResourceAllocationException,
NetworkRuleConflictException {
try {
OvsDeviceVO ovsDeviceVO = _ovsElementService.addOvsDevice(this);
if (ovsDeviceVO != null) {
OvsDeviceResponse response = _ovsElementService
.createOvsDeviceResponse(ovsDeviceVO);
response.setObjectName("ovsdevice");
response.setResponseName(getCommandName());
this.setResponseObject(response);
}
} catch (InvalidParameterValueException invalidParamExcp) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR,
invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
runtimeExcp.getMessage());
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_EXTERNAL_OVS_CONTROLLER_ADD;
}
@Override
public String getEventDescription() {
return "Adding an Ovs Controller";
}
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
return UserContext.current().getCaller().getId();
}
}

View File

@ -1,110 +0,0 @@
// 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.commands;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.SuccessResponse;
import com.cloud.api.response.OvsDeviceResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.element.OvsElementService;
import com.cloud.user.UserContext;
import com.cloud.utils.exception.CloudRuntimeException;
@APICommand(name = "deleteOvsDevice", responseObject = SuccessResponse.class, description = " delete a ovs device")
public class DeleteOvsDeviceCmd extends BaseAsyncCmd {
private static final String s_name = "deleteovsdeviceresponse";
@Inject
OvsElementService _ovsElementService;
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@Parameter(name = ApiConstants.OVS_DEVICE_ID, type = CommandType.UUID, entityType = OvsDeviceResponse.class, required = true, description = "Ovs device ID")
private Long ovsDeviceId;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getOvsDeviceId() {
return ovsDeviceId;
}
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException,
InsufficientCapacityException, ServerApiException,
ConcurrentOperationException, ResourceAllocationException,
NetworkRuleConflictException {
try {
boolean result = _ovsElementService.deleteOvsDevice(this);
if (result) {
SuccessResponse response = new SuccessResponse(getCommandName());
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
"Failed to delete Ovs device.");
}
} catch (InvalidParameterValueException invalidParamExcp) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR,
invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
runtimeExcp.getMessage());
}
}
@Override
public String getEventType() {
return EventTypes.EVENT_EXTERNAL_OVS_CONTROLLER_DELETE;
}
@Override
public String getEventDescription() {
return "Deleting Ovs Controller";
}
@Override
public String getCommandName() {
return s_name;
}
@Override
public long getEntityOwnerId() {
return UserContext.current().getCaller().getId();
}
}

View File

@ -1,114 +0,0 @@
// 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.commands;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.ListResponse;
import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
import org.apache.log4j.Logger;
import com.cloud.api.response.OvsDeviceResponse;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.NetworkRuleConflictException;
import com.cloud.exception.ResourceAllocationException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.element.OvsElementService;
import com.cloud.network.ovs.dao.OvsDeviceVO;
import com.cloud.utils.exception.CloudRuntimeException;
@APICommand(name = "listOvsDevices", responseObject = OvsDeviceResponse.class, description = "Lists Ovs devices")
public class ListOvsDevicesCmd extends BaseListCmd {
public static final Logger s_logger = Logger
.getLogger(ListOvsDevicesCmd.class.getName());
private static final String s_name = "listovsdeviceresponse";
@Inject
OvsElementService _ovsElementService;
// ///////////////////////////////////////////////////
// ////////////// API parameters /////////////////////
// ///////////////////////////////////////////////////
@Parameter(name = ApiConstants.PHYSICAL_NETWORK_ID, type = CommandType.UUID, entityType = PhysicalNetworkResponse.class, description = "the Physical Network ID")
private Long physicalNetworkId;
@Parameter(name = ApiConstants.OVS_DEVICE_ID, type = CommandType.UUID, entityType = OvsDeviceResponse.class, description = "ovs device ID")
private Long ovsDeviceId;
// ///////////////////////////////////////////////////
// ///////////////// Accessors ///////////////////////
// ///////////////////////////////////////////////////
public Long getOvsDeviceId() {
return ovsDeviceId;
}
public Long getPhysicalNetworkId() {
return physicalNetworkId;
}
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException,
InsufficientCapacityException, ServerApiException,
ConcurrentOperationException, ResourceAllocationException,
NetworkRuleConflictException {
try {
List<OvsDeviceVO> ovsDevices = _ovsElementService
.listOvsDevices(this);
ListResponse<OvsDeviceResponse> response = new ListResponse<OvsDeviceResponse>();
List<OvsDeviceResponse> ovsDevicesResponse = new ArrayList<OvsDeviceResponse>();
if (ovsDevices != null && !ovsDevices.isEmpty()) {
for (OvsDeviceVO ovsDeviceVO : ovsDevices) {
OvsDeviceResponse ovsDeviceResponse = _ovsElementService
.createOvsDeviceResponse(ovsDeviceVO);
ovsDevicesResponse.add(ovsDeviceResponse);
}
}
response.setResponses(ovsDevicesResponse);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {
throw new ServerApiException(ApiErrorCode.PARAM_ERROR,
invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR,
runtimeExcp.getMessage());
}
}
@Override
public String getCommandName() {
return s_name;
}
}

View File

@ -16,118 +16,305 @@
// under the License.
package com.cloud.network.element;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.ejb.Local;
import javax.inject.Inject;
import javax.naming.ConfigurationException;
import com.cloud.api.response.OvsDeviceResponse;
import org.apache.log4j.Logger;
import com.cloud.agent.api.StartupCommand;
import com.cloud.agent.api.StartupOvsCommand;
import com.cloud.deploy.DeployDestination;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.ResourceUnavailableException;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.network.Network;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
import com.cloud.network.NetworkModel;
import com.cloud.network.Networks;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.PhysicalNetworkServiceProvider;
import com.cloud.network.commands.AddOvsDeviceCmd;
import com.cloud.network.commands.DeleteOvsDeviceCmd;
import com.cloud.network.commands.ListOvsDevicesCmd;
import com.cloud.network.PublicIpAddress;
import com.cloud.network.dao.NetworkServiceMapDao;
import com.cloud.network.ovs.OvsTunnelManager;
import com.cloud.network.ovs.dao.OvsDeviceVO;
import com.cloud.network.rules.PortForwardingRule;
import com.cloud.network.rules.StaticNat;
import com.cloud.offering.NetworkOffering;
import com.cloud.resource.ResourceManager;
import com.cloud.resource.ResourceStateAdapter;
import com.cloud.resource.ServerResource;
import com.cloud.resource.UnableDeleteHostException;
import com.cloud.utils.component.AdapterBase;
import com.cloud.utils.db.DB;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachineProfile;
@Local(value = {NetworkElement.class})
public class OvsElement extends AdapterBase implements NetworkElement {
@Inject
OvsTunnelManager _ovsTunnelMgr;
@Local(value = { NetworkElement.class, ConnectivityProvider.class,
SourceNatServiceProvider.class, StaticNatServiceProvider.class,
PortForwardingServiceProvider.class, IpDeployer.class })
public class OvsElement extends AdapterBase implements NetworkElement,
OvsElementService, ConnectivityProvider, ResourceStateAdapter,
SourceNatServiceProvider, PortForwardingServiceProvider,
StaticNatServiceProvider, IpDeployer {
@Inject
OvsTunnelManager _ovsTunnelMgr;
@Inject
NetworkModel _networkModel;
@Inject
NetworkServiceMapDao _ntwkSrvcDao;
@Inject
ResourceManager _resourceMgr;
@Override
public boolean destroy(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
return true;
}
private static final Logger s_logger = Logger.getLogger(OvsElement.class);
private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
@Override
public Map<Service, Map<Capability, String>> getCapabilities() {
return null;
}
@Override
public Map<Service, Map<Capability, String>> getCapabilities() {
return capabilities;
}
@Override
public Provider getProvider() {
return null;
}
@Override
public Provider getProvider() {
return Provider.Ovs;
}
@Override
public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException, InsufficientCapacityException {
//Consider actually implementing the network here
return true;
}
protected boolean canHandle(Network network, Service service) {
s_logger.debug("Checking if OvsElement can handle service "
+ service.getName() + " on network " + network.getDisplayText());
if (network.getBroadcastDomainType() != BroadcastDomainType.Vswitch) {
return false;
}
@Override
public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Vswitch) {
return true;
}
if (!_networkModel.isProviderForNetwork(getProvider(), network.getId())) {
s_logger.debug("OvsElement is not a provider for network "
+ network.getDisplayText());
return false;
}
if (nic.getTrafficType() != Networks.TrafficType.Guest) {
return true;
}
if (!_ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(),
service, Network.Provider.Ovs)) {
s_logger.debug("OvsElement can't provide the " + service.getName()
+ " service on network " + network.getDisplayText());
return false;
}
_ovsTunnelMgr.VmCheckAndCreateTunnel(vm, network, dest);
//_ovsTunnelMgr.applyDefaultFlow(vm.getVirtualMachine(), dest);
return true;
}
return true;
}
@Override
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
super.configure(name, params);
_resourceMgr.registerResourceStateAdapter(name, this);
return true;
}
@Override
public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException {
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Vswitch) {
return true;
}
@Override
public boolean implement(Network network, NetworkOffering offering,
DeployDestination dest, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
s_logger.debug("entering OvsElement implement function for network "
+ network.getDisplayText() + " (state " + network.getState()
+ ")");
if (nic.getTrafficType() != Networks.TrafficType.Guest) {
return true;
}
if (!canHandle(network, Service.Connectivity)) {
return false;
}
// TODO: implement SourceNat immediately when we code L3 services
_ovsTunnelMgr.CheckAndDestroyTunnel(vm.getVirtualMachine(), network);
return true;
}
return true;
}
@Override
public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
return true;
}
@Override
public boolean prepare(Network network, NicProfile nic,
VirtualMachineProfile<? extends VirtualMachine> vm,
DeployDestination dest, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException,
InsufficientCapacityException {
if (!canHandle(network, Service.Connectivity)) {
return false;
}
@Override
public boolean isReady(PhysicalNetworkServiceProvider provider) {
return true;
}
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Vswitch) {
return false;
}
@Override
public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException {
return true;
}
if (nic.getTrafficType() != Networks.TrafficType.Guest) {
return false;
}
@Override
public boolean canEnableIndividualServices() {
return false;
}
_ovsTunnelMgr.VmCheckAndCreateTunnel(vm, network, dest);
@Override
public boolean verifyServicesCombination(Set<Service> services) {
return true;
}
return true;
}
@Override
public boolean release(Network network, NicProfile nic,
VirtualMachineProfile<? extends VirtualMachine> vm,
ReservationContext context) throws ConcurrentOperationException,
ResourceUnavailableException {
if (!canHandle(network, Service.Connectivity)) {
return false;
}
if (nic.getBroadcastType() != Networks.BroadcastDomainType.Vswitch) {
return false;
}
if (nic.getTrafficType() != Networks.TrafficType.Guest) {
return false;
}
_ovsTunnelMgr.CheckAndDestroyTunnel(vm.getVirtualMachine(), network);
return true;
}
@Override
public boolean shutdown(Network network, ReservationContext context,
boolean cleanup) throws ConcurrentOperationException,
ResourceUnavailableException {
if (!canHandle(network, Service.Connectivity)) {
return false;
}
return true;
}
@Override
public boolean destroy(Network network, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException {
if (!canHandle(network, Service.Connectivity)) {
return false;
}
return true;
}
@Override
public boolean isReady(PhysicalNetworkServiceProvider provider) {
return true;
}
@Override
public boolean shutdownProviderInstances(
PhysicalNetworkServiceProvider provider, ReservationContext context)
throws ConcurrentOperationException, ResourceUnavailableException {
return true;
}
@Override
public boolean canEnableIndividualServices() {
return true;
}
@Override
public boolean verifyServicesCombination(Set<Service> services) {
if (!services.contains(Service.Connectivity)) {
s_logger.warn("Unable to provide services without Connectivity service enabled for this element");
return false;
}
if ((services.contains(Service.PortForwarding) || services
.contains(Service.StaticNat))
&& !services.contains(Service.SourceNat)) {
s_logger.warn("Unable to provide StaticNat and/or PortForwarding without the SourceNat service");
return false;
}
return true;
}
private static Map<Service, Map<Capability, String>> setCapabilities() {
Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
// we need L3 support for coding L3 services in next period
// L2 Support : SDN provisioning
capabilities.put(Service.Connectivity, null);
// L3 Support : Generic?
capabilities.put(Service.Gateway, null);
// L3 Support : SourceNat
Map<Capability, String> sourceNatCapabilities = new HashMap<Capability, String>();
sourceNatCapabilities.put(Capability.SupportedSourceNatTypes,
"peraccount");
sourceNatCapabilities.put(Capability.RedundantRouter, "false");
capabilities.put(Service.SourceNat, sourceNatCapabilities);
// L3 Support : Port Forwarding
capabilities.put(Service.PortForwarding, null);
// L3 support : StaticNat
capabilities.put(Service.StaticNat, null);
return capabilities;
}
@Override
public List<Class<?>> getCommands() {
return null;
}
@Override
public HostVO createHostVOForConnectedAgent(HostVO host,
StartupCommand[] cmd) {
return null;
}
@Override
public HostVO createHostVOForDirectConnectAgent(HostVO host,
StartupCommand[] startup, ServerResource resource,
Map<String, String> details, List<String> hostTags) {
if (!(startup[0] instanceof StartupOvsCommand)) {
return null;
}
host.setType(Host.Type.L2Networking);
return host;
}
@Override
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
boolean isForceDeleteStorage) throws UnableDeleteHostException {
if (!(host.getType() == Host.Type.L2Networking)) {
return null;
}
return new DeleteHostAnswer(true);
}
// TODO: Adding L3 services below
@Override
public IpDeployer getIpDeployer(Network network) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean applyIps(Network network,
List<? extends PublicIpAddress> ipAddress, Set<Service> services)
throws ResourceUnavailableException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean applyStaticNats(Network config,
List<? extends StaticNat> rules)
throws ResourceUnavailableException {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean applyPFRules(Network network, List<PortForwardingRule> rules)
throws ResourceUnavailableException {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -1,22 +1,7 @@
package com.cloud.network.element;
import java.util.List;
import com.cloud.api.response.OvsDeviceResponse;
import com.cloud.network.commands.AddOvsDeviceCmd;
import com.cloud.network.commands.DeleteOvsDeviceCmd;
import com.cloud.network.commands.ListOvsDevicesCmd;
import com.cloud.network.ovs.dao.OvsDeviceVO;
import com.cloud.utils.component.PluggableService;
public interface OvsElementService extends PluggableService {
public OvsDeviceVO addOvsDevice(AddOvsDeviceCmd cmd);
public OvsDeviceResponse createOvsDeviceResponse(OvsDeviceVO ovsDeviceVO);
public boolean deleteOvsDevice(DeleteOvsDeviceCmd cmd);
public List<OvsDeviceVO> listOvsDevices(ListOvsDevicesCmd cmd);
}

View File

@ -30,86 +30,190 @@ import com.cloud.deploy.DeploymentPlan;
import com.cloud.event.ActionEventUtils;
import com.cloud.event.EventTypes;
import com.cloud.event.EventVO;
import com.cloud.exception.InsufficientAddressCapacityException;
import com.cloud.exception.InsufficientVirtualNetworkCapcityException;
import com.cloud.network.Network;
import com.cloud.network.Network.GuestType;
import com.cloud.network.Network.Service;
import com.cloud.network.Network.State;
import com.cloud.network.NetworkProfile;
import com.cloud.network.Networks.BroadcastDomainType;
import com.cloud.network.PhysicalNetwork;
import com.cloud.network.PhysicalNetwork.IsolationMethod;
import com.cloud.network.dao.NetworkVO;
import com.cloud.network.dao.PhysicalNetworkVO;
import com.cloud.network.ovs.OvsTunnelManager;
import com.cloud.offering.NetworkOffering;
import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
import com.cloud.user.Account;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
@Component
@Local(value = NetworkGuru.class)
public class OvsGuestNetworkGuru extends GuestNetworkGuru {
private static final Logger s_logger = Logger.getLogger(OvsGuestNetworkGuru.class);
private static final Logger s_logger = Logger
.getLogger(OvsGuestNetworkGuru.class);
@Inject
OvsTunnelManager _ovsTunnelMgr;
@Inject
OvsTunnelManager _ovsTunnelMgr;
@Inject
NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao;
OvsGuestNetworkGuru() {
super();
_isolationMethods = new IsolationMethod[] {IsolationMethod.GRE, IsolationMethod.L3, IsolationMethod.VLAN};
}
OvsGuestNetworkGuru() {
super();
_isolationMethods = new IsolationMethod[] { IsolationMethod.GRE,
IsolationMethod.L3, IsolationMethod.VLAN };
}
@Override
protected boolean canHandle(NetworkOffering offering, final NetworkType networkType, final PhysicalNetwork physicalNetwork) {
// This guru handles only Guest Isolated network that supports Source
// nat service
if (networkType == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && offering.getGuestType() == Network.GuestType.Isolated &&
isMyIsolationMethod(physicalNetwork)) {
return true;
} else {
s_logger.trace("We only take care of Guest networks of type " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced);
return false;
}
}
@Override
protected boolean canHandle(NetworkOffering offering,
final NetworkType networkType, final PhysicalNetwork physicalNetwork) {
// This guru handles only Guest Isolated network that supports Source
// nat service
if (networkType == NetworkType.Advanced
&& isMyTrafficType(offering.getTrafficType())
&& offering.getGuestType() == Network.GuestType.Isolated
&& isMyIsolationMethod(physicalNetwork)
&& _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(
offering.getId(), Service.Connectivity)) {
return true;
} else {
s_logger.trace("We only take care of Guest networks of type "
+ GuestType.Isolated + " in zone of type "
+ NetworkType.Advanced);
return false;
}
}
@Override
public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
@Override
public Network design(NetworkOffering offering, DeploymentPlan plan,
Network userSpecified, Account owner) {
if (!_ovsTunnelMgr.isOvsTunnelEnabled()) {
return null;
}
if (!_ovsTunnelMgr.isOvsTunnelEnabled()) {
return null;
}
PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan
.getPhysicalNetworkId());
DataCenter dc = _dcDao.findById(plan.getDataCenterId());
if (!canHandle(offering, dc.getNetworkType(), physnet)) {
s_logger.debug("Refusing to design this network");
return null;
}
NetworkVO config = (NetworkVO) super.design(offering, plan,
userSpecified, owner);
if (config == null) {
return null;
}
NetworkVO config = (NetworkVO)super.design(offering, plan, userSpecified, owner);
if (config == null) {
return null;
}
config.setBroadcastDomainType(BroadcastDomainType.Vswitch);
config.setBroadcastDomainType(BroadcastDomainType.Vswitch);
return config;
}
return config;
}
@Override
public Network implement(Network network, NetworkOffering offering,
DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException {
assert (network.getState() == State.Implementing) : "Why are we implementing "
+ network;
if (!_ovsTunnelMgr.isOvsTunnelEnabled()) {
return null;
}
long dcId = dest.getDataCenter().getId();
// get physical network id
Long physicalNetworkId = network.getPhysicalNetworkId();
// physical network id can be null in Guest Network in Basic zone, so
// locate the physical network
if (physicalNetworkId == null) {
physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId,
offering.getTags(), offering.getTrafficType());
}
NetworkVO implemented = (NetworkVO) super.implement(network, offering,
dest, context);
@Override
protected void allocateVnet(Network network, NetworkVO implemented, long dcId, long physicalNetworkId, String reservationId)
throws InsufficientVirtualNetworkCapcityException {
if (network.getBroadcastUri() == null) {
String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId, network.getAccountId(), reservationId, UseSystemGuestVlans.valueIn(network.getAccountId()));
if (vnet == null) {
throw new InsufficientVirtualNetworkCapcityException("Unable to allocate vnet as a part of network " + network + " implement ", DataCenter.class, dcId);
}
implemented.setBroadcastUri(BroadcastDomainType.Vswitch.toUri(vnet));
ActionEventUtils.onCompletedActionEvent(CallContext.current().getCallingUserId(), network.getAccountId(), EventVO.LEVEL_INFO,
EventTypes.EVENT_ZONE_VLAN_ASSIGN, "Assigned Zone Vlan: " + vnet + " Network Id: " + network.getId(), 0);
} else {
implemented.setBroadcastUri(network.getBroadcastUri());
}
}
if (network.getGateway() != null) {
implemented.setGateway(network.getGateway());
}
@Override
public Network implement(Network config, NetworkOffering offering, DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException {
assert (config.getState() == State.Implementing) : "Why are we implementing " + config;
if (!_ovsTunnelMgr.isOvsTunnelEnabled()) {
return null;
}
NetworkVO implemented = (NetworkVO)super.implement(config, offering, dest, context);
return implemented;
}
if (network.getCidr() != null) {
implemented.setCidr(network.getCidr());
}
String name = network.getName();
if (name == null || name.isEmpty()) {
name = ((NetworkVO) network).getUuid();
}
// do we need to create switch right now?
implemented.setBroadcastDomainType(BroadcastDomainType.Vswitch);
return implemented;
}
@Override
public void reserve(NicProfile nic, Network network,
VirtualMachineProfile<? extends VirtualMachine> vm,
DeployDestination dest, ReservationContext context)
throws InsufficientVirtualNetworkCapcityException,
InsufficientAddressCapacityException {
// TODO Auto-generated method stub
super.reserve(nic, network, vm, dest, context);
}
@Override
public boolean release(NicProfile nic,
VirtualMachineProfile<? extends VirtualMachine> vm,
String reservationId) {
// TODO Auto-generated method stub
return super.release(nic, vm, reservationId);
}
@Override
public void shutdown(NetworkProfile profile, NetworkOffering offering) {
NetworkVO networkObject = _networkDao.findById(profile.getId());
if (networkObject.getBroadcastDomainType() != BroadcastDomainType.Vswitch
|| networkObject.getBroadcastUri() == null) {
s_logger.warn("BroadcastUri is empty or incorrect for guestnetwork "
+ networkObject.getDisplayText());
return;
}
super.shutdown(profile, offering);
}
@Override
public boolean trash(Network network, NetworkOffering offering,
Account owner) {
return super.trash(network, offering, owner);
}
@Override
protected void allocateVnet(Network network, NetworkVO implemented,
long dcId, long physicalNetworkId, String reservationId)
throws InsufficientVirtualNetworkCapcityException {
if (network.getBroadcastUri() == null) {
String vnet = _dcDao.allocateVnet(dcId, physicalNetworkId,
network.getAccountId(), reservationId,
canUseSystemGuestVlan(network.getAccountId()));
if (vnet == null) {
throw new InsufficientVirtualNetworkCapcityException(
"Unable to allocate vnet as a part of network "
+ network + " implement ", DataCenter.class,
dcId);
}
implemented
.setBroadcastUri(BroadcastDomainType.Vswitch.toUri(vnet));
ActionEventUtils.onCompletedActionEvent(
UserContext.current().getCallerUserId(),
network.getAccountId(),
EventVO.LEVEL_INFO,
EventTypes.EVENT_ZONE_VLAN_ASSIGN,
"Assigned Zone Vlan: " + vnet + " Network Id: "
+ network.getId(), 0);
} else {
implemented.setBroadcastUri(network.getBroadcastUri());
}
}
}

View File

@ -1,78 +0,0 @@
// 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.ovs;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.log4j.Logger;
public class OvsApi {
private static final Logger s_logger = Logger.getLogger(OvsApi.class);
private final static String _protocol = "http";
private final static MultiThreadedHttpConnectionManager s_httpClientManager = new MultiThreadedHttpConnectionManager();
private String _host;
private final HttpClient _client;
protected HttpClient createHttpClient() {
return new HttpClient(s_httpClientManager);
}
protected HttpMethod createMethod(String type, String uri, int port)
throws OvsApiException {
String url;
try {
url = new URL(_protocol, _host, port, uri).toString();
} catch (MalformedURLException e) {
s_logger.error("Unable to build Ovs API URL", e);
throw new OvsApiException("Unable to Ovs API URL", e);
}
if ("post".equalsIgnoreCase(type)) {
return new PostMethod(url);
} else if ("get".equalsIgnoreCase(type)) {
return new GetMethod(url);
} else if ("delete".equalsIgnoreCase(type)) {
return new DeleteMethod(url);
} else if ("put".equalsIgnoreCase(type)) {
return new PutMethod(url);
} else {
throw new OvsApiException("Requesting unknown method type");
}
}
public OvsApi() {
_client = createHttpClient();
_client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
}
public void setControllerAddress(String address) {
this._host = address;
}
// TODO: implement requests
}

View File

@ -1,35 +0,0 @@
// 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.ovs;
public class OvsApiException extends Exception {
public OvsApiException() {
}
public OvsApiException(String message) {
super(message);
}
public OvsApiException(Throwable cause) {
super(cause);
}
public OvsApiException(String message, Throwable cause) {
super(message, cause);
}
}

View File

@ -1,69 +0,0 @@
// 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.ovs;
import com.cloud.agent.api.Command;
public class OvsCreateTunnelCommand extends Command {
Integer key;
String remoteIp;
Long from;
Long to;
long networkId;
// for debug info
String fromIp;
@Override
public boolean executeInSequence() {
return true;
}
public OvsCreateTunnelCommand(String remoteIp, Integer key, Long from, Long to, long networkId, String fromIp) {
this.remoteIp = remoteIp;
this.key = key;
this.from = from;
this.to = to;
this.networkId = networkId;
this.fromIp = fromIp;
}
public Integer getKey() {
return key;
}
public String getRemoteIp() {
return remoteIp;
}
public Long getFrom() {
return from;
}
public Long getTo() {
return to;
}
public long getNetworkId() {
return networkId;
}
public String getFromIp() {
return fromIp;
}
}

View File

@ -35,6 +35,13 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.OvsCreateTunnelAnswer;
import com.cloud.agent.api.OvsCreateTunnelCommand;
import com.cloud.agent.api.OvsDestroyBridgeCommand;
import com.cloud.agent.api.OvsDestroyTunnelCommand;
import com.cloud.agent.api.OvsFetchInterfaceAnswer;
import com.cloud.agent.api.OvsFetchInterfaceCommand;
import com.cloud.agent.api.OvsSetupBridgeCommand;
import com.cloud.agent.manager.Commands;
import com.cloud.configuration.Config;
import com.cloud.deploy.DeployDestination;

View File

@ -1,26 +0,0 @@
// 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.ovs.dao;
import java.util.List;
import com.cloud.utils.db.GenericDao;
public interface OvsDeviceDao extends GenericDao<OvsDeviceVO, Long> {
List<OvsDeviceVO> listByPhysicalNetwork(long physicalNetworkId);
}

View File

@ -1,49 +0,0 @@
// 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.ovs.dao;
import java.util.List;
import javax.ejb.Local;
import org.springframework.stereotype.Component;
import com.cloud.utils.db.GenericDaoBase;
import com.cloud.utils.db.SearchBuilder;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.SearchCriteria.Op;
@Component
@Local(value=OvsDeviceDao.class)
public class OvsDeviceDaoImpl extends GenericDaoBase<OvsDeviceVO, Long> implements OvsDeviceDao {
protected final SearchBuilder<OvsDeviceVO> physicalNetworkIdSearch;
public OvsDeviceDaoImpl() {
physicalNetworkIdSearch = createSearchBuilder();
physicalNetworkIdSearch.and("physicalNetworkId", physicalNetworkIdSearch.entity().getPhysicalNetworkId(), Op.EQ);
physicalNetworkIdSearch.done();
}
@Override
public List<OvsDeviceVO> listByPhysicalNetwork(long physicalNetworkId) {
SearchCriteria<OvsDeviceVO> sc = physicalNetworkIdSearch.create();
sc.setParameters("physicalNetworkId", physicalNetworkId);
return search(sc, null);
}
}

View File

@ -1,88 +0,0 @@
// 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.ovs.dao;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import org.apache.cloudstack.api.InternalIdentity;
@Entity
@Table(name="ovs_devices")
public class OvsDeviceVO implements InternalIdentity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private long id;
@Column(name="uuid")
private String uuid;
@Column(name="host_id")
private long hostId;
@Column(name="physical_network_id")
private long physicalNetworkId;
@Column(name="device_name")
private String deviceName;
public OvsDeviceVO() {
this.uuid = UUID.randomUUID().toString();
}
public OvsDeviceVO(long hostId, long physicalNetworkId,
String deviceName) {
super();
this.hostId = hostId;
this.physicalNetworkId = physicalNetworkId;
this.deviceName = deviceName;
this.uuid = UUID.randomUUID().toString();
}
public long getId() {
return id;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
public long getPhysicalNetworkId() {
return physicalNetworkId;
}
public long getHostId() {
return hostId;
}
public String getDeviceName() {
return deviceName;
}
}

View File

@ -1,175 +0,0 @@
package com.cloud.network.resource;
import java.util.Map;
import javax.naming.ConfigurationException;
import org.apache.log4j.Logger;
import com.cloud.agent.IAgentControl;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.MaintainAnswer;
import com.cloud.agent.api.MaintainCommand;
import com.cloud.agent.api.PingCommand;
import com.cloud.agent.api.ReadyAnswer;
import com.cloud.agent.api.ReadyCommand;
import com.cloud.agent.api.StartupCommand;
import com.cloud.host.Host;
import com.cloud.host.Host.Type;
import com.cloud.network.ovs.OvsApi;
import com.cloud.network.ovs.StartupOvsCommand;
import com.cloud.resource.ServerResource;
import com.cloud.utils.component.ManagerBase;
public class OvsResource extends ManagerBase implements ServerResource {
private static final Logger s_logger = Logger.getLogger(OvsResource.class);
private String _name;
private String _guid;
private String _zoneId;
private int _numRetries;
private OvsApi _ovsApi;
protected OvsApi createOvsApi() {
return new OvsApi();
}
@Override
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
_name = (String) params.get("name");
if (_name == null) {
throw new ConfigurationException("Unable to find name");
}
_guid = (String) params.get("guid");
if (_guid == null) {
throw new ConfigurationException("Unable to find the guid");
}
_zoneId = (String) params.get("zoneId");
if (_zoneId == null) {
throw new ConfigurationException("Unable to find zone");
}
_numRetries = 2;
String ip = (String) params.get("ip");
if (ip == null) {
throw new ConfigurationException("Unable to find IP");
}
_ovsApi = createOvsApi();
_ovsApi.setControllerAddress(ip);
return true;
}
@Override
public boolean start() {
return true;
}
@Override
public boolean stop() {
return true;
}
@Override
public String getName() {
return _name;
}
@Override
public Type getType() {
return Host.Type.L2Networking;
}
@Override
public StartupCommand[] initialize() {
StartupOvsCommand sc = new StartupOvsCommand();
sc.setGuid(_guid);
sc.setName(_name);
sc.setDataCenter(_zoneId);
sc.setPod("");
sc.setPrivateIpAddress("");
sc.setStorageIpAddress("");
sc.setVersion("");
return new StartupCommand[] { sc };
}
@Override
public PingCommand getCurrentStatus(long id) {
// TODO Auto-generated method stub
return null;
}
@Override
public Answer executeRequest(Command cmd) {
return executeRequest(cmd, _numRetries);
}
private Answer executeRequest(ReadyCommand cmd) {
return new ReadyAnswer(cmd);
}
private Answer executeRequest(MaintainCommand cmd) {
return new MaintainAnswer(cmd);
}
public Answer executeRequest(Command cmd, int numRetries) {
if (cmd instanceof ReadyCommand) {
return executeRequest((ReadyCommand) cmd);
} else if (cmd instanceof MaintainCommand) {
return executeRequest((MaintainCommand) cmd);
}
// TODO: implement services request
// else if (cmd instanceof CreateOvsNetworkCommand) {
// return executeRequest((CreateOvsNetworkCommand)cmd, numRetries);
// }
// else if (cmd instanceof DeleteOvsNetworkCommand) {
// return executeRequest((DeleteOvsNetworkCommand) cmd, numRetries);
// }
// else if (cmd instanceof CreateOvsPortCommand) {
// return executeRequest((CreateOvsPortCommand) cmd, numRetries);
// }
// else if (cmd instanceof DeleteOvsPortCommand) {
// return executeRequest((DeleteOvsPortCommand) cmd, numRetries);
// }
// else if (cmd instanceof UpdateOvsPortCommand) {
// return executeRequest((UpdateOvsPortCommand) cmd, numRetries);
// }
s_logger.debug("Received unsupported command " + cmd.toString());
return Answer.createUnsupportedCommandAnswer(cmd);
}
@Override
public void disconnected() {
}
private Answer retry(Command cmd, int numRetries) {
s_logger.warn("Retrying " + cmd.getClass().getSimpleName()
+ ". Number of retries remaining: " + numRetries);
return executeRequest(cmd, numRetries);
}
private String truncate(String string, int length) {
if (string.length() <= length) {
return string;
} else {
return string.substring(0, length);
}
}
@Override
public IAgentControl getAgentControl() {
return null;
}
@Override
public void setAgentControl(IAgentControl agentControl) {
}
}

View File

@ -196,7 +196,6 @@ DROP TABLE IF EXISTS `cloud`.`vm_network_map`;
DROP TABLE IF EXISTS `cloud`.`netapp_volume`;
DROP TABLE IF EXISTS `cloud`.`netapp_pool`;
DROP TABLE IF EXISTS `cloud`.`netapp_lun`;
DROP TABLE IF EXISTS `cloud`.`ovs_devices`;
DROP TABLE IF EXISTS `cloud`.`ovs_nic_map`;
CREATE TABLE `cloud`.`version` (
@ -2477,17 +2476,6 @@ CREATE TABLE `cloud`.`nicira_nvp_nic_map` (
CONSTRAINT `fk_nicira_nvp_nic_map__nic` FOREIGN KEY(`nic`) REFERENCES `nics`(`uuid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`ovs_devices` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`uuid` varchar(255) UNIQUE,
`physical_network_id` bigint unsigned NOT NULL COMMENT 'id of the physical network in to which ovs device is added',
`device_name` varchar(255) NOT NULL COMMENT 'name of the ovs device',
`host_id` bigint unsigned NOT NULL COMMENT 'host id coresponding to the ovs device',
PRIMARY KEY (`id`),
CONSTRAINT `fk_ovs_devices__host_id` FOREIGN KEY (`host_id`) REFERENCES `host`(`id`) ON DELETE CASCADE,
CONSTRAINT `fk_ovs_devices__physical_network_id` FOREIGN KEY (`physical_network_id`) REFERENCES `physical_network`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `cloud`.`ovs_nic_map` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
`logicalswitch` varchar(255) NOT NULL COMMENT 'uuid of logical switch this port is provisioned on',