use of org.onlab.packet.IpAddress in project ddosdn by ssulca.
the class IdsWebResource method getOrders.
/**
* Get hello world greeting.
*
* @return 200 OK
*/
@GET
@Path("ips")
@Produces(MediaType.APPLICATION_JSON)
public Response getOrders() {
ObjectNode node;
ArrayNode ipArray;
Set<IpAddress> idsResources;
idsResources = IdsResources.getInstance().getIpAddressSet();
node = mapper().createObjectNode();
ipArray = mapper().createArrayNode();
idsResources.forEach(ipAddress -> {
// Add IDS ips
ipArray.add(ipAddress.toString());
});
// add Array to Object
node.putArray(IP).addAll(ipArray);
return ok(node).build();
}
use of org.onlab.packet.IpAddress in project TFG by mattinelorza.
the class Ipv6RoutingComponent method setUpHostRules.
/**
* Sets up the given device with the necessary rules to route packets to the
* given host.
*
* @param deviceId deviceId the device ID
* @param host the host
*/
private void setUpHostRules(DeviceId deviceId, Host host) {
// Get all IPv6 addresses associated to this host. In this tutorial we
// use hosts with only 1 IPv6 address.
final Collection<Ip6Address> hostIpv6Addrs = host.ipAddresses().stream().filter(IpAddress::isIp6).map(IpAddress::getIp6Address).collect(Collectors.toSet());
if (hostIpv6Addrs.isEmpty()) {
// Ignore.
log.debug("No IPv6 addresses for host {}, ignore", host.id());
return;
} else {
log.info("Adding routes on {} for host {} [{}]", deviceId, host.id(), hostIpv6Addrs);
}
// Create an ECMP group with only one member, where the group ID is
// derived from the host MAC.
final MacAddress hostMac = host.mac();
int groupId = macToGroupId(hostMac);
final GroupDescription group = createNextHopGroup(groupId, Collections.singleton(hostMac), deviceId);
// Map each host IPV6 address to corresponding /128 prefix and obtain a
// flow rule that points to the group ID. In this tutorial we expect
// only one flow rule per host.
final List<FlowRule> flowRules = hostIpv6Addrs.stream().map(IpAddress::toIpPrefix).filter(IpPrefix::isIp6).map(IpPrefix::getIp6Prefix).map(prefix -> createRoutingRule(deviceId, prefix, groupId)).collect(Collectors.toList());
// Helper function to install flows after groups, since here flows
// points to the group and P4Runtime enforces this dependency during
// write operations.
insertInOrder(group, flowRules);
}
use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.
the class VirtualHostCreateCommand method doExecute.
@Override
protected void doExecute() {
VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
Set<IpAddress> hostIps = new HashSet<>();
if (hostIpStrings != null) {
Arrays.stream(hostIpStrings).forEach(s -> hostIps.add(IpAddress.valueOf(s)));
}
HostLocation hostLocation = new HostLocation(DeviceId.deviceId(hostLocationDeviceId), PortNumber.portNumber(hostLocationPortNumber), System.currentTimeMillis());
MacAddress macAddress = MacAddress.valueOf(mac);
VlanId vlanId = VlanId.vlanId(vlan);
service.createVirtualHost(NetworkId.networkId(networkId), HostId.hostId(macAddress, vlanId), macAddress, vlanId, hostLocation, hostIps);
print("Virtual host successfully created.");
}
use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.
the class VirtualHostCodecTest method testEncode.
@Test
public void testEncode() {
MockCodecContext context = new MockCodecContext();
NetworkId networkId = NetworkId.networkId(TEST_NETWORK_ID);
HostId id = NetTestTools.hid(TEST_HOST_ID);
MacAddress mac = MacAddress.valueOf(TEST_MAC_ADDRESS);
VlanId vlan = VlanId.vlanId(TEST_VLAN_ID);
HostLocation location = new HostLocation(CONNECT_POINT, 0L);
Set<IpAddress> ips = ImmutableSet.of(IpAddress.valueOf(TEST_IP1), IpAddress.valueOf(TEST_IP2));
VirtualHost host = new DefaultVirtualHost(networkId, id, mac, vlan, location, ips);
JsonCodec<VirtualHost> codec = context.codec(VirtualHost.class);
ObjectNode node = codec.encode(host, context);
assertThat(node.get(VirtualHostCodec.NETWORK_ID).asLong(), is(TEST_NETWORK_ID));
assertThat(node.get(VirtualHostCodec.HOST_ID).asText(), is(TEST_HOST_ID));
assertThat(node.get(VirtualHostCodec.MAC_ADDRESS).asText(), is(TEST_MAC_ADDRESS));
assertThat(node.get(VirtualHostCodec.VLAN).asInt(), is((int) TEST_VLAN_ID));
assertThat(node.get(VirtualHostCodec.HOST_LOCATION).get(0).get("elementId").asText(), is(location.deviceId().toString()));
assertThat(node.get(VirtualHostCodec.HOST_LOCATION).get(0).get("port").asLong(), is(location.port().toLong()));
JsonNode jsonIps = node.get(VirtualHostCodec.IP_ADDRESSES);
assertThat(jsonIps, notNullValue());
assertThat(jsonIps.isArray(), is(true));
assertThat(jsonIps.size(), is(ips.size()));
IntStream.of(0, 1).forEach(index -> assertThat(jsonIps.get(index).asText(), isOneOf(TEST_IP1, TEST_IP2)));
}
use of org.onlab.packet.IpAddress in project onos by opennetworkinglab.
the class KubevirtListIpAddressCommand method doExecute.
@Override
protected void doExecute() throws Exception {
KubevirtNetworkService service = get(KubevirtNetworkService.class);
if (networkId == null) {
error("No network identifier was specified");
return;
}
KubevirtNetwork network = service.network(networkId);
if (network == null) {
print("No network was found with the given network ID");
return;
}
KubevirtIpPool pool = network.ipPool();
if (pool == null) {
print("No IP pool was found with the given network ID");
return;
}
String format = genFormatString(ImmutableList.of(CLI_IP_ADDRESS_LENGTH, CLI_IP_ADDRESS_AVAILABILITY));
print(format, "IP Address", "Availability");
List<IpAddress> sortedAllocatedIps = new ArrayList<>(pool.allocatedIps());
Collections.sort(sortedAllocatedIps);
for (IpAddress ip : sortedAllocatedIps) {
print(format, ip.toString(), "[ X ]");
}
List<IpAddress> sortedAvailableIps = new ArrayList<>(pool.availableIps());
Collections.sort(sortedAvailableIps);
for (IpAddress ip : sortedAvailableIps) {
print(format, ip.toString(), "[ O ]");
}
}
Aggregations