use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class JuniperUtils method parseJuniperLldp.
/**
* Parses neighbours discovery information and returns a list of
* link abstractions.
*
* @param info interface configuration
* @return set of link abstractions
*/
public static Set<LinkAbstraction> parseJuniperLldp(HierarchicalConfiguration info) {
Set<LinkAbstraction> neighbour = new HashSet<>();
List<HierarchicalConfiguration> subtrees = info.configurationsAt(LLDP_LIST_NBR_INFO);
for (HierarchicalConfiguration neighborsInfo : subtrees) {
List<HierarchicalConfiguration> neighbors = neighborsInfo.configurationsAt(LLDP_NBR_INFO);
for (HierarchicalConfiguration neighbor : neighbors) {
String localPortName = neighbor.getString(LLDP_LO_PORT);
MacAddress mac = MacAddress.valueOf(neighbor.getString(LLDP_REM_CHASS));
String remotePortId = null;
long remotePortIndex = -1;
String remotePortIdSubtype = neighbor.getString(LLDP_REM_PORT_SUBTYPE, null);
if (remotePortIdSubtype != null) {
if (remotePortIdSubtype.equals(LLDP_SUBTYPE_MAC) || remotePortIdSubtype.equals(LLDP_SUBTYPE_INTERFACE_NAME)) {
remotePortId = neighbor.getString(LLDP_REM_PORT, null);
} else {
remotePortIndex = neighbor.getLong(LLDP_REM_PORT, -1);
}
}
String remotePortDescription = neighbor.getString(LLDP_REM_PORT_DES, null);
LinkAbstraction link = new LinkAbstraction(localPortName, mac.toLong(), remotePortIndex, remotePortId, remotePortDescription);
neighbour.add(link);
}
}
return neighbour;
}
use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class CastorArpManager method updateMac.
/**
* Updates the IP address to mac address map.
*
* @param context The message context.
*/
private void updateMac(MessageContext context) {
if ((castorStore.getAddressMap()).containsKey(context.sender())) {
return;
}
Ethernet eth = context.packet();
MacAddress macAddress = eth.getSourceMAC();
IpAddress ipAddress = context.sender();
castorStore.setAddressMap(ipAddress, macAddress);
}
use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class MdIdMacUint method asMdId.
public static MdId asMdId(String mdName) {
if (mdName == null || !mdName.matches(MACUINT_PATTERN)) {
throw new IllegalArgumentException("MD Name must follow pattern " + MACUINT_PATTERN + " Rejecting: " + mdName);
}
MacAddress macAddress = MacAddress.valueOf(mdName.substring(0, 17));
int uInt = Integer.parseInt(mdName.substring(18));
return asMdId(macAddress, uInt);
}
use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class MepLbCreateCodec method decode.
/**
* Decodes the MepLbCreate entity from JSON.
*
* @param json JSON to decode
* @param context decoding context
* @return decoded MepLbCreate
* @throws java.lang.UnsupportedOperationException if the codec does not
* support decode operations
*/
@Override
public MepLbCreate decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode loopbackNode = json.get(LOOPBACK);
JsonNode remoteMepIdNode = loopbackNode.get(REMOTE_MEP_ID);
JsonNode remoteMepMacNode = loopbackNode.get(REMOTE_MEP_MAC);
MepLbCreate.MepLbCreateBuilder lbCreateBuilder;
if (remoteMepIdNode != null) {
MepId remoteMepId = MepId.valueOf((short) remoteMepIdNode.asInt());
lbCreateBuilder = DefaultMepLbCreate.builder(remoteMepId);
} else if (remoteMepMacNode != null) {
MacAddress remoteMepMac = MacAddress.valueOf(remoteMepMacNode.asText());
lbCreateBuilder = DefaultMepLbCreate.builder(remoteMepMac);
} else {
throw new IllegalArgumentException("Either a remoteMepId or a remoteMepMac");
}
JsonNode numMessagesNode = loopbackNode.get(NUMBER_MESSAGES);
if (numMessagesNode != null) {
int numMessages = numMessagesNode.asInt();
lbCreateBuilder.numberMessages(numMessages);
}
JsonNode vlanDropEligibleNode = loopbackNode.get(VLAN_DROP_ELIGIBLE);
if (vlanDropEligibleNode != null) {
boolean vlanDropEligible = vlanDropEligibleNode.asBoolean();
lbCreateBuilder.vlanDropEligible(vlanDropEligible);
}
JsonNode vlanPriorityNode = loopbackNode.get(VLAN_PRIORITY);
if (vlanPriorityNode != null) {
short vlanPriority = (short) vlanPriorityNode.asInt();
lbCreateBuilder.vlanPriority(Priority.values()[vlanPriority]);
}
JsonNode dataTlvHexNode = loopbackNode.get(DATA_TLV_HEX);
if (dataTlvHexNode != null) {
String dataTlvHex = loopbackNode.get(DATA_TLV_HEX).asText();
if (!dataTlvHex.isEmpty()) {
lbCreateBuilder.dataTlv(HexString.fromHexString(dataTlvHex));
}
}
return lbCreateBuilder.build();
}
use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.
the class Dhcp6HandlerImpl method removeHostOrRoute.
/**
* remove host or route and update dhcp relay record attributes.
*
* @param directConnFlag flag to show that packet is from directly connected client
* @param location client side connect point
* @param dhcp6Packet the dhcp6 payload
* @param clientPacket client's ethernet packet
* @param clientIpv6 client's Ipv6 packet
* @param clientInterface client interfaces
*/
private void removeHostOrRoute(boolean directConnFlag, ConnectPoint location, DHCP6 dhcp6Packet, Ethernet clientPacket, IPv6 clientIpv6, Interface clientInterface) {
log.debug("removeHostOrRoute enters {}", dhcp6Packet);
VlanId vlanId = clientInterface.vlan();
// could be gw or host
MacAddress srcMac = clientPacket.getSourceMAC();
MacAddress leafClientMac;
byte leafMsgType;
log.debug("client mac {} client vlan {}", HexString.toHexString(srcMac.toBytes(), ":"), vlanId);
Dhcp6ClientIdOption clientIdOption = Dhcp6HandlerUtil.extractClientId(directConnFlag, dhcp6Packet);
if (clientIdOption != null) {
if ((clientIdOption.getDuid().getDuidType() == Dhcp6Duid.DuidType.DUID_LLT) || (clientIdOption.getDuid().getDuidType() == Dhcp6Duid.DuidType.DUID_LL)) {
leafClientMac = MacAddress.valueOf(clientIdOption.getDuid().getLinkLayerAddress());
} else {
log.warn("Link-Layer Address not supported in CLIENTID option. No DhcpRelay Record created.");
// dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_LINKLOCAL_FAIL);
return;
}
} else {
log.warn("CLIENTID option NOT found. Don't create DhcpRelay Record.");
// dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_CLIENTID_FAIL);
return;
}
HostId leafHostId = HostId.hostId(leafClientMac, vlanId);
DhcpRecord record = dhcpRelayStore.getDhcpRecord(leafHostId).orElse(null);
if (record == null) {
record = new DhcpRecord(leafHostId);
} else {
record = record.clone();
}
Boolean isMsgRelease = Dhcp6HandlerUtil.isDhcp6Release(dhcp6Packet);
IpAddressInfo ipInfo;
PdPrefixInfo pdInfo = null;
if (directConnFlag) {
// Add to host store if it is connected to network directly
ipInfo = extractIpAddress(dhcp6Packet);
if (ipInfo != null) {
if (isMsgRelease) {
HostId hostId = HostId.hostId(srcMac, vlanId);
log.debug("remove Host {} ip for directly connected.", hostId.toString());
providerService.removeIpFromHost(hostId, ipInfo.ip6Address);
}
} else {
log.debug("ipAddress not found. Do not remove Host {} for directly connected.", HostId.hostId(srcMac, vlanId).toString());
}
leafMsgType = dhcp6Packet.getMsgType();
} else {
// Remove from route store if it is not connected to network directly
// pick out the first link-local ip address
IpAddress nextHopIp = getFirstIpByHost(directConnFlag, srcMac, vlanId);
if (nextHopIp == null) {
log.warn("Can't find link-local IP address of gateway mac {} vlanId {}", srcMac, vlanId);
// dhcpRelayCountersStore.incrementCounter(gCount, DhcpRelayCounters.NO_LINKLOCAL_GW);
return;
}
DHCP6 leafDhcp = Dhcp6HandlerUtil.getDhcp6Leaf(dhcp6Packet);
ipInfo = extractIpAddress(leafDhcp);
if (ipInfo == null) {
log.debug("ip is null");
} else {
if (isMsgRelease) {
Route routeForIP = new Route(Route.Source.DHCP, ipInfo.ip6Address.toIpPrefix(), nextHopIp);
log.debug("removing route of 128 address for indirectly connected.");
log.debug("128 ip {}, nexthop {}", HexString.toHexString(ipInfo.ip6Address.toOctets(), ":"), HexString.toHexString(nextHopIp.toOctets(), ":"));
routeStore.removeRoute(routeForIP);
}
}
pdInfo = extractPrefix(leafDhcp);
if (pdInfo == null) {
log.debug("ipPrefix is null ");
} else {
if (isMsgRelease) {
Route routeForPrefix = new Route(Route.Source.DHCP, pdInfo.pdPrefix, nextHopIp);
log.debug("removing route of PD for indirectly connected.");
log.debug("pd ip {}, nexthop {}", HexString.toHexString(pdInfo.pdPrefix.address().toOctets(), ":"), HexString.toHexString(nextHopIp.toOctets(), ":"));
routeStore.removeRoute(routeForPrefix);
if (this.dhcpFpmEnabled) {
dhcpFpmPrefixStore.removeFpmRecord(pdInfo.pdPrefix);
}
}
}
leafMsgType = leafDhcp.getMsgType();
}
if (isMsgRelease) {
log.debug("DHCP6 RELEASE msg.");
if (record != null) {
if (ipInfo != null) {
log.debug("DhcpRelay Record ip6Address is set to null.");
record.ip6Address(null);
}
if (pdInfo != null) {
log.debug("DhcpRelay Record pdPrefix is set to null.");
}
if (!record.ip6Address().isPresent() && !record.pdPrefix().isPresent()) {
log.warn("IP6 address and IP6 PD both are null. Remove record.");
// do not remove a record. Let timer task handler it.
// dhcpRelayStore.removeDhcpRecord(HostId.hostId(leafClientMac, vlanId));
}
}
}
if (record != null) {
record.getV6Counters().incrementCounter(Dhcp6HandlerUtil.getMsgTypeStr(leafMsgType));
record.addLocation(new HostLocation(location, System.currentTimeMillis()));
record.ip6Status(DHCP6.MsgType.getType(leafMsgType));
record.setDirectlyConnected(directConnFlag);
if (!directConnFlag) {
// Update gateway mac address if the host is not directly connected
record.nextHop(srcMac);
}
record.updateLastSeen();
}
dhcpRelayStore.updateDhcpRecord(leafHostId, record);
/*
// TODO Use AtomicInteger for the counters
try {
recordSemaphore.acquire();
try {
dhcpRelayCountersStore.incrementCounter(gCount, Dhcp6HandlerUtil.getMsgTypeStr(leafMsgType));
} finally {
// calling release() after a successful acquire()
recordSemaphore.release();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
*/
}
Aggregations