use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class ReactiveForwardingCommand method doExecute.
@Override
protected void doExecute() {
ReactiveForwarding reactiveForwardingService = AbstractShellCommand.get(ReactiveForwarding.class);
MacAddress macAddress = null;
if (mac != null) {
macAddress = MacAddress.valueOf(mac);
}
reactiveForwardingService.printMetric(macAddress);
}
use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class MacAddressCompleter method complete.
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
StringsCompleter delegate = new StringsCompleter();
OpenstackNetworkService osNetService = get(OpenstackNetworkService.class);
Set<MacAddress> set = osNetService.externalPeerRouters().stream().map(ExternalPeerRouter::macAddress).collect(Collectors.toSet());
SortedSet<String> strings = delegate.getStrings();
Iterator<MacAddress> it = set.iterator();
while (it.hasNext()) {
strings.add(it.next().toString());
}
return delegate.complete(session, commandLine, candidates);
}
use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class K8sIpAddressListCommand method doExecute.
@Override
protected void doExecute() {
K8sIpamService ipamService = get(K8sIpamService.class);
K8sNetworkService networkService = get(K8sNetworkService.class);
if (networkIds == null || networkIds.length == 0) {
networkIds = networkService.networks().stream().map(K8sNetwork::networkId).toArray(String[]::new);
}
Map<String, Map<IpAddress, MacAddress>> ipMacs = Maps.newConcurrentMap();
if (available && reserved) {
error("Only one of list options (available | reserved) can be specified.");
return;
}
if (!(available || reserved)) {
error("At least one of list options (available | reserved) should be specified.");
return;
}
for (String networkId : networkIds) {
Map<IpAddress, MacAddress> tmpIpMacs = Maps.newConcurrentMap();
if (available) {
ipamService.availableIps(networkId).forEach(n -> tmpIpMacs.put(n, ZERO));
}
if (reserved) {
Set<K8sPort> ports = networkService.ports(networkId);
ipamService.allocatedIps(networkId).forEach(ip -> {
MacAddress mac = ports.stream().filter(p -> p.ipAddress().equals(ip)).map(K8sPort::macAddress).findAny().orElse(ZERO);
tmpIpMacs.put(ip, mac);
});
}
ipMacs.put(networkId, tmpIpMacs);
}
if (ipMacs.size() > 0) {
print(FORMAT, "Network ID", "IP Address", "MAC Address");
ipMacs.forEach((k, v) -> v.forEach((ip, mac) -> print(FORMAT, k, ip, mac)));
} else {
print("No IP addresses are available or reserved.");
}
}
use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class PimInterface method processHello.
/**
* Process an incoming PIM Hello message. There are a few things going on in
* this method:
* <ul>
* <li>We <em>may</em> have to create a new neighbor if one does not already exist</li>
* <li>We <em>may</em> need to re-elect a new DR if new information is received</li>
* <li>We <em>may</em> need to send an existing neighbor all joins if the genid changed</li>
* <li>We will refresh the neighbor's timestamp</li>
* </ul>
*
* @param ethPkt the Ethernet packet header
*/
public void processHello(Ethernet ethPkt) {
if (log.isTraceEnabled()) {
log.trace("Received a PIM hello packet");
}
// We'll need to save our neighbors MAC address
MacAddress nbrmac = ethPkt.getSourceMAC();
// And we'll need to save neighbors IP Address.
IPv4 iphdr = (IPv4) ethPkt.getPayload();
IpAddress srcip = IpAddress.valueOf(iphdr.getSourceAddress());
PIM pimhdr = (PIM) iphdr.getPayload();
if (pimhdr.getPimMsgType() != PIM.TYPE_HELLO) {
log.error("process Hello has received a non hello packet type: " + pimhdr.getPimMsgType());
return;
}
// get the DR values for later calculation
PimNeighbor dr = pimNeighbors.get(drIpaddress);
checkNotNull(dr);
IpAddress drip = drIpaddress;
int drpri = dr.priority();
// Assume we do not need to run a DR election
boolean reElectDr = false;
boolean genidChanged = false;
PIMHello hello = (PIMHello) pimhdr.getPayload();
// Determine if we already have a PIMNeighbor
PimNeighbor nbr = pimNeighbors.getOrDefault(srcip, null);
PimNeighbor newNbr = PimNeighbor.createPimNeighbor(srcip, nbrmac, hello.getOptions().values());
if (nbr == null) {
pimNeighbors.putIfAbsent(srcip, newNbr);
nbr = newNbr;
} else if (!nbr.equals(newNbr)) {
if (newNbr.holdtime() == 0) {
// Neighbor has shut down. Remove them and clean up
pimNeighbors.remove(srcip, nbr);
return;
} else {
// Neighbor has changed one of their options.
pimNeighbors.put(srcip, newNbr);
nbr = newNbr;
}
}
// Refresh this neighbor's timestamp
nbr.refreshTimestamp();
/*
* the election method will first determine if an election
* needs to be run, if so it will run the election. The
* IP address of the DR will be returned. If the IP address
* of the DR is different from what we already have we know a
* new DR has been elected.
*/
IpAddress electedIp = election(nbr, drip, drpri);
if (!drip.equals(electedIp)) {
// we have a new DR.
drIpaddress = electedIp;
}
}
use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class HostToHostIntentCompilerTest method setUp.
@Override
@Before
public void setUp() {
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);
}
Aggregations