本文整理汇总了Java中org.onosproject.net.HostLocation类的典型用法代码示例。如果您正苦于以下问题:Java HostLocation类的具体用法?Java HostLocation怎么用?Java HostLocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HostLocation类属于org.onosproject.net包,在下文中一共展示了HostLocation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSingleHostByMacAndVlanFetch
import org.onosproject.net.HostLocation; //导入依赖的package包/类
/**
* 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));
}
示例2: parseHost
import org.onosproject.net.HostLocation; //导入依赖的package包/类
/**
* Creates and adds new host based on given data and returns its host ID.
*
* @param node JsonNode containing host information
* @return host ID of new host created
*/
private HostId parseHost(JsonNode node) {
MacAddress mac = MacAddress.valueOf(node.get("mac").asText());
VlanId vlanId = VlanId.vlanId((short) node.get("vlan").asInt(VlanId.UNTAGGED));
JsonNode locationNode = node.get("location");
String deviceAndPort = locationNode.get("elementId").asText() + "/" +
locationNode.get("port").asText();
HostLocation hostLocation = new HostLocation(ConnectPoint.deviceConnectPoint(deviceAndPort), 0);
Iterator<JsonNode> ipStrings = node.get("ipAddresses").elements();
Set<IpAddress> ips = new HashSet<>();
while (ipStrings.hasNext()) {
ips.add(IpAddress.valueOf(ipStrings.next().asText()));
}
// try to remove elements from json node after reading them
SparseAnnotations annotations = annotations(removeElements(node, REMOVAL_KEYS));
// Update host inventory
HostId hostId = HostId.hostId(mac, vlanId);
DefaultHostDescription desc = new DefaultHostDescription(mac, vlanId, hostLocation, ips, annotations);
hostProviderService.hostDetected(hostId, desc, false);
return hostId;
}
示例3: testSingleHostByIdFetch
import org.onosproject.net.HostLocation; //导入依赖的package包/类
/**
* 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));
}
示例4: updateHost
import org.onosproject.net.HostLocation; //导入依赖的package包/类
private void updateHost(UiHost uiHost, Host h) {
UiLink existing = uiTopology.findLink(uiHost.edgeLinkId());
EdgeLink currentElink = synthesizeLink(h);
UiLinkId currentElinkId = uiLinkId(currentElink);
if (existing != null) {
if (!currentElinkId.equals(existing.id())) {
// edge link has changed
insertNewUiLink(currentElinkId, currentElink);
uiHost.setEdgeLinkId(currentElinkId);
uiTopology.remove(existing);
}
} else {
// no previously existing edge link
insertNewUiLink(currentElinkId, currentElink);
uiHost.setEdgeLinkId(currentElinkId);
}
HostLocation hloc = h.location();
uiHost.setLocation(hloc.deviceId(), hloc.port());
}
示例5: createHost
import org.onosproject.net.HostLocation; //导入依赖的package包/类
/**
* Creates a default host connected at the given edge device and port. Note
* that an identifying hex character ("a" - "f") should be supplied. This
* will be included in the MAC address of the host (and equivalent value
* as last byte in IP address).
*
* @param device edge device
* @param port port number
* @param hexChar identifying hex character
* @return host connected at that location
*/
protected static Host createHost(Device device, int port, String hexChar) {
DeviceId deviceId = device.id();
String devNum = deviceId.toString().substring(1);
MacAddress mac = MacAddress.valueOf(HOST_MAC_PREFIX + devNum + hexChar);
HostId hostId = hostId(String.format("%s/-1", mac));
int ipByte = Integer.valueOf(hexChar, 16);
if (ipByte < 10 || ipByte > 15) {
throw new IllegalArgumentException("hexChar must be a-f");
}
HostLocation loc = new HostLocation(deviceId, portNumber(port), 0);
IpAddress ip = ip("10." + devNum + ".0." + ipByte);
return new DefaultHost(ProviderId.NONE, hostId, mac, VlanId.NONE,
loc, ImmutableSet.of(ip));
}
示例6: discoverHost
import org.onosproject.net.HostLocation; //导入依赖的package包/类
/**
* Integrates hosts learned through DHCP into topology.
* @param context context of the incoming message
* @param ipAssigned IP Address assigned to the host by DHCP Manager
*/
private void discoverHost(PacketContext context, Ip4Address ipAssigned) {
if (!allowHostDiscovery) {
// host discovery is not allowed, do nothing
return;
}
Ethernet packet = context.inPacket().parsed();
MacAddress mac = packet.getSourceMAC();
VlanId vlanId = VlanId.vlanId(packet.getVlanID());
HostLocation hostLocation = new HostLocation(context.inPacket().receivedFrom(), 0);
Set<IpAddress> ips = new HashSet<>();
ips.add(ipAssigned);
HostId hostId = HostId.hostId(mac, vlanId);
DefaultHostDescription desc = new DefaultHostDescription(mac, vlanId, hostLocation, ips);
log.info("Discovered host {}", desc);
hostProviderService.hostDetected(hostId, desc, false);
}
示例7: createHost
import org.onosproject.net.HostLocation; //导入依赖的package包/类
private Host createHost() {
MacAddress mac = MacAddress.valueOf("00:00:11:00:00:01");
VlanId vlan = VlanId.vlanId((short) 10);
HostLocation loc = new HostLocation(
DeviceId.deviceId("of:foo"),
PortNumber.portNumber(100),
123L
);
Set<IpAddress> ipset = Sets.newHashSet(
IpAddress.valueOf("10.0.0.1"),
IpAddress.valueOf("10.0.0.2")
);
HostId hid = HostId.hostId(mac, vlan);
return new DefaultHost(
new ProviderId("of", "foo"), hid, mac, vlan, loc, ipset);
}
示例8: encode
import org.onosproject.net.HostLocation; //导入依赖的package包/类
@Override
public ObjectNode encode(Host host, CodecContext context) {
checkNotNull(host, "Host cannot be null");
final JsonCodec<HostLocation> locationCodec =
context.codec(HostLocation.class);
final ObjectNode result = context.mapper().createObjectNode()
.put("id", host.id().toString())
.put("mac", host.mac().toString())
.put("vlan", host.vlan().toString());
final ArrayNode jsonIpAddresses = result.putArray("ipAddresses");
for (final IpAddress ipAddress : host.ipAddresses()) {
jsonIpAddresses.add(ipAddress.toString());
}
result.set("ipAddresses", jsonIpAddresses);
result.set("location", locationCodec.encode(host.location(), context));
return annotate(result, host, context);
}
示例9: testRemoveIp
import org.onosproject.net.HostLocation; //导入依赖的package包/类
/**
* Tests the removeIp method call.
*/
@Test
public void testRemoveIp() {
Set<IpAddress> ips = new HashSet<>();
ips.add(IP1);
ips.add(IP2);
HostDescription description = new DefaultHostDescription(HOSTID.mac(),
HOSTID.vlanId(),
HostLocation.NONE,
ips);
ecXHostStore.createOrUpdateHost(PID, HOSTID, description, false);
ecXHostStore.removeIp(HOSTID, IP1);
Host host = ecXHostStore.getHost(HOSTID);
assertFalse(host.ipAddresses().contains(IP1));
assertTrue(host.ipAddresses().contains(IP2));
}
示例10: addAccessAgentInstance
import org.onosproject.net.HostLocation; //导入依赖的package包/类
private void addAccessAgentInstance(ConnectPoint connectPoint) {
AccessAgentData agent = cordConfig.getAccessAgent(connectPoint.deviceId()).get();
DefaultAnnotations.Builder annotations = DefaultAnnotations.builder()
.set(Instance.NETWORK_TYPE, ACCESS_AGENT.name())
.set(Instance.NETWORK_ID, NOT_APPLICABLE)
.set(Instance.PORT_ID, NOT_APPLICABLE)
.set(Instance.CREATE_TIME, String.valueOf(System.currentTimeMillis()));
HostDescription hostDesc = new DefaultHostDescription(
agent.getAgentMac(),
VlanId.NONE,
new HostLocation(connectPoint, System.currentTimeMillis()),
Sets.newHashSet(),
annotations.build());
HostId hostId = HostId.hostId(agent.getAgentMac());
hostProvider.hostDetected(hostId, hostDesc, false);
}
示例11: parseHost
import org.onosproject.net.HostLocation; //导入依赖的package包/类
private void parseHost(HostProviderService hps, JsonNode node) {
MacAddress mac = MacAddress.valueOf(get(node, "mac"));
VlanId vlanId = VlanId.vlanId(node.get("vlan").shortValue());
HostId hostId = HostId.hostId(mac, vlanId);
SparseAnnotations annotations = annotations(node.get("annotations"));
HostLocation location = new HostLocation(connectPoint(get(node, "location")), 0);
String[] ipStrings = get(node, "ip").split(",");
Set<IpAddress> ips = new HashSet<>();
for (String ip : ipStrings) {
ips.add(IpAddress.valueOf(ip.trim()));
}
DefaultHostDescription desc =
new DefaultHostDescription(mac, vlanId, location, ips, annotations);
hps.hostDetected(hostId, desc);
}
示例12: testSingleHostByIdFetch
import org.onosproject.net.HostLocation; //导入依赖的package包/类
/**
* 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);
WebResource rs = resource();
String response = rs.path("hosts/00:00:11:00:00:01%2F1").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
assertThat(result, matchesHost(host1));
}
示例13: testSingleHostByMacAndVlanFetch
import org.onosproject.net.HostLocation; //导入依赖的package包/类
/**
* 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);
WebResource rs = resource();
String response = rs.path("hosts/00:00:11:00:00:01/1").get(String.class);
final JsonObject result = JsonObject.readFrom(response);
assertThat(result, matchesHost(host1));
}
示例14: updateHost
import org.onosproject.net.HostLocation; //导入依赖的package包/类
private void updateHost(UiHost uiHost, Host h) {
UiEdgeLink existing = uiTopology.findEdgeLink(uiHost.edgeLinkId());
// TODO: review - do we need EdgeLink now that we are creating from id only?
EdgeLink currentElink = synthesizeLink(h);
UiLinkId currentElinkId = uiLinkId(currentElink);
if (existing != null) {
if (!currentElinkId.equals(existing.id())) {
// edge link has changed
insertNewUiEdgeLink(currentElinkId);
uiHost.setEdgeLinkId(currentElinkId);
uiTopology.remove(existing);
}
} else {
// no previously existing edge link
insertNewUiEdgeLink(currentElinkId);
uiHost.setEdgeLinkId(currentElinkId);
}
HostLocation hloc = h.location();
uiHost.setLocation(hloc.deviceId(), hloc.port());
}
示例15: populateHosts
import org.onosproject.net.HostLocation; //导入依赖的package包/类
private static void populateHosts() {
ip1 = IpAddress.valueOf("10.1.1.1");
IpAddress ip2 = IpAddress.valueOf("10.1.1.2");
IpAddress ip3 = IpAddress.valueOf("10.1.1.3");
mac1 = MacAddress.valueOf("67:11:23:45:87:11");
MacAddress mac2 = MacAddress.valueOf("67:11:23:45:87:12");
MacAddress mac3 = MacAddress.valueOf("67:11:23:45:87:13");
id1 = HostId.hostId(mac1);
HostId id2 = HostId.hostId(mac2);
HostId id3 = HostId.hostId(mac3);
deviceId = DeviceId.deviceId("test");
c1 = new ConnectPoint(deviceId, PortNumber.portNumber(101));
HostLocation hostLocation1 = new HostLocation(deviceId, PortNumber.portNumber(101), 0);
HostLocation hostLocation2 = new HostLocation(deviceId, PortNumber.portNumber(102), 0);
HostLocation hostLocation3 = new HostLocation(deviceId, PortNumber.portNumber(103), 0);
h1 = new DefaultHost(ProviderId.NONE, id1, mac1, VlanId.NONE,
hostLocation1, ImmutableSet.of(ip1));
allHosts.add(h1);
allHosts.add(new DefaultHost(ProviderId.NONE, id2, mac2, VlanId.NONE,
hostLocation2, ImmutableSet.of(ip2)));
allHosts.add(new DefaultHost(ProviderId.NONE, id3, mac3, VlanId.NONE,
hostLocation3, ImmutableSet.of(ip3)));
}