use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class FibInstaller method updateMcastFilteringObjective.
/**
* Installs or removes multicast filtering objectives relating to an interface.
*
* @param routerIntf interface to update objectives for
* @param install true to install the objectives, false to remove them
*/
private void updateMcastFilteringObjective(InterfaceProvisionRequest routerIntf, boolean install) {
Interface intf = routerIntf.intf();
VlanId assignedVlan = (egressVlan().equals(VlanId.NONE)) ? VlanId.vlanId(ASSIGNED_VLAN) : egressVlan();
FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
// first add filter for the interface
fob.withKey(Criteria.matchInPort(intf.connectPoint().port())).addCondition(Criteria.matchEthDstMasked(MacAddress.IPV4_MULTICAST, MacAddress.IPV4_MULTICAST_MASK)).addCondition(Criteria.matchVlanId(ingressVlan()));
fob.withPriority(PRIORITY_OFFSET);
TrafficTreatment tt = DefaultTrafficTreatment.builder().pushVlan().setVlanId(assignedVlan).build();
fob.withMeta(tt);
fob.permit().fromApp(fibAppId);
sendFilteringObjective(install, fob, intf);
}
use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class FibInstaller method updateFilteringObjective.
/**
* Installs or removes unicast filtering objectives relating to an interface.
*
* @param routerIntf interface to update objectives for
* @param install true to install the objectives, false to remove them
*/
private void updateFilteringObjective(InterfaceProvisionRequest routerIntf, boolean install) {
Interface intf = routerIntf.intf();
VlanId assignedVlan = (egressVlan().equals(VlanId.NONE)) ? VlanId.vlanId(ASSIGNED_VLAN) : egressVlan();
FilteringObjective.Builder fob = DefaultFilteringObjective.builder();
// first add filter for the interface
fob.withKey(Criteria.matchInPort(intf.connectPoint().port())).addCondition(Criteria.matchEthDst(intf.mac())).addCondition(Criteria.matchVlanId(intf.vlan()));
fob.withPriority(PRIORITY_OFFSET);
if (intf.vlan() == VlanId.NONE) {
TrafficTreatment tt = DefaultTrafficTreatment.builder().pushVlan().setVlanId(assignedVlan).build();
fob.withMeta(tt);
}
fob.permit().fromApp(fibAppId);
sendFilteringObjective(install, fob, intf);
// then add the same mac/vlan filters for control-plane connect point
fob.withKey(Criteria.matchInPort(routerIntf.controlPlaneConnectPoint().port()));
sendFilteringObjective(install, fob, intf);
}
use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class ComponentCodec method decode.
/**
* Decodes the Component entity from JSON.
*
* @param json JSON to decode
* @param context decoding context
* @return decoded Component
* @throws java.lang.UnsupportedOperationException if the codec does not
* support decode operations
*/
@Override
public Component decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
JsonNode componentNode = json.get(COMPONENT);
int componentId = nullIsIllegal(componentNode.get(COMPONENT_ID), "component-id is required").asInt();
Component.ComponentBuilder componentBuilder = DefaultComponent.builder(componentId);
List<VlanId> vidList = (new VidCodec()).decode((ArrayNode) nullIsIllegal(componentNode.get(VID_LIST), "vid-list is required"), context);
if (vidList == null || vidList.isEmpty()) {
throw new IllegalArgumentException("A least one VID is required in component: " + componentId);
}
for (VlanId vid : vidList) {
componentBuilder = componentBuilder.addToVidList(vid);
}
if (componentNode.get(TAG_TYPE) != null) {
componentBuilder = componentBuilder.tagType(Component.TagType.valueOf(componentNode.get(TAG_TYPE).asText()));
}
if (componentNode.get(MHF_CREATION_TYPE) != null) {
componentBuilder = componentBuilder.mhfCreationType(Component.MhfCreationType.valueOf(componentNode.get(MHF_CREATION_TYPE).asText()));
}
if (componentNode.get(ID_PERMISSION) != null) {
componentBuilder = componentBuilder.idPermission(Component.IdPermissionType.valueOf(componentNode.get(ID_PERMISSION).asText()));
}
return componentBuilder.build();
}
use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class Dhcp4HandlerImpl method processLeaseQueryFromServer.
/**
* Build the DHCP offer/ack with proper client port.
*
* @param ethernetPacket the original packet comes from server
* @return new packet which will send to the client
*/
private InternalPacket processLeaseQueryFromServer(Ethernet ethernetPacket) {
// get dhcp header.
Ethernet etherReply = (Ethernet) ethernetPacket.clone();
IPv4 ipv4Packet = (IPv4) etherReply.getPayload();
UDP udpPacket = (UDP) ipv4Packet.getPayload();
DHCP dhcpPayload = (DHCP) udpPacket.getPayload();
// determine the vlanId of the client host - note that this vlan id
// could be different from the vlan in the packet from the server
Interface clientInterface = null;
MacAddress destinationMac = MacAddress.valueOf(dhcpPayload.getClientHardwareAddress());
if (!learnRouteFromLeasequery) {
int giaddr = ipv4Packet.getDestinationAddress();
IpAddress destinationAddress = Ip4Address.valueOf(giaddr);
log.debug("DHCPLEASEQUERYRESP giaddr: {}({})", giaddr, destinationAddress);
Host destinationHost = hostService.getHostsByIp(destinationAddress).stream().findFirst().orElse(null);
if (destinationHost != null) {
destinationMac = destinationHost.mac();
log.trace("DHCPLEASEQUERYRESP destination mac is: {}", destinationMac);
ConnectPoint destinationLocation = destinationHost.location();
log.trace("Lookup for client interface by destination location {}", destinationLocation);
clientInterface = interfaceService.getInterfacesByPort(destinationLocation).stream().filter(iface -> interfaceContainsVlan(iface, VlanId.vlanId(etherReply.getVlanID()))).findFirst().orElse(null);
log.trace("Found Host {} by ip {}", destinationHost, destinationAddress);
log.debug("DHCPLEASEQUERYRESP Client interface: {}", (clientInterface != null ? clientInterface : "not resolved"));
}
} else {
clientInterface = getClientInterface(ethernetPacket, dhcpPayload).orElse(null);
}
if (clientInterface == null) {
log.warn("Cannot find the interface for the DHCP {}", dhcpPayload);
return null;
}
VlanId vlanId;
if (clientInterface.vlanTagged().isEmpty()) {
vlanId = clientInterface.vlan();
} else {
// might be multiple vlan in same interface
vlanId = getVlanIdFromRelayAgentOption(dhcpPayload);
}
if (vlanId == null) {
vlanId = VlanId.NONE;
}
etherReply.setVlanID(vlanId.toShort());
etherReply.setSourceMACAddress(clientInterface.mac());
if (!directlyConnected(dhcpPayload) && learnRouteFromLeasequery) {
// if client is indirectly connected, try use next hop mac address
MacAddress macAddress = MacAddress.valueOf(dhcpPayload.getClientHardwareAddress());
HostId hostId = HostId.hostId(macAddress, vlanId);
DhcpRecord record = dhcpRelayStore.getDhcpRecord(hostId).orElse(null);
if (record != null) {
// if next hop can be found, use mac address of next hop
Optional<MacAddress> nextHop = record.nextHopTemp();
if (!nextHop.isPresent()) {
nextHop = record.nextHop();
}
nextHop.ifPresent(etherReply::setDestinationMACAddress);
} else {
// otherwise, discard the packet
log.warn("Can't find record for host id {}, discard packet", hostId);
return null;
}
} else {
etherReply.setDestinationMACAddress(destinationMac);
}
udpPacket.setSourcePort(UDP.DHCP_SERVER_PORT);
if (directlyConnected(dhcpPayload)) {
udpPacket.setDestinationPort(UDP.DHCP_CLIENT_PORT);
} else {
udpPacket.setDestinationPort(UDP.DHCP_SERVER_PORT);
}
udpPacket.setPayload(dhcpPayload);
ipv4Packet.setPayload(udpPacket);
etherReply.setPayload(ipv4Packet);
udpPacket.resetChecksum();
return InternalPacket.internalPacket(etherReply, clientInterface.connectPoint());
}
use of org.onlab.packet.VlanId in project onos by opennetworkinglab.
the class Dhcp4HandlerImpl method handleDhcpAck.
/**
* Send the DHCP ack to the requester host.
* Modify Host or Route store according to the type of DHCP.
*
* @param ethernetPacketAck the packet
* @param dhcpPayload the DHCP data
*/
private void handleDhcpAck(Ethernet ethernetPacketAck, DHCP dhcpPayload) {
Optional<Interface> outInterface = getClientInterface(ethernetPacketAck, dhcpPayload);
if (!outInterface.isPresent()) {
log.warn("Can't find output interface for dhcp: {}", dhcpPayload);
return;
}
Interface outIface = outInterface.get();
ConnectPoint location = outIface.connectPoint();
if (!location.port().hasName()) {
location = translateSwitchPort(location);
}
HostLocation hostLocation = new HostLocation(location, System.currentTimeMillis());
MacAddress macAddress = MacAddress.valueOf(dhcpPayload.getClientHardwareAddress());
VlanId vlanId = getVlanIdFromRelayAgentOption(dhcpPayload);
if (vlanId == null) {
vlanId = outIface.vlan();
}
HostId hostId = HostId.hostId(macAddress, vlanId);
Ip4Address ip = Ip4Address.valueOf(dhcpPayload.getYourIPAddress());
if (directlyConnected(dhcpPayload)) {
// Add to host store if it connect to network directly
Set<IpAddress> ips = Sets.newHashSet(ip);
Host host = hostService.getHost(hostId);
Set<HostLocation> hostLocations = Sets.newHashSet(hostLocation);
if (host != null) {
// Dual homing support:
// if host exists, use old locations and new location
hostLocations.addAll(host.locations());
}
HostDescription desc = new DefaultHostDescription(macAddress, vlanId, hostLocations, ips, false);
// Add IP address when dhcp server give the host new ip address
providerService.hostDetected(hostId, desc, false);
} else {
// Add to route store if it does not connect to network directly
// Get gateway host IP according to host mac address
// TODO: remove relay store here
DhcpRecord record = dhcpRelayStore.getDhcpRecord(hostId).orElse(null);
if (record == null) {
log.warn("Can't find DHCP record of host {}", hostId);
return;
}
MacAddress gwMac = record.nextHop().orElse(null);
if (gwMac == null) {
log.warn("Can't find gateway mac address from record {}", record);
return;
}
HostId gwHostId = HostId.hostId(gwMac, record.vlanId());
Host gwHost = hostService.getHost(gwHostId);
if (gwHost == null) {
log.warn("Can't find gateway host {}", gwHostId);
return;
}
Ip4Address nextHopIp = gwHost.ipAddresses().stream().filter(IpAddress::isIp4).map(IpAddress::getIp4Address).findFirst().orElse(null);
if (nextHopIp == null) {
log.warn("Can't find IP address of gateway {}", gwHost);
return;
}
Route route = new Route(Route.Source.DHCP, ip.toIpPrefix(), nextHopIp);
routeStore.replaceRoute(route);
}
}
Aggregations