@Override public Set<Interface> getInterfacesByVlan(VlanId vlan) { return interfaces.values() .stream() .flatMap(Collection::stream) .filter(intf -> intf.vlan().equals(vlan)) .collect(collectingAndThen(toSet(), ImmutableSet::copyOf)); }
@Override public Set<Host> getHosts(VlanId vlanId) { Set<Host> vlanset = new HashSet<>(); for (Host h : hosts.values()) { if (h.vlan().equals(vlanId)) { vlanset.add(h); } } return vlanset; }
@Override public boolean inUse(VlanId vlanId) { for (Set<Interface> intfs : interfaces.values()) { for (Interface intf : intfs) { if (intf.vlan().equals(vlanId) || intf.vlanNative().equals(vlanId) || intf.vlanUntagged().equals(vlanId) || intf.vlanTagged().contains(vlanId)) { return true; } } } return false; }
/** * Returns untagged VLAN configured on given connect point. * <p> * Only returns the first match if there are multiple untagged VLAN configured * on the connect point. * * @param connectPoint connect point * @return untagged VLAN or null if not configured */ @Override public VlanId getUntaggedVlanId(ConnectPoint connectPoint) { return getInterfacesByPort(connectPoint).stream() .filter(intf -> !intf.vlanUntagged().equals(VlanId.NONE)) .map(Interface::vlanUntagged) .findFirst().orElse(null); }
/** * Returns native VLAN configured on given connect point. * <p> * Only returns the first match if there are multiple native VLAN configured * on the connect point. * * @param connectPoint connect point * @return native VLAN or null if not configured */ @Override public VlanId getNativeVlanId(ConnectPoint connectPoint) { Set<Interface> interfaces = getInterfacesByPort(connectPoint); return interfaces.stream() .filter(intf -> !intf.vlanNative().equals(VlanId.NONE)) .map(Interface::vlanNative) .findFirst() .orElse(null); }
if (!intf.vlan().equals(VlanId.NONE)) { formatStringBuilder.append(VLAN_FORMAT); formatStringBuilder.append(intf.vlan().toString()); if (!intf.vlanUntagged().equals(VlanId.NONE)) { formatStringBuilder.append(VLAN_UNTAGGED); formatStringBuilder.append(intf.vlanUntagged().toString()); if (!intf.vlanNative().equals(VlanId.NONE)) { formatStringBuilder.append(VLAN_NATIVE); formatStringBuilder.append(intf.vlanNative().toString());
interfaceService.getInterfacesByPort(peer.location()).stream() .filter(intf -> interfaces.isEmpty() || interfaces.contains(intf.name())) .filter(intf -> peer.vlan().equals(intf.vlan())) .findFirst(); if (!peerIntf.isPresent()) {
/** * Update the flows comparing previous event and current event. * * @param prevIntf the previous interface event * @param intf the current occured update envent **/ private void updateInterface(Interface prevIntf, Interface intf) { if (!prevIntf.vlan().equals(intf.vlan()) || !prevIntf.mac().equals(intf)) { removeInterface(prevIntf); provisionInterface(intf); } else { List<InterfaceIpAddress> removeIps = prevIntf.ipAddressesList().stream() .filter(pre -> !intf.ipAddressesList().contains(pre)) .collect(Collectors.toList()); List<InterfaceIpAddress> addIps = intf.ipAddressesList().stream() .filter(cur -> !prevIntf.ipAddressesList().contains(cur)) .collect(Collectors.toList()); // removing flows with match parameters present in previous subject modifyBasicInterfaceForwarding(new Interface(prevIntf.name(), prevIntf.connectPoint(), removeIps, prevIntf.mac(), prevIntf.vlan()), false); // adding flows with match parameters present in event subject modifyBasicInterfaceForwarding(new Interface(intf.name(), intf.connectPoint(), addIps, intf.mac(), intf.vlan()), true); } }
@Override public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) { ExtensionSelectorType type = extensionSelector.type(); if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) { VlanId vlanId = ((OfdpaMatchVlanVid) extensionSelector).vlanId(); // Special VLAN 0x0000/0x1FFF required by OFDPA if (vlanId.equals(VlanId.NONE)) { OFVlanVidMatch vid = OFVlanVidMatch.ofRawVid((short) 0x0000); OFVlanVidMatch mask = OFVlanVidMatch.ofRawVid((short) 0x1FFF); return factory.oxms().vlanVidMasked(vid, mask); // Normal case } else if (vlanId.equals(VlanId.ANY)) { return factory.oxms().vlanVidMasked(OFVlanVidMatch.PRESENT, OFVlanVidMatch.PRESENT); } else { return factory.oxms().vlanVid(OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vlanId.toShort()))); } } throw new UnsupportedOperationException( "Unexpected ExtensionSelector: " + extensionSelector.toString()); }
private void peerAdded(HostEvent event) { Host peer = event.subject(); Optional<Interface> peerIntf = interfaceService.getInterfacesByPort(peer.location()).stream() .filter(intf -> interfaces.isEmpty() || interfaces.contains(intf.name())) .filter(intf -> peer.vlan().equals(intf.vlan())) .findFirst(); if (!peerIntf.isPresent()) { log.debug("Adding peer {}/{} on {} but the interface is not configured", peer.mac(), peer.vlan(), peer.location()); return; } // Generate L3 Unicast groups and store it in the map int toRouterL3Unicast = createPeerGroup(peer.mac(), peerIntf.get().mac(), peer.vlan(), peer.location().deviceId(), controlPlaneConnectPoint.port()); int toPeerL3Unicast = createPeerGroup(peerIntf.get().mac(), peer.mac(), peer.vlan(), peer.location().deviceId(), peer.location().port()); peerNextId.put(peer, ImmutableSortedSet.of(toRouterL3Unicast, toPeerL3Unicast)); // From peer to router peerIntf.get().ipAddresses().forEach(routerIp -> { flowObjectiveService.forward(peer.location().deviceId(), createPeerObjBuilder(toRouterL3Unicast, routerIp.ipAddress().toIpPrefix()).add()); }); // From router to peer peer.ipAddresses().forEach(peerIp -> { flowObjectiveService.forward(peer.location().deviceId(), createPeerObjBuilder(toPeerL3Unicast, peerIp.toIpPrefix()).add()); }); }
@Override public void forward(NeighbourMessageContext context, Interface outIntf) { Ethernet packetOut = context.packet().duplicate(); if (outIntf.vlan().equals(VlanId.NONE)) { // The egress interface has no VLAN Id. Send out an untagged // packet packetOut.setVlanID(Ethernet.VLAN_UNTAGGED); } else { // The egress interface has a VLAN set. Send out a tagged packet packetOut.setVlanID(outIntf.vlan().toShort()); } sendTo(packetOut, outIntf.connectPoint()); }
(egressVlan != null && !assignedVlan.equals(egressVlan)) ? egressVlan : assignedVlan; int l2gk = l2InterfaceGroupKey(deviceId, l2InterfaceGroupVlan, portNum.toLong());
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; }
private void createMcastFilteringObjective(boolean install, Interface 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(routerAppId); sendFilteringObjective(install, fob, intf); }
if (!egressIntf.vlan().equals(VlanId.NONE)) { treatment.pushVlan() .setVlanId(egressIntf.vlan())
if (!v.vlanId().equals(VlanId.NONE)) { treatment.popVlan();
private Ethernet buildArpRequest(IpAddress targetIp, IpAddress sourceIp, MacAddress sourceMac, VlanId vlan) { ARP arp = new ARP(); arp.setHardwareType(ARP.HW_TYPE_ETHERNET) .setHardwareAddressLength((byte) Ethernet.DATALAYER_ADDRESS_LENGTH) .setProtocolType(ARP.PROTO_TYPE_IP) .setProtocolAddressLength((byte) IpAddress.INET_BYTE_LENGTH) .setOpCode(ARP.OP_REQUEST); arp.setSenderHardwareAddress(sourceMac.toBytes()) .setSenderProtocolAddress(sourceIp.toOctets()) .setTargetHardwareAddress(ZERO_MAC_ADDRESS) .setTargetProtocolAddress(targetIp.toOctets()); Ethernet ethernet = new Ethernet(); ethernet.setEtherType(Ethernet.TYPE_ARP) .setDestinationMACAddress(MacAddress.BROADCAST) .setSourceMACAddress(sourceMac) .setPayload(arp); if (!vlan.equals(VlanId.NONE)) { ethernet.setVlanID(vlan.toShort()); } ethernet.setPad(true); return ethernet; }
if (!ingressVlanId.equals(VlanId.NONE)) { builder.matchVlanId(VlanId.ANY);
private void createFilteringObjective(boolean install, Interface 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(routerAppId); sendFilteringObjective(install, fob, intf); if (controlPlaneConnectPoint != null) { // then add the same mac/vlan filters for control-plane connect point fob.withKey(Criteria.matchInPort(controlPlaneConnectPoint.port())); sendFilteringObjective(install, fob, intf); } }