use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.
the class InstancePortManagerTest method testRemoveInstanceFromMigration.
/**
* Tests if it triggers the instance removal event from migration status.
*/
@Test
public void testRemoveInstanceFromMigration() {
InstancePort instancePort = instancePort1;
target.createInstancePort(instancePort);
InstancePort inactiveInstancePort = instancePort.updateState(MIGRATING);
target.updateInstancePort(inactiveInstancePort);
assertEquals("Number of instance port did not match", 1, target.instancePorts().size());
assertNotNull("Instance port did not match", target.instancePort(PORT_ID_1));
target.removeInstancePort(PORT_ID_1);
assertEquals("Number of instance port did not match", 0, target.instancePorts().size());
assertNull("Instance port did not match", target.instancePort(PORT_ID_1));
validateEvents(OPENSTACK_INSTANCE_PORT_DETECTED, OPENSTACK_INSTANCE_MIGRATION_STARTED, OPENSTACK_INSTANCE_PORT_VANISHED);
}
use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.
the class InstancePortManagerTest method testMigrateInstanceStart.
/**
* Tests if it triggers the instance migration start event.
*/
@Test
public void testMigrateInstanceStart() {
InstancePort instancePort = instancePort1;
target.createInstancePort(instancePort);
InstancePort migratingPort = instancePort.updateState(MIGRATING);
target.updateInstancePort(migratingPort);
assertEquals("Number of instance port did not match", 1, target.instancePorts().size());
assertNotNull("Instance port did not match", target.instancePort(PORT_ID_1));
validateEvents(OPENSTACK_INSTANCE_PORT_DETECTED, OPENSTACK_INSTANCE_MIGRATION_STARTED);
}
use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.
the class InstancePortManagerTest method testGetInstancePortByMac.
/**
* Tests if getting an instance port with MAC returns correct port.
*/
@Test
public void testGetInstancePortByMac() {
createBasicInstancePorts();
InstancePort port = target.instancePort(MAC_ADDRESS_1);
assertEquals("Instance port did not match", port, instancePort1);
}
use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.
the class InstancePortListCommand method doExecute.
@Override
protected void doExecute() {
InstancePortService service = get(InstancePortService.class);
OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
List<InstancePort> instancePorts = Lists.newArrayList(service.instancePorts());
instancePorts.sort(Comparator.comparing(InstancePort::portId));
if (outputJson()) {
print("%s", json(this, instancePorts));
} else {
print(FORMAT, "Port ID", "VM Device ID", "State", "Device ID", "Port Number", "Fixed IP");
for (InstancePort port : instancePorts) {
Port neutronPort = osNetService.port(port.portId());
String vmId = "N/A";
if (neutronPort != null) {
vmId = neutronPort.getDeviceId();
}
print(FORMAT, port.portId(), vmId, port.state(), port.deviceId().toString(), port.portNumber().toLong(), port.ipAddress().toString());
}
}
}
use of org.onosproject.openstacknetworking.api.InstancePort in project onos by opennetworkinglab.
the class OpenstackAddAclCommand method doExecute.
@Override
protected void doExecute() {
OpenstackFlowRuleService flowRuleService = get(OpenstackFlowRuleService.class);
CoreService coreService = get(CoreService.class);
ApplicationId appId = coreService.getAppId(OPENSTACK_NETWORKING_APP_ID);
InstancePortService instancePortService = get(InstancePortService.class);
IpAddress srcIpAddress;
IpAddress dstIpAddress;
try {
srcIpAddress = IpAddress.valueOf(srcIpStr);
dstIpAddress = IpAddress.valueOf(dstIpStr);
} catch (IllegalArgumentException e) {
log.error("IllegalArgumentException occurred because of {}", e);
return;
}
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_IPV4).matchIPSrc(srcIpAddress.toIpPrefix()).matchIPDst(dstIpAddress.toIpPrefix());
TrafficTreatment treatment = DefaultTrafficTreatment.builder().drop().build();
if (srcPort != 0 || dstPort != 0) {
sBuilder.matchIPProtocol(IPv4.PROTOCOL_TCP);
if (srcPort != 0) {
sBuilder.matchTcpSrc(TpPort.tpPort(srcPort));
}
if (dstPort != 0) {
sBuilder.matchTcpDst(TpPort.tpPort(dstPort));
}
}
log.info("Deny the packet from srcIp: {}, dstPort: {} to dstIp: {}, dstPort: {}", srcIpAddress.toString(), srcPort, dstIpAddress.toString(), dstPort);
Optional<InstancePort> instancePort = instancePortService.instancePorts().stream().filter(port -> port.ipAddress().toString().equals(dstIpStr)).findAny();
if (!instancePort.isPresent()) {
log.info("Instance port that matches with the given dst ip address isn't present {}");
return;
}
flowRuleService.setRule(appId, instancePort.get().deviceId(), sBuilder.build(), treatment, PRIORITY_FORCED_ACL_RULE, DHCP_TABLE, true);
}
Aggregations