Search in sources :

Example 21 with IpAddress

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();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IpAddress(org.onlab.packet.IpAddress) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 22 with IpAddress

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);
}
Also used : GroupDescription(org.onosproject.net.group.GroupDescription) IpPrefix(org.onlab.packet.IpPrefix) NetworkConfigService(org.onosproject.net.config.NetworkConfigService) Interface(org.onosproject.net.intf.Interface) PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) Link(org.onosproject.net.Link) FlowRuleService(org.onosproject.net.flow.FlowRuleService) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) ApplicationId(org.onosproject.core.ApplicationId) MastershipService(org.onosproject.mastership.MastershipService) PiTableAction(org.onosproject.net.pi.runtime.PiTableAction) Ip6Address(org.onlab.packet.Ip6Address) Device(org.onosproject.net.Device) Deactivate(org.osgi.service.component.annotations.Deactivate) FabricDeviceConfig(org.onosproject.ngsdn.tutorial.common.FabricDeviceConfig) Collection(java.util.Collection) Set(java.util.Set) ItemNotFoundException(org.onlab.util.ItemNotFoundException) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Collectors(java.util.stream.Collectors) LinkListener(org.onosproject.net.link.LinkListener) List(java.util.List) INITIAL_SETUP_DELAY(org.onosproject.ngsdn.tutorial.AppConstants.INITIAL_SETUP_DELAY) FlowRule(org.onosproject.net.flow.FlowRule) DeviceEvent(org.onosproject.net.device.DeviceEvent) LinkService(org.onosproject.net.link.LinkService) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) GroupDescription(org.onosproject.net.group.GroupDescription) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) IpPrefix(org.onlab.packet.IpPrefix) Host(org.onosproject.net.Host) LinkEvent(org.onosproject.net.link.LinkEvent) HostListener(org.onosproject.net.host.HostListener) InterfaceService(org.onosproject.net.intf.InterfaceService) HostService(org.onosproject.net.host.HostService) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) HostEvent(org.onosproject.net.host.HostEvent) Activate(org.osgi.service.component.annotations.Activate) Utils(org.onosproject.ngsdn.tutorial.common.Utils) IpAddress(org.onlab.packet.IpAddress) DeviceListener(org.onosproject.net.device.DeviceListener) Logger(org.slf4j.Logger) GroupService(org.onosproject.net.group.GroupService) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) Ip6Prefix(org.onlab.packet.Ip6Prefix) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Streams.stream(com.google.common.collect.Streams.stream) PiAction(org.onosproject.net.pi.runtime.PiAction) MacAddress(org.onlab.packet.MacAddress) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) PiActionId(org.onosproject.net.pi.model.PiActionId) Ip6Address(org.onlab.packet.Ip6Address) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) IpAddress(org.onlab.packet.IpAddress) FlowRule(org.onosproject.net.flow.FlowRule) MacAddress(org.onlab.packet.MacAddress)

Example 23 with IpAddress

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.");
}
Also used : HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) VirtualNetworkAdminService(org.onosproject.incubator.net.virtual.VirtualNetworkAdminService) VlanId(org.onlab.packet.VlanId) HashSet(java.util.HashSet)

Example 24 with IpAddress

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)));
}
Also used : DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) MockCodecContext(org.onosproject.codec.impl.MockCodecContext) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) HostId(org.onosproject.net.HostId) MacAddress(org.onlab.packet.MacAddress) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) VirtualHost(org.onosproject.incubator.net.virtual.VirtualHost) DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test)

Example 25 with IpAddress

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 ]");
    }
}
Also used : KubevirtNetworkService(org.onosproject.kubevirtnetworking.api.KubevirtNetworkService) KubevirtNetwork(org.onosproject.kubevirtnetworking.api.KubevirtNetwork) ArrayList(java.util.ArrayList) IpAddress(org.onlab.packet.IpAddress) KubevirtIpPool(org.onosproject.kubevirtnetworking.api.KubevirtIpPool) KubevirtNetworkingUtil.genFormatString(org.onosproject.kubevirtnetworking.util.KubevirtNetworkingUtil.genFormatString)

Aggregations

IpAddress (org.onlab.packet.IpAddress)288 MacAddress (org.onlab.packet.MacAddress)63 VlanId (org.onlab.packet.VlanId)52 ConnectPoint (org.onosproject.net.ConnectPoint)48 Set (java.util.Set)46 DeviceId (org.onosproject.net.DeviceId)44 Logger (org.slf4j.Logger)40 Test (org.junit.Test)37 Collectors (java.util.stream.Collectors)36 Ethernet (org.onlab.packet.Ethernet)36 IpPrefix (org.onlab.packet.IpPrefix)36 HostId (org.onosproject.net.HostId)33 Host (org.onosproject.net.Host)32 Optional (java.util.Optional)30 HostLocation (org.onosproject.net.HostLocation)30 LoggerFactory (org.slf4j.LoggerFactory)30 ApplicationId (org.onosproject.core.ApplicationId)29 CoreService (org.onosproject.core.CoreService)29 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)29 JsonNode (com.fasterxml.jackson.databind.JsonNode)28