Committed by
Gerrit Code Review
Moving vpls app from onos-app-samples to onos repo
Change-Id: I27f8bcac00350b072a6dc33debc8adc589033490
Showing
7 changed files
with
558 additions
and
0 deletions
| ... | @@ -67,6 +67,7 @@ | ... | @@ -67,6 +67,7 @@ |
| 67 | <module>vrouter</module> | 67 | <module>vrouter</module> |
| 68 | <module>openstackrouting</module> | 68 | <module>openstackrouting</module> |
| 69 | <module>cordmcast</module> | 69 | <module>cordmcast</module> |
| 70 | + <module>vpls</module> | ||
| 70 | </modules> | 71 | </modules> |
| 71 | 72 | ||
| 72 | <properties> | 73 | <properties> | ... | ... |
apps/vpls/features.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
| 2 | +<!-- | ||
| 3 | + ~ Copyright 2015 Open Networking Laboratory | ||
| 4 | + ~ | ||
| 5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 6 | + ~ you may not use this file except in compliance with the License. | ||
| 7 | + ~ You may obtain a copy of the License at | ||
| 8 | + ~ | ||
| 9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | + ~ | ||
| 11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
| 12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| 13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 14 | + ~ See the License for the specific language governing permissions and | ||
| 15 | + ~ limitations under the License. | ||
| 16 | + --> | ||
| 17 | +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> | ||
| 18 | + <feature name="${project.artifactId}" version="${project.version}" | ||
| 19 | + description="${project.description}"> | ||
| 20 | + <feature>onos-api</feature> | ||
| 21 | + <bundle>mvn:${project.groupId}/${project.artifactId}/${project.version}</bundle> | ||
| 22 | + <bundle>mvn:${project.groupId}/onos-app-routing-api/${project.version}</bundle> | ||
| 23 | + </feature> | ||
| 24 | +</features> |
apps/vpls/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!-- | ||
| 3 | + ~ Copyright 2014-2016 Open Networking Laboratory | ||
| 4 | + ~ | ||
| 5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 6 | + ~ you may not use this file except in compliance with the License. | ||
| 7 | + ~ You may obtain a copy of the License at | ||
| 8 | + ~ | ||
| 9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | + ~ | ||
| 11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
| 12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| 13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 14 | + ~ See the License for the specific language governing permissions and | ||
| 15 | + ~ limitations under the License. | ||
| 16 | + --> | ||
| 17 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 18 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 19 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
| 20 | + <modelVersion>4.0.0</modelVersion> | ||
| 21 | + | ||
| 22 | + <parent> | ||
| 23 | + <groupId>org.onosproject</groupId> | ||
| 24 | + <artifactId>onos-apps</artifactId> | ||
| 25 | + <version>1.5.0-SNAPSHOT</version> | ||
| 26 | + <relativePath>../pom.xml</relativePath> | ||
| 27 | + </parent> | ||
| 28 | + | ||
| 29 | + <artifactId>onos-app-vpls</artifactId> | ||
| 30 | + <packaging>bundle</packaging> | ||
| 31 | + | ||
| 32 | + <description>Application to create L2 broadcast network using VLAN</description> | ||
| 33 | + | ||
| 34 | + <properties> | ||
| 35 | + <onos.app.name>org.onosproject.vpls</onos.app.name> | ||
| 36 | + </properties> | ||
| 37 | + | ||
| 38 | + <dependencies> | ||
| 39 | + <dependency> | ||
| 40 | + <groupId>org.onosproject</groupId> | ||
| 41 | + <artifactId>onos-incubator-api</artifactId> | ||
| 42 | + </dependency> | ||
| 43 | + <dependency> | ||
| 44 | + <groupId>org.onosproject</groupId> | ||
| 45 | + <artifactId>onos-app-routing-api</artifactId> | ||
| 46 | + <version>${project.version}</version> | ||
| 47 | + </dependency> | ||
| 48 | + <dependency> | ||
| 49 | + <groupId>org.onosproject</groupId> | ||
| 50 | + <artifactId>onos-api</artifactId> | ||
| 51 | + <version>${project.version}</version> | ||
| 52 | + <scope>test</scope> | ||
| 53 | + <classifier>tests</classifier> | ||
| 54 | + </dependency> | ||
| 55 | + <dependency> | ||
| 56 | + <groupId>org.onosproject</groupId> | ||
| 57 | + <artifactId>onos-app-sdnip</artifactId> | ||
| 58 | + <version>${project.version}</version> | ||
| 59 | + </dependency> | ||
| 60 | + <dependency> | ||
| 61 | + <groupId>org.easymock</groupId> | ||
| 62 | + <artifactId>easymock</artifactId> | ||
| 63 | + <scope>test</scope> | ||
| 64 | + </dependency> | ||
| 65 | + <dependency> | ||
| 66 | + <groupId>org.onosproject</groupId> | ||
| 67 | + <artifactId>onlab-junit</artifactId> | ||
| 68 | + <scope>test</scope> | ||
| 69 | + </dependency> | ||
| 70 | + </dependencies> | ||
| 71 | +</project> |
| 1 | +package org.onosproject.vpls; | ||
| 2 | + | ||
| 3 | +import com.google.common.collect.SetMultimap; | ||
| 4 | +import javafx.util.Pair; | ||
| 5 | +import org.onlab.packet.MacAddress; | ||
| 6 | +import org.onlab.packet.VlanId; | ||
| 7 | +import org.onosproject.core.ApplicationId; | ||
| 8 | +import org.onosproject.net.ConnectPoint; | ||
| 9 | +import org.onosproject.net.flow.DefaultTrafficSelector; | ||
| 10 | +import org.onosproject.net.flow.DefaultTrafficTreatment; | ||
| 11 | +import org.onosproject.net.flow.TrafficSelector; | ||
| 12 | +import org.onosproject.net.flow.TrafficTreatment; | ||
| 13 | +import org.onosproject.net.intent.Intent; | ||
| 14 | +import org.onosproject.net.intent.IntentService; | ||
| 15 | +import org.onosproject.net.intent.Key; | ||
| 16 | +import org.onosproject.net.intent.MultiPointToSinglePointIntent; | ||
| 17 | +import org.onosproject.net.intent.SinglePointToMultiPointIntent; | ||
| 18 | +import org.onosproject.routing.IntentSynchronizationService; | ||
| 19 | +import org.slf4j.Logger; | ||
| 20 | +import org.slf4j.LoggerFactory; | ||
| 21 | + | ||
| 22 | +import java.util.ArrayList; | ||
| 23 | +import java.util.Collection; | ||
| 24 | +import java.util.HashSet; | ||
| 25 | +import java.util.List; | ||
| 26 | +import java.util.Set; | ||
| 27 | +import java.util.stream.Collectors; | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | + * Synchronizes intents between the in-memory intent store and the | ||
| 31 | + * IntentService. | ||
| 32 | + */ | ||
| 33 | +public class IntentInstaller { | ||
| 34 | + private static final Logger log = LoggerFactory.getLogger( | ||
| 35 | + IntentInstaller.class); | ||
| 36 | + | ||
| 37 | + private static final int PRIORITY_OFFSET = 1000; | ||
| 38 | + | ||
| 39 | + private static final String PREFIX_BROADCAST = "brc"; | ||
| 40 | + private static final String PREFIX_UNICAST = "uni"; | ||
| 41 | + | ||
| 42 | + private final ApplicationId appId; | ||
| 43 | + private final IntentSynchronizationService intentSynchronizer; | ||
| 44 | + private final IntentService intentService; | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * Class constructor. | ||
| 48 | + * | ||
| 49 | + * @param appId the Application ID | ||
| 50 | + * @param intentService the intent service | ||
| 51 | + * @param intentSynchronizer the intent synchronizer service | ||
| 52 | + */ | ||
| 53 | + public IntentInstaller(ApplicationId appId, IntentService intentService, | ||
| 54 | + IntentSynchronizationService intentSynchronizer) { | ||
| 55 | + this.appId = appId; | ||
| 56 | + this.intentService = intentService; | ||
| 57 | + this.intentSynchronizer = intentSynchronizer; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + /** | ||
| 61 | + * Formats the requests for creating and submit intents. | ||
| 62 | + * Single Points to Multi Point intents are created for all the conigured | ||
| 63 | + * Connect Points. Multi Point to Single Point intents are created for | ||
| 64 | + * Connect Points configured that have hosts attached. | ||
| 65 | + * | ||
| 66 | + * @param confHostPresentCPoint A map of Connect Points with the eventual | ||
| 67 | + * MAC address of the host attached, by VLAN | ||
| 68 | + */ | ||
| 69 | + protected void installIntents(SetMultimap<VlanId, | ||
| 70 | + Pair<ConnectPoint, | ||
| 71 | + MacAddress>> confHostPresentCPoint) { | ||
| 72 | + List<Intent> intents = new ArrayList<>(); | ||
| 73 | + | ||
| 74 | + confHostPresentCPoint.asMap().keySet() | ||
| 75 | + .forEach(vlanId -> { | ||
| 76 | + List<Pair<ConnectPoint, MacAddress>> cPoints = | ||
| 77 | + confHostPresentCPoint.get(vlanId).stream().collect(Collectors.toList()); | ||
| 78 | + | ||
| 79 | + if (cPoints != null && !cPoints.isEmpty()) { | ||
| 80 | + for (int i = 0; i < cPoints.size(); i++) { | ||
| 81 | + ConnectPoint src = cPoints.get(i).getKey(); | ||
| 82 | + Set<ConnectPoint> dsts = new HashSet<>(); | ||
| 83 | + MacAddress mac = cPoints.get(i).getValue(); | ||
| 84 | + for (int j = 0; j < cPoints.size(); j++) { | ||
| 85 | + ConnectPoint dst = cPoints.get(j).getKey(); | ||
| 86 | + if (!dst.equals(src)) { | ||
| 87 | + dsts.add(dst); | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + Key brcKey = buildKey(PREFIX_BROADCAST, src, vlanId); | ||
| 91 | + if (intentService.getIntent(brcKey) == null) { | ||
| 92 | + SinglePointToMultiPointIntent brcIntent = | ||
| 93 | + buildBrcIntent(brcKey, src, dsts, vlanId); | ||
| 94 | + intents.add(brcIntent); | ||
| 95 | + } | ||
| 96 | + if (mac != null && countMacInCPoints(cPoints) > 1) { | ||
| 97 | + Key uniKey = buildKey(PREFIX_UNICAST, src, vlanId); | ||
| 98 | + if (intentService.getIntent(uniKey) == null) { | ||
| 99 | + MultiPointToSinglePointIntent uniIntent = | ||
| 100 | + buildUniIntent(uniKey, | ||
| 101 | + dsts, | ||
| 102 | + src, | ||
| 103 | + vlanId, | ||
| 104 | + mac); | ||
| 105 | + intents.add(uniIntent); | ||
| 106 | + } | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + }); | ||
| 111 | + submitIntents(intents); | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + /** | ||
| 115 | + * Requests to install the intents passed as argument to the Intent Service. | ||
| 116 | + * | ||
| 117 | + * @param intents intents to be submitted | ||
| 118 | + */ | ||
| 119 | + private void submitIntents(Collection<Intent> intents) { | ||
| 120 | + log.debug("Submitting intents to the IntentSynchronizer"); | ||
| 121 | + | ||
| 122 | + for (Intent intent : intents) { | ||
| 123 | + intentSynchronizer.submit(intent); | ||
| 124 | + } | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * Builds a Single Point to Multi Point intent. | ||
| 129 | + * | ||
| 130 | + * @param src The source Connect Point | ||
| 131 | + * @param dsts The destination Connect Points | ||
| 132 | + * @return Single Point to Multi Point intent generated. | ||
| 133 | + */ | ||
| 134 | + private SinglePointToMultiPointIntent buildBrcIntent(Key key, | ||
| 135 | + ConnectPoint src, | ||
| 136 | + Set<ConnectPoint> dsts, | ||
| 137 | + VlanId vlanId) { | ||
| 138 | + log.debug("Building p2mp intent from {}", src); | ||
| 139 | + | ||
| 140 | + SinglePointToMultiPointIntent intent; | ||
| 141 | + | ||
| 142 | + TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); | ||
| 143 | + | ||
| 144 | + TrafficSelector.Builder builder = DefaultTrafficSelector.builder() | ||
| 145 | + .matchEthDst(MacAddress.BROADCAST) | ||
| 146 | + .matchVlanId(vlanId); | ||
| 147 | + | ||
| 148 | + TrafficSelector selector = builder.build(); | ||
| 149 | + | ||
| 150 | + intent = SinglePointToMultiPointIntent.builder() | ||
| 151 | + .appId(appId) | ||
| 152 | + .key(key) | ||
| 153 | + .selector(selector) | ||
| 154 | + .treatment(treatment) | ||
| 155 | + .ingressPoint(src) | ||
| 156 | + .egressPoints(dsts) | ||
| 157 | + .priority(PRIORITY_OFFSET) | ||
| 158 | + .build(); | ||
| 159 | + return intent; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + /** | ||
| 163 | + * Builds a Multi Point to Single Point intent. | ||
| 164 | + * | ||
| 165 | + * @param srcs The source Connect Points | ||
| 166 | + * @param dst The destination Connect Point | ||
| 167 | + * @return Multi Point to Single Point intent generated. | ||
| 168 | + */ | ||
| 169 | + private MultiPointToSinglePointIntent buildUniIntent(Key key, | ||
| 170 | + Set<ConnectPoint> srcs, | ||
| 171 | + ConnectPoint dst, | ||
| 172 | + VlanId vlanId, | ||
| 173 | + MacAddress mac) { | ||
| 174 | + log.debug("Building mp2p intent to {}", dst); | ||
| 175 | + | ||
| 176 | + MultiPointToSinglePointIntent intent; | ||
| 177 | + | ||
| 178 | + TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment(); | ||
| 179 | + | ||
| 180 | + TrafficSelector.Builder builder = DefaultTrafficSelector.builder() | ||
| 181 | + .matchEthDst(mac) | ||
| 182 | + .matchVlanId(vlanId); | ||
| 183 | + | ||
| 184 | + TrafficSelector selector = builder.build(); | ||
| 185 | + | ||
| 186 | + intent = MultiPointToSinglePointIntent.builder() | ||
| 187 | + .appId(appId) | ||
| 188 | + .key(key) | ||
| 189 | + .selector(selector) | ||
| 190 | + .treatment(treatment) | ||
| 191 | + .ingressPoints(srcs) | ||
| 192 | + .egressPoint(dst) | ||
| 193 | + .priority(PRIORITY_OFFSET) | ||
| 194 | + .build(); | ||
| 195 | + return intent; | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + /** | ||
| 199 | + * Builds an intent Key for either for a Single Point to Multi Point or | ||
| 200 | + * Multi Point to Single Point intent, based on a prefix that defines | ||
| 201 | + * the type of intent, the single connection point representing the source | ||
| 202 | + * or the destination and the vlan id representing the network. | ||
| 203 | + * | ||
| 204 | + * @param cPoint the source or destination connect point | ||
| 205 | + * @param vlanId the network vlan id | ||
| 206 | + * @param prefix prefix string | ||
| 207 | + * @return | ||
| 208 | + */ | ||
| 209 | + private Key buildKey(String prefix, ConnectPoint cPoint, VlanId vlanId) { | ||
| 210 | + String keyString = new StringBuilder() | ||
| 211 | + .append(prefix) | ||
| 212 | + .append("-") | ||
| 213 | + .append(cPoint.deviceId()) | ||
| 214 | + .append("-") | ||
| 215 | + .append(cPoint.port()) | ||
| 216 | + .append("-") | ||
| 217 | + .append(vlanId) | ||
| 218 | + .toString(); | ||
| 219 | + | ||
| 220 | + return Key.of(keyString, appId); | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + /** | ||
| 224 | + * Counts the number of mac addresses associated to a specific list of | ||
| 225 | + * ConnectPoint. | ||
| 226 | + * | ||
| 227 | + * @param cPoints List of ConnectPoints, eventually binded to the MAC of the | ||
| 228 | + * host attached | ||
| 229 | + * @return number of mac addresses found. | ||
| 230 | + */ | ||
| 231 | + private int countMacInCPoints(List<Pair<ConnectPoint, MacAddress>> cPoints) { | ||
| 232 | + int macFound = 0; | ||
| 233 | + for (Pair<ConnectPoint, MacAddress> p : cPoints) { | ||
| 234 | + if (p.getValue() != null) { | ||
| 235 | + macFound++; | ||
| 236 | + } | ||
| 237 | + } | ||
| 238 | + return macFound; | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2014-2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.vpls; | ||
| 17 | + | ||
| 18 | +import com.google.common.collect.HashMultimap; | ||
| 19 | +import com.google.common.collect.SetMultimap; | ||
| 20 | +import javafx.util.Pair; | ||
| 21 | +import org.apache.felix.scr.annotations.Activate; | ||
| 22 | +import org.apache.felix.scr.annotations.Component; | ||
| 23 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 24 | +import org.apache.felix.scr.annotations.Reference; | ||
| 25 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 26 | +import org.onlab.packet.MacAddress; | ||
| 27 | +import org.onlab.packet.VlanId; | ||
| 28 | +import org.onosproject.app.ApplicationService; | ||
| 29 | +import org.onosproject.core.ApplicationId; | ||
| 30 | +import org.onosproject.core.CoreService; | ||
| 31 | +import org.onosproject.incubator.net.intf.InterfaceService; | ||
| 32 | +import org.onosproject.net.ConnectPoint; | ||
| 33 | +import org.onosproject.net.Host; | ||
| 34 | +import org.onosproject.net.host.HostEvent; | ||
| 35 | +import org.onosproject.net.host.HostListener; | ||
| 36 | +import org.onosproject.net.host.HostService; | ||
| 37 | +import org.onosproject.net.intent.IntentService; | ||
| 38 | +import org.onosproject.routing.IntentSynchronizationAdminService; | ||
| 39 | +import org.onosproject.routing.IntentSynchronizationService; | ||
| 40 | +import org.slf4j.Logger; | ||
| 41 | + | ||
| 42 | +import java.util.Map; | ||
| 43 | +import java.util.Set; | ||
| 44 | + | ||
| 45 | +import static org.slf4j.LoggerFactory.getLogger; | ||
| 46 | + | ||
| 47 | +/** | ||
| 48 | + * Application to create L2 broadcast overlay networks using VLAN. | ||
| 49 | + */ | ||
| 50 | +@Component(immediate = true) | ||
| 51 | +public class Vpls { | ||
| 52 | + private static final String VPLS_APP = "org.onosproject.vpls"; | ||
| 53 | + private final Logger log = getLogger(getClass()); | ||
| 54 | + | ||
| 55 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 56 | + protected ApplicationService applicationService; | ||
| 57 | + | ||
| 58 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 59 | + protected CoreService coreService; | ||
| 60 | + | ||
| 61 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 62 | + protected HostService hostService; | ||
| 63 | + | ||
| 64 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 65 | + protected IntentService intentService; | ||
| 66 | + | ||
| 67 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 68 | + protected InterfaceService interfaceService; | ||
| 69 | + | ||
| 70 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 71 | + protected IntentSynchronizationService intentSynchronizer; | ||
| 72 | + | ||
| 73 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 74 | + protected IntentSynchronizationAdminService intentSynchronizerAdmin; | ||
| 75 | + | ||
| 76 | + private final HostListener hostListener = new InternalHostListener(); | ||
| 77 | + | ||
| 78 | + private IntentInstaller intentInstaller; | ||
| 79 | + | ||
| 80 | + private ApplicationId appId; | ||
| 81 | + | ||
| 82 | + @Activate | ||
| 83 | + public void activate() { | ||
| 84 | + appId = coreService.registerApplication(VPLS_APP); | ||
| 85 | + | ||
| 86 | + intentInstaller = new IntentInstaller(appId, | ||
| 87 | + intentService, | ||
| 88 | + intentSynchronizer); | ||
| 89 | + | ||
| 90 | + applicationService.registerDeactivateHook(appId, | ||
| 91 | + intentSynchronizerAdmin::removeIntents); | ||
| 92 | + | ||
| 93 | + hostService.addListener(hostListener); | ||
| 94 | + | ||
| 95 | + setupConnectivity(); | ||
| 96 | + | ||
| 97 | + log.info("Started"); | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + @Deactivate | ||
| 101 | + public void deactivate() { | ||
| 102 | + log.info("Stopped"); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + protected void setupConnectivity() { | ||
| 106 | + /* | ||
| 107 | + * Parse Configuration and get Connect Point by VlanId. | ||
| 108 | + */ | ||
| 109 | + SetMultimap<VlanId, ConnectPoint> confCPointsByVlan = getConfigCPoints(); | ||
| 110 | + | ||
| 111 | + /* | ||
| 112 | + * Check that configured Connect Points have hosts attached and | ||
| 113 | + * associate their Mac Address to the Connect Points configured. | ||
| 114 | + */ | ||
| 115 | + SetMultimap<VlanId, Pair<ConnectPoint, MacAddress>> confHostPresentCPoint = | ||
| 116 | + pairAvailableHosts(confCPointsByVlan); | ||
| 117 | + | ||
| 118 | + /* | ||
| 119 | + * Create and submit intents between the Connect Points. | ||
| 120 | + * Intents for broadcast between all the configured Connect Points. | ||
| 121 | + * Intents for unicast between all the configured Connect Points with | ||
| 122 | + * hosts attached. | ||
| 123 | + */ | ||
| 124 | + intentInstaller.installIntents(confHostPresentCPoint); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * Computes the list of configured interfaces with a VLAN Id. | ||
| 129 | + * | ||
| 130 | + * @return the interfaces grouped by vlan id | ||
| 131 | + */ | ||
| 132 | + protected SetMultimap<VlanId, ConnectPoint> getConfigCPoints() { | ||
| 133 | + log.debug("Checking interface configuration"); | ||
| 134 | + | ||
| 135 | + SetMultimap<VlanId, ConnectPoint> confCPointsByVlan = | ||
| 136 | + HashMultimap.create(); | ||
| 137 | + | ||
| 138 | + interfaceService.getInterfaces() | ||
| 139 | + .forEach(intf -> confCPointsByVlan.put(intf.vlan(), | ||
| 140 | + intf.connectPoint())); | ||
| 141 | + return confCPointsByVlan; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + /** | ||
| 145 | + * Checks if for any ConnectPoint configured there's an host present | ||
| 146 | + * and in case it associate them together. | ||
| 147 | + * | ||
| 148 | + * @param confCPointsByVlan the configured ConnectPoints grouped by vlan id | ||
| 149 | + * @return the configured ConnectPoints with eventual hosts associated. | ||
| 150 | + */ | ||
| 151 | + protected SetMultimap<VlanId, Pair<ConnectPoint, MacAddress>> pairAvailableHosts( | ||
| 152 | + SetMultimap<VlanId, ConnectPoint> confCPointsByVlan) { | ||
| 153 | + log.debug("Binding connected hosts mac addresses"); | ||
| 154 | + | ||
| 155 | + SetMultimap<VlanId, Pair<ConnectPoint, MacAddress>> confHostPresentCPoint = | ||
| 156 | + HashMultimap.create(); | ||
| 157 | + | ||
| 158 | + confCPointsByVlan.entries() | ||
| 159 | + .forEach(e -> bindMacAddr(e, confHostPresentCPoint)); | ||
| 160 | + | ||
| 161 | + return confHostPresentCPoint; | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + private void bindMacAddr(Map.Entry<VlanId, ConnectPoint> e, | ||
| 165 | + SetMultimap<VlanId, Pair<ConnectPoint, | ||
| 166 | + MacAddress>> confHostPresentCPoint) { | ||
| 167 | + VlanId vlanId = e.getKey(); | ||
| 168 | + ConnectPoint cp = e.getValue(); | ||
| 169 | + Set<Host> connectedHosts = hostService.getConnectedHosts(cp); | ||
| 170 | + if (!connectedHosts.isEmpty()) { | ||
| 171 | + connectedHosts.forEach(host -> { | ||
| 172 | + if (host.vlan().equals(vlanId)) { | ||
| 173 | + confHostPresentCPoint.put(vlanId, new Pair<>(cp, host.mac())); | ||
| 174 | + } else { | ||
| 175 | + confHostPresentCPoint.put(vlanId, new Pair<>(cp, null)); | ||
| 176 | + } | ||
| 177 | + }); | ||
| 178 | + } else { | ||
| 179 | + confHostPresentCPoint.put(vlanId, new Pair<>(cp, null)); | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + /** | ||
| 184 | + * Listener for host events. | ||
| 185 | + */ | ||
| 186 | + class InternalHostListener implements HostListener { | ||
| 187 | + @Override | ||
| 188 | + public void event(HostEvent event) { | ||
| 189 | + log.debug("Received HostEvent {}", event); | ||
| 190 | + switch (event.type()) { | ||
| 191 | + case HOST_ADDED: | ||
| 192 | + case HOST_UPDATED: | ||
| 193 | + case HOST_REMOVED: | ||
| 194 | + setupConnectivity(); | ||
| 195 | + break; | ||
| 196 | + default: | ||
| 197 | + break; | ||
| 198 | + } | ||
| 199 | + } | ||
| 200 | + } | ||
| 201 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2014 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * Application to create L2 broadcast network using VLAN. | ||
| 19 | + */ | ||
| 20 | +package org.onosproject.vpls; |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment