Search in sources :

Example 21 with HostId

use of org.onosproject.net.HostId in project onos by opennetworkinglab.

the class BasicHostConfigTest method testConstruction.

/**
 * Tests construction, setters and getters of a BasicHostConfig object.
 */
@Test
public void testConstruction() {
    BasicHostConfig config = new BasicHostConfig();
    ConfigApplyDelegate delegate = configApply -> {
    };
    ObjectMapper mapper = new ObjectMapper();
    HostId hostId = NetTestTools.hid("12:34:56:78:90:ab/1");
    IpAddress ip1 = IpAddress.valueOf("1.1.1.1");
    IpAddress ip2 = IpAddress.valueOf("1.1.1.2");
    IpAddress ip3 = IpAddress.valueOf("1.1.1.3");
    Set<IpAddress> ips = ImmutableSet.of(ip1, ip2, ip3);
    HostLocation loc1 = new HostLocation(NetTestTools.connectPoint("d1", 1), System.currentTimeMillis());
    HostLocation loc2 = new HostLocation(NetTestTools.connectPoint("d2", 2), System.currentTimeMillis());
    Set<HostLocation> locs = ImmutableSet.of(loc1, loc2);
    HostLocation loc3 = new HostLocation(NetTestTools.connectPoint("d3", 1), System.currentTimeMillis());
    HostLocation loc4 = new HostLocation(NetTestTools.connectPoint("d4", 2), System.currentTimeMillis());
    Set<HostLocation> auxLocations = ImmutableSet.of(loc3, loc4);
    VlanId vlanId = VlanId.vlanId((short) 10);
    EthType ethType = EthType.EtherType.lookup((short) 0x88a8).ethType();
    config.init(hostId, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
    config.setIps(ips).setLocations(locs).setAuxLocations(auxLocations).setInnerVlan(vlanId).setOuterTpid(ethType);
    assertThat(config.isValid(), is(true));
    assertThat(config.name(), is("-"));
    assertThat(config.ipAddresses(), hasSize(3));
    assertThat(config.ipAddresses(), hasItems(ip1, ip2, ip3));
    assertThat(config.locations(), hasSize(2));
    assertThat(config.locations(), hasItems(loc1, loc2));
    assertThat(config.auxLocations(), hasSize(2));
    assertThat(config.auxLocations(), hasItems(loc3, loc4));
    assertThat(config.innerVlan(), is(vlanId));
    assertThat(config.outerTpid(), is(ethType));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) HostLocation(org.onosproject.net.HostLocation) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Test(org.junit.Test) Matchers.hasItems(org.hamcrest.Matchers.hasItems) EthType(org.onlab.packet.EthType) NetTestTools(org.onosproject.net.NetTestTools) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Matchers.hasSize(org.hamcrest.Matchers.hasSize) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) EthType(org.onlab.packet.EthType) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) HostId(org.onosproject.net.HostId) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VlanId(org.onlab.packet.VlanId) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Test(org.junit.Test)

Example 22 with HostId

use of org.onosproject.net.HostId in project onos by opennetworkinglab.

the class HostToHostIntentTest method testSameEquals.

/**
 * Tests the equals() method where two HostToHostIntents have references
 * to the same hosts. These should compare equal.
 */
@Test
public void testSameEquals() {
    HostId one = hid("00:00:00:00:00:01/-1");
    HostId two = hid("00:00:00:00:00:02/-1");
    HostToHostIntent i1 = makeHostToHost(one, two);
    HostToHostIntent i2 = makeHostToHost(one, two);
    assertThat(i1.one(), is(equalTo(i2.one())));
    assertThat(i1.two(), is(equalTo(i2.two())));
}
Also used : HostId(org.onosproject.net.HostId) Test(org.junit.Test)

Example 23 with HostId

use of org.onosproject.net.HostId in project onos by opennetworkinglab.

the class McastRouteWebResource method addSinks.

/**
 * Adds sinks for a given existing multicast route.
 *
 * @param group  group IP address
 * @param srcIp  source IP address
 * @param stream host sinks JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel McastSinksAdd
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("sinks/{group}/{srcIp}")
public Response addSinks(@PathParam("group") String group, @PathParam("srcIp") String srcIp, InputStream stream) {
    MulticastRouteService service = get(MulticastRouteService.class);
    Optional<McastRoute> route = getMcastRoute(group, srcIp);
    if (route.isPresent()) {
        ArrayNode jsonTree;
        try {
            jsonTree = (ArrayNode) mapper().readTree(stream).get(SINKS);
            Set<HostId> sinks = new HashSet<>();
            jsonTree.elements().forEachRemaining(sink -> {
                sinks.add(HostId.hostId(sink.asText()));
            });
            if (!sinks.isEmpty()) {
                sinks.forEach(sink -> {
                    service.addSink(route.get(), sink);
                });
            }
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }
        return Response.ok().build();
    }
    return Response.noContent().build();
}
Also used : MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) McastRoute(org.onosproject.mcast.api.McastRoute) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) HostId(org.onosproject.net.HostId) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 24 with HostId

use of org.onosproject.net.HostId in project onos by opennetworkinglab.

the class McastRouteWebResource method addSources.

/**
 * Adds sources for a given existing multicast route.
 *
 * @param group  group IP address
 * @param srcIp  source IP address
 * @param stream host sinks JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel McastSourcesAdd
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("sources/{group}/{srcIp}")
public Response addSources(@PathParam("group") String group, @PathParam("srcIp") String srcIp, InputStream stream) {
    MulticastRouteService service = get(MulticastRouteService.class);
    Optional<McastRoute> route = getMcastRoute(group, srcIp);
    if (route.isPresent()) {
        ArrayNode jsonTree;
        try {
            jsonTree = (ArrayNode) mapper().readTree(stream).get(SOURCES);
            Set<HostId> sources = new HashSet<>();
            jsonTree.elements().forEachRemaining(src -> {
                sources.add(HostId.hostId(src.asText()));
            });
            if (!sources.isEmpty()) {
                sources.forEach(src -> {
                    service.addSource(route.get(), src);
                });
            }
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        }
        return Response.ok().build();
    }
    return Response.noContent().build();
}
Also used : MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) McastRoute(org.onosproject.mcast.api.McastRoute) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) HostId(org.onosproject.net.HostId) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 25 with HostId

use of org.onosproject.net.HostId in project onos by opennetworkinglab.

the class McastRouteWebResource method createRoute.

/**
 * Create new multicast route.
 *
 * @param stream multicast route JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel McastRoute
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response createRoute(InputStream stream) {
    MulticastRouteService service = get(MulticastRouteService.class);
    try {
        ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
        McastRoute route = codec(McastRoute.class).decode(jsonTree, this);
        service.add(route);
        Set<HostId> sources = new HashSet<>();
        jsonTree.path(SOURCES).elements().forEachRemaining(src -> {
            sources.add(HostId.hostId(src.asText()));
        });
        Set<HostId> sinks = new HashSet<>();
        jsonTree.path(SINKS).elements().forEachRemaining(sink -> {
            sinks.add(HostId.hostId(sink.asText()));
        });
        if (!sources.isEmpty()) {
            sources.forEach(source -> {
                service.addSource(route, source);
            });
        }
        if (!sinks.isEmpty()) {
            sinks.forEach(sink -> {
                service.addSink(route, sink);
            });
        }
    } catch (IOException ex) {
        throw new IllegalArgumentException(ex);
    }
    return Response.created(URI.create("")).build();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MulticastRouteService(org.onosproject.mcast.api.MulticastRouteService) McastRoute(org.onosproject.mcast.api.McastRoute) IOException(java.io.IOException) HostId(org.onosproject.net.HostId) HashSet(java.util.HashSet) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Aggregations

HostId (org.onosproject.net.HostId)86 IpAddress (org.onlab.packet.IpAddress)27 DeviceId (org.onosproject.net.DeviceId)24 VlanId (org.onlab.packet.VlanId)23 HostLocation (org.onosproject.net.HostLocation)23 MacAddress (org.onlab.packet.MacAddress)21 Test (org.junit.Test)18 ConnectPoint (org.onosproject.net.ConnectPoint)17 Host (org.onosproject.net.Host)17 HostDescription (org.onosproject.net.host.HostDescription)16 DefaultHostDescription (org.onosproject.net.host.DefaultHostDescription)14 Set (java.util.Set)13 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)12 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)11 HashSet (java.util.HashSet)11 Logger (org.slf4j.Logger)11 ImmutableSet (com.google.common.collect.ImmutableSet)10 Device (org.onosproject.net.Device)10 Path (org.onosproject.net.Path)10 LoggerFactory (org.slf4j.LoggerFactory)10