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));
}
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())));
}
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();
}
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();
}
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();
}
Aggregations