本文整理汇总了Java中org.onlab.packet.MacAddress类的典型用法代码示例。如果您正苦于以下问题:Java MacAddress类的具体用法?Java MacAddress怎么用?Java MacAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MacAddress类属于org.onlab.packet包,在下文中一共展示了MacAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSingleHostByMacAndVlanFetch
import org.onlab.packet.MacAddress; //导入依赖的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: testSingleHostByIdFetch
import org.onlab.packet.MacAddress; //导入依赖的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));
}
示例3: createHost
import org.onlab.packet.MacAddress; //导入依赖的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));
}
示例4: createVbng
import org.onlab.packet.MacAddress; //导入依赖的package包/类
/**
* Creates a new vBNG.
*
* @param privateIpAddress a private IP address
* @param publicIpAddress the public IP address for the private IP address
* @param hostMacAddress the MAC address for the private IP address
* @param hostName the host name for the private IP address
*/
private void createVbng(IpAddress privateIpAddress,
IpAddress publicIpAddress,
MacAddress hostMacAddress,
String hostName) {
boolean result = vbngConfigurationService
.assignSpecifiedPublicIp(publicIpAddress, privateIpAddress);
if (!result) {
log.info("Assign public IP address {} for private IP address {} "
+ "failed!", publicIpAddress, privateIpAddress);
log.info("Failed to create vBNG for private IP address {}",
privateIpAddress);
return;
}
log.info("[ADD] Private IP to Public IP mapping: {} --> {}",
privateIpAddress, publicIpAddress);
// Setup paths between the host configured with private IP and
// next hop
if (!setupForwardingPaths(privateIpAddress, publicIpAddress,
hostMacAddress, hostName)) {
privateIpAddressMap.put(privateIpAddress,
new VcpeHost(hostMacAddress, hostName));
}
}
示例5: createPeerGroup
import org.onlab.packet.MacAddress; //导入依赖的package包/类
private int createPeerGroup(MacAddress srcMac, MacAddress dstMac,
VlanId vlanId, DeviceId deviceId, PortNumber port) {
int nextId = flowObjectiveService.allocateNextId();
NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder()
.withId(nextId)
.withType(NextObjective.Type.SIMPLE)
.fromApp(appId);
TrafficTreatment.Builder ttBuilder = DefaultTrafficTreatment.builder();
ttBuilder.setEthSrc(srcMac);
ttBuilder.setEthDst(dstMac);
ttBuilder.setOutput(port);
nextObjBuilder.addTreatment(ttBuilder.build());
TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder();
VlanId matchVlanId = (vlanId.equals(VlanId.NONE)) ?
VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN) :
vlanId;
metabuilder.matchVlanId(matchVlanId);
nextObjBuilder.withMeta(metabuilder.build());
flowObjectiveService.next(deviceId, nextObjBuilder.add());
return nextId;
}
示例6: processAppConfigUpdated
import org.onlab.packet.MacAddress; //导入依赖的package包/类
/**
* Processes Segment Routing App Config updated event.
*
* @param event network config updated event
*/
protected void processAppConfigUpdated(NetworkConfigEvent event) {
log.info("Processing vRouter CONFIG_UPDATED");
SegmentRoutingAppConfig config = (SegmentRoutingAppConfig) event.config().get();
SegmentRoutingAppConfig prevConfig = (SegmentRoutingAppConfig) event.prevConfig().get();
deviceService.getAvailableDevices().forEach(device -> {
Set<MacAddress> macAddresses = new HashSet<>(getMacAddresses(config));
Set<MacAddress> prevMacAddresses = new HashSet<>(getMacAddresses(prevConfig));
// Avoid removing and re-adding unchanged MAC addresses since
// FlowObjective does not guarantee the execution order.
Set<MacAddress> sameMacAddresses = new HashSet<>(macAddresses);
sameMacAddresses.retainAll(prevMacAddresses);
macAddresses.removeAll(sameMacAddresses);
prevMacAddresses.removeAll(sameMacAddresses);
revokeVRouter(device.id(), prevMacAddresses);
populateVRouter(device.id(), macAddresses);
});
}
示例7: getMacFromOpenstack
import org.onlab.packet.MacAddress; //导入依赖的package包/类
/**
* Returns MAC address of a host with a given target IP address by asking to
* OpenStack. It does not support overlapping IP.
*
* @param targetIp target ip address
* @return mac address, or null if it fails to fetch the mac
*/
private MacAddress getMacFromOpenstack(IpAddress targetIp) {
checkNotNull(targetIp);
OpenstackPort openstackPort = openstackService.ports()
.stream()
.filter(port -> port.fixedIps().containsValue(targetIp))
.findFirst()
.orElse(null);
if (openstackPort != null) {
log.debug("Found MAC from OpenStack for {}", targetIp.toString());
return openstackPort.macAddress();
} else {
return null;
}
}
示例8: buildArpRequest
import org.onlab.packet.MacAddress; //导入依赖的package包/类
private Ethernet buildArpRequest(IpAddress targetIp, IpAddress sourceIp,
MacAddress sourceMac) {
ARP arp = new ARP();
arp.setHardwareType(ARP.HW_TYPE_ETHERNET)
.setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH)
.setProtocolType(ARP.PROTO_TYPE_IP)
.setProtocolAddressLength((byte) Ip4Address.BYTE_LENGTH)
.setOpCode(ARP.OP_REQUEST);
arp.setSenderHardwareAddress(sourceMac.toBytes())
.setSenderProtocolAddress(sourceIp.getIp4Address().toInt())
.setTargetHardwareAddress(ZERO_MAC_ADDRESS)
.setTargetProtocolAddress(targetIp.getIp4Address().toInt());
Ethernet ethernet = new Ethernet();
ethernet.setEtherType(Ethernet.TYPE_ARP)
.setDestinationMACAddress(MacAddress.BROADCAST)
.setSourceMACAddress(sourceMac)
.setPayload(arp);
ethernet.setPad(true);
return ethernet;
}
示例9: populateFloatingIpOutgoingRules
import org.onlab.packet.MacAddress; //导入依赖的package包/类
private void populateFloatingIpOutgoingRules(OpenstackFloatingIP floatingIP, OpenstackPort port) {
Port outputPort = checkNotNull(getPortOfExternalInterface(), PORTNOTNULL);
TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
sBuilder.matchEthType(Ethernet.TYPE_IPV4)
.matchTunnelId(getVni(port.networkId()))
.matchIPSrc(IpPrefix.valueOf(floatingIP.fixedIpAddress(), 32));
tBuilder.setIpSrc(floatingIP.floatingIpAddress())
.setEthSrc(MacAddress.valueOf(config.gatewayExternalInterfaceMac()))
.setEthDst(MacAddress.valueOf(config.physicalRouterMac()))
.setOutput(outputPort.number());
ForwardingObjective fo = DefaultForwardingObjective.builder()
.withSelector(sBuilder.build())
.withTreatment(tBuilder.build())
.withFlag(ForwardingObjective.Flag.VERSATILE)
.withPriority(FLOATING_RULE_PRIORITY)
.fromApp(appId)
.add();
flowObjectiveService.forward(getGatewayNode().id(), fo);
}
示例10: setUp
import org.onlab.packet.MacAddress; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
super.setUp();
Host hostOne = createMock(Host.class);
expect(hostOne.mac()).andReturn(new MacAddress(HOST_ONE_MAC.getBytes())).anyTimes();
expect(hostOne.vlan()).andReturn(VlanId.vlanId()).anyTimes();
replay(hostOne);
Host hostTwo = createMock(Host.class);
expect(hostTwo.mac()).andReturn(new MacAddress(HOST_TWO_MAC.getBytes())).anyTimes();
expect(hostTwo.vlan()).andReturn(VlanId.vlanId()).anyTimes();
replay(hostTwo);
mockHostService = createMock(HostService.class);
expect(mockHostService.getHost(eq(hostOneId))).andReturn(hostOne).anyTimes();
expect(mockHostService.getHost(eq(hostTwoId))).andReturn(hostTwo).anyTimes();
replay(mockHostService);
}
示例11: testTrafficTreatmentEncode
import org.onlab.packet.MacAddress; //导入依赖的package包/类
/**
* Tests encoding of a traffic treatment object.
*/
@Test
public void testTrafficTreatmentEncode() {
Instruction output = Instructions.createOutput(PortNumber.portNumber(0));
Instruction modL2Src = Instructions.modL2Src(MacAddress.valueOf("11:22:33:44:55:66"));
Instruction modL2Dst = Instructions.modL2Dst(MacAddress.valueOf("44:55:66:77:88:99"));
MeterId meterId = MeterId.meterId(0);
Instruction meter = Instructions.meterTraffic(meterId);
Instruction transition = Instructions.transition(1);
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
TrafficTreatment treatment = tBuilder
.add(output)
.add(modL2Src)
.add(modL2Dst)
.add(meter)
.add(transition)
.build();
ObjectNode treatmentJson = trafficTreatmentCodec.encode(treatment, context);
assertThat(treatmentJson, TrafficTreatmentJsonMatcher.matchesTrafficTreatment(treatment));
}
示例12: inPacket
import org.onlab.packet.MacAddress; //导入依赖的package包/类
@Override
public InboundPacket inPacket() {
RouterAdvertisement ns = new RouterAdvertisement();
ICMP6 icmp6 = new ICMP6();
icmp6.setPayload(ns);
IPv6 ipv6 = new IPv6();
ipv6.setPayload(icmp6);
ipv6.setDestinationAddress(Ip6Address.valueOf("ff02::1").toOctets());
ipv6.setSourceAddress(IP2);
Ethernet eth = new Ethernet();
eth.setEtherType(Ethernet.TYPE_IPV6)
.setVlanID(VLAN.toShort())
.setSourceMACAddress(MAC2.toBytes())
.setDestinationMACAddress(MacAddress.valueOf("33:33:00:00:00:01"))
.setPayload(ipv6);
ConnectPoint receivedFrom = new ConnectPoint(deviceId(deviceId),
portNumber(INPORT));
return new DefaultInboundPacket(receivedFrom, eth,
ByteBuffer.wrap(eth.serialize()));
}
示例13: removeStaticIP
import org.onlab.packet.MacAddress; //导入依赖的package包/类
@Override
public boolean removeStaticIP(MacAddress macID) {
HostId host = HostId.hostId(macID);
if (allocationMap.containsKey(host)) {
IpAssignment assignment = allocationMap.get(host).value();
if (assignment.assignmentStatus().equals(Option_RangeNotEnforced)) {
allocationMap.remove(host);
return true;
}
Ip4Address freeIP = assignment.ipAddress();
if (assignment.leasePeriod() < 0) {
allocationMap.remove(host);
if (ipWithinRange(freeIP)) {
freeIPPool.add(freeIP);
}
return true;
}
}
return false;
}
示例14: revokeIpRuleForHost
import org.onlab.packet.MacAddress; //导入依赖的package包/类
/**
* Removes IP rules for host when the host is gone.
*
* @param deviceId device ID of the device that host attaches to
* @param hostIp IP address of the host
* @param hostMac MAC address of the host
* @param outPort port that host attaches to
*/
public void revokeIpRuleForHost(DeviceId deviceId, Ip4Address hostIp,
MacAddress hostMac, PortNumber outPort) {
log.debug("Revoke IP table entry for host {} at {}:{}",
hostIp, deviceId, outPort);
ForwardingObjective.Builder fwdBuilder;
try {
fwdBuilder = getForwardingObjectiveBuilder(
deviceId, hostIp, hostMac, outPort);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting revokeIpRuleForHost.");
return;
}
ObjectiveContext context = new DefaultObjectiveContext(
(objective) -> log.debug("IP rule for host {} revoked", hostIp),
(objective, error) ->
log.warn("Failed to revoke IP rule for host {}: {}", hostIp, error));
srManager.flowObjectiveService.forward(deviceId, fwdBuilder.remove(context));
}
示例15: populateIpRuleForHost
import org.onlab.packet.MacAddress; //导入依赖的package包/类
/**
* Populates IP flow rules for specific hosts directly connected to the
* switch.
*
* @param deviceId switch ID to set the rules
* @param hostIp host IP address
* @param hostMac host MAC address
* @param outPort port where the host is connected
*/
public void populateIpRuleForHost(DeviceId deviceId, Ip4Address hostIp,
MacAddress hostMac, PortNumber outPort) {
log.debug("Populate IP table entry for host {} at {}:{}",
hostIp, deviceId, outPort);
ForwardingObjective.Builder fwdBuilder;
try {
fwdBuilder = getForwardingObjectiveBuilder(
deviceId, hostIp, hostMac, outPort);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting populateIpRuleForHost.");
return;
}
if (fwdBuilder == null) {
log.warn("Aborting host routing table entries due "
+ "to error for dev:{} host:{}", deviceId, hostIp);
return;
}
ObjectiveContext context = new DefaultObjectiveContext(
(objective) -> log.debug("IP rule for host {} populated", hostIp),
(objective, error) ->
log.warn("Failed to populate IP rule for host {}: {}", hostIp, error));
srManager.flowObjectiveService.forward(deviceId, fwdBuilder.add(context));
rulePopulationCounter.incrementAndGet();
}