sanghoshin

SONA: OpenstackSwitching - remove flows

 - Remove the corresponding flows when VMs are removed.
 - Remove the IP mapping of the VM removed from the DHCP service (even when doNotPushFlows is true)
 - Updated the network config json file to reflect the change of cordvtn
Change-Id: I4c359d456422ece37b93e6366f2fd4daaf081a37
......@@ -35,13 +35,14 @@ public interface OpenstackSwitchingService {
* Removes flow rules corresponding to the port removed by Openstack.
*
*/
void deletePorts();
void deletePort(String uuid);
/**
* Updates flow rules corresponding to the port information updated by Openstack.
*
* @param openstackPort
*/
void updatePorts();
void updatePort(OpenstackPort openstackPort);
/**
* Stores the network information created by openstack.
......
......@@ -40,6 +40,9 @@
</api.description>
<api.package>org.onosproject.openstackswitching.web</api.package>
<onos.app.origin>SKT, Inc.</onos.app.origin>
<onos.app.requires>
org.onosproject.dhcp
</onos.app.requires>
</properties>
......
......@@ -131,6 +131,21 @@ public class OpenstackSwitchingRulePopulator {
}
/**
* Remove flows rules for the VM removed.
*
* @param deviceId device to remove rules
* @param vmIp IP address of the VM removed
*/
public void removeSwitchingRules(DeviceId deviceId, Ip4Address vmIp) {
removeFlowRuleForVMsInSameCnode(deviceId, vmIp);
deviceService.getAvailableDevices().forEach(device -> {
if (!device.id().equals(deviceId)) {
removeVxLanFlowRule(device.id(), vmIp);
}
});
}
/**
* Populates the flow rules for traffic to VMs in the same Cnode as the sender.
*
* @param device device to put the rules
......@@ -170,9 +185,10 @@ public class OpenstackSwitchingRulePopulator {
Ip4Address hostIpx = Ip4Address.valueOf(cidx.split(":")[0]);
MacAddress vmMacx = getVmMacAddressForPort(pName);
Ip4Address fixedIpx = getFixedIpAddressForPort(pName);
setVxLanFlowRule(vni, device.id(), hostIpx, fixedIpx, vmMacx);
setVxLanFlowRule(vni, d.id(), hostIpAddress, fixedIp, vmMac);
if (port.isEnabled()) {
setVxLanFlowRule(vni, device.id(), hostIpx, fixedIpx, vmMacx);
setVxLanFlowRule(vni, d.id(), hostIpAddress, fixedIp, vmMac);
}
}
});
}
......@@ -246,7 +262,7 @@ public class OpenstackSwitchingRulePopulator {
.findFirst().orElse(null);
if (port == null) {
log.error("There is port information for port name {}", portName);
log.error("There is no port information for port name {}", portName);
return null;
}
......@@ -341,6 +357,40 @@ public class OpenstackSwitchingRulePopulator {
flowObjectiveService.forward(id, fo);
}
private void removeFlowRuleForVMsInSameCnode(DeviceId id, Ip4Address vmIp) {
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
sBuilder.matchEthType(Ethernet.TYPE_IPV4)
.matchIPDst(vmIp.toIpPrefix());
ForwardingObjective fo = DefaultForwardingObjective.builder()
.withSelector(sBuilder.build())
.withTreatment(DefaultTrafficTreatment.builder().build())
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(SWITCHING_RULE_PRIORITY)
.fromApp(appId)
.remove();
flowObjectiveService.forward(id, fo);
}
private void removeVxLanFlowRule(DeviceId id, Ip4Address vmIp) {
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
// XXX: Later, more matches will be added when multiple table is implemented.
sBuilder.matchEthType(Ethernet.TYPE_IPV4)
.matchIPDst(vmIp.toIpPrefix());
ForwardingObjective fo = DefaultForwardingObjective.builder()
.withSelector(sBuilder.build())
.withTreatment(DefaultTrafficTreatment.builder().build())
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(SWITCHING_RULE_PRIORITY)
.fromApp(appId)
.remove();
flowObjectiveService.forward(id, fo);
}
private ExtensionTreatment buildNiciraExtenstion(DeviceId id, Ip4Address hostIp) {
Driver driver = driverService.getDriver(id);
DriverHandler driverHandler = new DefaultDriverHandler(new DefaultDriverData(driver, id));
......
......@@ -28,6 +28,7 @@ import javax.ws.rs.DELETE;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
......@@ -68,12 +69,9 @@ public class OpenstackPortWebResource extends AbstractWebResource {
}
}
@Path("{portUUID}")
@DELETE
@Path("{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response deletesPorts(InputStream input) {
log.debug("REST API ports is called with {}", input.toString());
public Response deletePorts(@PathParam("portUUID") String id) {
return Response.status(Response.Status.OK).build();
}
......@@ -82,7 +80,6 @@ public class OpenstackPortWebResource extends AbstractWebResource {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updatePorts(InputStream input) {
log.info("REST API ports is called with {}", input.toString());
return Response.status(Response.Status.OK).build();
}
}
......
......@@ -32,19 +32,31 @@
"nodes" : [
{
"hostname" : "compute-01",
<<<<<<< HEAD
"ovsdbIp" : "10.40.101.208",
=======
"ovsdbIp" : "127.0.0.1",
>>>>>>> 6a78e2e... SONA: OpenstackSwitching - remove flows
"ovsdbPort" : "6640",
"bridgeId" : "of:0000000000000001"
},
{
"hostname" : "compute-02",
<<<<<<< HEAD
"ovsdbIp" : "10.40.101.227",
=======
"ovsdbIp" : "127.0.0.1",
>>>>>>> 6a78e2e... SONA: OpenstackSwitching - remove flows
"ovsdbPort" : "6640",
"bridgeId" : "of:0000000000000002"
},
{
"hostname" : "network",
<<<<<<< HEAD
"ovsdbIp" : "10.40.101.209",
=======
"ovsdbIp" : "127.0.0.1",
>>>>>>> 6a78e2e... SONA: OpenstackSwitching - remove flows
"ovsdbPort" : "6640",
"bridgeId" : "of:0000000000000003"
}
......