use of org.onosproject.net.DefaultHost in project onos by opennetworkinglab.
the class HostServiceAdapter method getHost.
@Override
public Host getHost(HostId hostId) {
ProviderId providerId = ProviderId.NONE;
MacAddress mac = MacAddress.valueOf("fa:12:3e:56:ee:a2");
VlanId vlan = VlanId.NONE;
HostLocation location = HostLocation.NONE;
Set<IpAddress> ips = Sets.newHashSet();
Annotations annotations = null;
return new DefaultHost(providerId, hostId, mac, vlan, location, ips, annotations);
}
use of org.onosproject.net.DefaultHost in project onos by opennetworkinglab.
the class HostCodec method decode.
@Override
public Host decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
MacAddress mac = MacAddress.valueOf(nullIsIllegal(json.get(MAC), MAC + MISSING_MEMBER_MESSAGE).asText());
VlanId vlanId = VlanId.vlanId(nullIsIllegal(json.get(VLAN), VLAN + MISSING_MEMBER_MESSAGE).asText());
HostId id = HostId.hostId(mac, vlanId);
ArrayNode locationNodes = nullIsIllegal((ArrayNode) json.get(HOST_LOCATIONS), HOST_LOCATIONS + MISSING_MEMBER_MESSAGE);
Set<HostLocation> hostLocations = context.codec(HostLocation.class).decode(locationNodes, context).stream().collect(Collectors.toSet());
ArrayNode ipNodes = nullIsIllegal((ArrayNode) json.get(IP_ADDRESSES), IP_ADDRESSES + MISSING_MEMBER_MESSAGE);
Set<IpAddress> ips = new HashSet<>();
ipNodes.forEach(ipNode -> {
ips.add(IpAddress.valueOf(ipNode.asText()));
});
// check optional fields
JsonNode innerVlanIdNode = json.get(INNER_VLAN);
VlanId innerVlanId = (null == innerVlanIdNode) ? VlanId.NONE : VlanId.vlanId(innerVlanIdNode.asText());
JsonNode outerTpidNode = json.get(OUTER_TPID);
EthType outerTpid = (null == outerTpidNode) ? EthType.EtherType.UNKNOWN.ethType() : EthType.EtherType.lookup((short) (Integer.decode(outerTpidNode.asText()) & 0xFFFF)).ethType();
JsonNode configuredNode = json.get(IS_CONFIGURED);
boolean configured = (null == configuredNode) ? false : configuredNode.asBoolean();
JsonNode suspendedNode = json.get(IS_SUSPENDED);
boolean suspended = (null == suspendedNode) ? false : suspendedNode.asBoolean();
ArrayNode auxLocationNodes = (ArrayNode) json.get(AUX_LOCATIONS);
Set<HostLocation> auxHostLocations = (null == auxLocationNodes) ? null : context.codec(HostLocation.class).decode(auxLocationNodes, context).stream().collect(Collectors.toSet());
Annotations annotations = extractAnnotations(json, context);
return new DefaultHost(ProviderId.NONE, id, mac, vlanId, hostLocations, auxHostLocations, ips, innerVlanId, outerTpid, configured, suspended, annotations);
}
use of org.onosproject.net.DefaultHost in project onos by opennetworkinglab.
the class HostResourceTest method testSingleHostByIdFetch.
/**
* Tests fetch of one host by Id.
*/
@Test
public void testSingleHostByIdFetch() {
final ProviderId pid = new ProviderId("of", "foo");
final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01");
final Set<IpAddress> ips1 = ImmutableSet.of(IpAddress.valueOf("1111:1111:1111:1::"));
final Host host1 = new DefaultHost(pid, HostId.hostId(mac1), valueOf(1), vlanId((short) 1), new HostLocation(DeviceId.deviceId("1"), portNumber(11), 1), ips1);
hosts.add(host1);
expect(mockHostService.getHost(HostId.hostId("00:00:11:00:00:01/1"))).andReturn(host1).anyTimes();
replay(mockHostService);
WebTarget wt = target();
String response = wt.path("hosts/00:00:11:00:00:01%2F1").request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, matchesHost(host1));
}
use of org.onosproject.net.DefaultHost in project onos by opennetworkinglab.
the class HostResourceTest method testSingleHostByMacAndVlanFetch.
/**
* Tests fetch of one host by mac and vlan.
*/
@Test
public void testSingleHostByMacAndVlanFetch() {
final ProviderId pid = new ProviderId("of", "foo");
final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01");
final Set<IpAddress> ips1 = ImmutableSet.of(IpAddress.valueOf("1111:1111:1111:1::"));
final Host host1 = new DefaultHost(pid, HostId.hostId(mac1), valueOf(1), vlanId((short) 1), new HostLocation(DeviceId.deviceId("1"), portNumber(11), 1), ips1);
hosts.add(host1);
expect(mockHostService.getHost(HostId.hostId("00:00:11:00:00:01/1"))).andReturn(host1).anyTimes();
replay(mockHostService);
WebTarget wt = target();
String response = wt.path("hosts/00:00:11:00:00:01/1").request().get(String.class);
final JsonObject result = Json.parse(response).asObject();
assertThat(result, matchesHost(host1));
}
use of org.onosproject.net.DefaultHost in project onos by opennetworkinglab.
the class DefaultInstancePortTest method setUp.
/**
* Initial setup for this unit test.
*/
@Before
public void setUp() {
HostLocation location1 = new HostLocation(DEV_ID_1, PORT_NUM_1, TIME_1);
HostLocation location2 = new HostLocation(DEV_ID_2, PORT_NUM_2, TIME_2);
DefaultAnnotations.Builder annotations1 = DefaultAnnotations.builder().set(ANNOTATION_NETWORK_ID, NETWORK_ID_1).set(ANNOTATION_PORT_ID, PORT_ID_1).set(ANNOTATION_CREATE_TIME, String.valueOf(TIME_1));
DefaultAnnotations.Builder annotations2 = DefaultAnnotations.builder().set(ANNOTATION_NETWORK_ID, NETWORK_ID_2).set(ANNOTATION_PORT_ID, PORT_ID_2).set(ANNOTATION_CREATE_TIME, String.valueOf(TIME_2));
Host host1 = new DefaultHost(PROVIDER_ID, HOST_ID_1, MAC_ADDRESS_1, VLAN_ID, location1, ImmutableSet.of(IP_ADDRESS_1), annotations1.build());
Host host2 = new DefaultHost(PROVIDER_ID, HOST_ID_2, MAC_ADDRESS_2, VLAN_ID, location2, ImmutableSet.of(IP_ADDRESS_2), annotations2.build());
instancePort1 = DefaultInstancePort.from(host1, ACTIVE);
sameAsInstancePort1 = DefaultInstancePort.from(host1, ACTIVE);
instancePort2 = DefaultInstancePort.from(host2, ACTIVE);
}
Aggregations